satpp 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- satpp/__init__.py +29 -0
- satpp/astronomy/__init__.py +10 -0
- satpp/astronomy/daylight.py +403 -0
- satpp/astronomy/solar.py +178 -0
- satpp/chlorophyll/__init__.py +12 -0
- satpp/chlorophyll/profiles.py +85 -0
- satpp/chlorophyll/size_classes.py +39 -0
- satpp/chlorophyll/uitz2006.py +101 -0
- satpp/config.py +60 -0
- satpp/diagnostics/__init__.py +10 -0
- satpp/diagnostics/light_fields.py +1038 -0
- satpp/diagnostics/model_pages.py +1046 -0
- satpp/hybrid.py +963 -0
- satpp/light/__init__.py +16 -0
- satpp/light/clear_sky.py +328 -0
- satpp/light/diurnal.py +59 -0
- satpp/light/spectra.py +31 -0
- satpp/light/surface.py +139 -0
- satpp/light/underwater.py +138 -0
- satpp/models/__init__.py +64 -0
- satpp/models/abpm.py +201 -0
- satpp/models/arrigo08.py +283 -0
- satpp/models/arteaga16.py +253 -0
- satpp/models/asanuma.py +179 -0
- satpp/models/asaoka20.py +140 -0
- satpp/models/balch92.py +120 -0
- satpp/models/barnes14.py +149 -0
- satpp/models/belanger13.py +118 -0
- satpp/models/brewin17.py +324 -0
- satpp/models/cafe.py +340 -0
- satpp/models/cbpm.py +171 -0
- satpp/models/cbpm05.py +135 -0
- satpp/models/dierssen00.py +87 -0
- satpp/models/drpp.py +156 -0
- satpp/models/eppley85.py +50 -0
- satpp/models/fox22.py +255 -0
- satpp/models/globcolour.py +121 -0
- satpp/models/goci_abpm.py +244 -0
- satpp/models/hill13.py +84 -0
- satpp/models/hirata09.py +46 -0
- satpp/models/hirawake.py +108 -0
- satpp/models/hoepffner94.py +191 -0
- satpp/models/howard_yoder.py +148 -0
- satpp/models/kahru09.py +54 -0
- satpp/models/kameda05.py +152 -0
- satpp/models/kiefer_mitchell.py +118 -0
- satpp/models/kosc_vgpm.py +164 -0
- satpp/models/ma14.py +150 -0
- satpp/models/marra03.py +187 -0
- satpp/models/morel91.py +164 -0
- satpp/models/morel_berthon89.py +82 -0
- satpp/models/ondrusek01.py +190 -0
- satpp/models/psm.py +122 -0
- satpp/models/smyth05.py +330 -0
- satpp/models/son05.py +204 -0
- satpp/models/tripathy12.py +64 -0
- satpp/models/uitz10.py +141 -0
- satpp/models/vgpm.py +80 -0
- satpp/models/wrm.py +376 -0
- satpp/models/zoffoli18.py +104 -0
- satpp/optics/__init__.py +28 -0
- satpp/optics/attenuation.py +174 -0
- satpp/optics/case1.py +108 -0
- satpp/optics/cdom.py +44 -0
- satpp/optics/euphotic.py +46 -0
- satpp/optics/phytoplankton.py +189 -0
- satpp/optics/retrieval.py +143 -0
- satpp/optics/water.py +193 -0
- satpp/physiology/__init__.py +14 -0
- satpp/physiology/photoacclimation.py +27 -0
- satpp/physiology/pi_curves.py +69 -0
- satpp/physiology/quantum_yield.py +52 -0
- satpp/physiology/temperature.py +25 -0
- satpp/units.py +25 -0
- satpp-0.2.0.dist-info/METADATA +80 -0
- satpp-0.2.0.dist-info/RECORD +78 -0
- satpp-0.2.0.dist-info/WHEEL +4 -0
- satpp-0.2.0.dist-info/licenses/LICENSE +21 -0
satpp/__init__.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Satellite primary production models.
|
|
2
|
+
|
|
3
|
+
Subpackages
|
|
4
|
+
-----------
|
|
5
|
+
astronomy
|
|
6
|
+
Solar geometry and day length.
|
|
7
|
+
light
|
|
8
|
+
Surface irradiance, its daily course and propagation with depth.
|
|
9
|
+
optics
|
|
10
|
+
Water, CDOM and phytoplankton optics, Case-1 IOPs, attenuation, euphotic depth.
|
|
11
|
+
chlorophyll
|
|
12
|
+
Vertical Chl profiles and phytoplankton size classes.
|
|
13
|
+
physiology
|
|
14
|
+
P-I curves, quantum yield, photoacclimation and temperature dependence.
|
|
15
|
+
models
|
|
16
|
+
One module per primary production model.
|
|
17
|
+
diagnostics
|
|
18
|
+
Tools that run several models side by side.
|
|
19
|
+
|
|
20
|
+
Modules
|
|
21
|
+
-------
|
|
22
|
+
hybrid
|
|
23
|
+
Mix-and-match of optics, light and physiology from PSM, CAFE, AbPM and WRM.
|
|
24
|
+
config
|
|
25
|
+
Default wavelength and depth grids of the PSM.
|
|
26
|
+
units
|
|
27
|
+
Unit conversions.
|
|
28
|
+
"""
|
|
29
|
+
__version__ = "0.2.0"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Solar geometry and day length.
|
|
2
|
+
|
|
3
|
+
Modules
|
|
4
|
+
-------
|
|
5
|
+
solar
|
|
6
|
+
Yearday-based geometry with the OSU/CAFE conventions, used by most models.
|
|
7
|
+
daylight
|
|
8
|
+
Datetime-based geometry and top-of-atmosphere irradiance, used by the PSM.
|
|
9
|
+
"""
|
|
10
|
+
from . import daylight, solar # noqa: F401
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"""Datetime-based solar geometry used by the PSM.
|
|
2
|
+
|
|
3
|
+
Declination follows Spencer (1971), the top-of-atmosphere irradiance follows
|
|
4
|
+
Thekaekara (1973), and ``daylength`` uses the Brock model (Forsythe et al. 1995).
|
|
5
|
+
Times are local solar time taken from the datetime.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
import pandas as pd
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def all(dtm, lat):
|
|
13
|
+
"""Top-of-atmosphere irradiance, sunrise, day length and zenith angle.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
dtm : datetime-like
|
|
18
|
+
Date and local solar time.
|
|
19
|
+
lat : float
|
|
20
|
+
Latitude [degrees north].
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
dict
|
|
25
|
+
``TOA_Irr`` [W m-2], ``sunrise`` (Timestamp), ``daylength`` [h, Brock model]
|
|
26
|
+
and ``zenith_rad`` [rad] at `dtm`.
|
|
27
|
+
"""
|
|
28
|
+
dtm = pd.to_datetime(dtm)
|
|
29
|
+
sunr = sunrise(dtm, lat)
|
|
30
|
+
return dict(
|
|
31
|
+
TOA_Irr = thekaekara(dtm),
|
|
32
|
+
sunrise = sunr,
|
|
33
|
+
daylength = daylength(dtm, lat),
|
|
34
|
+
zenith_rad = zenith(dtm, lat)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def time_of_day(dtm):
|
|
38
|
+
"""Decimal hour of a datetime.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
dtm : datetime-like
|
|
43
|
+
Date and time.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
float
|
|
48
|
+
Hour of the day [h].
|
|
49
|
+
"""
|
|
50
|
+
dtm = pd.to_datetime(dtm)
|
|
51
|
+
#return dtm.hour/24 + dtm.minute/60/24 + dtm.second/60/60/24
|
|
52
|
+
return dtm.hour + dtm.minute/60 + dtm.second/60/60
|
|
53
|
+
|
|
54
|
+
def thekaekara(dtm):
|
|
55
|
+
"""Top-of-atmosphere solar irradiance for the day of the year.
|
|
56
|
+
|
|
57
|
+
Linear interpolation in the Thekaekara (1973) table.
|
|
58
|
+
|
|
59
|
+
Parameters
|
|
60
|
+
----------
|
|
61
|
+
dtm : datetime-like
|
|
62
|
+
Date.
|
|
63
|
+
|
|
64
|
+
Returns
|
|
65
|
+
-------
|
|
66
|
+
float
|
|
67
|
+
Solar irradiance [W m-2].
|
|
68
|
+
"""
|
|
69
|
+
dtm = pd.to_datetime(dtm)
|
|
70
|
+
jday = dtm.day_of_year
|
|
71
|
+
day_points = [
|
|
72
|
+
0., 3., 31., 42., 59., 78., 90., 93., 120., 133., 151., 170.,
|
|
73
|
+
181., 183., 206., 212., 243., 265., 273., 277., 304., 306.,
|
|
74
|
+
334., 355., 365.
|
|
75
|
+
]
|
|
76
|
+
ir_points = [
|
|
77
|
+
1399., 1399., 1393., 1389., 1378., 1364., 1355., 1353.,
|
|
78
|
+
1332., 1324., 1316., 1310., 1309., 1309., 1312., 1313.,
|
|
79
|
+
1329., 1344., 1350., 1353., 1347., 1375., 1392., 1398., 1399.
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
# Linear interpolation in the table. (The loop used to compare the index i with jday
|
|
83
|
+
# instead of day_points[i], so from late January on it extrapolated the last
|
|
84
|
+
# segment;
|
|
85
|
+
# the error cancels when the spectrum is scaled to daily PAR.)
|
|
86
|
+
return float(np.interp(jday, day_points, ir_points))
|
|
87
|
+
|
|
88
|
+
def delta(dtm):
|
|
89
|
+
"""Solar declination (Spencer 1971).
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
dtm : datetime-like
|
|
94
|
+
Date.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
float
|
|
99
|
+
Declination [rad].
|
|
100
|
+
"""
|
|
101
|
+
dtm = pd.to_datetime(dtm)
|
|
102
|
+
day_of_year = dtm.day_of_year
|
|
103
|
+
theta = (2 * np.pi * day_of_year) / 365.
|
|
104
|
+
delta = (0.006918 -
|
|
105
|
+
0.399912 * np.cos(theta) +
|
|
106
|
+
0.070257 * np.sin(theta) -
|
|
107
|
+
0.006758 * np.cos(2. * theta) +
|
|
108
|
+
0.000907 * np.sin(2. * theta) -
|
|
109
|
+
0.002697 * np.cos(3. * theta) +
|
|
110
|
+
0.001480 * np.sin(3. * theta))
|
|
111
|
+
return delta
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def zenith(dtm, lat):
|
|
116
|
+
"""Solar zenith angle at a given date and local solar time.
|
|
117
|
+
|
|
118
|
+
Parameters
|
|
119
|
+
----------
|
|
120
|
+
dtm : datetime-like
|
|
121
|
+
Date and local solar time.
|
|
122
|
+
lat : float
|
|
123
|
+
Latitude [degrees north].
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
float
|
|
128
|
+
Zenith angle [rad].
|
|
129
|
+
"""
|
|
130
|
+
dtm = pd.to_datetime(dtm)
|
|
131
|
+
tod = time_of_day(dtm)
|
|
132
|
+
dlt = delta(dtm)
|
|
133
|
+
phi = np.deg2rad(lat)
|
|
134
|
+
th = (tod - 12) * (np.pi / 12)
|
|
135
|
+
zen = np.sin(dlt) * np.sin(phi) + np.cos(dlt) * np.cos(phi) * np.cos(th)
|
|
136
|
+
zen = np.maximum(zen, -1)
|
|
137
|
+
zen = np.minimum(zen, 1)
|
|
138
|
+
return (np.pi / 2.) - np.asin(zen)
|
|
139
|
+
|
|
140
|
+
def zenith_time(dtm, lat, zenith_deg, return_dtm=True):
|
|
141
|
+
"""Morning time at which the sun reaches a given zenith angle.
|
|
142
|
+
|
|
143
|
+
Parameters
|
|
144
|
+
----------
|
|
145
|
+
dtm : datetime-like
|
|
146
|
+
Date.
|
|
147
|
+
lat : float
|
|
148
|
+
Latitude [degrees north].
|
|
149
|
+
zenith_deg : float or ndarray
|
|
150
|
+
Zenith angle [degrees].
|
|
151
|
+
return_dtm : bool, optional
|
|
152
|
+
Return a Timestamp (default) instead of a decimal hour.
|
|
153
|
+
|
|
154
|
+
Returns
|
|
155
|
+
-------
|
|
156
|
+
Timestamp, float, ndarray or None
|
|
157
|
+
Time before noon at which the zenith angle is `zenith_deg`. For a scalar
|
|
158
|
+
angle the sun never reaches, None (or -1.0 if `return_dtm` is False). For an
|
|
159
|
+
array, decimal hours with -1 where the angle is never reached and 0 where the
|
|
160
|
+
sun never sets.
|
|
161
|
+
"""
|
|
162
|
+
dtm = pd.to_datetime(dtm)
|
|
163
|
+
dlt = delta(dtm)
|
|
164
|
+
phi = np.deg2rad(lat)
|
|
165
|
+
zenith_rad = np.deg2rad(zenith_deg)
|
|
166
|
+
cos_theta = ((np.cos(zenith_rad) - (np.sin(dlt) * np.sin(phi))) /
|
|
167
|
+
(np.cos(dlt) * np.cos(phi)))
|
|
168
|
+
theta_1 = np.arccos(cos_theta)
|
|
169
|
+
|
|
170
|
+
def scalar_theta2time(theta_1):
|
|
171
|
+
"""Convert one hour angle to a time.
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
theta_1 : float
|
|
176
|
+
Hour angle [rad].
|
|
177
|
+
|
|
178
|
+
Returns
|
|
179
|
+
-------
|
|
180
|
+
Timestamp, float or None
|
|
181
|
+
Time of day, as described in `zenith_time`.
|
|
182
|
+
"""
|
|
183
|
+
if cos_theta <= -1.0:
|
|
184
|
+
local_time = 0.0
|
|
185
|
+
elif cos_theta >= 1.0:
|
|
186
|
+
# The sun never gets this close to the zenith on this day
|
|
187
|
+
return None if return_dtm else -1.0
|
|
188
|
+
else:
|
|
189
|
+
local_time = 12.0 + (theta_1 / (np.pi / 12.0))
|
|
190
|
+
if local_time > 12.0 :
|
|
191
|
+
local_time = 24.0 - local_time
|
|
192
|
+
if return_dtm:
|
|
193
|
+
return decimal_hour_to_dtm(dtm, local_time)
|
|
194
|
+
return local_time
|
|
195
|
+
|
|
196
|
+
def array_theta2time(theta_1):
|
|
197
|
+
"""Convert an array of hour angles to decimal hours.
|
|
198
|
+
|
|
199
|
+
Parameters
|
|
200
|
+
----------
|
|
201
|
+
theta_1 : ndarray
|
|
202
|
+
Hour angles [rad].
|
|
203
|
+
|
|
204
|
+
Returns
|
|
205
|
+
-------
|
|
206
|
+
ndarray
|
|
207
|
+
Decimal hours, as described in `zenith_time`.
|
|
208
|
+
"""
|
|
209
|
+
local_time = 12.0 + (theta_1 / (np.pi / 12.0))
|
|
210
|
+
local_time[cos_theta <= -1.0] = 0
|
|
211
|
+
local_time[cos_theta >= 1.0] = -1
|
|
212
|
+
local_time[local_time > 12.0] = 24.0 - local_time[local_time > 12.0]
|
|
213
|
+
return local_time
|
|
214
|
+
|
|
215
|
+
try:
|
|
216
|
+
return array_theta2time(theta_1)
|
|
217
|
+
except TypeError:
|
|
218
|
+
return scalar_theta2time(theta_1)
|
|
219
|
+
|
|
220
|
+
def decimal_hour_to_dtm(dtm, hour):
|
|
221
|
+
"""Combine a date and a decimal hour into a Timestamp.
|
|
222
|
+
|
|
223
|
+
Parameters
|
|
224
|
+
----------
|
|
225
|
+
dtm : Timestamp
|
|
226
|
+
Date.
|
|
227
|
+
hour : float
|
|
228
|
+
Decimal hour [h].
|
|
229
|
+
|
|
230
|
+
Returns
|
|
231
|
+
-------
|
|
232
|
+
Timestamp
|
|
233
|
+
Date at the given hour, to the second.
|
|
234
|
+
"""
|
|
235
|
+
mn,hr = np.modf(hour)
|
|
236
|
+
sc,mn = np.modf(mn*60)
|
|
237
|
+
_, sc = np.modf(sc*60)
|
|
238
|
+
return dtm.normalize() + pd.Timedelta(f'{hr:02.0f}:{mn:02.0f}:{sc:02.0f}')
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def sunrise(dtm, lat, return_dtm=True, return_all=False):
|
|
242
|
+
"""Time of sunrise.
|
|
243
|
+
|
|
244
|
+
Parameters
|
|
245
|
+
----------
|
|
246
|
+
dtm : datetime-like
|
|
247
|
+
Date.
|
|
248
|
+
lat : float
|
|
249
|
+
Latitude [degrees north].
|
|
250
|
+
return_dtm : bool, optional
|
|
251
|
+
Return a Timestamp (default) instead of a decimal hour.
|
|
252
|
+
return_all : bool, optional
|
|
253
|
+
Also return the declination and the latitude in radians.
|
|
254
|
+
|
|
255
|
+
Returns
|
|
256
|
+
-------
|
|
257
|
+
sunrise : Timestamp or float
|
|
258
|
+
Time of sunrise.
|
|
259
|
+
delta : float
|
|
260
|
+
Declination [rad], only if `return_all` is True.
|
|
261
|
+
phi : float
|
|
262
|
+
Latitude [rad], only if `return_all` is True.
|
|
263
|
+
"""
|
|
264
|
+
dtm = pd.to_datetime(dtm)
|
|
265
|
+
phi = np.deg2rad(lat)
|
|
266
|
+
phidel = -np.tan(phi) * np.tan(delta(dtm))
|
|
267
|
+
phidel = np.maximum(phidel, -1)
|
|
268
|
+
phidel = np.minimum(phidel, 1)
|
|
269
|
+
srise = 12 - np.rad2deg(np.arccos(phidel)) / 15
|
|
270
|
+
if return_dtm:
|
|
271
|
+
srise = decimal_hour_to_dtm(dtm, srise)
|
|
272
|
+
if return_all:
|
|
273
|
+
return srise, delta(dtm), phi
|
|
274
|
+
else:
|
|
275
|
+
return srise
|
|
276
|
+
|
|
277
|
+
def time_range(dtm, lat, steps=12, zenith_deg=None):
|
|
278
|
+
"""Equally spaced times between sunrise and the symmetric afternoon time.
|
|
279
|
+
|
|
280
|
+
Parameters
|
|
281
|
+
----------
|
|
282
|
+
dtm : datetime-like
|
|
283
|
+
Date.
|
|
284
|
+
lat : float
|
|
285
|
+
Latitude [degrees north].
|
|
286
|
+
steps : int, optional
|
|
287
|
+
Number of times. Default 12.
|
|
288
|
+
zenith_deg : float, optional
|
|
289
|
+
Start when the sun reaches this zenith angle instead of at sunrise.
|
|
290
|
+
|
|
291
|
+
Returns
|
|
292
|
+
-------
|
|
293
|
+
DatetimeIndex
|
|
294
|
+
Times from the start to its mirror image about noon.
|
|
295
|
+
"""
|
|
296
|
+
dtm = pd.to_datetime(dtm)
|
|
297
|
+
dtm1 = None if zenith_deg is None else zenith_time(dtm, lat, zenith_deg)
|
|
298
|
+
if dtm1 is None:
|
|
299
|
+
# no zenith limit, or the sun never reaches zenith_deg: start at sunrise
|
|
300
|
+
dtm1 = sunrise(dtm, lat)
|
|
301
|
+
noon = dtm.normalize() + pd.Timedelta('12:00:00')
|
|
302
|
+
return pd.date_range(dtm1, noon+(noon-dtm1), periods=steps)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def daylength_hours(dtm, lat):
|
|
307
|
+
"""Day length consistent with `sunrise`.
|
|
308
|
+
|
|
309
|
+
Parameters
|
|
310
|
+
----------
|
|
311
|
+
dtm : datetime-like
|
|
312
|
+
Date.
|
|
313
|
+
lat : float
|
|
314
|
+
Latitude [degrees north].
|
|
315
|
+
|
|
316
|
+
Returns
|
|
317
|
+
-------
|
|
318
|
+
float
|
|
319
|
+
Day length [h], ``2 (12 - sunrise)``.
|
|
320
|
+
"""
|
|
321
|
+
return 2 * (12 - sunrise(dtm, lat, return_dtm=False))
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def time_midpoints(dtm, lat, steps=12):
|
|
325
|
+
"""Mid-points of equal intervals between sunrise and sunset.
|
|
326
|
+
|
|
327
|
+
Integrating a rate over these times with the midpoint rule gives a daily total,
|
|
328
|
+
and `satpp.light.surface.instant` never sees sunrise or sunset exactly.
|
|
329
|
+
|
|
330
|
+
Parameters
|
|
331
|
+
----------
|
|
332
|
+
dtm : datetime-like
|
|
333
|
+
Date.
|
|
334
|
+
lat : float
|
|
335
|
+
Latitude [degrees north].
|
|
336
|
+
steps : int, optional
|
|
337
|
+
Number of intervals. Default 12.
|
|
338
|
+
|
|
339
|
+
Returns
|
|
340
|
+
-------
|
|
341
|
+
times : DatetimeIndex
|
|
342
|
+
Interval mid-points.
|
|
343
|
+
dt_h : float
|
|
344
|
+
Interval length [h].
|
|
345
|
+
"""
|
|
346
|
+
dtm = pd.to_datetime(dtm)
|
|
347
|
+
sr = sunrise(dtm, lat)
|
|
348
|
+
dl = daylength_hours(dtm, lat)
|
|
349
|
+
frac = (np.arange(steps) + 0.5) / steps
|
|
350
|
+
return pd.DatetimeIndex([sr + pd.Timedelta(hours=f * dl) for f in frac]), dl / steps
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def daylength(dtm, lat):
|
|
354
|
+
"""Day length with the Brock model.
|
|
355
|
+
|
|
356
|
+
Parameters
|
|
357
|
+
----------
|
|
358
|
+
dtm : datetime-like
|
|
359
|
+
Date.
|
|
360
|
+
lat : float or array_like
|
|
361
|
+
Latitude [degrees north].
|
|
362
|
+
|
|
363
|
+
Returns
|
|
364
|
+
-------
|
|
365
|
+
float or ndarray
|
|
366
|
+
Day length [h]; 24 under the midnight sun and 0 in polar night.
|
|
367
|
+
|
|
368
|
+
References
|
|
369
|
+
----------
|
|
370
|
+
Forsythe, W. C. et al. (1995). A model comparison for daylength as a function of
|
|
371
|
+
latitude and day of year. Ecological Modelling, 80, 87-95.
|
|
372
|
+
"""
|
|
373
|
+
dtm = pd.to_datetime(dtm)
|
|
374
|
+
day_of_year = dtm.day_of_year
|
|
375
|
+
latInRad = np.deg2rad(lat)
|
|
376
|
+
declinationOfEarth = 23.45*np.sin(np.deg2rad(360.0*(283.0+day_of_year)/365.0))
|
|
377
|
+
mask = -np.tan(latInRad) * np.tan(np.deg2rad(declinationOfEarth))
|
|
378
|
+
hourAngle = np.rad2deg(
|
|
379
|
+
np.arccos(-np.tan(latInRad) * np.tan(np.deg2rad(declinationOfEarth))))
|
|
380
|
+
day_hours = np.atleast_1d(2.0*hourAngle/15.0)
|
|
381
|
+
day_hours[mask<=-1.0] = 24.0
|
|
382
|
+
day_hours[mask>= 1.0] = 0
|
|
383
|
+
day_hours = np.squeeze(day_hours)
|
|
384
|
+
return day_hours.item() if day_hours.ndim==0 else day_hours
|
|
385
|
+
#return 2 * (12. - sunrise(dtm, lat, return_dtm=False))
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
#def mns_to_doy(mnlist):
|
|
389
|
+
# """_summary_
|
|
390
|
+
#
|
|
391
|
+
# Parameters
|
|
392
|
+
# ----------
|
|
393
|
+
# mnlist
|
|
394
|
+
# list of months to convert
|
|
395
|
+
#
|
|
396
|
+
# Returns
|
|
397
|
+
# -------
|
|
398
|
+
# _description_
|
|
399
|
+
# """
|
|
400
|
+
# mnlen = [31,28,31,30,31,30,31,31,30,31,30,31]
|
|
401
|
+
# np.cumsum(mnlen) - 15
|
|
402
|
+
# cmnlen = np.cumsum(mnlen) - 15
|
|
403
|
+
# return cmnlen[mnlist-1]
|
satpp/astronomy/solar.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""Solar geometry from latitude and yearday.
|
|
2
|
+
|
|
3
|
+
The functions follow the conventions of the OSU/CAFE C code: the declination is
|
|
4
|
+
``23.5 cos(2 pi (yd - 172) / 365)`` degrees, there is no equation of time, and
|
|
5
|
+
hours are local solar time (noon = 12). For datetime-based geometry with the
|
|
6
|
+
Thekaekara top-of-atmosphere irradiance, used by the PSM surface-light model, see
|
|
7
|
+
`satpp.astronomy.daylight`.
|
|
8
|
+
"""
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def declination_rad(yd):
|
|
13
|
+
"""Solar declination with the OSU/CAFE formula.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
yd : float or array_like
|
|
18
|
+
Day of the year.
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
-------
|
|
22
|
+
float or ndarray
|
|
23
|
+
Declination [rad].
|
|
24
|
+
"""
|
|
25
|
+
return 23.5 * np.cos(2 * np.pi * (yd - 172) / 365) * np.pi / 180
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def daylength_days(lat, yd):
|
|
29
|
+
"""Day length as a fraction of a day.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
lat : float or array_like
|
|
34
|
+
Latitude [degrees north].
|
|
35
|
+
yd : float or array_like
|
|
36
|
+
Day of the year.
|
|
37
|
+
|
|
38
|
+
Returns
|
|
39
|
+
-------
|
|
40
|
+
float or ndarray
|
|
41
|
+
Day length [d], between 0 (polar night) and 1 (midnight sun).
|
|
42
|
+
"""
|
|
43
|
+
x = np.clip(-np.tan(np.deg2rad(lat)) * np.tan(declination_rad(yd)), -1, 1)
|
|
44
|
+
return np.arccos(x) / np.pi
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def daylength_hours(lat, yd):
|
|
48
|
+
"""Day length in hours.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
lat : float
|
|
53
|
+
Latitude [degrees north].
|
|
54
|
+
yd : float
|
|
55
|
+
Day of the year.
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
float
|
|
60
|
+
Day length [h].
|
|
61
|
+
"""
|
|
62
|
+
return float(daylength_days(lat, yd) * 24.0)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def sun_times(lat, yd):
|
|
66
|
+
"""Sunrise and sunset in local solar time.
|
|
67
|
+
|
|
68
|
+
Parameters
|
|
69
|
+
----------
|
|
70
|
+
lat : float
|
|
71
|
+
Latitude [degrees north].
|
|
72
|
+
yd : float
|
|
73
|
+
Day of the year.
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
-------
|
|
77
|
+
sunrise, sunset : float
|
|
78
|
+
Times [h], symmetric about noon.
|
|
79
|
+
"""
|
|
80
|
+
half = daylength_hours(lat, yd) / 2
|
|
81
|
+
return 12.0 - half, 12.0 + half
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def noon_zenith_deg(lat, yd):
|
|
85
|
+
"""Solar zenith angle at local noon.
|
|
86
|
+
|
|
87
|
+
The C code's construction with ``cos(pi)`` reduces to ``|lat - declination|``.
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
lat : float
|
|
92
|
+
Latitude [degrees north].
|
|
93
|
+
yd : float
|
|
94
|
+
Day of the year.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
float
|
|
99
|
+
Zenith angle [degrees].
|
|
100
|
+
"""
|
|
101
|
+
return abs(lat - np.rad2deg(declination_rad(yd)))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def solar_zenith_deg(lat, yd, hour):
|
|
105
|
+
"""Solar zenith angle at a given local solar time.
|
|
106
|
+
|
|
107
|
+
Parameters
|
|
108
|
+
----------
|
|
109
|
+
lat : float
|
|
110
|
+
Latitude [degrees north].
|
|
111
|
+
yd : float
|
|
112
|
+
Day of the year.
|
|
113
|
+
hour : float or array_like
|
|
114
|
+
Local solar time [h].
|
|
115
|
+
|
|
116
|
+
Returns
|
|
117
|
+
-------
|
|
118
|
+
float or ndarray
|
|
119
|
+
Zenith angle [degrees]; values above 90 mean the sun is below the horizon.
|
|
120
|
+
"""
|
|
121
|
+
decl = declination_rad(yd)
|
|
122
|
+
phi = np.deg2rad(lat)
|
|
123
|
+
h = np.deg2rad(15.0 * (np.asarray(hour, float) - 12.0))
|
|
124
|
+
cosz = np.sin(phi) * np.sin(decl) + np.cos(phi) * np.cos(decl) * np.cos(h)
|
|
125
|
+
return np.rad2deg(np.arccos(np.clip(cosz, -1, 1)))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def solar_cosine(lat, yd, frac):
|
|
129
|
+
"""Cosine of the solar zenith angle at fractions of the photoperiod.
|
|
130
|
+
|
|
131
|
+
Parameters
|
|
132
|
+
----------
|
|
133
|
+
lat : float
|
|
134
|
+
Latitude [degrees north].
|
|
135
|
+
yd : float
|
|
136
|
+
Day of the year.
|
|
137
|
+
frac : float or array_like
|
|
138
|
+
Fraction of the photoperiod, 0 at sunrise and 1 at sunset.
|
|
139
|
+
|
|
140
|
+
Returns
|
|
141
|
+
-------
|
|
142
|
+
float or ndarray
|
|
143
|
+
Cosine of the zenith angle, clipped to [0, 1].
|
|
144
|
+
"""
|
|
145
|
+
decl = declination_rad(yd)
|
|
146
|
+
phi = np.deg2rad(lat)
|
|
147
|
+
h0 = np.arccos(np.clip(-np.tan(phi) * np.tan(decl), -1, 1))
|
|
148
|
+
h = -h0 + 2 * h0 * np.asarray(frac, float)
|
|
149
|
+
return np.clip(np.sin(phi) * np.sin(decl) + np.cos(phi) * np.cos(decl) * np.cos(h),
|
|
150
|
+
0, 1)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def mean_daylight_zenith_deg(lat, yd, n=200):
|
|
154
|
+
"""Mean solar zenith angle over the daylight hours.
|
|
155
|
+
|
|
156
|
+
Parameters
|
|
157
|
+
----------
|
|
158
|
+
lat : float
|
|
159
|
+
Latitude [degrees north].
|
|
160
|
+
yd : float
|
|
161
|
+
Day of the year.
|
|
162
|
+
n : int, optional
|
|
163
|
+
Number of hour angles between sunrise and sunset. Default 200.
|
|
164
|
+
|
|
165
|
+
Returns
|
|
166
|
+
-------
|
|
167
|
+
float
|
|
168
|
+
Mean zenith angle [degrees]; 90 during polar night.
|
|
169
|
+
"""
|
|
170
|
+
decl = declination_rad(yd)
|
|
171
|
+
phi = np.deg2rad(lat)
|
|
172
|
+
x = np.clip(-np.tan(phi) * np.tan(decl), -1, 1)
|
|
173
|
+
h0 = np.arccos(x) # half-day hour angle
|
|
174
|
+
if h0 <= 0:
|
|
175
|
+
return 90.0
|
|
176
|
+
h = np.linspace(-h0, h0, n)
|
|
177
|
+
cosz = np.sin(phi) * np.sin(decl) + np.cos(phi) * np.cos(decl) * np.cos(h)
|
|
178
|
+
return float(np.rad2deg(np.arccos(np.clip(cosz, -1, 1))).mean())
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Chlorophyll: vertical profiles and phytoplankton size classes.
|
|
2
|
+
|
|
3
|
+
Modules
|
|
4
|
+
-------
|
|
5
|
+
profiles
|
|
6
|
+
Shifted-Gaussian profiles (Platt et al. 1988) and the PSM surface-scaled form.
|
|
7
|
+
size_classes
|
|
8
|
+
Pico, nano and micro fractions of Chl (Brewin et al. 2010).
|
|
9
|
+
uitz2006
|
|
10
|
+
Size-class Chl profiles by trophic class (Uitz et al. 2006).
|
|
11
|
+
"""
|
|
12
|
+
from . import profiles, size_classes, uitz2006 # noqa: F401
|