Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt ogc app cwl 2 #16

Merged
merged 22 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RQADeforestation.jl
12 changes: 7 additions & 5 deletions ogc-app-cwl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM julia:1.11.2-bookworm
WORKDIR /work

ENV JULIA_PROJECT=/work
ENV JULIA_NUM_THREADS=auto

COPY Project.toml .
COPY Manifest.toml .
RUN julia -e 'using Pkg; Pkg.instantiate()'
ENV JULIA_DEPOT_PATH=/.julia
RUN julia -e 'using Pkg; Pkg.activate("/.julia/environments/v1.11"); Pkg.instantiate(); Pkg.status()'
COPY Project.toml /.julia/environments/v1.11/
COPY Manifest.toml /.julia/environments/v1.11/
RUN julia -e 'using Pkg; Pkg.activate("/.julia/environments/v1.11"); Pkg.instantiate(); Pkg.status()'
ENV JULIA_DEPOT_PATH=~/.julia:/.julia

ADD run.jl ./
ENTRYPOINT ["/work/run.jl"]
ENTRYPOINT ["/work/run.jl"]
32 changes: 16 additions & 16 deletions ogc-app-cwl/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.11.2"
manifest_format = "2.0"
project_hash = "fcba262f40e7f619c7dd24e2647b2795d595bca9"
project_hash = "c5fb35d827c7d4456361ae4b4a9d46d5b535215a"

[[deps.ADTypes]]
git-tree-sha1 = "72af59f5b8f09faee36b4ec48e014a79210f2f4f"
Expand Down Expand Up @@ -975,9 +975,9 @@ version = "1.14.3+3"

[[deps.HTTP]]
deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "PrecompileTools", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"]
git-tree-sha1 = "6c22309e9a356ac1ebc5c8a217045f9bae6f8d9a"
git-tree-sha1 = "627fcacdb7cb51dc67f557e1598cdffe4dda386d"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "1.10.13"
version = "1.10.14"

[[deps.HarfBuzz_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll"]
Expand Down Expand Up @@ -1146,9 +1146,9 @@ weakdeps = ["Dates", "Test"]
InverseFunctionsTestExt = "Test"

[[deps.InvertedIndices]]
git-tree-sha1 = "0dc7b50b8d436461be01300fd8cd45aa0274b038"
git-tree-sha1 = "6da3c4316095de0f5ee2ebd875df8721e7e0bdbe"
uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
version = "1.3.0"
version = "1.3.1"

[[deps.Ipopt]]
deps = ["Ipopt_jll", "LinearAlgebra", "MathOptInterface", "OpenBLAS32_jll", "PrecompileTools"]
Expand Down Expand Up @@ -1427,9 +1427,9 @@ version = "2.16.0+0"

[[deps.LogExpFunctions]]
deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "a2d09619db4e765091ee5c6ffe8872849de0feea"
git-tree-sha1 = "13ca9e2586b89836fd20cccf56e57e2b9ae7f38f"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.28"
version = "0.3.29"

[deps.LogExpFunctions.extensions]
LogExpFunctionsChainRulesCoreExt = "ChainRulesCore"
Expand Down Expand Up @@ -1566,10 +1566,10 @@ version = "0.9.20"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.ManifoldsBase]]
deps = ["LinearAlgebra", "Markdown", "Printf", "Random", "Requires"]
git-tree-sha1 = "2bddabebe8f7ec16cdd693ce8615fb5d3625af87"
deps = ["LinearAlgebra", "Markdown", "Printf", "Random"]
git-tree-sha1 = "57df0b7daa74bf82d3367702e133d936c28882ff"
uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
version = "0.15.22"
version = "0.15.23"

[deps.ManifoldsBase.extensions]
ManifoldsBasePlotsExt = "Plots"
Expand Down Expand Up @@ -1820,9 +1820,9 @@ version = "3.2.4+0"

