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

Adding two leaf irradience model #245

Draft
wants to merge 54 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
cc90b94
Created two leaf constants dataclass
j-emberton Jun 4, 2024
20b58b9
Auto-generated profiling results [skip actions]
davidorme Jun 5, 2024
0ec30c2
Auto-generated profiling results [skip actions]
vgro Jun 5, 2024
3da610e
more work on irradience class
j-emberton Jun 5, 2024
f7022a0
Minor fix
j-emberton Jun 7, 2024
b67ef47
Added pysolar calc for beta
j-emberton Jun 7, 2024
707b5f7
changes variables to lower case
j-emberton Jun 7, 2024
f6e94ba
Fixed capital PA0
j-emberton Jun 7, 2024
219e0c3
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] May 27, 2024
ec6725d
Auto-generated profiling results [skip actions]
davidorme Jun 5, 2024
e83a94e
Unsticking stuck workflow
davidorme Jun 6, 2024
06d69d3
Rebuild of QA chain using ruff
davidorme Apr 22, 2024
1a569a7
Removing QA on pytest
davidorme Jun 6, 2024
0fc6984
Missing dev dependencies for local use of jupyterlab with Myst notebooks
davidorme Jun 6, 2024
5c77794
Forgot jupytext in dev dependencies
davidorme Jun 6, 2024
c384586
Extending RUF testing and add ruff auto-fix to pre-commit
davidorme Jun 6, 2024
4cba1f2
Resolving newly revealed issues from using RUF settings
davidorme Jun 6, 2024
5905b40
Remove kernelspec setting step in RTD and GH actions
davidorme Jun 5, 2024
9cf9b0a
Switch Myst notebook kernel specs to use python3
davidorme Jun 5, 2024
bbd93ca
Tidying notebook code cells automatically
davidorme Jun 5, 2024
6b9e8f3
Auto-generated profiling results [skip actions]
davidorme Jun 5, 2024
c928f56
Auto-generated profiling results [skip actions]
vgro Jun 5, 2024
4911eec
Created two leaf constants dataclass
j-emberton Jun 4, 2024
d9a1434
Auto-generated profiling results [skip actions]
davidorme Jun 5, 2024
1844bac
Auto-generated profiling results [skip actions]
vgro Jun 5, 2024
337e3fd
more work on irradience class
j-emberton Jun 5, 2024
fd225bf
Minor fix
j-emberton Jun 7, 2024
16e631f
Added pysolar calc for beta
j-emberton Jun 7, 2024
bad57d5
changes variables to lower case
j-emberton Jun 7, 2024
40b18c4
Fixed capital PA0
j-emberton Jun 7, 2024
4747cfb
Auto-generated profiling results [skip actions]
davidorme Jun 5, 2024
5a0db3c
Unsticking stuck workflow
davidorme Jun 6, 2024
100f1a4
Rebuild of QA chain using ruff
davidorme Apr 22, 2024
e57bc11
Removing QA on pytest
davidorme Jun 6, 2024
8b04a38
Missing dev dependencies for local use of jupyterlab with Myst notebooks
davidorme Jun 6, 2024
b6b83a1
Auto-generated profiling results [skip actions]
davidorme Jun 5, 2024
4c96406
Auto-generated profiling results [skip actions]
vgro Jun 5, 2024
2e24adc
Merge branch 'Two_leaf_irradience_model' of github.com:ImperialColleg…
j-emberton Jun 7, 2024
c6f2099
Offerings to the angry god Ruff
j-emberton Jun 7, 2024
f0b09f9
Offerings to the angry god Ruff
j-emberton Jun 7, 2024
71f478f
Removed new Beta calc and pysolar import
j-emberton Jun 7, 2024
dc7cf66
merged in develop
j-emberton Jul 17, 2024
16c2251
starting documentation
j-emberton Jul 17, 2024
4d627f8
Doesn't pass pre-commit but have questions
j-emberton Jul 24, 2024
8b6a5dd
First draft of two leaf classes complete
j-emberton Jul 29, 2024
b683b51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 29, 2024
3fe4bdc
defined unit tests for the irradience classes - all working
j-emberton Aug 19, 2024
87b2f49
added docstring
j-emberton Aug 19, 2024
b5c20e7
added class unit tests - all working
j-emberton Aug 19, 2024
0a8ed70
first stab at defining regression tests
j-emberton Aug 19, 2024
0f55afe
writing tests
j-emberton Sep 17, 2024
9434fd2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 17, 2024
1874eeb
Merge branch 'develop' into Two_leaf_irradience_model
j-emberton Oct 22, 2024
92e6fb1
docstring updates
j-emberton Sep 25, 2024
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
27 changes: 27 additions & 0 deletions pyrealm/constants/two_leaf_canopy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""To do."""

from dataclasses import dataclass

import numpy as np

from pyrealm.constants import ConstantsClass


@dataclass(frozen=True)
class TwoLeafConst(ConstantsClass):
"""Pyrealm two leaf canopy model constants dataclass."""

# two leaf canopy model constants

k_fa: float = 0.426 # needs citation
"""scattering coefficient of PAR in the atmosphere, dimensionless"""
k_sigma: float = 0.15 # needs citation
"""leaf scattering coefficient of PAR (relections and transmissivity),
dimensionless"""
k_rho_cd: float = 0.036 # needs citation
"""canopy reflection coefficient for diffuse PAR, dimensionless"""
k_kd_prime: float = 0.719 # needs citation
"""diffuse and scattered diffuse PAR extinction coefficient, dimensionless"""

k_sol_obs_angle: float = np.deg2rad(1) # needs a citation
""" solar obscurity angle, radians"""
31 changes: 31 additions & 0 deletions pyrealm/pmodel/two_leaf_irradience.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""To do."""

import numpy as np
from numpy.typing import NDArray


class TwoLeafIrradience:
"""Calculates two-leaf irradience."""

def __init__(self, beta_angle: NDArray, PPFD: NDArray, LAI: NDArray, PATM: NDArray):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although these variable names are acronyms, I think we should stick to lower case variable names: ppfd, lai, patm (and arguably longer - leaf_area_index, although I know I'm guilty of using patm and tc elsewhere.

We could do with a sweep to standardise /check variable names, really!


self.beta_angle: NDArray = beta_angle


def beta_angle(lat: NDArray, d: NDArray, h: NDArray) -> NDArray:
"""Calculates solar beta angle.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The reference for this is page 554 of this:
https://onlinelibrary.wiley.com/doi/epdf/10.1111/j.1365-3040.1997.00094.x

I think beta_angle here is (or should be) solar elevation angle - which might make it part of the solar functionality rather than an irradiance specific thing. If we move to using one of the existing solar packages, we might get a more accurate model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added pysolar alternatives in the latest commit which calculate solar elevation directly from latitude, longitude and date time. However, they don't take array inputs natively so you need to use and enumerate operation, so there will be a speed accuracy trade.

The best pysolar solar elevation implementation includes atmospheric distortion, but they also have a faster/simpler version which is the same as the first version I wrote. Because the first version uses numpy vectorisation it may well be faster but I've included the pysolar fast version anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will move these calcs into the core solar library in a sec


Calculates solar beta angle using Eq A13 of dePury & Farquhar (1997).

Args:
lat: array of latitudes (rads)
d: array of declinations (rads)
h: array of hour angle (rads)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've adopted Keith's short variable names in my rough and ready translation to Python, but we should shift to longer names (latitude, declination, hour_angle)?


Returns:
beta: array of solar beta angles
"""

beta = np.sin(lat) * np.sin(d) + np.cos(lat) * np.cos(d) * np.cos(h)

return beta
Loading