From 970f4bf2335ffc05d1b8e841da88f4fb14fa08db Mon Sep 17 00:00:00 2001 From: Daniel Loos Date: Wed, 11 Dec 2024 16:47:18 +0100 Subject: [PATCH] Update cwl directory output --- ogc-app-cwl/fairsendd.cwl | 18 ++++++++++++++---- ogc-app-cwl/run.jl | 36 ++++++++++++++++++++++++++++-------- ogc-app-cwl/run.sh | 7 ++----- 3 files changed, 44 insertions(+), 17 deletions(-) mode change 100644 => 100755 ogc-app-cwl/fairsendd.cwl diff --git a/ogc-app-cwl/fairsendd.cwl b/ogc-app-cwl/fairsendd.cwl old mode 100644 new mode 100755 index 76784f3..48ad287 --- a/ogc-app-cwl/fairsendd.cwl +++ b/ogc-app-cwl/fairsendd.cwl @@ -10,6 +10,10 @@ $graph: label: continent doc: Continent ID within Equi7Grid. One of AF, AN, AS, EU, NA, OC, SA type: string + in-dir: + label: in-dir + doc: Path to input directory containing Sentinel-1 Sigma0 tile data + type: Directory tile: label: tile doc: tile ID of the area to be analyzed within Equi7Grid, e.g. E036N075T3 @@ -18,13 +22,14 @@ $graph: outputs: out_cube: doc: Path to output zarr data cube - type: File + type: Directory outputSource: rqa/out_cube steps: rqa: in: continent: continent + in-dir: in-dir tile: tile run: '#cmd-rqa' out: @@ -35,21 +40,26 @@ $graph: requirements: DockerRequirement: dockerPull: danlooo/fairsendd:latest - InlineJavascriptRequirement: {} inputs: continent: type: string + inputBinding: + position: 2 + in-dir: + type: Directory inputBinding: position: 1 tile: type: string inputBinding: - position: 2 + position: 3 outputs: out_cube: - type: stdout + type: Directory + outputBinding: + glob: out.zarr id: cmd-rqa $namespaces: edam: http://edamontology.org/ diff --git a/ogc-app-cwl/run.jl b/ogc-app-cwl/run.jl index 8233792..5281dc1 100755 --- a/ogc-app-cwl/run.jl +++ b/ogc-app-cwl/run.jl @@ -5,7 +5,7 @@ using Glob: glob using YAXArrays: YAXDefaults using ArgParse using RQADeforestation: gdalcube, rqatrend -using DimensionalData: (..) +using DimensionalData using Dates: Date using Distributed: addprocs, @everywhere @@ -35,6 +35,10 @@ function parse_commandline() help = "Path to output zarr dataset" default = "out.zarr" + "in-dir" + help = "Path to input" + required = true + "continent" help = "continent code for the tile to be processed" required = true @@ -54,18 +58,33 @@ function main() orbit = parsed_args["orbit"] thresh = parsed_args["threshold"] - indir = "/eodc/products/eodc.eu/S1_CSAR_IWGRDH/SIG0/" + indir = parsed_args["in-dir"] + readdir(indir) # check if inputdir is available + + if isdir(indir) && isempty(indir) + @error "Input directory $indir must not be empty" + end + outdir = parsed_args["out-dir"] + if isdir(outdir) + @warn "Resume from existing output directory" + else + mkdir(outdir) + @info "Write output to $outdir" + end + YAXDefaults.workdir[] = outdir - println(outdir) continent = parsed_args["continent"] - tilefolder = parsed_args["tile"] - folders = ["V01R01", "V0M2R4", "V1M0R1", "V1M1R1", "V1M1R2"] + tile = parsed_args["tile"] - filenamelist = [glob("$(sub)/*$(continent)*20M/$(tilefolder)/*$(pol)_$(orbit)*.tif", indir) for sub in folders] - allfilenames = collect(Iterators.flatten(filenamelist)) + pattern = "V*R*/EQUI7_$continent*20M/$tile/*" + allfilenames = glob(pattern, indir) |> collect + + if length(allfilenames) == 0 + error("No input files found for given tile $tile") + end relorbits = unique([split(basename(x), "_")[5][2:end] for x in allfilenames]) y = parsed_args["year"] @@ -74,7 +93,8 @@ function main() filenames = allfilenames[findall(contains("$(relorbit)_E"), allfilenames)] cube = gdalcube(filenames) - path = joinpath(outdir, "$(tilefolder)_rqatrend_$(pol)_$(relorbit)_thresh_$(thresh)_year_$(y)") + path = joinpath(outdir, "$(tile)_rqatrend_$(pol)_$(relorbit)_thresh_$(thresh)_year_$(y)") + ispath(path * ".done") && continue tcube = cube[Time=Date(y - 1, 7, 1) .. Date(y + 1, 7, 1)] diff --git a/ogc-app-cwl/run.sh b/ogc-app-cwl/run.sh index 6ce25e5..99feaab 100755 --- a/ogc-app-cwl/run.sh +++ b/ogc-app-cwl/run.sh @@ -1,8 +1,5 @@ #! /usr/bin/env sh docker build . -t danlooo/fairsendd -docker push danlooo/fairsendd - -cwltool fairsendd.cwl#rqa --continent AF --tile E036N075T3 -docker run danlooo/fairsendd AF E036N075T3 -docker run --env=HOME=/tmp/YgEokx --user 1234:1234 danlooo/fairsendd AF E036N075T3 \ No newline at end of file +# docker push danlooo/fairsendd +cwltool fairsendd.cwl#rqa --continent NA --tile E036N075T3 --in-dir ../etc/data/eodc/products/eodc.eu/S1_CSAR_IWGRDH/SIG0/ \ No newline at end of file