Skip to content

Commit

Permalink
Tidying up repr methods
Browse files Browse the repository at this point in the history
  • Loading branch information
davidorme committed Sep 30, 2024
1 parent 89a2960 commit d4a21af
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
16 changes: 12 additions & 4 deletions docs/source/api/demography_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,26 @@ kernelspec:
:members:
```

## The {mod}`~pyrealm.demography.community` module
## The {mod}`~pyrealm.demography.t_model_functions` module

```{eval-rst}
.. automodule:: pyrealm.demography.community
.. automodule:: pyrealm.demography.t_model_functions
:autosummary:
:members:
```

## The {mod}`~pyrealm.demography.t_model_functions` module
## The {mod}`~pyrealm.demography.crown` module

```{eval-rst}
.. automodule:: pyrealm.demography.t_model_functions
.. automodule:: pyrealm.demography.crown
:autosummary:
:members:
```

## The {mod}`~pyrealm.demography.community` module

```{eval-rst}
.. automodule:: pyrealm.demography.community
:autosummary:
:members:
```
11 changes: 6 additions & 5 deletions docs/source/users/demography/crown.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ax2.set_aspect("equal")

The examples below show the calculation of crown profiles for a set of plant functional
types (PFTs) with differing crown trait values. We first need to create a
:class:`~pyrealm.demography.flora.Flora` object that defines those PFTs.
{class}`~pyrealm.demography.flora.Flora` object that defines those PFTs.

```{code-cell}
flora = Flora(
Expand Down Expand Up @@ -223,6 +223,9 @@ for pft_idx, offset, colour in zip((0, 1, 2), (0, 5, 12), ("r", "g", "b")):
linestyle=":",
)
ax.set_xlabel("Crown profile")
ax.set_ylabel("Height above ground (m)")
ax.set_aspect(aspect=1)
```

Expand Down Expand Up @@ -275,8 +278,6 @@ for pft_idx, offset, colour in zip((0, 1, 2), (0, 5, 10), ("r", "g", "b")):
color=colour,
linestyle="--",
)
```

```{code-cell}
ax.set_xlabel("Projected area (m2)")
ax.set_ylabel("Height above ground (m)")
```
21 changes: 21 additions & 0 deletions pyrealm/demography/crown.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ class CrownProfile:
projected_leaf_area: NDArray[np.float32] = field(init=False)
"""An array of the projected leaf area of stems at z heights"""

# Information attributes
_n_pred: int = field(init=False)
"""The number of predictions per stem."""
_n_stems: int = field(init=False)
"""The number of stems."""

def __post_init__(
self,
stem_traits: StemTraits | Flora,
Expand Down Expand Up @@ -431,3 +437,18 @@ def __post_init__(
stem_height=stem_allometry.stem_height,
z_max=stem_allometry.crown_z_max,
)

# Set the number of observations per stem (one if dbh is 1D, otherwise size of
# the first axis)
if self.relative_crown_radius.ndim == 1:
self._n_pred = 1
else:
self._n_pred = self.relative_crown_radius.shape[0]

self._n_stems = stem_traits._n_stems

def __repr__(self) -> str:
return (
f"CrownProfile: Prediction for {self._n_stems} stems "
f"at {self._n_pred} observations."
)
11 changes: 9 additions & 2 deletions pyrealm/demography/t_model_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ class StemAllometry:
"""Crown radius scaling factor (-)"""
crown_z_max: NDArray[np.float32] = field(init=False)
"""Height of maximum crown radius (metres)"""

# Information attributes
_n_pred: int = field(init=False)
"""The number of predictions per stem."""
Expand Down Expand Up @@ -789,7 +790,7 @@ def __post_init__(

def __repr__(self) -> str:
return (
f"StemAllometry: Prediction for {self._n_stems} stems at se"
f"StemAllometry: Prediction for {self._n_stems} stems "
f"at {self._n_pred} DBH values."
)

Expand Down Expand Up @@ -860,6 +861,12 @@ class StemAllocation:
delta_foliage_mass: NDArray[np.float32] = field(init=False)
"""Predicted increase in foliar mass from growth allocation (g C)"""

# Information attributes
_n_pred: int = field(init=False)
"""The number of predictions per stem."""
_n_stems: int = field(init=False)
"""The number of stems."""

def __post_init__(
self,
stem_traits: Flora | StemTraits,
Expand Down Expand Up @@ -936,6 +943,6 @@ def __post_init__(

def __repr__(self) -> str:
return (
f"StemAllocation: Prediction for {self._n_stems} stems"
f"StemAllocation: Prediction for {self._n_stems} stems "
f"at {self._n_pred} observations."
)

0 comments on commit d4a21af

Please sign in to comment.