[[deps.OpenJpeg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libtiff_jll", "LittleCMS_jll", "libpng_jll"]
git-tree-sha1 = "f4cb457ffac5f5cf695699f82c537073958a6a6c"
git-tree-sha1 = "0a41c2d8e204a3ad713242139628e01a29556967"
uuid = "643b3616-a352-519d-856d-80112ee9badc"
version = "2.5.2+0"
version = "2.5.3+0"

[[deps.OpenLibm_jll]]
deps = ["Artifacts", "Libdl"]
Expand Down Expand Up @@ -2116,8 +2116,8 @@ version = "1.11.0"
[[deps.RQADeforestation]]
deps = ["ArchGDAL", "ArgParse", "CairoMakie", "ConstructionBase", "Dates", "DimensionalData", "DiskArrayEngine", "DiskArrayTools", "DiskArrays", "Distances", "Distributed", "Distributions", "Extents", "FillArrays", "GDAL", "GeoFormatTypes", "Glob", "KML", "LoggingExtras", "Missings", "NetCDF", "Proj", "Rasters", "RecurrenceAnalysis", "Statistics", "StatsBase", "TimeseriesSurrogates", "UnicodePlots", "YAXArrayBase", "YAXArrays", "Zarr"]
git-tree-sha1 = "797418ea1c3f97e67364d6bd61d2f48cb6b81c39"
repo-rev = "main"
repo-url = "https://github.com/EarthyScience/RQADeforestation.jl#a611912"
repo-rev = "a611912"
repo-url = "https://github.com/EarthyScience/RQADeforestation.jl"
uuid = "3f1d9318-18cc-4ffd-9937-04025ce33b74"
version = "1.0.0-DEV"

Expand Down Expand Up @@ -2415,9 +2415,9 @@ version = "1.11.0"

[[deps.SpecialFunctions]]
deps = ["IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
git-tree-sha1 = "2f5d4697f21388cbe1ff299430dd169ef97d7e14"
git-tree-sha1 = "64cca0c26b4f31ba18f13f6c12af7c85f478cfde"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "2.4.0"
version = "2.5.0"
weakdeps = ["ChainRulesCore"]

[deps.SpecialFunctions.extensions]
Expand Down
4 changes: 4 additions & 0 deletions ogc-app-cwl/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
RQADeforestation = "3f1d9318-18cc-4ffd-9937-04025ce33b74"
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
74 changes: 0 additions & 74 deletions ogc-app-cwl/example.cwl

This file was deleted.

79 changes: 79 additions & 0 deletions ogc-app-cwl/fairsendd.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env cwl-runner

$graph:
- class: Workflow
label: rqa
doc: FAIRSenDD Recurrence Analysis for Sentinel-1 based Deforestation Detection

inputs:
continent:
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
type: string

outputs:
out_cube:
doc: Path to output zarr data cube
type: Directory
outputSource: rqa/out_cube

steps:
rqa:
in:
continent: continent
in-dir: in-dir
tile: tile
run: '#cmd-rqa'
out:
- out_cube
id: rqa
- class: CommandLineTool

requirements:
DockerRequirement:
dockerPull: danlooo/fairsendd:latest

inputs:
continent:
type: string
inputBinding:
position: 2
in-dir:
type: Directory
inputBinding:
position: 1
tile:
type: string
inputBinding:
position: 3

outputs:
out_cube:
type: Directory
outputBinding:
glob: out.zarr
id: cmd-rqa
$namespaces:
edam: http://edamontology.org/
s: https://schema.org/
$schemas:
- https://schema.org/version/latest/schemaorg-current-https.rdf
- http://edamontology.org/EDAM_1.18.owl
cwlVersion: v1.2
s:author:
- class: s:Person
s:email: [email protected]
s:identifier: https://orcid.org/0000-0002-4024-4443
s:name: Daniel Loos
s:citation: https://dx.doi.org/10.6084/m9.figshare.3115156.v2
s:codeRepository: https://github.com/EarthyScience/FAIRSenDD/
s:dateCreated: '2024-10-28'
s:license: https://spdx.org/licenses/Apache-2.0
61 changes: 42 additions & 19 deletions ogc-app-cwl/run.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#!/usr/bin/env -S julia --color=yes --startup-file=no --project=. --threads=auto
#!/usr/bin/env -S julia --color=yes --startup-file=no --threads=auto

using YAXArrays: YAXDefaults
using Pkg
using Glob: glob
using YAXArrays: YAXDefaults
using ArgParse
using RQADeforestation: gdalcube, rqatrend
using DimensionalData: (..)
using DimensionalData
using Dates: Date
using Distributed: addprocs, @everywhere

YAXDefaults.workdir[] = "/mnt/felix1/worldmap/data"
exeflags = `--threads=10 --heap-size-hint=8G`
#addprocs(4;exeflags)
#@everywhere using YAXArrays, RQADeforestation


function parse_commandline()
s = ArgParseSettings()

Expand All @@ -36,6 +31,14 @@ function parse_commandline()
help = "One of: Orbit number, 'A' for ascending, 'D' for descending, '*' for all orbits"
default = "*"

"--out-dir", "-d"
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
Expand All @@ -50,32 +53,52 @@ end

function main()
parsed_args = parse_commandline()
@info parsed_args

pol = parsed_args["polarisation"]
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

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"]

for relorbit in relorbits
filenames = allfilenames[findall(contains("$(relorbit)_E"), allfilenames)]
@time cube = gdalcube(filenames)
path = joinpath(YAXDefaults.workdir[], "$(tilefolder)_rqatrend_$(pol)_$(relorbit)_thresh_$(thresh)_year_$(y)")

cube = gdalcube(filenames)
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)]

@time rqatrend(tcube; thresh, outpath=path * ".zarr", overwrite=true)
touch(path * ".done")
rqatrend(tcube; thresh, outpath=path * ".zarr", overwrite=true)
end
end

Expand Down
6 changes: 3 additions & 3 deletions ogc-app-cwl/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env sh

docker build . -t danlooo/cwl-example
docker push danlooo/cwl-example
cwltool example.cwl#add-numbers -a 1.2 -b 3.4
docker build . -t danlooo/fairsendd
# docker push danlooo/fairsendd
cwltool fairsendd.cwl#rqa --continent NA --tile E036N075T3 --in-dir ../etc/data/eodc/products/eodc.eu/S1_CSAR_IWGRDH/SIG0/