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

236 develop pyrealmcoresolar function radiation calc library #237

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
9a3dafd
Started breaking out solar functions from splash.solar and moving to …
j-emberton May 22, 2024
66c90d3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2024
e967bf5
Added type hints
j-emberton May 22, 2024
0a635c9
Fixed corrupted docstrings and fixed formatting in core.solar
j-emberton May 23, 2024
1cb54a5
Fixed incorrect reference to const
j-emberton May 23, 2024
2f0e938
Added unit test for core.solar.calc_distance_factor
j-emberton May 23, 2024
11fadd8
Added unit test for core.solar.calc_declination_angle_delta
j-emberton May 23, 2024
4680e30
Added unit test for core.solar.calc_lat_delta_intermediates
j-emberton May 23, 2024
188228d
Minor code formatting change
j-emberton May 23, 2024
a0fa7e2
Fixed parametrize mispelling
j-emberton May 23, 2024
87d0101
Fixed missing brackets
j-emberton May 23, 2024
5f4766b
Fixed erroneous data in delta values for calc_lat_delta_intermediates…
j-emberton May 23, 2024
9c066eb
Added unit test for core.solar.calc_sunset_hour_angle
j-emberton May 24, 2024
554a998
Fixed splash.solar imports and function calls
j-emberton May 24, 2024
cfc5626
Added calc_daily_solar_radiation and changed splash function call
j-emberton May 24, 2024
22a355a
Added calc_transmissivity and changed splash.solar function call
j-emberton May 24, 2024
af0dd1c
Added unit test calc_daily_solar_radiation
j-emberton May 24, 2024
3788821
Bugfix solar hour angle unit test
j-emberton May 24, 2024
3fb55be
Added transmissivity unit test
j-emberton May 26, 2024
dced850
Added remaining Splash.solar calculations to core.solar
j-emberton May 26, 2024
dd22b8e
Further solar unit tests updates
j-emberton Jun 4, 2024
53e141c
Changed core solar unit tests
j-emberton Jun 19, 2024
bb95ceb
Started breaking out solar functions from splash.solar and moving to …
j-emberton May 22, 2024
9933e74
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2024
863f412
Added type hints
j-emberton May 22, 2024
361b9a3
Fixed corrupted docstrings and fixed formatting in core.solar
j-emberton May 23, 2024
d5ca476
Added unit test for core.solar.calc_distance_factor
j-emberton May 23, 2024
d0d12f4
Added unit test for core.solar.calc_declination_angle_delta
j-emberton May 23, 2024
0384b6b
Added unit test for core.solar.calc_lat_delta_intermediates
j-emberton May 23, 2024
3db9685
Minor code formatting change
j-emberton May 23, 2024
aa2ee37
Fixed parametrize mispelling
j-emberton May 23, 2024
f7fdc1b
Fixed missing brackets
j-emberton May 23, 2024
8fa51e8
Fixed erroneous data in delta values for calc_lat_delta_intermediates…
j-emberton May 23, 2024
326fadf
Changed core solar unit tests
j-emberton Jun 19, 2024
3242e52
Fixed docstrings
j-emberton Jun 19, 2024
148f10b
fixed parametrize issue in test_solar
j-emberton Jun 20, 2024
d10f89d
removed errant parametrize
j-emberton Jun 20, 2024
b40fe02
fixed error in k_pir
j-emberton Jun 20, 2024
2d77442
fixed unit tests
j-emberton Jul 16, 2024
46189d9
improved api for internal calcs
j-emberton Jul 16, 2024
673074a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 16, 2024
46449ed
fixed docstrings
j-emberton Jul 16, 2024
66b24db
bugfix
j-emberton Jul 16, 2024
e8c7a6c
fixed tests to incorporate davids proposed changes
j-emberton Jul 16, 2024
4b28ed5
refactored solar lib to remove intermediates as args
j-emberton Jul 17, 2024
9ffaed1
emoved comments
j-emberton Jul 17, 2024
9059bee
all unit and regression tests now working
j-emberton Jul 17, 2024
48d3396
added tests
j-emberton Jul 18, 2024
86c36ce
fixed doctest
j-emberton Jul 18, 2024
428fe63
added tests
j-emberton Jul 18, 2024
39d3ffb
Add autodoc directive to build API for core.solar
davidorme Aug 2, 2024
8e542a6
Update distance factor return value
j-emberton Aug 3, 2024
17c3abe
suggested changes from David
j-emberton Aug 3, 2024
cf60e30
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 3, 2024
27b982f
refactored code to new standard
j-emberton Aug 4, 2024
dfc2efe
refactored tests to new standard
j-emberton Aug 4, 2024
157e27b
fixed test errors
j-emberton Aug 4, 2024
f2b0a92
fixed docstrings for publication
j-emberton Aug 4, 2024
e041b3a
fixed tests again
j-emberton Aug 5, 2024
57a2809
rework + locationdatetime object experiment
j-emberton Aug 8, 2024
6577b2c
tests all working
j-emberton Aug 12, 2024
f41adb3
finalised
j-emberton Aug 13, 2024
a8669b3
Fixing up doc issues - some formatting, some xref
davidorme Aug 29, 2024
4f0a751
minor fixes
j-emberton Aug 13, 2024
c88136d
fixed citations
j-emberton Sep 16, 2024
ce48f39
fixed test descriptions
j-emberton Sep 16, 2024
bda71f9
updated refs.bib witha dditional citations
j-emberton Sep 16, 2024
8543cfc
added missing refs
j-emberton Sep 16, 2024
c691882
fixed trailing commas
j-emberton Sep 16, 2024
0eeef71
changes to LocationDateTime docstring
j-emberton Sep 16, 2024
c54bdbb
trying different 'noindex' approach
j-emberton Sep 16, 2024
3895056
fixed no-index
j-emberton Sep 16, 2024
0d5e47b
fixed no-index
j-emberton Sep 16, 2024
aa00677
fixed no-index
j-emberton Sep 16, 2024
a6eaf9f
fixing noindex
j-emberton Sep 16, 2024
1d59218
trying a new fix
j-emberton Sep 16, 2024
6667099
Fixing docstring structure issue
davidorme Sep 16, 2024
725a109
fixed maths rendering
j-emberton Sep 24, 2024
f567bc9
fix equation new line
j-emberton Sep 24, 2024
514698f
updated citations format with backticks and adjusted line lengths
j-emberton Sep 24, 2024
ca1ed65
renamed calc rnl
j-emberton Sep 24, 2024
3bf9e8e
removed requirement for UTC off set in LocationDateTime
j-emberton Sep 25, 2024
b0be387
reworked LocationDateTime for better handling of local standard meridian
j-emberton Sep 25, 2024
efcfb1b
fixed variable rendering in docstrings
j-emberton Sep 25, 2024
2389dfd
updated citation
j-emberton Sep 25, 2024
f581b7a
citation udpates
j-emberton Oct 16, 2024
ffe91cc
citation fixes
j-emberton Oct 16, 2024
0877e85
fixed tests after rebase
j-emberton Oct 21, 2024
b8a510c
fixing docs
j-emberton Oct 21, 2024
6ba5878
docs fixes
j-emberton Oct 21, 2024
55131c1
fixed accidentally broken test
j-emberton Oct 21, 2024
dc28fd4
Merge branch 'develop' into 236-develop-pyrealmcoresolar-function-rad…
j-emberton Oct 21, 2024
282150f
more docs fixes
j-emberton Oct 22, 2024
c13f81f
removed extra backslashes
j-emberton Oct 23, 2024
486e91a
Merge branch 'develop' into 236-develop-pyrealmcoresolar-function-rad…
j-emberton Oct 29, 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
8 changes: 8 additions & 0 deletions docs/source/api/core_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ language_info:
:autosummary:
:members:
```

## The {mod}`~pyrealm.core.solar` submodule

```{eval-rst}
.. automodule:: pyrealm.core.solar
:autosummary:
:members:
```
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class MyReferenceStyle(AuthorYearReferenceStyle):
("py:class", "numpy.dtype"),
("py:class", "numpy.dtype[+ScalarType]"),
("py:class", "numpy.typing.NDArray"),
("py:class", "numpy.NDArray"),
("py:class", "NDArray"),
("py:class", "dataclasses.InitVar"),
(
"py:class",
Expand Down
212 changes: 109 additions & 103 deletions docs/source/refs.bib

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyrealm/constants/core_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class CoreConst(ConstantsClass):
k_d = 0.50 # angular coefficient of transmittivity (Linacre, 1968)
k_fFEC = 2.04 # from flux to energy conversion, umol/J (Meek et al., 1984)
k_Gsc = 1360.8 # solar constant, W/m^2 (Kopp & Lean, 2011)
k_secs_d = 86400 # seconds in one solar day

# Paleoclimate variables:
ke = 0.0167 # eccentricity for 2000 CE (Berger, 1978)
Expand Down
87 changes: 87 additions & 0 deletions pyrealm/core/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,90 @@ def __repr__(self) -> str:
"""Representation of a Calendar instance."""

return f"Calendar({self.dates[0]!s}, {self.dates[-1]!s})"


@dataclass
class LocationDateTime:
"""A data class representing an observation location and date and time information.

This class encapsulates the latitude and longitude of a location along with a
corresponding time array. It automatically calculates the latitude and longitude in
radians, the Julian days from the date-time information, and a decimal
representation of the local time.

Example:
>>> import numpy as np
>>> ldt = LocationDateTime(
... latitude=-35.058333,
... longitude=147.34167,
... year_date_time=np.array([np.datetime64("2024-08-12T10:30")]),
... )
>>> print(ldt.latitude_rad)
-0.6118833411105811
>>> print(ldt.decimal_time)
[10.5]
>>> print(ldt.local_standard_meridian)
150
"""

latitude: float
"""The latitude of the location in degrees."""
latitude_rad: float = field(init=False)
"""The latitude of the location in radians, calculated automatically."""
longitude: float
"""The longitude of the location in degrees."""
longitude_rad: float = field(init=False)
"""The longitude of the location in radians, calculated automatically."""
year_date_time: np.ndarray
"""An array of np.datetime64 values corresponding to observations at the
location (local time)."""
julian_days: np.ndarray = field(init=False)
"""An array of Julian day of the year numbers calculated from the
``year_date_time``."""
decimal_time: np.ndarray = field(init=False)
"""An array of decimal hour values calculated from local ``year_date_time``."""
local_standard_meridian: int = field(init=False)
"""An int describing time offset from local meridian to Greenwich meridian
in hours."""

def __post_init__(self) -> None:
"""Initialise calculated attributes.

Initializes calculated attributes like ``latitude_rad``, ``longitude_rad``,
``julian_days``, and ``local_time`` after the object is instantiated.
"""

self.julian_days = Calendar(self.year_date_time).julian_day
self.decimal_time = self.decimal_hour()
self.latitude_rad = self.latitude * np.pi / 180
self.longitude_rad = self.longitude * np.pi / 180
self.local_standard_meridian = self.get_local_standard_meridian()

def decimal_hour(self) -> np.ndarray:
"""Convert ``year_date_time`` to a decimal representation of hours.

This method extracts the hours and minutes from the `year_date_time` attribute
and converts them into a decimal representation of hours.

Returns:
An array of decimal hour values.
"""

# Extract hours
hours = self.year_date_time.astype("datetime64[h]").astype(int) % 24

# Extract minutes
minutes = self.year_date_time.astype("datetime64[m]").astype(int) % 60

# Convert to decimal hours
return hours + minutes / 60

def get_local_standard_meridian(self) -> int:
"""Calculates local meridian from longitude.

Returns:
An integer in degrees format representing local meridian offset from
Greenwich.
"""

return 30 * round(self.longitude / 30)
Loading
Loading