From 1292331f8a62b0a72c9021dc4fb939a4ad9a3586 Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 6 Oct 2023 11:32:26 -0400 Subject: [PATCH] weightLayers script --- scripts/Block3/weightLayers.jl | 43 +++++++++++++++++++++++++++++++++ scripts/Block3/weightLayers.yml | 33 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 scripts/Block3/weightLayers.jl create mode 100644 scripts/Block3/weightLayers.yml diff --git a/scripts/Block3/weightLayers.jl b/scripts/Block3/weightLayers.jl new file mode 100644 index 00000000..3f01da7e --- /dev/null +++ b/scripts/Block3/weightLayers.jl @@ -0,0 +1,43 @@ +using JSON +using CSV +using DataFrames +using SpeciesDistributionToolkit + +function read_inputs_dict(runtime_dir) + filepath = joinpath(runtime_dir, "input.json") + output_dir = joinpath(runtime_dir, "data/") + isdir(output_dir) || mkdir(output_dir) + return JSON.parsefile(filepath) +end + +function write_outputs(runtime_dir, priority) + outpath = joinpath(runtime_dir, "priority.tif") + SpeciesDistributionToolkit._write_geotiff(outpath, priority; compress="COG") + + output_json_path = joinpath(runtime_dir, "output.json") + open(output_json_path, "w") do f + write(f, JSON.json(Dict(:priority_map=>outpath))) + end +end + +function main() + runtime_dir = ARGS[1] + inputs = read_inputs_dict(runtime_dir) + + β = inputs["weights"] + + uncert_path = inputs["uncertainty"] + uniqueness_path = inputs["climate_uniqueness"] + velocity_path = inputs["climate_velocity"] + access_path = inputs["accessability"] + + layer_paths = [uncert_path, uniqueness_path, velocity_path, access_path] + + layers = [rescale(SimpleSDMPredictor(joinpath(runtime_dir, layer_path)), (0,1)) for layer_path in layer_paths] + + priority = sum([β[i] .* layers[i].grid for i in eachindex(β)]) + + write_outputs(runtime_dir, priority) +end + +main() \ No newline at end of file diff --git a/scripts/Block3/weightLayers.yml b/scripts/Block3/weightLayers.yml new file mode 100644 index 00000000..c6cbad19 --- /dev/null +++ b/scripts/Block3/weightLayers.yml @@ -0,0 +1,33 @@ +script: weightLayers.jl +name: Weight Layers +description: "This script takes in multiple layers and computes a priority map based on a weighted average of those layers" +author: + - name: Michael D. Catchen + identifier: https://orcid.org/0000-0002-6506-6487 +inputs: + uncertainty: + label: uncertainty + description: uncertainty in the inference of some value across space + example: null + climate_uniqueness: + label: climate uniqueness + description: foobar + example: null + climate_velocity: + label: climate uniqueness + description: foobar + example: null + accessibility: + label: accessibility + descrpition: foobar + example: null + weights: + label: weights + description: weight vector that sums to one. Weights correnspond to layers in this order, [uncertainty, uniqueness, velocity, accessability] + example: [0.3, 0.2, 0.4, 0.1] +outputs: + priority_map: + label: priority_map + description: Sampling priority map. + type: image/tiff;application=geotiff +