Skip to content

Commit 5e0af40

Browse files
Merge pull request #33 from open-AIMS/RME-version-updates
Changes to support RME v1.0.42
2 parents 5ecdbc5 + e2fef86 commit 5e0af40

16 files changed

+663
-60
lines changed

.JuliaFormatter

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
style = "blue"
2+
indent = 4
3+
margin = 92
4+
always_for_in = "nothing"
5+
for_in_replacement = "∈"
6+
whitespace_typedefs = false
7+
import_to_using = true
8+
whitespace_in_kwargs = false
9+
align_struct_field = true
10+
align_assignment = false
11+
align_conditional = true
12+
align_pair_arrow = false
13+
normalize_line_endings = "unix"
14+
align_matrix = true
15+
join_lines_based_on_source = true
16+
indent_submodule = true
17+
surround_whereop_typeparameters = false
18+
yas_style_nesting = true
19+
trailing_comma = false
20+
short_to_long_function_def = false
21+
conditional_to_if = false

Project.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ReefModEngine"
22
uuid = "f4ffb74a-bba7-4ac3-ad08-f8621d7c6d1d"
33
authors = ["Takuya Iwanaga", "Daniel Tan", "Pedro Ribeiro de Almeida"]
4-
version = "1.4.1"
4+
version = "1.5.0"
55

66
[deps]
77
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
@@ -13,12 +13,18 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1313
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1414
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
1515

16+
[extras]
17+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
18+
19+
[targets]
20+
test = ["Test"]
21+
1622
[compat]
1723
CSV = "0.10"
1824
DataFrames = "1"
1925
JSON = "0.21.4"
2026
NetCDF = "0.11.8"
21-
Statistics = "1.10.0"
27+
Statistics = "1"
2228
StatsBase = "0.33, 0.34"
2329
YAXArrays = "0.5.5"
2430
julia = "1"

docs/src/.vitepress/config.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export default defineConfig({
5151
// items: [
5252
// { text: 'Link text', link: '/url_path' },
5353
// ]
54-
}
54+
},
55+
{text: 'Results Store', link: '/result_store'}
5556
],
5657
editLink: {
5758
pattern: 'https://github.com/open-AIMS/ReefModEngine.jl/edit/main/docs/src/:path'

docs/src/getting_started.md

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,29 @@ A copy of the ReefMod Engine is available on request from its current developers
2525

2626
:::
2727

28-
## Pre-initialization setup
29-
30-
Before using RME with ReefModEngine.jl, two changes must be done to the RME data files and
31-
configuration.
32-
33-
1. A copy of the [Canonical Reefs](https://github.com/gbrrestoration/canonical-reefs)
34-
geopackage must be placed inside the `data_files/region` directory with the name
35-
`reefmod_gbr.gpkg`.
36-
37-
This is to aid in aligning the reef ids as used by ReefMod/RME with those used by
38-
AIMS/ADRIA/GBRMPA.
39-
40-
2. Inside the `data_files/config` directory, there is a `config.xml` file.
41-
Make a backup of this file by making a copy of it.
42-
(e.g., naming it `_config.xml` or `original_config.xml`)
43-
44-
Edit the `config.xml` file by removing all of the leading `../` from directory paths.
45-
(a simple "search and replace all" will suffice).
46-
47-
The reason is that when used in MATLAB (the original intended use case for RME), the
48-
assumed initial start location is inside `data_files/config`. The leading `../` moves
49-
changes the directory up one level.
50-
51-
ReefModEngine.jl on the other hand treats `data_files` as the initial library location,
52-
and so there is no need to move up one level.
53-
5428
## Initialization
5529

56-
Before anything can be done, the RME library has to first be initialized.
30+
Use of RME with ReefModEngine.jl requires the RME library to first be initialized.
5731

5832
```julia
59-
# Initialize RME (may take a minute or two)
33+
# Initialize RME
6034
init_rme("path to RME directory")
61-
# [ Info: Loaded RME 1.0.28
35+
# [ Info: Loaded RME 1.0.42
6236
```
6337

38+
::: info
39+
40+
[ADRIA](https://github.com/open-AIMS/ADRIA.jl) is able to run GBR-wide simulations with
41+
[CoraBlox](https://github.com/open-AIMS/CoralBlox.jl), using RME datasets to represent the
42+
GBR. Before doing so, however, a copy of the
43+
[Canonical Reefs](https://github.com/gbrrestoration/canonical-reefs) geopackage must be
44+
placed inside the `data_files/region` directory with the name `reefmod_gbr.gpkg`.
45+
46+
This is to aid in aligning the reef ids as used by ReefMod/RME with those used by
47+
AIMS/ADRIA/GBRMPA.
48+
49+
:::
50+
6451
## Setting RME options
6552

6653
RME is able to run multiple simulations at the same time via multi-threading.
@@ -267,7 +254,7 @@ to run each replicate individually and store results as they complete.
267254

268255
::: warning
269256

270-
ReefModEngine.jl's result store is currently memory-based as well, so the only advantage
257+
ReefModEngine.jl's result store is currently memory-based, so the only advantage
271258
to this approach currently is avoiding storing results when they are no longer necessary.
272259
Efforts will be made to move to a disk-backed store.
273260

src/ReefModEngine.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ macro RME(func)
2525
end
2626

2727
"""
28-
Only for use when RME functions return non-error numeric results.
28+
Only for use when RME functions return numeric results that are not error codes.
2929
3030
# Examples
3131
@@ -38,28 +38,32 @@ macro getRME(func)
3838
end
3939

4040
"""
41-
rme_version_info()::@NamedTuple{major::Int64, minor::Int64, patch::Int64}
41+
rme_version_info()::VersionNumber
4242
43-
Get RME version
43+
Get RME version.
4444
"""
45-
function rme_version_info()::@NamedTuple{major::Int64, minor::Int64, patch::Int64}
45+
function rme_version_info()::VersionNumber
4646
rme_ver = @RME version()::Cstring
47-
rme_ver = parse.(Int64, split(rme_ver, '.'))
48-
return (major=rme_ver[1], minor=rme_ver[2], patch=rme_ver[3])
47+
return VersionNumber(rme_ver)
4948
end
5049

5150
export rme_version_info
5251

5352
include("rme_init.jl")
5453
include("interface.jl")
5554
include("deployment.jl")
55+
include("intervention.jl")
5656
include("io.jl")
5757
include("ResultStore.jl")
58+
include("logging.jl")
5859

5960
# Set up and initialization
6061
export
6162
init_rme, reset_rme, @RME, @getRME, set_option, run_init, RME_PATH, RME
6263

64+
# Parameter interface
65+
export set_iv_param, get_iv_param, get_param, iv_add
66+
6367
# Convenience/utility methods
6468
export
6569
reef_ids, deployment_area, set_outplant_deployment!, set_enrichment_deployment!,
@@ -69,4 +73,11 @@ export
6973
export
7074
ResultStore, concat_results!, save_result_store
7175

76+
# Logging
77+
export
78+
log_set_all_items_enabled, log_set_item_enabled,
79+
log_set_all_reefs_enabled, log_set_reef_enabled,
80+
log_get_reef_data_ref, log_get_reef_data_int,
81+
log_get_run_data_ref, log_get_run_data_int
82+
7283
end

src/ResultStore.jl

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function save_result_store(dir_name::String, result_store::ResultStore)::Nothing
5252
open(scenario_info_path, "w") do f
5353
write(f, si_json_string)
5454
end
55+
5556
return nothing
5657
end
5758

@@ -71,70 +72,70 @@ function create_dataset(start_year::Int, end_year::Int, n_reefs::Int, reps::Int)
7172
zeros(arr_size...);
7273
timesteps=start_year:end_year,
7374
locations=1:n_reefs,
74-
scenarios=1:(2 * reps)
75+
scenarios=1:(2*reps)
7576
)
7677
# Number of juvenile corals
7778
nb_coral_juv = DataCube(
7879
zeros(arr_size...);
7980
timesteps=start_year:end_year,
8081
locations=1:n_reefs,
81-
scenarios=1:(2 * reps)
82+
scenarios=1:(2*reps)
8283
)
8384
# Percentage rubble cover
8485
rubble = DataCube(
8586
zeros(arr_size...);
8687
timesteps=start_year:end_year,
8788
locations=1:n_reefs,
88-
scenarios=1:(2 * reps)
89+
scenarios=1:(2*reps)
8990
)
9091
# Percentage rubble cover
9192
relative_shelter_volume = DataCube(
9293
zeros(arr_size...);
9394
timesteps=start_year:end_year,
9495
locations=1:n_reefs,
95-
scenarios=1:(2 * reps)
96+
scenarios=1:(2*reps)
9697
)
9798
# DHW [degree heating weeks]
9899
dhw = DataCube(
99100
zeros(arr_size...);
100101
timesteps=start_year:end_year,
101102
locations=1:n_reefs,
102-
scenarios=1:(2 * reps)
103+
scenarios=1:(2*reps)
103104
)
104105
# DHW mortality [% of population (to be confirmed)]
105106
dhw_mortality = DataCube(
106107
zeros(arr_size...);
107108
timesteps=start_year:end_year,
108109
locations=1:n_reefs,
109-
scenarios=1:(2 * reps)
110+
scenarios=1:(2*reps)
110111
)
111112
# Cyclone mortality [% of population (to be confirmed)]
112113
cyc_mortality = DataCube(
113114
zeros(arr_size...);
114115
timesteps=start_year:end_year,
115116
locations=1:n_reefs,
116-
scenarios=1:(2 * reps)
117+
scenarios=1:(2*reps)
117118
)
118119
# Cyclone categories [0 to 5]
119120
cyc_cat = DataCube(
120121
zeros(arr_size...);
121122
timesteps=start_year:end_year,
122123
locations=1:n_reefs,
123-
scenarios=1:(2 * reps)
124+
scenarios=1:(2*reps)
124125
)
125126
# Crown-of-Thorn Starfish population [per ha]
126127
cots = DataCube(
127128
zeros(arr_size...);
128129
timesteps=start_year:end_year,
129130
locations=1:n_reefs,
130-
scenarios=1:(2 * reps)
131+
scenarios=1:(2*reps)
131132
)
132133
# Mortality caused by Crown-of-Thorn Starfish [% of population (to be confirmed)]
133134
cots_mortality = DataCube(
134135
zeros(arr_size...);
135136
timesteps=start_year:end_year,
136137
locations=1:n_reefs,
137-
scenarios=1:(2 * reps)
138+
scenarios=1:(2*reps)
138139
)
139140
# Total Species cover [% of total reef area]
140141
n_species = 6
@@ -144,7 +145,7 @@ function create_dataset(start_year::Int, end_year::Int, n_reefs::Int, reps::Int)
144145
timesteps=start_year:end_year,
145146
locations=1:n_reefs,
146147
taxa=1:n_species,
147-
scenarios=1:(2 * reps)
148+
scenarios=1:(2*reps)
148149
)
149150

150151
return Dataset(;
@@ -223,7 +224,7 @@ function preallocate_concat!(rs, start_year, end_year, reps::Int64)::Nothing
223224
axlist = (
224225
Dim{:timesteps}(start_year:end_year),
225226
Dim{:locations}(1:(rs.n_reefs)),
226-
Dim{:scenarios}((prev_reps + 1):new_n_reps)
227+
Dim{:scenarios}((prev_reps+1):new_n_reps)
227228
)
228229

229230
# Concatenate total_taxa_cover cube separately.
@@ -252,7 +253,7 @@ function preallocate_concat!(rs, start_year, end_year, reps::Int64)::Nothing
252253
Dim{:timesteps}(start_year:end_year),
253254
Dim{:locations}(1:(rs.n_reefs)),
254255
Dim{:taxa}(1:n_species),
255-
Dim{:scenarios}((prev_reps + 1):new_n_reps)
256+
Dim{:scenarios}((prev_reps+1):new_n_reps)
256257
)
257258
rs.results.cubes[:total_taxa_cover] = cat(
258259
rs.results.cubes[:total_taxa_cover],
@@ -277,8 +278,8 @@ function n_corals_calculation(
277278
return round(
278279
Int,
279280
(
280-
sum((count_per_year .* target_reef_area_km² .* (1 / m2_TO_km2)))
281-
)
281+
sum((count_per_year .* target_reef_area_km² .* (1 / m2_TO_km2)))
282+
)
282283
)
283284
end
284285

@@ -341,7 +342,7 @@ function append_scenarios!(rs::ResultStore, reps::Int)::Nothing
341342
@getRME reefSetGetAsVector(
342343
reefset_name::Cstring, iv_reef_ids_idx::Ptr{Cint}, length(iv_reef_ids_idx)::Cint
343344
)::Cint
344-
iv_reef_ids = reef_ids()[iv_reef_ids_idx .!== 0]
345+
iv_reef_ids = reef_ids()[iv_reef_ids_idx.!==0]
345346
scenario_dict[reefset_name] = iv_reef_ids
346347

347348
# Get reef areas for intervention reefset

0 commit comments

Comments
 (0)