Skip to content

Commit

Permalink
Simple test of StemAllometry
Browse files Browse the repository at this point in the history
  • Loading branch information
davidorme committed Sep 29, 2024
1 parent ea10d77 commit 742f02c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyrealm/demography/t_model_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
""" # noqa: D205

from dataclasses import InitVar, dataclass, field
from typing import ClassVar

import numpy as np
from numpy.typing import NDArray
Expand Down Expand Up @@ -625,6 +626,18 @@ class StemAllometry:
allometry values.
"""

allometry_attrs: ClassVar[tuple[str, ...]] = (
"dbh",
"stem_height",
"crown_area",
"crown_fraction",
"stem_mass",
"foliage_mass",
"sapwood_mass",
"canopy_r0",
"canopy_z_max",
)

# Init vars
stem_traits: InitVar[Flora | StemTraits]
at_dbh: InitVar[NDArray[np.float32]]
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/demography/test_t_model_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,18 @@ def test_calculate_dbh_from_height_edge_cases():

# Undefined entries
assert np.all(np.isnan(dbh) == np.array([[0, 0], [0, 0], [0, 0], [1, 0], [1, 1]]))


def test_StemAllometry(rtmodel_flora, rtmodel_data):
"""Test the StemAllometry class."""

from pyrealm.demography.t_model_functions import StemAllometry

stem_allometry = StemAllometry(
stem_traits=rtmodel_flora, at_dbh=rtmodel_data["dbh"][:, [0]]
)

# Check the variables provided by the rtmodel implementation
to_check = set(stem_allometry.allometry_attrs) - set(["canopy_r0", "canopy_z_max"])
for var in to_check:
assert np.allclose(getattr(stem_allometry, var), rtmodel_data[var])

0 comments on commit 742f02c

Please sign in to comment.