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

Investigate solver options for finding canopy layer closure heights #293

Open
Tracked by #321
davidorme opened this issue Sep 23, 2024 · 1 comment
Open
Tracked by #321

Comments

@davidorme
Copy link
Collaborator

The closure heights of the canopy layers in pyrealm.demography.canopy.Canopy are found by using a root solver:

# TODO - the solution here is predictably closer to the upper bracket, might
# be a better algorithm to find the root.
solution = root_scalar(
solve_community_projected_canopy_area,
args=(
community.cohort_data["stem_height"].to_numpy(),
community.cohort_data["crown_area"].to_numpy(),
community.cohort_data["m"].to_numpy(),
community.cohort_data["n"].to_numpy(),
community.cohort_data["q_m"].to_numpy(),
community.cohort_data["canopy_z_max"].to_numpy(),
community.cohort_data["n_individuals"].to_numpy(),
target_area,
False, # validate
),
bracket=(0, starting_guess),
xtol=layer_tolerance,
)

The default method works well, but we might be able to improve the performance if we can make use of the fact that the root is likely to be much closer to the upper bound (the previously closed layer) than the lower bound (the ground).

@davidorme
Copy link
Collaborator Author

davidorme commented Oct 3, 2024

Actually, it might be more effective to set the lower bound - we know the number of stems and crown areas of each cohort and the vertical height of maximum crown area ($z_{max}$), so can determine some known heights where a particular community crown area has to be filled.

It's probably a tiny runtime saving but in simulation this routine will be called a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant