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

Fix error when setting outplanting levels due to latest RME expecting density as vector #29

Merged
merged 12 commits into from
Dec 12, 2024

Conversation

Rosejoycrocker
Copy link
Collaborator

Resolves #28

@Rosejoycrocker Rosejoycrocker added the bug Something isn't working label Dec 6, 2024
Comment on lines 6 to 9
function version_check()::Vector{Int64}
rme_ver = @RME version()::Cstring
return parse.(Int64, split(rme_ver, '.'))
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an issue with the function name in that it doesn't perform a "check".

To me, it should be rme_version() or similar as it simply returns the version number (albeit separated).
Simply version_check can be confusing. It's unclear at first glance: What does it mean? Version of the Julia package?

I'm also hesitant to accept it returning a vector of integers. Version numbers should be treated as IDs firstly.

I also dislike how this is being used. Remember that if you're hardcoding index values, then it's usually a smell telling you there's a better way.

In this case, I would prefer:

  1. a named tuple be returned: (major=1, minor=0, patch=28) (following SemVer)
  2. the function name be changed to rme_version_info()

Comment on lines 183 to 184
Set outplanting deployments across a range of years, automatically determining the
coral deployment density to maintain the set grid size.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indent for main text in docstrings

req_area = area_needed(max_n_corals, density)

# Divide by half (i.e., `* 0.5`) as RME simulates two deployments per year
mod_density = (n_corals * 0.5) / (req_area / m2_TO_km2)
deployment_area_pct = min((req_area / sum(target_areas)) * 100.0, 100.0)
mod_density = (n_corals * 0.5) ./ (req_area ./ m2_TO_km2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line a duplication of area_needed()?

mod_density = (n_corals * 0.5) / (req_area / m2_TO_km2)
deployment_area_pct = min((req_area / sum(target_areas)) * 100.0, 100.0)
mod_density = (n_corals * 0.5) ./ (req_area ./ m2_TO_km2)
deployment_area_pct = min((sum(req_area) / sum(target_areas)) * 100.0, 100.0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calculate sum(req_area) once beforehand and replace the repeated sum() here and below please.

deployment_area_pct = min((req_area / sum(target_areas)) * 100.0, 100.0)

# In RME versions higher than 1.0.28 density needs to be a vector with each element representing density per species
version_vec = version_check()
density = (version_vec[3] <= 28) && (version_vec[1] == 1) ? density : fill(density, 6)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring the hardcoded indexing here, think about what would happen if the RME version advances to v1.2.28

@@ -130,15 +156,30 @@ function set_outplant_deployment!(
last_year::Int64,
year_step::Int64,
area_km2::Vector{Float64},
density::Float64
density::Vector{Float64}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this break backward compatibility?

Comment on lines 214 to 216
# Add 3 DHW enhancement to outplanted corals
set_option("restoration_dhw_tolerance_outplants", 3)

Copy link
Collaborator

@ConnectedSystems ConnectedSystems Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify why the outplanting is removed in the example?

The commit message for this change just says "fix docs"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restoration_dhw_tolerance_outplants was removed in version 1.0.31

Copy link
Collaborator

@ConnectedSystems ConnectedSystems Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we dropping backwards compatibility?

Check update to include major, minor and patch
Define sum(area_req) as variable to avoid multiple summations

Fix docs
@Rosejoycrocker
Copy link
Collaborator Author

I believe I've addressed your comments @ConnectedSystems

Comment on lines +7 to +8
rme_ver = @RME version()::Cstring
rme_ver = parse.(Int64, split(rme_ver, '.'))
Copy link
Collaborator

@ConnectedSystems ConnectedSystems Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change required here, just noting this is type unstable (going from string to vector of ints) so might need an adjustment later.

Comment on lines 20 to 21
- `density` : Stocking density per m². In RME versions higher than 1.0.28 density needs to be a vector
with each element representing density per species
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `density` : Stocking density per m². In RME versions higher than 1.0.28 density needs to be a vector
with each element representing density per species
- `density` : Stocking density per m². In RME versions higher than v1.0.28, density is expected to be a vector
with each element representing the density per functional group

@RME ivSetOutplantCountPerM2(name::Cstring, mod_density::Cdouble)::Cint

rme_version = rme_version_info()
if !((rme_version.patch <= 28) && (rme_version.minor == 0) && (rme_version.major == 1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reorder to be in logical order please: major, minor, patch.

@Rosejoycrocker
Copy link
Collaborator Author

I've addressed your comments @ConnectedSystems, let me know if there are others

@ConnectedSystems
Copy link
Collaborator

ConnectedSystems commented Dec 10, 2024

@Rosejoycrocker there's still the question of what to do with the example currently in the docs.

It would be best to show how to do intervention runs with the most recent version of RME we have at the very least, with a note on how to do it with older versions.

@Rosejoycrocker
Copy link
Collaborator Author

@Rosejoycrocker there's still the question of what to do with the example currently in the docs.

It would be best to show how to do intervention runs with the most recent version of RME we have at the very least, with a note on how to do it with older versions.

I'll add the removed example as a comment with a note about the version

Comment on lines 214 to 217
# Adding dhw tolerance was removed in v1.0.31
# Add 3 DHW enhancement to outplanted corals
# set_option("restoration_dhw_tolerance_outplants", 3)

Copy link
Collaborator

@ConnectedSystems ConnectedSystems Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to demonstrate what to do with versions > v1.0.31

From the docs and matlab files it looks like they added an rme_iv_set_outplant_heat_tolerance function.

The relevant RME functions are:

ivSetOutplantHeatToleranceMeanDhw and ivSetOutplantHeatToleranceSdDhw

Both of which expect a vector of values for each functional group.


Actually, I'm going to accept and merge this as is and address the above later.

@ConnectedSystems ConnectedSystems merged commit a6d3cfa into main Dec 12, 2024
1 check passed
@ConnectedSystems ConnectedSystems deleted the fix-outplant-function branch December 12, 2024 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants