Skip to content

Commit d7b96f9

Browse files
committed
clean up
1 parent 84a7b36 commit d7b96f9

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

src/earthkit/meteo/solar/array/solar.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _julian_day_scalar(d: datetime.datetime) -> float:
2020
2121
Parameters
2222
----------
23-
d : datetime.datetime
23+
d: datetime.datetime
2424
Input datetime.
2525
2626
Returns
@@ -41,7 +41,7 @@ def julian_day(date) -> float:
4141
4242
Parameters
4343
----------
44-
date : datetime.datetime, numpy.datetime64, or numpy.ndarray
44+
date: datetime.datetime, numpy.datetime64, or numpy.ndarray
4545
Input date(s). May be a scalar or array of numpy.datetime64 or
4646
datetime.datetime objects.
4747
@@ -80,7 +80,7 @@ def solar_declination_angle(date) -> tuple[float, float]:
8080
8181
Parameters
8282
----------
83-
date : datetime.datetime, numpy.datetime64, or numpy.ndarray
83+
date: datetime.datetime, numpy.datetime64, or numpy.ndarray
8484
Input date(s). May be scalar or array.
8585
8686
Returns
@@ -105,6 +105,7 @@ def solar_declination_angle(date) -> tuple[float, float]:
105105
"""
106106
angle = julian_day(date) / DAYS_PER_YEAR * np.pi * 2
107107

108+
# declination in [degrees]
108109
declination = (
109110
0.396372
110111
- 22.91327 * np.cos(angle)
@@ -114,7 +115,7 @@ def solar_declination_angle(date) -> tuple[float, float]:
114115
- 0.154527 * np.cos(3 * angle)
115116
+ 0.084798 * np.sin(3 * angle)
116117
)
117-
118+
# time correction in [ h.degrees ]
118119
time_correction = (
119120
0.004297
120121
+ 0.107029 * np.cos(angle)
@@ -138,44 +139,46 @@ def cos_solar_zenith_angle(
138139
139140
Parameters
140141
----------
141-
date : datetime.datetime
142-
Date and time of the observation.
143-
latitudes : array-like
142+
date: datetime.datetime
143+
Date.
144+
latitudes: array-like
144145
Latitude values in degrees.
145-
longitudes : array-like
146+
longitudes: array-like
146147
Longitude values in degrees.
147148
148149
Returns
149150
-------
150151
array-like
151152
Cosine of the solar zenith angle. Negative values are clipped to 0.
153+
[Hogan_and_Hirahara2015]_. See also:
154+
http://answers.google.com/answers/threadview/id/782886.html
152155
153-
Notes
154-
-----
155-
Supports any array type compatible with the Python Array API standard,
156-
including numpy, cupy, and torch tensors.
157-
158-
The result is clipped to ensure physically meaningful values.
159156
"""
160157
xp = array_namespace(latitudes, longitudes)
161158
latitudes = xp.asarray(latitudes)
162159
longitudes = xp.asarray(longitudes)
163160
device = xp.device(latitudes)
164161

162+
# declination angle + time correction for solar angle
165163
declination, time_correction = solar_declination_angle(date)
166164

167165
declination = xp.asarray(declination, device=device)
168166
time_correction = xp.asarray(time_correction, device=device)
169167

168+
# solar_declination_angle returns degrees
169+
# TODO: deg2rad() is not part of the array API standard
170170
declination = xp.deg2rad(declination)
171171
latitudes = xp.deg2rad(latitudes)
172172

173173
sindec_sinlat = xp.sin(declination) * xp.sin(latitudes)
174174
cosdec_coslat = xp.cos(declination) * xp.cos(latitudes)
175175

176+
# solar hour angle [h.deg]
177+
# TODO: deg2rad() is not part of the array API standard
176178
solar_angle = xp.deg2rad((date.hour - 12) * 15 + longitudes + time_correction)
177179
zenith_angle = sindec_sinlat + cosdec_coslat * xp.cos(solar_angle)
178180

181+
# Clip negative values
179182
return xp.clip(zenith_angle, 0.0, None)
180183

181184

src/earthkit/meteo/solar/xarray/solar.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ def julian_day(date: xr.DataArray) -> xr.DataArray:
2828
-------
2929
xarray.DataArray
3030
Day of year as a fractional number. January 1st at 00:00 is 0.0.
31-
32-
Notes
33-
-----
34-
Xarray typically stores time values as ``numpy.datetime64``. The underlying
35-
array implementation must be able to handle that representation (or convert
36-
to ``datetime.datetime``).
3731
"""
3832
return xarray_ufunc(array.julian_day, date, xarray_ufunc_kwargs={"vectorize": True})
3933

@@ -153,12 +147,6 @@ def incoming_solar_radiation(date: xr.DataArray) -> xr.DataArray:
153147
-------
154148
xarray.DataArray
155149
Incoming solar radiation at TOA.
156-
157-
Notes
158-
-----
159-
Xarray typically stores time values as ``numpy.datetime64``. The underlying
160-
array implementation must be able to handle that representation (or convert
161-
to ``datetime.datetime``).
162150
"""
163151
return xarray_ufunc(array.incoming_solar_radiation, date, xarray_ufunc_kwargs={"vectorize": True})
164152

0 commit comments

Comments
 (0)