Skip to content

Commit

Permalink
weightLayers script
Browse files Browse the repository at this point in the history
  • Loading branch information
gottacatchenall committed Oct 6, 2023
1 parent 6a271ac commit 1292331
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
43 changes: 43 additions & 0 deletions scripts/Block3/weightLayers.jl
Original file line number Diff line number Diff line change
@@ -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()
33 changes: 33 additions & 0 deletions scripts/Block3/weightLayers.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1292331

Please sign in to comment.