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

Using pyrealm within the Plants model #707

Merged
merged 61 commits into from
Feb 14, 2025
Merged
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
39080ff
Update to PlantsModel JSON schema
davidorme Jan 7, 2025
c994578
Singular pft_definition throughout model schema
davidorme Jan 7, 2025
83092aa
Update plant PFT configs in core testing and get tests working
davidorme Jan 7, 2025
2d9e265
Adding new pyrealm flora loader and testing
davidorme Jan 7, 2025
1ee8152
Added split_arrays_by_grouping_variable to core.utils: might move
davidorme Jan 8, 2025
af271f3
Updated test PFT names and functional type testing
davidorme Jan 8, 2025
f7c1a74
First draft of pyrealm community structure
davidorme Jan 8, 2025
0858c4b
Updated community tests
davidorme Jan 8, 2025
81a6fe5
Adding test flora data
davidorme Jan 9, 2025
7cc07f8
Using update community code in _setup
davidorme Jan 9, 2025
b462714
Added new function calculate_canopies to get pyrealm canopy objects a…
davidorme Jan 9, 2025
c223e95
Updated test data - more and taller stems to give actual closed canopy
davidorme Jan 9, 2025
3de09ab
Remove outdated canopy cimpiler function
davidorme Jan 10, 2025
037fdd4
Incomplete new canopy compiler
davidorme Jan 10, 2025
dba946b
Updating plant cohort test data
davidorme Jan 10, 2025
94f18b1
Making plant test data have more than one cohort per community and no…
davidorme Jan 10, 2025
b0450ce
Starting to define layers correctly
davidorme Jan 21, 2025
f5f27fe
Updating PlantsModel.update_canopy_layers
davidorme Jan 23, 2025
457652a
Fixing update_canopy_layers, set_canopy_absorption
davidorme Jan 24, 2025
aee67df
Working on GPP
davidorme Jan 24, 2025
7a47068
Merge branch 'develop' into 659-use-pyrealm-flora
davidorme Jan 25, 2025
f21c464
Estimating stem GPP, next need to estimate transpiration
davidorme Jan 28, 2025
bb3182c
Refactored estimate_gpp before testing
davidorme Jan 29, 2025
54eebc2
Fixing estimate_gpp method issues
davidorme Jan 29, 2025
9752a7b
Simplified tests on estimate_gpp to get it passing - no value testing
davidorme Jan 29, 2025
50353a4
Removing GPP allocation to get model running
davidorme Jan 29, 2025
59be3d5
Updating plants model specific tests - all now pass
davidorme Jan 29, 2025
b651b86
Merge branch 'develop' into 659-use-pyrealm-flora
davidorme Jan 30, 2025
8e40f50
Updating community handling
davidorme Jan 30, 2025
8f91a1a
Updated plant config in animal conftest
davidorme Jan 30, 2025
f1760da
Updating plants.canopy testing
davidorme Jan 30, 2025
7e33abb
Fixing testing on PlantCommunities.__init__
davidorme Jan 30, 2025
4dcee14
Removing outdated code
davidorme Jan 30, 2025
e469caf
Updating example data config
davidorme Jan 30, 2025
117855e
Merge branch 'develop' into 659-use-pyrealm-flora
davidorme Jan 30, 2025
0f98e0f
Merge branch '709-allow-data-to-be-configured-in-different-files' int…
davidorme Jan 30, 2025
0df2eba
Moving plant data to plant config, adding plant cohort CSV generation
davidorme Jan 30, 2025
7ae7d8c
Merge branch 'develop' into 659-use-pyrealm-flora
davidorme Jan 31, 2025
2149b2b
New plant model example data
davidorme Jan 31, 2025
e23b503
Merge branch '715-extend-path-resolution-in-configuration-files' into…
davidorme Feb 1, 2025
39bbf02
Comments
davidorme Feb 2, 2025
1d3016f
Evapotranspiration needs vertical structure - was collapsed to total …
davidorme Feb 3, 2025
f000c59
Fixing test
davidorme Feb 3, 2025
9b1d3ff
TODO functionality
davidorme Feb 4, 2025
33e4641
Adding plant model flow diagram
davidorme Feb 4, 2025
19609de
Updating docstrings and API
davidorme Feb 5, 2025
d2de394
Stopping using aliases for pyrealm imports
davidorme Feb 5, 2025
bcd57c9
Minor doc tweaks
davidorme Feb 6, 2025
633ec6d
Update model docstring
davidorme Feb 6, 2025
f4b6875
Merge branch 'develop' into 659-use-pyrealm-flora
davidorme Feb 6, 2025
de7ddd4
Moving community.py to communities.py and updating docs
davidorme Feb 10, 2025
82665c9
Updated data frame check and split functions
davidorme Feb 10, 2025
8d0e5f2
Merge branch 'develop' into 659-use-pyrealm-flora
davidorme Feb 10, 2025
44d3ca4
Stable sorting order in split_arrays_by_grouping_variable
davidorme Feb 10, 2025
8880d9e
Merge branch 'develop' into 659-use-pyrealm-flora
davidorme Feb 10, 2025
0389095
Updates from @vgro review
davidorme Feb 12, 2025
6a68eca
Renaming canopy_absorption
davidorme Feb 13, 2025
f33e8d5
Typo
davidorme Feb 13, 2025
d9d7bd1
Merge branch 'develop' into 659-use-pyrealm-flora
davidorme Feb 13, 2025
9000ec9
xarray error message change
davidorme Feb 13, 2025
c531ed6
Something odd with error messages on local and origin
davidorme Feb 13, 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
Prev Previous commit
Next Next commit
Starting to define layers correctly
davidorme committed Jan 21, 2025
commit b0450ce38420bfcedfa179a78e250aef3eb34c72
38 changes: 26 additions & 12 deletions virtual_ecosystem/models/plants/plants_model.py
Original file line number Diff line number Diff line change
@@ -284,8 +284,6 @@ def update_canopy_layers(self) -> None:
radation at ground level (``canopy_absorption``).
"""

# layers = ["layer_heights", "leaf_area_index", "layer_fapar", "layer_heights"]

heights = np.zeros((self.layer_structure.n_canopy_layers, self.grid.n_cells))
fapar = np.zeros((self.layer_structure.n_canopy_layers, self.grid.n_cells))
lai = np.zeros((self.layer_structure.n_canopy_layers, self.grid.n_cells))
@@ -295,27 +293,43 @@ def update_canopy_layers(self) -> None:
for cell_id, canopy, community in zip(
self.canopies, self.canopies.values(), self.communities.values()
):
# Get the indices of the array to be filled in
fill_idx = (slice(0, canopy.heights.size), (cell_id,))

# Insert layer heights
heights[: canopy.heights.size, (cell_id,)] = canopy.heights
heights[fill_idx] = canopy.heights

# Insert canopy fapar
fapar[: canopy.heights.size, (cell_id,)] = canopy.community_data.fapar
# TODO: check with @vgro what goes where
# - what values at the bottom of the layers, so the last one is ground level
# - layer bounds versus centres

# Insert canopy fapar:
# TODO: currently 1D, not 2D - consistency in pyrealm? keepdims?
fapar[fill_idx] = canopy.community_data.fapar.reshape((-1, 1))

# Partition the total stem foliage masses across cohorts vertically
# following the leaf area within each layer.
# TODO - need to expose the per cohort data to allow selective herbivory. Do
# we need the total leaf mass per layer for anything
per_cohort_leaf_mass = (
community.stem_allometry.foliage_mass * community.cohorts.n_individuals
# we need the total leaf mass per layer for anything?
leaf_mass_per_cohort_per_layer = (
community.stem_allometry.foliage_mass
* community.cohorts.n_individuals
* (canopy.cohort_data.lai / canopy.cohort_data.lai.sum(axis=0))
)
mass[fill_idx] = leaf_mass_per_cohort_per_layer.sum(axis=1, keepdims=True)

# LAI - add up LAI across cohorts within layers
lai[fill_idx] = canopy.cohort_data.lai.sum(axis=1, keepdims=True)

# Tranmission needs to insert the final value at _ground_ level.
# Absorption
absorption[fill_idx] = canopy.community_data.f_abs.reshape((-1, 1))

# Insert the canopy layers into the data objects
self.data["layer_heights"][self._canopy_layer_indices, :] = heights
# self.data["leaf_area_index"][self._canopy_layer_indices, :] = canopy_data[1]
# self.data["layer_fapar"][self._canopy_layer_indices, :] = canopy_data[2]
# self.data["layer_leaf_mass"][self._canopy_layer_indices, :] = canopy_data[3]
self.data["leaf_area_index"][self._canopy_layer_indices, :] = lai
self.data["layer_fapar"][self._canopy_layer_indices, :] = fapar
self.data["layer_leaf_mass"][self._canopy_layer_indices, :] = mass
self.data["absorption"][self._canopy_layer_indices, :] = absorption

# # Update the above canopy heights
# self.data["layer_heights"][0, :] = (