Skip to content

C~Scape Result Interface #919

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

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d760ff3
add result interface
DanTanAtAims Aug 2, 2024
65760d0
update viz scenario input type
DanTanAtAims Aug 2, 2024
5887a0f
add generic variable loading to cscape interface to allow for more fl…
DanTanAtAims Aug 5, 2024
c0eaa26
restore CScape interface documentation
DanTanAtAims Aug 14, 2024
9c9ee88
add documentation for load_variable!
DanTanAtAims Aug 14, 2024
c4d5920
fix documentation error for CScape interface
DanTanAtAims Aug 15, 2024
efa035a
Small adjustment to string creation
ConnectedSystems Aug 27, 2024
e075289
Minor adjustment to docstrings for clarity
ConnectedSystems Aug 27, 2024
b0aad2c
Micro-performance change: maintain same types for stability
ConnectedSystems Aug 27, 2024
3677ce6
Modified loading strategy
ConnectedSystems Aug 27, 2024
feb8bca
Use of specific datatypes
ConnectedSystems Aug 27, 2024
6517665
Clarify comments
ConnectedSystems Aug 27, 2024
3c51ae9
Set up use of a dummy selector
ConnectedSystems Aug 27, 2024
3c0abb3
Use dummy selector to read data in as needed
ConnectedSystems Aug 27, 2024
78673cd
Avoid additional calculations if there is no data (all zeros)
ConnectedSystems Aug 27, 2024
3c2f91c
Provide type info
ConnectedSystems Aug 27, 2024
d8fb66b
Format file
ConnectedSystems Aug 27, 2024
77e91bd
Standardize/format docs
ConnectedSystems Aug 28, 2024
ec7ee39
Indicate data loading progress
ConnectedSystems Aug 28, 2024
eba0407
correct calculation of available coral cover
DanTanAtAims Sep 16, 2024
e53da19
update cscape interface to use loc instead of site
DanTanAtAims Sep 16, 2024
f1e001d
remove manual id correction with update datapackage
DanTanAtAims Sep 16, 2024
0653b26
run julia formatter
DanTanAtAims Sep 16, 2024
eec2217
correct calculation of relative cover
DanTanAtAims Sep 17, 2024
3858b0b
format file
DanTanAtAims Sep 17, 2024
bcc251e
resolve misplaced habitable area
DanTanAtAims Sep 17, 2024
876fa1d
use NetCDF.jl for raw set
DanTanAtAims Sep 17, 2024
7b96248
migrate coral size diameter extraction to use NetCDF interface
DanTanAtAims Sep 18, 2024
24ff4ac
migrate relative cover loading to use netcdf api
DanTanAtAims Sep 18, 2024
2781d8f
migrate load variable to use NetCDF.jl api
DanTanAtAims Sep 18, 2024
c61ccfa
format interface
DanTanAtAims Sep 18, 2024
2ebbb90
rename dimension from sites to locations
DanTanAtAims Sep 23, 2024
95a94db
format interface
DanTanAtAims Sep 23, 2024
74cf0c6
throw more informative error message
DanTanAtAims Sep 23, 2024
f64ac64
add scenario id to scenario dataframe
DanTanAtAims Sep 23, 2024
8e1a6a2
use fill not repeat
DanTanAtAims Sep 24, 2024
3d1e8f5
remove unused tuple in fill call
DanTanAtAims Sep 25, 2024
3ca4734
add option to remove cscape result interface loading progress bar
DanTanAtAims Jan 17, 2025
b2eadd4
add constant to model spec
DanTanAtAims Feb 3, 2025
a3e5cc5
add metrics to cscape interface
DanTanAtAims Feb 5, 2025
96066e7
integrate cscape interface with existing metric code
DanTanAtAims Feb 10, 2025
27aa3f3
use NetCDF library to read variable
DanTanAtAims Feb 10, 2025
fbb937b
remove manual scenario type calculation for cscape and use ADRIA
DanTanAtAims Feb 10, 2025
fe0f660
remove manual plotting dispatch
DanTanAtAims Feb 10, 2025
4671989
format files
DanTanAtAims Feb 10, 2025
65f6bd2
add coral evenness metric
DanTanAtAims Feb 12, 2025
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
60 changes: 58 additions & 2 deletions docs/src/usage/results.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,66 @@ data_dir
results.nc
scenarios.csv
```
In order to reduce the duplication of geospatial and conectivity data, the data directory
and results directory can be supplied seperately to avoid having copies for each resuilt set

In order to reduce the duplication of geospatial and connectivity data, the data directory
and results directory can be supplied separately to avoid having copies for each result set
analysed.

```julia
rs = ADRIA.load_domain(RMEResultSet, "<path to data dir>", "<path to results dir>")
```

## Loading C~scape Results

Results from C~scape can be loaded with the `load_results` function.

```julia
# Assumes NetCDFs are contained in result subdirectory (see example directory tree below)
rs = ADRIA.load_results(CScapeResultSet, "<path to data dir>")

# Retrieves NetCDFs from separate directory
rs = ADRIA.load_results(CScapeResultSet, "<path to data dir>", "<path to result directory>")

# Manually pass in a list of files to load as results
rs = ADRIA.load_results(CScapeResultSet, "<path to data dir>", ["netcdf_fn1", "netcdf_fn2", ...])
```

The expected directory structure is:

```bash
data_dir
│ ScenarioID.csv
├───connectivity
│ connectivity.csv
├───site_data
│ geospatial_data.gpkg
├───initial_cover
│ initial_cover.csv
└───results (optional)
NetCDF_Scn_140001.nc
NetCDF_Scn_140002.nc
NetCDF_Scn_140003.nc
...
```

### Loading Variables using the interface

All variables except from relative cover are not loaded automatically. The outcomes
dictionary contained in the result structure is where all outputs are stored.

```julia
julia> rs.outcomes[:relative_cover]
```

To analyse a variable contained in the NetCDFs, use the function

```julia
julia> var = ADRIA.load_variable!(rs, :var_name)

# The variable will also be stored in the outcomes dictionary.
julia> rs.outcomes[:var_name]
```
2 changes: 2 additions & 0 deletions src/ADRIA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ include("io/ResultSet.jl")
include("spatial/spatial.jl")
include("io/result_io.jl")
include("io/rme_result_io.jl")
include("io/cscape_result_io.jl")
include("io/result_post_processing.jl")
include("io/sampling.jl")
include("metrics/metrics.jl")
Expand Down Expand Up @@ -98,6 +99,7 @@ export RMEDomain
export ReefModDomain

export RMEResultSet
export CScapeResultSet
# metric helper methods
# export dims, ndims

Expand Down
32 changes: 25 additions & 7 deletions src/analysis/scenario.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,41 @@ end

function counterfactual(scenarios::DataFrame)::BitVector
no_seed = _no_seed(scenarios)
no_fog = scenarios.fogging .== 0
no_SRM = scenarios.SRM .== 0
has_fog_col = "fogging" in names(scenarios)
no_fog = has_fog_col ? scenarios.fogging .== 0 : fill(true, size(scenarios, 1))
has_SRM_col = "SRM" in names(scenarios)
no_SRM = has_SRM_col ? scenarios.SRM .== 0 : fill(true, size(scenarios, 1))

return no_seed .& no_fog .& no_SRM
end

function unguided(scenarios::DataFrame)::BitVector
has_guided_col = "guided" in names(scenarios)
# If the results set does not have a guided type column default to unguided
is_unguided = has_guided_col ? scenarios.guided .== 0 : fill(true, size(scenarios, 1))

has_fog_col = "fogging" in names(scenarios)
has_fog = has_fog_col ? scenarios.fogging .> 0 : fill(true, size(scenarios, 1))

has_SRM_col = "SRM" in names(scenarios)
has_SRM = has_SRM_col ? scenarios.SRM .> 0 : fill(true, size(scenarios, 1))

has_seed = .!_no_seed(scenarios)
has_shade = (scenarios.fogging .> 0) .| (scenarios.SRM .> 0)
return (scenarios.guided .== 0) .& (has_seed .| has_shade)
has_shade = (has_fog) .| (has_SRM)

return is_unguided .& (has_seed .| has_shade)
end

function guided(scenarios::DataFrame)::BitVector
return .!(counterfactual(scenarios) .| unguided(scenarios))
end

function _no_seed(scenarios::DataFrame)::BitVector
return (scenarios.N_seed_TA .== 0) .&
(scenarios.N_seed_CA .== 0) .&
(scenarios.N_seed_SM .== 0)
seed_cols::Vector{String} = filter(
x -> contains(x, "N_seed_"), names(scenarios)
)

return BitVector(
all(collect(scen_row) .== 0) for scen_row in eachrow(scenarios[:, seed_cols])
)
end
2 changes: 1 addition & 1 deletion src/ecosystem/corals/Corals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function coral_spec()::NamedTuple
params.coral_id = String[join(x, "_") for x in zip(tn, params.taxa_id, params.class_id)]

# Ecological parameters
# To be more consistent with parameters in ReefMod, C~Scape and RRAP
# To be more consistent with parameters in ReefMod, C~scape and RRAP
# interventions, we express coral abundance as colony numbers in different
# size classes and growth rates as linear extension (in cm per year).
colony_area_mean_cm², mean_colony_diameter_m = colony_areas()
Expand Down
Loading