PythonicDISORT 0.7.0__py3-none-any.whl → 0.8.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.
- PythonicDISORT/_assemble_intensity_and_fluxes.py +181 -53
- PythonicDISORT/_solve_for_coeffs.py +3 -3
- PythonicDISORT/_solve_for_gen_and_part_sols.py +16 -14
- PythonicDISORT/pydisort.py +173 -96
- PythonicDISORT/subroutines.py +40 -24
- {PythonicDISORT-0.7.0.dist-info → PythonicDISORT-0.8.0.dist-info}/METADATA +25 -25
- PythonicDISORT-0.8.0.dist-info/RECORD +11 -0
- PythonicDISORT-0.7.0.dist-info/RECORD +0 -11
- {PythonicDISORT-0.7.0.dist-info → PythonicDISORT-0.8.0.dist-info}/LICENSE.md +0 -0
- {PythonicDISORT-0.7.0.dist-info → PythonicDISORT-0.8.0.dist-info}/WHEEL +0 -0
- {PythonicDISORT-0.7.0.dist-info → PythonicDISORT-0.8.0.dist-info}/top_level.txt +0 -0
|
@@ -28,9 +28,9 @@ def _assemble_intensity_and_fluxes(
|
|
|
28
28
|
NLayers_to_use_sparse, # Number of layers above or equal which to use sparse matrices
|
|
29
29
|
_autograd_compatible, # Should the output functions be compatible with autograd?
|
|
30
30
|
):
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
"""Assembles the solution functions: intensity `u`, upward flux `flux_up`, downward flux `flux_down`
|
|
32
|
+
from the previously solved eigenpairs and coefficients from the boundary conditions.
|
|
33
|
+
Returns these solution functions.
|
|
34
34
|
This function is wrapped by the `pydisort` function.
|
|
35
35
|
It should be called through `pydisort` and never directly.
|
|
36
36
|
It has many seemingly redundant arguments, which are described below,
|
|
@@ -161,7 +161,15 @@ def _assemble_intensity_and_fluxes(
|
|
|
161
161
|
|
|
162
162
|
# Construct the intensity function (refer to Section 3.7 of the Comprehensive Documentation)
|
|
163
163
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
164
|
-
def u(tau, phi, return_Fourier_error=False):
|
|
164
|
+
def u(tau, phi, return_Fourier_error=False, is_antiderivative_wrt_tau=False):
|
|
165
|
+
"""
|
|
166
|
+
Intensity function with arguments `(tau, phi)` of types `(array or float, array or float)`.
|
|
167
|
+
Returns an ndarray with axes corresponding to variation with `mu, tau, phi` respectively.
|
|
168
|
+
Pass `return_Fourier_error = True` (defaults to `False`) to return the
|
|
169
|
+
Cauchy / Fourier convergence evaluation (type: float) for the last Fourier term.
|
|
170
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
171
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
172
|
+
"""
|
|
165
173
|
tau = np.atleast_1d(tau)
|
|
166
174
|
phi = np.atleast_1d(phi)
|
|
167
175
|
assert np.all(tau >= 0)
|
|
@@ -179,7 +187,7 @@ def _assemble_intensity_and_fluxes(
|
|
|
179
187
|
scaled_tau = scaled_tau_arr_l - scaled_tau_dist_from_top
|
|
180
188
|
else:
|
|
181
189
|
scaled_tau = tau
|
|
182
|
-
|
|
190
|
+
|
|
183
191
|
exponent = np.concatenate(
|
|
184
192
|
[
|
|
185
193
|
K_collect[:, l, :N] * (scaled_tau - scaled_tau_arr_lm1)[None, :, None],
|
|
@@ -187,14 +195,33 @@ def _assemble_intensity_and_fluxes(
|
|
|
187
195
|
],
|
|
188
196
|
axis=-1,
|
|
189
197
|
)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
198
|
+
|
|
199
|
+
if is_antiderivative_wrt_tau:
|
|
200
|
+
if there_is_beam_source:
|
|
201
|
+
um = np.einsum(
|
|
202
|
+
"mtij, mtj -> mti",
|
|
203
|
+
GC_collect[:, l, :, :],
|
|
204
|
+
np.exp(exponent) / (scale_tau[None, l, None] * K_collect[:, l, :]),
|
|
205
|
+
optimize=True,
|
|
206
|
+
) + B_collect[:, l, :] * np.exp(-scaled_tau[None, :, None] / mu0) / (
|
|
207
|
+
-scale_tau[None, l, None] / mu0
|
|
208
|
+
)
|
|
209
|
+
else:
|
|
210
|
+
um = np.einsum(
|
|
211
|
+
"mtij, mtj -> mti",
|
|
212
|
+
GC_collect[:, l, :, :],
|
|
213
|
+
np.exp(exponent) / (scale_tau[None, l, None] * K_collect[:, l, :]),
|
|
214
|
+
optimize=True,
|
|
215
|
+
)
|
|
194
216
|
else:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
217
|
+
if there_is_beam_source:
|
|
218
|
+
um = np.einsum(
|
|
219
|
+
"mtij, mtj -> mti", GC_collect[:, l, :, :], np.exp(exponent), optimize=True
|
|
220
|
+
) + B_collect[:, l, :] * np.exp(-scaled_tau[None, :, None] / mu0)
|
|
221
|
+
else:
|
|
222
|
+
um = np.einsum(
|
|
223
|
+
"mtij, mtj -> mti", GC_collect[:, l, :, :], np.exp(exponent), optimize=True
|
|
224
|
+
)
|
|
198
225
|
|
|
199
226
|
# Contribution from particular solution for isotropic internal sources
|
|
200
227
|
if there_is_iso_source:
|
|
@@ -207,6 +234,7 @@ def _assemble_intensity_and_fluxes(
|
|
|
207
234
|
G_inv_collect_0,
|
|
208
235
|
mu_arr,
|
|
209
236
|
_autograd_compatible,
|
|
237
|
+
is_antiderivative_wrt_tau
|
|
210
238
|
)
|
|
211
239
|
|
|
212
240
|
if _autograd_compatible:
|
|
@@ -229,20 +257,43 @@ def _assemble_intensity_and_fluxes(
|
|
|
229
257
|
],
|
|
230
258
|
axis=-1,
|
|
231
259
|
)
|
|
232
|
-
if
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
260
|
+
if is_antiderivative_wrt_tau:
|
|
261
|
+
if there_is_beam_source:
|
|
262
|
+
ulast = np.einsum(
|
|
263
|
+
"tij, tj -> it",
|
|
264
|
+
GC_collect[-1, l, :, :],
|
|
265
|
+
np.exp(exponent) / (scale_tau[l, None] * K_collect[-1, l, :]),
|
|
266
|
+
optimize=True,
|
|
267
|
+
) + B_collect[-1, l, :].T * np.exp(-scaled_tau[None, :] / mu0) / (
|
|
268
|
+
-scale_tau[None, l] / mu0
|
|
269
|
+
)
|
|
270
|
+
else:
|
|
271
|
+
ulast = np.einsum(
|
|
272
|
+
"tij, tj -> it",
|
|
273
|
+
GC_collect[-1, l, :, :],
|
|
274
|
+
np.exp(exponent) / (scale_tau[l, None] * K_collect[-1, l, :]),
|
|
275
|
+
optimize=True,
|
|
276
|
+
)
|
|
236
277
|
else:
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
278
|
+
if there_is_beam_source:
|
|
279
|
+
ulast = np.einsum(
|
|
280
|
+
"tij, tj -> it", GC_collect[-1, l, :, :], np.exp(exponent), optimize=True
|
|
281
|
+
) + B_collect[-1, l, :].T * np.exp(-scaled_tau[None, :] / mu0)
|
|
282
|
+
else:
|
|
283
|
+
ulast = np.einsum(
|
|
284
|
+
"tij, tj -> it", GC_collect[-1, l, :, :], np.exp(exponent), optimize=True
|
|
285
|
+
)
|
|
286
|
+
|
|
240
287
|
intensities_abs = np.abs(intensities)
|
|
241
288
|
Fourier_error = np.max(
|
|
242
|
-
np.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
289
|
+
np.divide(
|
|
290
|
+
np.abs(
|
|
291
|
+
ulast[:, :, None] * np.cos((NFourier - 1) * (phi0 - phi))[None, None, :]
|
|
292
|
+
),
|
|
293
|
+
intensities_abs,
|
|
294
|
+
out=np.zeros_like(intensities_abs),
|
|
295
|
+
where=intensities_abs > 1e-8,
|
|
296
|
+
)
|
|
246
297
|
)
|
|
247
298
|
return I0_orig * np.squeeze(intensities), Fourier_error
|
|
248
299
|
else:
|
|
@@ -251,7 +302,16 @@ def _assemble_intensity_and_fluxes(
|
|
|
251
302
|
|
|
252
303
|
# Construct u0
|
|
253
304
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
254
|
-
def u0(tau,
|
|
305
|
+
def u0(tau, is_antiderivative_wrt_tau=False, _return_act_dscale_for_reclass=False):
|
|
306
|
+
"""
|
|
307
|
+
Zeroth Fourier mode of the intensity with argument `tau` (type: array or float).
|
|
308
|
+
Returns an ndarray with axes corresponding to variation with `mu` and `tau` respectively.
|
|
309
|
+
This function is useful for calculating actinic fluxes and other quantities of interest,
|
|
310
|
+
but reclassification of delta-scaled flux and other corrections must be done manually
|
|
311
|
+
(for actinic flux `generate_diff_act_flux_funcs` will automatically perform the reclassification).
|
|
312
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
313
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
314
|
+
"""
|
|
255
315
|
tau = np.atleast_1d(tau)
|
|
256
316
|
assert np.all(tau >= 0)
|
|
257
317
|
assert np.all(tau <= tau_arr[-1])
|
|
@@ -268,11 +328,14 @@ def _assemble_intensity_and_fluxes(
|
|
|
268
328
|
scaled_tau = scaled_tau_arr_l - scaled_tau_dist_from_top
|
|
269
329
|
# The following complements the function `subroutines.generate_diff_act_flux_funcs`
|
|
270
330
|
# in performing the reclassification of delta-scaled actinic flux
|
|
271
|
-
if
|
|
272
|
-
|
|
331
|
+
if _return_act_dscale_for_reclass:
|
|
332
|
+
if is_antiderivative_wrt_tau:
|
|
333
|
+
act_dscale_reclassification = I0 * np.exp(-scaled_tau / mu0) / (-scale_tau[l] / mu0) - I0 * np.exp(-tau / mu0) * -mu0
|
|
334
|
+
else:
|
|
335
|
+
act_dscale_reclassification = I0 * np.exp(-scaled_tau / mu0) - I0 * np.exp(-tau / mu0)
|
|
273
336
|
else:
|
|
274
337
|
scaled_tau = tau
|
|
275
|
-
if
|
|
338
|
+
if _return_act_dscale_for_reclass:
|
|
276
339
|
act_dscale_reclassification = 0
|
|
277
340
|
|
|
278
341
|
exponent = np.concatenate(
|
|
@@ -282,14 +345,33 @@ def _assemble_intensity_and_fluxes(
|
|
|
282
345
|
],
|
|
283
346
|
axis=-1,
|
|
284
347
|
)
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
348
|
+
|
|
349
|
+
if is_antiderivative_wrt_tau:
|
|
350
|
+
if there_is_beam_source:
|
|
351
|
+
u0 = np.einsum(
|
|
352
|
+
"tij, tj -> it",
|
|
353
|
+
GC_collect_0[l, :, :],
|
|
354
|
+
np.exp(exponent) / (scale_tau[l, None] * K_collect_0[l, :]),
|
|
355
|
+
optimize=True,
|
|
356
|
+
) + B_collect_0[l, :].T * np.exp(-scaled_tau[None, :] / mu0) / (
|
|
357
|
+
-scale_tau[None, l] / mu0
|
|
358
|
+
)
|
|
359
|
+
else:
|
|
360
|
+
u0 = np.einsum(
|
|
361
|
+
"tij, tj -> it",
|
|
362
|
+
GC_collect_0[l, :, :],
|
|
363
|
+
np.exp(exponent) / (scale_tau[l, None] * K_collect_0[l, :]),
|
|
364
|
+
optimize=True,
|
|
365
|
+
)
|
|
289
366
|
else:
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
367
|
+
if there_is_beam_source:
|
|
368
|
+
u0 = np.einsum(
|
|
369
|
+
"tij, tj -> it", GC_collect_0[l, :, :], np.exp(exponent), optimize=True
|
|
370
|
+
) + B_collect_0[l, :].T * np.exp(-scaled_tau[None, :] / mu0)
|
|
371
|
+
else:
|
|
372
|
+
u0 = np.einsum(
|
|
373
|
+
"tij, tj -> it", GC_collect_0[l, :, :], np.exp(exponent), optimize=True
|
|
374
|
+
)
|
|
293
375
|
|
|
294
376
|
# Contribution from particular solution for isotropic internal sources
|
|
295
377
|
if there_is_iso_source:
|
|
@@ -302,10 +384,11 @@ def _assemble_intensity_and_fluxes(
|
|
|
302
384
|
G_inv_collect_0,
|
|
303
385
|
mu_arr,
|
|
304
386
|
_autograd_compatible,
|
|
387
|
+
is_antiderivative_wrt_tau
|
|
305
388
|
)
|
|
306
|
-
u0
|
|
389
|
+
u0 = u0 + _mathscr_v_contribution
|
|
307
390
|
|
|
308
|
-
if
|
|
391
|
+
if _return_act_dscale_for_reclass:
|
|
309
392
|
return I0_orig * np.squeeze(u0), act_dscale_reclassification
|
|
310
393
|
else:
|
|
311
394
|
return I0_orig * np.squeeze(u0)
|
|
@@ -320,7 +403,13 @@ def _assemble_intensity_and_fluxes(
|
|
|
320
403
|
B_neg = B_collect_0[:, N:].T
|
|
321
404
|
|
|
322
405
|
|
|
323
|
-
def flux_up(tau):
|
|
406
|
+
def flux_up(tau, is_antiderivative_wrt_tau=False):
|
|
407
|
+
"""
|
|
408
|
+
(Energetic) Flux function with argument `tau` (type: array or float) for positive (upward) `mu` values.
|
|
409
|
+
Returns the diffuse flux magnitudes (same type and size as `tau`).
|
|
410
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
411
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
412
|
+
"""
|
|
324
413
|
tau = np.atleast_1d(tau)
|
|
325
414
|
assert np.all(tau >= 0)
|
|
326
415
|
assert np.all(tau <= tau_arr[-1])
|
|
@@ -348,12 +437,18 @@ def _assemble_intensity_and_fluxes(
|
|
|
348
437
|
G_inv_collect_0,
|
|
349
438
|
mu_arr,
|
|
350
439
|
_autograd_compatible,
|
|
440
|
+
is_antiderivative_wrt_tau
|
|
351
441
|
)[:N, :]
|
|
352
442
|
else:
|
|
353
443
|
_mathscr_v_contribution = 0
|
|
354
|
-
|
|
444
|
+
|
|
355
445
|
if there_is_beam_source:
|
|
356
|
-
|
|
446
|
+
if is_antiderivative_wrt_tau:
|
|
447
|
+
direct_beam_contribution = (
|
|
448
|
+
B_pos[:, l] * np.exp(-scaled_tau[None, :] / mu0) / (-scale_tau[None, l] / mu0)
|
|
449
|
+
)
|
|
450
|
+
else:
|
|
451
|
+
direct_beam_contribution = B_pos[:, l] * np.exp(-scaled_tau[None, :] / mu0)
|
|
357
452
|
else:
|
|
358
453
|
direct_beam_contribution = 0
|
|
359
454
|
|
|
@@ -364,17 +459,36 @@ def _assemble_intensity_and_fluxes(
|
|
|
364
459
|
],
|
|
365
460
|
axis=-1,
|
|
366
461
|
)
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
462
|
+
|
|
463
|
+
if is_antiderivative_wrt_tau:
|
|
464
|
+
u0_pos = (
|
|
465
|
+
np.einsum(
|
|
466
|
+
"tij, tj -> it",
|
|
467
|
+
GC_pos[l, :, :],
|
|
468
|
+
np.exp(exponent) / (scale_tau[l, None] * K_collect_0[l, :]),
|
|
469
|
+
)
|
|
470
|
+
+ direct_beam_contribution
|
|
471
|
+
+ _mathscr_v_contribution
|
|
472
|
+
)
|
|
473
|
+
else:
|
|
474
|
+
u0_pos = (
|
|
475
|
+
np.einsum("tij, tj -> it", GC_pos[l, :, :], np.exp(exponent))
|
|
476
|
+
+ direct_beam_contribution
|
|
477
|
+
+ _mathscr_v_contribution
|
|
478
|
+
)
|
|
372
479
|
|
|
373
480
|
flux = 2 * pi * (mu_arr_pos * W) @ u0_pos
|
|
374
481
|
return I0_orig * np.squeeze(flux)[()]
|
|
375
482
|
|
|
376
483
|
|
|
377
|
-
def flux_down(tau):
|
|
484
|
+
def flux_down(tau, is_antiderivative_wrt_tau=False):
|
|
485
|
+
"""
|
|
486
|
+
(Energetic) Flux function with argument `tau` (type: array or float) for negative (downward) `mu` values.
|
|
487
|
+
Returns a tuple of the diffuse and direct flux magnitudes respectively where each entry is of the
|
|
488
|
+
same type and size as `tau`.
|
|
489
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
490
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
491
|
+
"""
|
|
378
492
|
tau = np.atleast_1d(tau)
|
|
379
493
|
assert np.all(tau >= 0)
|
|
380
494
|
assert np.all(tau <= tau_arr[-1])
|
|
@@ -402,14 +516,20 @@ def _assemble_intensity_and_fluxes(
|
|
|
402
516
|
G_inv_collect_0,
|
|
403
517
|
mu_arr,
|
|
404
518
|
_autograd_compatible,
|
|
519
|
+
is_antiderivative_wrt_tau
|
|
405
520
|
)[N:, :]
|
|
406
521
|
else:
|
|
407
522
|
_mathscr_v_contribution = 0
|
|
408
523
|
|
|
409
524
|
if there_is_beam_source:
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
525
|
+
if is_antiderivative_wrt_tau:
|
|
526
|
+
direct_beam_contribution = B_neg[:, l] * np.exp(-scaled_tau[None, :] / mu0) / (-scale_tau[None, l] / mu0)
|
|
527
|
+
direct_beam = I0 * mu0 * np.exp(-tau / mu0) * -mu0
|
|
528
|
+
direct_beam_scaled = I0 * mu0 * np.exp(-scaled_tau / mu0) / (-scale_tau[None, l] / mu0)
|
|
529
|
+
else:
|
|
530
|
+
direct_beam_contribution = B_neg[:, l] * np.exp(-scaled_tau[None, :] / mu0)
|
|
531
|
+
direct_beam = I0 * mu0 * np.exp(-tau / mu0)
|
|
532
|
+
direct_beam_scaled = I0 * mu0 * np.exp(-scaled_tau / mu0)
|
|
413
533
|
else:
|
|
414
534
|
direct_beam_contribution = 0
|
|
415
535
|
direct_beam = 0
|
|
@@ -422,11 +542,19 @@ def _assemble_intensity_and_fluxes(
|
|
|
422
542
|
],
|
|
423
543
|
axis=-1,
|
|
424
544
|
)
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
545
|
+
|
|
546
|
+
if is_antiderivative_wrt_tau:
|
|
547
|
+
u0_neg = (
|
|
548
|
+
np.einsum("tij, tj -> it", GC_neg[l, :, :], np.exp(exponent) / (scale_tau[l, None] * K_collect_0[l, :]))
|
|
549
|
+
+ direct_beam_contribution
|
|
550
|
+
+ _mathscr_v_contribution
|
|
551
|
+
)
|
|
552
|
+
else:
|
|
553
|
+
u0_neg = (
|
|
554
|
+
np.einsum("tij, tj -> it", GC_neg[l, :, :], np.exp(exponent))
|
|
555
|
+
+ direct_beam_contribution
|
|
556
|
+
+ _mathscr_v_contribution
|
|
557
|
+
)
|
|
430
558
|
|
|
431
559
|
diffuse_flux = 2 * pi * (mu_arr_pos * W) @ u0_neg + direct_beam_scaled - direct_beam
|
|
432
560
|
return (
|
|
@@ -29,9 +29,9 @@ def _solve_for_coeffs(
|
|
|
29
29
|
NLayers_to_use_sparse, # Number of layers above or equal which to use sparse matrices
|
|
30
30
|
):
|
|
31
31
|
"""
|
|
32
|
-
|
|
33
|
-
of
|
|
34
|
-
|
|
32
|
+
Uses the boundary conditions to solve for the unknown coefficients
|
|
33
|
+
of the general solution to the system of ordinary differential equations for each Fourier mode.
|
|
34
|
+
Returns the product of the coefficients and the eigenvectors.
|
|
35
35
|
This function is wrapped by the `_assemble_intensity_and_fluxes` function.
|
|
36
36
|
It has many seemingly redundant arguments to maximize precomputation in the `pydisort` function.
|
|
37
37
|
See the Jupyter Notebook, especially section 3, for documentation, explanation and derivation.
|
|
@@ -17,9 +17,9 @@ def _solve_for_gen_and_part_sols(
|
|
|
17
17
|
there_is_iso_source, # Is there an isotropic source?
|
|
18
18
|
):
|
|
19
19
|
"""
|
|
20
|
-
|
|
21
|
-
and the eigenpairs
|
|
22
|
-
|
|
20
|
+
Diagonalizes the coefficient matrix of the system of ordinary differential equations (ODEs)
|
|
21
|
+
for each Fourier mode and returns the eigenpairs which give the general solution up to unknown coefficients.
|
|
22
|
+
Also solves for the particular solution to each system of ODEs and returns its coefficient vector.
|
|
23
23
|
This function is wrapped by the `_assemble_intensity_and_fluxes` function.
|
|
24
24
|
It has many seemingly redundant arguments to maximize precomputation in the `pydisort` function.
|
|
25
25
|
See the Jupyter Notebook, especially section 3, for documentation, explanation and derivation.
|
|
@@ -46,16 +46,18 @@ def _solve_for_gen_and_part_sols(
|
|
|
46
46
|
| `there_is_iso_source` | boolean |
|
|
47
47
|
|
|
48
48
|
Notable internal variables of _solve_for_gen_and_part_sols
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
| `ells_all`
|
|
52
|
-
| `G_collect`
|
|
53
|
-
| `K_collect`
|
|
54
|
-
| `alpha_arr`
|
|
55
|
-
| `beta_arr`
|
|
56
|
-
| `X_tilde_arr`
|
|
57
|
-
| `B_collect`
|
|
58
|
-
| `
|
|
49
|
+
| Variable | Type / Shape |
|
|
50
|
+
| ------------------- | -------------------------------------- |
|
|
51
|
+
| `ells_all` | `NLeg` |
|
|
52
|
+
| `G_collect` | `NFourier*NLayers x NQuad x NQuad` | Reshaped to NFourier x NLayers x NQuad x NQuad
|
|
53
|
+
| `K_collect` | `NFourier*NLayers x NQuad` | Reshaped to NFourier x NLayers x NQuad
|
|
54
|
+
| `alpha_arr` | `NFourier*NLayers x NQuad/2 x NQuad/2` | Reshaped to NFourier x NLayers x NQuad/2 x NQuad/2
|
|
55
|
+
| `beta_arr` | `NFourier*NLayers x NQuad/2 x NQuad/2` | Reshaped to NFourier x NLayers x NQuad/2 x NQuad/2
|
|
56
|
+
| `X_tilde_arr` | `NFourier*NLayers x NQuad` | Reshaped to NFourier x NLayers x NQuad
|
|
57
|
+
| `B_collect` | `NFourier*NLayers x NQuad` or `None` | Reshaped to NFourier x NLayers x NQuad
|
|
58
|
+
| `eigenvecs_GpG_arr` | `NFourier*NLayers x NQuad/2 x NQuad |
|
|
59
|
+
| `eigenvecs_GmG_arr` | `NFourier*NLayers x NQuad/2 x NQuad |
|
|
60
|
+
| `G_inv_collect_0` | `NLayers x NQuad x NQuad` or `None` |
|
|
59
61
|
|
|
60
62
|
"""
|
|
61
63
|
############################### Assemble system and diagonalize coefficient matrix #########################################
|
|
@@ -190,7 +192,7 @@ def _solve_for_gen_and_part_sols(
|
|
|
190
192
|
G_inv_collect_0[no_shortcut_indices_0, :, :] = G_inv_arr[: len(no_shortcut_indices_0), :, :]
|
|
191
193
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
192
194
|
|
|
193
|
-
# Particular solution for the
|
|
195
|
+
# Particular solution for the direct beam source (refer to Section 3.6.1 of the Comprehensive Documentation)
|
|
194
196
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
195
197
|
if there_is_beam_source:
|
|
196
198
|
X_tilde_arr = X_tilde_arr[: len(no_shortcut_indices), :]
|
PythonicDISORT/pydisort.py
CHANGED
|
@@ -28,6 +28,7 @@ def pydisort(
|
|
|
28
28
|
"""Solves the 1D RTE for the fluxes, and optionally intensity,
|
|
29
29
|
of a multi-layer atmosphere with the specified optical properties, boundary conditions
|
|
30
30
|
and sources. Optionally performs delta-M scaling and NT corrections.
|
|
31
|
+
Refer to the `*_test.ipynb` Jupyter Notebooks in the `pydisotest` directory for examples of use.
|
|
31
32
|
|
|
32
33
|
See https://pythonic-disort.readthedocs.io/en/latest/Pythonic-DISORT.html#1.-USER-INPUT-REQUIRED:-Choose-parameters
|
|
33
34
|
for a more detailed explanation of each parameter.
|
|
@@ -64,7 +65,7 @@ def pydisort(
|
|
|
64
65
|
Dirichlet boundary condition for the downward direction.
|
|
65
66
|
only_flux : optional, bool
|
|
66
67
|
Do NOT compute the intensity function?
|
|
67
|
-
f_arr : optional, array
|
|
68
|
+
f_arr : optional, array or float
|
|
68
69
|
Fractional scattering into peak for each atmospheric layer.
|
|
69
70
|
NT_cor : optional, bool
|
|
70
71
|
Perform Nakajima-Tanaka intensity corrections?
|
|
@@ -79,25 +80,36 @@ def pydisort(
|
|
|
79
80
|
|
|
80
81
|
Returns
|
|
81
82
|
-------
|
|
82
|
-
mu_arr : array
|
|
83
|
+
mu_arr : array or float
|
|
83
84
|
All `mu` (cosine of polar angle) quadrature nodes.
|
|
84
85
|
Fp(tau) : function, function
|
|
85
|
-
(Energetic) Flux function with argument `tau` (type: array) for positive (upward) `mu` values.
|
|
86
|
-
Returns the diffuse flux magnitudes (type
|
|
86
|
+
(Energetic) Flux function with argument `tau` (type: array or float) for positive (upward) `mu` values.
|
|
87
|
+
Returns the diffuse flux magnitudes (same type and size as `tau`).
|
|
88
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
89
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
90
|
+
For example, `Fp(tau0, is_antiderivative_wrt_tau=True) - Fp(0, is_antiderivative_wrt_tau=True)`
|
|
91
|
+
will give the tau-integral of `Fp` from `tau0` to `0`.
|
|
87
92
|
Fm(tau) : function
|
|
88
|
-
(Energetic) Flux function with argument `tau` (type: array) for negative (downward) `mu` values.
|
|
89
|
-
Returns a tuple of the diffuse and direct flux magnitudes respectively
|
|
93
|
+
(Energetic) Flux function with argument `tau` (type: array or float) for negative (downward) `mu` values.
|
|
94
|
+
Returns a tuple of the diffuse and direct flux magnitudes respectively where each entry is of the
|
|
95
|
+
same type and size as `tau`.
|
|
96
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
97
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
90
98
|
u0(tau) : function
|
|
91
|
-
Zeroth Fourier mode of the intensity with argument `tau` (type: array).
|
|
99
|
+
Zeroth Fourier mode of the intensity with argument `tau` (type: array or float).
|
|
92
100
|
Returns an ndarray with axes corresponding to variation with `mu` and `tau` respectively.
|
|
93
101
|
This function is useful for calculating actinic fluxes and other quantities of interest,
|
|
94
102
|
but reclassification of delta-scaled flux and other corrections must be done manually
|
|
95
103
|
(for actinic flux `generate_diff_act_flux_funcs` will automatically perform the reclassification).
|
|
104
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
105
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
96
106
|
u(tau, phi) : function, optional
|
|
97
|
-
Intensity function with arguments `(tau, phi
|
|
107
|
+
Intensity function with arguments `(tau, phi)` of types `(array or float, array or float)`.
|
|
98
108
|
Returns an ndarray with axes corresponding to variation with `mu, tau, phi` respectively.
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
Pass `return_Fourier_error = True` (defaults to `False`) to return the
|
|
110
|
+
Cauchy / Fourier convergence evaluation (type: float) for the last Fourier term.
|
|
111
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
112
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
101
113
|
|
|
102
114
|
"""
|
|
103
115
|
|
|
@@ -310,9 +322,9 @@ def pydisort(
|
|
|
310
322
|
_autograd_compatible,
|
|
311
323
|
)
|
|
312
324
|
|
|
313
|
-
# TMS correction
|
|
325
|
+
# TMS correction for the intensity (see Section 3.7.2)
|
|
314
326
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
315
|
-
def TMS_correction(tau, phi):
|
|
327
|
+
def TMS_correction(tau, phi, is_antiderivative_wrt_tau):
|
|
316
328
|
Ntau = len(tau)
|
|
317
329
|
Nphi = len(phi)
|
|
318
330
|
# Atmospheric layer indices
|
|
@@ -357,20 +369,36 @@ def pydisort(
|
|
|
357
369
|
)
|
|
358
370
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
359
371
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
372
|
+
if is_antiderivative_wrt_tau:
|
|
373
|
+
TMS_correction_pos = (
|
|
374
|
+
np.exp(-scaled_tau / mu0)[None, :] / (-scale_tau[None, l] / mu0)
|
|
375
|
+
- np.exp(
|
|
376
|
+
(scaled_tau - scaled_tau_arr_l)[None, :] / mu_arr_pos[:, None]
|
|
377
|
+
- scaled_tau_arr_l[None, :] / mu0
|
|
378
|
+
) / (scale_tau[None, l] / mu_arr_pos[:, None])
|
|
365
379
|
)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
-
|
|
380
|
+
TMS_correction_neg = (
|
|
381
|
+
np.exp(-scaled_tau / mu0)[None, :] / (-scale_tau[None, l] / mu0)
|
|
382
|
+
- np.exp(
|
|
383
|
+
(scaled_tau_arr_lm1 - scaled_tau)[None, :] / mu_arr_pos[:, None]
|
|
384
|
+
- scaled_tau_arr_lm1[None, :] / mu0
|
|
385
|
+
) / (-scale_tau[None, l] / mu_arr_pos[:, None])
|
|
386
|
+
)
|
|
387
|
+
else:
|
|
388
|
+
TMS_correction_pos = (
|
|
389
|
+
np.exp(-scaled_tau / mu0)[None, :]
|
|
390
|
+
- np.exp(
|
|
391
|
+
(scaled_tau - scaled_tau_arr_l)[None, :] / mu_arr_pos[:, None]
|
|
392
|
+
- scaled_tau_arr_l[None, :] / mu0
|
|
393
|
+
)
|
|
394
|
+
)
|
|
395
|
+
TMS_correction_neg = (
|
|
396
|
+
np.exp(-scaled_tau / mu0)[None, :]
|
|
397
|
+
- np.exp(
|
|
398
|
+
(scaled_tau_arr_lm1 - scaled_tau)[None, :] / mu_arr_pos[:, None]
|
|
399
|
+
- scaled_tau_arr_lm1[None, :] / mu0
|
|
400
|
+
)
|
|
372
401
|
)
|
|
373
|
-
)
|
|
374
402
|
|
|
375
403
|
## Contribution from other layers
|
|
376
404
|
# TODO: Despite being vectorized and despite many attempts at further optimization,
|
|
@@ -392,72 +420,114 @@ def pydisort(
|
|
|
392
420
|
|
|
393
421
|
layers_arr_repeat = np.repeat(layers_arr, Ntau)
|
|
394
422
|
scaled_tau_tile = np.tile(scaled_tau, NLayers)
|
|
395
|
-
scaled_tau_arr_with_0_repeat = np.repeat(scaled_tau_arr_with_0, Ntau)
|
|
396
423
|
|
|
397
424
|
if any_pos_contribution:
|
|
398
425
|
contribution_from_each_other_layer_pos = np.zeros((N, NLayers * Ntau, Nphi))
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
]
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
426
|
+
scaled_tau_tile_pos = scaled_tau_tile[pos_contribution_mask]
|
|
427
|
+
|
|
428
|
+
layers_arr_repeat_pos = layers_arr_repeat[pos_contribution_mask]
|
|
429
|
+
mathscr_B_repeat_pos = mathscr_B[:N, layers_arr_repeat_pos, :]
|
|
430
|
+
scaled_tau_arr_with_0_l_repeat_pos = scaled_tau_arr_with_0[:-1][layers_arr_repeat_pos]
|
|
431
|
+
scaled_tau_arr_with_0_lp1_repeat_pos = scaled_tau_arr_with_0[1:][layers_arr_repeat_pos]
|
|
432
|
+
|
|
433
|
+
if is_antiderivative_wrt_tau:
|
|
434
|
+
scale_tau_repeat_pos = scale_tau[layers_arr_repeat_pos]
|
|
435
|
+
contribution_from_each_other_layer_pos[:, pos_contribution_mask, :] = (
|
|
436
|
+
mathscr_B_repeat_pos
|
|
437
|
+
* (
|
|
438
|
+
(
|
|
439
|
+
np.exp(
|
|
440
|
+
(scaled_tau_tile_pos - scaled_tau_arr_with_0_l_repeat_pos)
|
|
441
|
+
/ mu_arr_pos[:, None]
|
|
442
|
+
- scaled_tau_arr_with_0_l_repeat_pos / mu0
|
|
443
|
+
)
|
|
444
|
+
- np.exp(
|
|
445
|
+
(scaled_tau_tile_pos - scaled_tau_arr_with_0_lp1_repeat_pos)
|
|
446
|
+
/ mu_arr_pos[:, None]
|
|
447
|
+
- scaled_tau_arr_with_0_lp1_repeat_pos / mu0
|
|
448
|
+
)
|
|
449
|
+
)
|
|
450
|
+
/ (scale_tau_repeat_pos / mu_arr_pos[:, None])
|
|
451
|
+
)[:, :, None]
|
|
452
|
+
)
|
|
453
|
+
contribution_from_other_layers_pos = np.sum(
|
|
454
|
+
contribution_from_each_other_layer_pos.reshape((N, NLayers, Ntau, Nphi)),
|
|
455
|
+
axis=1,
|
|
456
|
+
)
|
|
457
|
+
else:
|
|
458
|
+
contribution_from_each_other_layer_pos[:, pos_contribution_mask, :] = (
|
|
459
|
+
mathscr_B_repeat_pos
|
|
460
|
+
* (
|
|
461
|
+
np.exp(
|
|
462
|
+
(scaled_tau_tile_pos - scaled_tau_arr_with_0_l_repeat_pos)
|
|
463
|
+
/ mu_arr_pos[:, None]
|
|
464
|
+
- scaled_tau_arr_with_0_l_repeat_pos / mu0
|
|
465
|
+
)
|
|
466
|
+
- np.exp(
|
|
467
|
+
(scaled_tau_tile_pos - scaled_tau_arr_with_0_lp1_repeat_pos)
|
|
468
|
+
/ mu_arr_pos[:, None]
|
|
469
|
+
- scaled_tau_arr_with_0_lp1_repeat_pos / mu0
|
|
470
|
+
)
|
|
471
|
+
)[:, :, None]
|
|
472
|
+
)
|
|
473
|
+
contribution_from_other_layers_pos = np.sum(
|
|
474
|
+
contribution_from_each_other_layer_pos.reshape((N, NLayers, Ntau, Nphi)),
|
|
475
|
+
axis=1,
|
|
476
|
+
)
|
|
477
|
+
|
|
429
478
|
if any_neg_contribution:
|
|
430
479
|
contribution_from_each_other_layer_neg = np.zeros((N, NLayers * Ntau, Nphi))
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
]
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
]
|
|
438
|
-
scaled_tau_arr_with_0_lp1_tile_negmasked = scaled_tau_arr_with_0_repeat[Ntau:][
|
|
439
|
-
neg_contribution_mask
|
|
440
|
-
]
|
|
480
|
+
scaled_tau_tile_neg = scaled_tau_tile[neg_contribution_mask]
|
|
481
|
+
|
|
482
|
+
layers_arr_repeat_neg = layers_arr_repeat[neg_contribution_mask]
|
|
483
|
+
mathscr_B_repeat_neg = mathscr_B[N:, layers_arr_repeat_neg, :]
|
|
484
|
+
scaled_tau_arr_with_0_l_repeat_neg = scaled_tau_arr_with_0[:-1][layers_arr_repeat_neg]
|
|
485
|
+
scaled_tau_arr_with_0_lp1_repeat_neg = scaled_tau_arr_with_0[1:][layers_arr_repeat_neg]
|
|
441
486
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
487
|
+
if is_antiderivative_wrt_tau:
|
|
488
|
+
scale_tau_repeat_neg = scale_tau[layers_arr_repeat_neg]
|
|
489
|
+
contribution_from_each_other_layer_neg[:, neg_contribution_mask, :] = (
|
|
490
|
+
mathscr_B_repeat_neg
|
|
491
|
+
* (
|
|
492
|
+
(
|
|
493
|
+
np.exp(
|
|
494
|
+
(scaled_tau_arr_with_0_lp1_repeat_neg - scaled_tau_tile_neg)
|
|
495
|
+
/ mu_arr_pos[:, None]
|
|
496
|
+
- scaled_tau_arr_with_0_lp1_repeat_neg / mu0
|
|
497
|
+
)
|
|
498
|
+
- np.exp(
|
|
499
|
+
(scaled_tau_arr_with_0_l_repeat_neg - scaled_tau_tile_neg)
|
|
500
|
+
/ mu_arr_pos[:, None]
|
|
501
|
+
- scaled_tau_arr_with_0_l_repeat_neg / mu0
|
|
502
|
+
)
|
|
503
|
+
)
|
|
504
|
+
/ (-scale_tau_repeat_pos / mu_arr_pos[:, None])
|
|
505
|
+
)[:, :, None]
|
|
506
|
+
)
|
|
507
|
+
contribution_from_other_layers_neg = np.sum(
|
|
508
|
+
contribution_from_each_other_layer_neg.reshape((N, NLayers, Ntau, Nphi)),
|
|
509
|
+
axis=1,
|
|
510
|
+
)
|
|
511
|
+
else:
|
|
512
|
+
contribution_from_each_other_layer_neg[:, neg_contribution_mask, :] = (
|
|
513
|
+
mathscr_B_repeat_neg
|
|
514
|
+
* (
|
|
515
|
+
np.exp(
|
|
516
|
+
(scaled_tau_arr_with_0_lp1_repeat_neg - scaled_tau_tile_neg)
|
|
517
|
+
/ mu_arr_pos[:, None]
|
|
518
|
+
- scaled_tau_arr_with_0_lp1_repeat_neg / mu0
|
|
519
|
+
)
|
|
520
|
+
- np.exp(
|
|
521
|
+
(scaled_tau_arr_with_0_l_repeat_neg - scaled_tau_tile_neg)
|
|
522
|
+
/ mu_arr_pos[:, None]
|
|
523
|
+
- scaled_tau_arr_with_0_l_repeat_neg / mu0
|
|
524
|
+
)
|
|
525
|
+
)[:, :, None]
|
|
526
|
+
)
|
|
527
|
+
contribution_from_other_layers_neg = np.sum(
|
|
528
|
+
contribution_from_each_other_layer_neg.reshape((N, NLayers, Ntau, Nphi)),
|
|
529
|
+
axis=1,
|
|
530
|
+
)
|
|
461
531
|
|
|
462
532
|
if _autograd_compatible:
|
|
463
533
|
if not any_pos_contribution:
|
|
@@ -481,7 +551,7 @@ def pydisort(
|
|
|
481
551
|
return solution
|
|
482
552
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
483
553
|
|
|
484
|
-
# IMS correction
|
|
554
|
+
# IMS correction for the intensity (see Section 3.7.2)
|
|
485
555
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
486
556
|
sum1 = np.sum(omega_arr * tau_arr)
|
|
487
557
|
omega_avg = sum1 / np.sum(tau_arr)
|
|
@@ -495,15 +565,22 @@ def pydisort(
|
|
|
495
565
|
)
|
|
496
566
|
scaled_mu0 = mu0 / (1 - omega_avg * f_avg)
|
|
497
567
|
|
|
498
|
-
def IMS_correction(tau, phi):
|
|
568
|
+
def IMS_correction(tau, phi, is_antiderivative_wrt_tau):
|
|
499
569
|
nu = subroutines.atleast_2d_append(
|
|
500
570
|
subroutines.calculate_nu(-mu_arr_pos, phi, -mu0, phi0)
|
|
501
571
|
)
|
|
502
572
|
x = 1 / mu_arr_pos - 1 / scaled_mu0
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
573
|
+
if is_antiderivative_wrt_tau:
|
|
574
|
+
chi = (
|
|
575
|
+
(scaled_mu0 - x[:, None] * scaled_mu0 * (scaled_mu0 + tau)[None, :])
|
|
576
|
+
* np.exp(-tau / scaled_mu0)[None, :]
|
|
577
|
+
- mu_arr_pos[:, None] * np.exp(-tau[None, :] / mu_arr_pos[:, None])
|
|
578
|
+
) / (mu_arr_pos * scaled_mu0 * x**2)[:, None]
|
|
579
|
+
else:
|
|
580
|
+
chi = (
|
|
581
|
+
(tau[None, :] - 1 / x[:, None]) * np.exp(-tau / scaled_mu0)[None, :]
|
|
582
|
+
+ np.exp(-tau[None, :] / mu_arr_pos[:, None]) / x[:, None]
|
|
583
|
+
) / (mu_arr_pos * scaled_mu0 * x)[:, None]
|
|
507
584
|
return (
|
|
508
585
|
I0
|
|
509
586
|
/ (4 * pi)
|
|
@@ -518,26 +595,26 @@ def pydisort(
|
|
|
518
595
|
|
|
519
596
|
# The corrected intensity
|
|
520
597
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
521
|
-
def u_corrected(tau, phi, return_Fourier_error=False):
|
|
598
|
+
def u_corrected(tau, phi, return_Fourier_error=False, is_antiderivative_wrt_tau=False):
|
|
522
599
|
tau = np.atleast_1d(tau)
|
|
523
600
|
phi = np.atleast_1d(phi)
|
|
524
|
-
NT_corrections = TMS_correction(tau, phi)
|
|
601
|
+
NT_corrections = TMS_correction(tau, phi, is_antiderivative_wrt_tau)
|
|
525
602
|
|
|
526
603
|
if _autograd_compatible:
|
|
527
604
|
NT_corrections = NT_corrections + np.concatenate(
|
|
528
|
-
[np.zeros((N, len(tau), len(phi))), IMS_correction(tau, phi)], axis=0
|
|
605
|
+
[np.zeros((N, len(tau), len(phi))), IMS_correction(tau, phi, is_antiderivative_wrt_tau)], axis=0
|
|
529
606
|
)
|
|
530
607
|
else:
|
|
531
|
-
NT_corrections[N:, :, :] += IMS_correction(tau, phi)
|
|
608
|
+
NT_corrections[N:, :, :] += IMS_correction(tau, phi, is_antiderivative_wrt_tau)
|
|
532
609
|
|
|
533
610
|
if return_Fourier_error:
|
|
534
|
-
u_star_outputs = u_star(tau, phi, True)
|
|
611
|
+
u_star_outputs = u_star(tau, phi, True, is_antiderivative_wrt_tau)
|
|
535
612
|
return (
|
|
536
613
|
u_star_outputs[0] + I0_orig * np.squeeze(NT_corrections),
|
|
537
614
|
u_star_outputs[1],
|
|
538
615
|
)
|
|
539
616
|
else:
|
|
540
|
-
return u_star(tau, phi, False) + I0_orig * np.squeeze(NT_corrections)
|
|
617
|
+
return u_star(tau, phi, False, is_antiderivative_wrt_tau) + I0_orig * np.squeeze(NT_corrections)
|
|
541
618
|
# --------------------------------------------------------------------------------------------------------------------------
|
|
542
619
|
|
|
543
620
|
return mu_arr, flux_up, flux_down, u0, u_corrected
|
PythonicDISORT/subroutines.py
CHANGED
|
@@ -238,33 +238,40 @@ def generate_diff_act_flux_funcs(u0):
|
|
|
238
238
|
function
|
|
239
239
|
Actinic flux function with argument `tau` (type: array) for positive (upward) `mu` values.
|
|
240
240
|
Returns the diffuse flux magnitudes (type: array).
|
|
241
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
242
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
241
243
|
function
|
|
242
244
|
Actinic flux function with argument `tau` (type: array) for negative (downward) `mu` values.
|
|
243
245
|
Returns the diffuse flux magnitudes (type: array).
|
|
246
|
+
Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
|
|
247
|
+
to switch to an antiderivative of the function with respect to `tau`.
|
|
244
248
|
|
|
245
249
|
"""
|
|
246
250
|
N = np.shape(u0(0))[0] // 2
|
|
247
251
|
GL_weights = Gauss_Legendre_quad(N, 0, 1)[1]
|
|
248
252
|
|
|
249
253
|
# Note that the zeroth axis of the array u0(tau) captures variation with mu
|
|
250
|
-
flux_act_up =
|
|
251
|
-
|
|
252
|
-
|
|
254
|
+
def flux_act_up(tau, is_antiderivative_wrt_tau=False):
|
|
255
|
+
return 2 * pi * GL_weights @ u0(tau, is_antiderivative_wrt_tau)[:N]
|
|
256
|
+
|
|
257
|
+
def flux_act_down_diffuse(tau, is_antiderivative_wrt_tau=False):
|
|
258
|
+
u0_cache, act_dscale_reclassification = u0(tau, is_antiderivative_wrt_tau, _return_act_dscale_for_reclass=True)
|
|
253
259
|
result_without_reclassification = 2 * pi * GL_weights @ u0_cache[N:]
|
|
254
260
|
return result_without_reclassification + act_dscale_reclassification
|
|
255
261
|
|
|
256
262
|
return flux_act_up, flux_act_down_diffuse
|
|
257
263
|
|
|
258
264
|
|
|
259
|
-
def _mathscr_v(tau,
|
|
260
|
-
l,
|
|
261
|
-
s_poly_coeffs,
|
|
262
|
-
Nscoeffs,
|
|
263
|
-
G,
|
|
264
|
-
K,
|
|
265
|
-
G_inv,
|
|
266
|
-
mu_arr,
|
|
267
|
-
_autograd_compatible=False
|
|
265
|
+
def _mathscr_v(tau, # Input optical depths
|
|
266
|
+
l, # Layer index of each input optical depth
|
|
267
|
+
s_poly_coeffs, # Polynomial coefficients of isotropic source
|
|
268
|
+
Nscoeffs, # Number of isotropic source polynomial coefficients
|
|
269
|
+
G, # Eigenvector matrices
|
|
270
|
+
K, # Eigenvalues
|
|
271
|
+
G_inv, # Inverse of eigenvector matrix
|
|
272
|
+
mu_arr, # Quadrature nodes for both hemispheres
|
|
273
|
+
_autograd_compatible=False, # Should the output functions be compatible with autograd?
|
|
274
|
+
is_antiderivative_wrt_tau=False # Switch to an antiderivative of the function?
|
|
268
275
|
):
|
|
269
276
|
"""Particular solution for isotropic internal sources.
|
|
270
277
|
Refer to Section 3.6.1 of the Comprehensive Documentation.
|
|
@@ -273,16 +280,17 @@ def _mathscr_v(tau, # Input optical depths
|
|
|
273
280
|
and `_solve_for_coeffs` functions which call it.
|
|
274
281
|
|
|
275
282
|
Arguments of _mathscr_v
|
|
276
|
-
|
|
|
277
|
-
|
|
|
278
|
-
| `tau`
|
|
279
|
-
| `l`
|
|
280
|
-
| `s_poly_coeffs`
|
|
281
|
-
| `G`
|
|
282
|
-
| `K`
|
|
283
|
-
| `G_inv`
|
|
284
|
-
| `mu_arr`
|
|
285
|
-
| `_autograd_compatible`
|
|
283
|
+
| Variable | Shape |
|
|
284
|
+
| --------------------------- | ------------------------------------- |
|
|
285
|
+
| `tau` | `Ntau` |
|
|
286
|
+
| `l` | `Ntau` |
|
|
287
|
+
| `s_poly_coeffs` | `NLayers x Nscoeffs` or `Nscoeffs` |
|
|
288
|
+
| `G` | `NLayers<= x NQuad x NQuad` |
|
|
289
|
+
| `K` | `NLayers<= x NQuad` |
|
|
290
|
+
| `G_inv` | `NLayers<= x NQuad x NQuad` or `None` |
|
|
291
|
+
| `mu_arr` | `NQuad` |
|
|
292
|
+
| `_autograd_compatible` | boolean |
|
|
293
|
+
| `is_antiderivative_wrt_tau` | boolean |
|
|
286
294
|
|
|
287
295
|
Notable internal variables of _mathscr_v
|
|
288
296
|
| Variable | Shape |
|
|
@@ -340,11 +348,17 @@ def _mathscr_v(tau, # Input optical depths
|
|
|
340
348
|
0,
|
|
341
349
|
),
|
|
342
350
|
)
|
|
343
|
-
|
|
351
|
+
|
|
352
|
+
powers = np.flip(np.arange(Nscoeffs))[None, :]
|
|
353
|
+
if is_antiderivative_wrt_tau:
|
|
354
|
+
tau_poly = tau[:, None] ** (powers + 1) / (powers + 1)
|
|
355
|
+
else:
|
|
356
|
+
tau_poly = tau[:, None] ** powers
|
|
357
|
+
|
|
344
358
|
return np.einsum(
|
|
345
359
|
"tik, tc, ctk, tkj, j -> it",
|
|
346
360
|
G[l, :, :],
|
|
347
|
-
|
|
361
|
+
tau_poly,
|
|
348
362
|
mathscr_v_coeffs[:, l, :],
|
|
349
363
|
G_inv[l, :, :],
|
|
350
364
|
1 / mu_arr,
|
|
@@ -365,6 +379,7 @@ def _compare(results, mu_to_compare, reorder_mu, flux_up, flux_down, u):
|
|
|
365
379
|
which are stored in .npz files, against results from PythonicDISORT. Used in our PyTests.
|
|
366
380
|
|
|
367
381
|
"""
|
|
382
|
+
# Load saved results from Stamnes' DISORT
|
|
368
383
|
uu = results["uu"]
|
|
369
384
|
flup = results["flup"]
|
|
370
385
|
rfldn = results["rfldn"]
|
|
@@ -438,6 +453,7 @@ def _compare(results, mu_to_compare, reorder_mu, flux_up, flux_down, u):
|
|
|
438
453
|
diff_tau_pt = tau_test_arr[max_diff_tau_index]
|
|
439
454
|
ratio_tau_pt = tau_test_arr[max_ratio_tau_index]
|
|
440
455
|
print("Intensities")
|
|
456
|
+
print()
|
|
441
457
|
print("At tau = " + str(diff_tau_pt))
|
|
442
458
|
print("Max pointwise difference =", np.max(diff[:, max_diff_tau_index, :]))
|
|
443
459
|
print("At tau = " + str(ratio_tau_pt))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PythonicDISORT
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Discrete Ordinates Solver for the (1D) Radiative Transfer Equation in a single or multi-layer atmosphere.
|
|
5
5
|
Author-email: Dion HO Jia Xu <dh3065@columbia.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/LDEO-CREW/Pythonic-DISORT
|
|
@@ -20,42 +20,43 @@ Provides-Extra: pytest
|
|
|
20
20
|
Requires-Dist: pytest >=6.2.5 ; extra == 'pytest'
|
|
21
21
|
|
|
22
22
|
# Introduction
|
|
23
|
-
The PythonicDISORT package is a Discrete Ordinates Solver for the (1D) Radiative Transfer Equation
|
|
23
|
+
The PythonicDISORT package is a Discrete Ordinates Solver for the (1D) Radiative Transfer Equation
|
|
24
|
+
in a plane-parallel, horizontally homogeneous atmosphere.
|
|
24
25
|
It is coded entirely in Python 3 and is a reimplementation instead of a wrapper.
|
|
25
26
|
While PythonicDISORT has been optimized for speed, it will naturally be slower than similar FORTRAN algorithms.
|
|
26
27
|
On the other hand, PythonicDISORT should be easier to install, use, and modify than FORTRAN-based Discrete Ordinates Solvers.
|
|
27
28
|
|
|
28
|
-
PythonicDISORT is based on Stamnes' FORTRAN DISORT (see References, in particular [2, 3, 8]) and has its main features:
|
|
29
|
-
delta-M scaling, Nakajima-Tanaka (NT) corrections, only flux option, isotropic internal
|
|
29
|
+
PythonicDISORT is based on Stamnes' FORTRAN DISORT (see References, in particular [2, 3, 8]) and has its main features: multi-layer solver,
|
|
30
|
+
delta-M scaling, Nakajima-Tanaka (NT) corrections, only flux option, direct beam source, isotropic internal source (blackbody emission),
|
|
30
31
|
Dirichlet boundary conditions (diffuse flux boundary sources), Bi-Directional Reflectance Function (BDRF) for surface reflection, and more.
|
|
31
|
-
In addition,
|
|
32
|
+
In addition, subroutine to calculate actinic fluxes was added to satisfy a user request and further feature requests as well as feedback are welcome.
|
|
32
33
|
|
|
33
34
|
You may contact me, Dion, through dh3065@columbia.edu.
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
The original was downloaded from http://www.rtatmocn.com/disort/. The wrapper is inspired by https://github.com/kconnour/pyRT_DISORT.
|
|
36
|
+
The **GitHub repository** is https://github.com/LDEO-CREW/Pythonic-DISORT.
|
|
37
37
|
|
|
38
38
|
# Documentation
|
|
39
39
|
https://pythonic-disort.readthedocs.io/en/latest/
|
|
40
40
|
|
|
41
41
|
Also see the accompanying Jupyter Notebook `Pythonic-DISORT.ipynb` in the `docs` directory
|
|
42
42
|
of our GitHub repository.
|
|
43
|
-
|
|
43
|
+
This Jupyter Notebook provides comprehensive documentation, suggested inputs, explanations,
|
|
44
44
|
mathematical derivations and verification tests.
|
|
45
|
-
|
|
45
|
+
It is highly recommended that new users read the non-optional parts of sections 1 and 2.
|
|
46
46
|
|
|
47
47
|
## PyTest and examples of how to use PythonicDISORT
|
|
48
48
|
|
|
49
|
-
Not only
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
Not only are there verification tests in `Pythonic-DISORT.ipynb`,
|
|
50
|
+
most of the test problems in Stamnes' `disotest.f90` (download DISORT 4.0.99 from http://www.rtatmocn.com/disort/) have also been recreated.
|
|
51
|
+
In these tests, the solutions from PythonicDISORT are compared against solutions
|
|
52
|
+
from a F2PY-wrapped Stamnes' DISORT (version 4.0.99; wrapper inspired by https://github.com/kconnour/pyRT_DISORT). With PyTest installed, execute the console command `pytest`
|
|
53
|
+
in the `pydisotest` directory to run these tests. The `pydisotest` directory also contains Jupyter Notebooks that correspond to each test
|
|
54
|
+
to show how it was implemented. These notebooks double up as examples of how to use PythonicDISORT.
|
|
54
55
|
|
|
55
56
|
# Installation
|
|
56
57
|
|
|
57
58
|
* From PyPI: `pip install PythonicDISORT`
|
|
58
|
-
* From Conda-forge: (TODO:
|
|
59
|
+
* From Conda-forge: (TODO: need to first publish on Conda-forge)
|
|
59
60
|
* By cloning repository: `pip install .` in the `Pythonic-DISORT` directory; `pip install -r all_optional_dependencies.txt` to install all optional dependencies (see *Requirements to run PythonicDISORT*)
|
|
60
61
|
|
|
61
62
|
## Requirements to run PythonicDISORT
|
|
@@ -64,21 +65,18 @@ to show how the tests were implemented. These notebooks double up as examples of
|
|
|
64
65
|
* `scipy >= 1.8.0`
|
|
65
66
|
* (OPTIONAL) `pytest >= 6.2.5` (Required to use the command `pytest`, see *PyTest and examples of how to use PythonicDISORT*)
|
|
66
67
|
|
|
67
|
-
## Additional requirements to run the Jupyter Notebook
|
|
68
|
+
## (OPTIONAL) Additional requirements to run the Jupyter Notebook
|
|
68
69
|
* `autograd >= 1.5`
|
|
69
70
|
* `jupyter > 1.0.0`
|
|
70
71
|
* `notebook > 6.5.2`
|
|
72
|
+
* `matplotlib >= 3.6.0`
|
|
71
73
|
|
|
72
|
-
In addition,
|
|
73
|
-
must be set up to run the last section (section 6).
|
|
74
|
+
In addition, a F2PY-wrapped Stamnes' DISORT, or equivalent, is required to properly run the last section (section 6).
|
|
74
75
|
|
|
75
76
|
## Compatibility
|
|
76
77
|
|
|
77
|
-
The PythonicDISORT package
|
|
78
|
-
|
|
79
|
-
The latter will almost certainly need user edits to work and in any case it requires FORTRAN compilers which
|
|
80
|
-
are not included in our GitHub repository. Everything in the repository was built and tested on Windows 11 but
|
|
81
|
-
not yet tested on other systems.
|
|
78
|
+
The PythonicDISORT package should be system agnostic given its minimal dependencies and pure Python code.
|
|
79
|
+
Everything in the repository was built and tested on Windows 11.
|
|
82
80
|
|
|
83
81
|
# Acknowledgements
|
|
84
82
|
|
|
@@ -106,6 +104,8 @@ Science and Technology Center (STC) (Award #2019625) under which this package wa
|
|
|
106
104
|
|
|
107
105
|
10) Trefethen, L. N.. 1996. *Finite difference and spectral methods for ordinary and partial differential equations.* https://people.maths.ox.ac.uk/trefethen/pdetext.html.
|
|
108
106
|
|
|
109
|
-
11)
|
|
107
|
+
11) Knut Stamnes. 1982. *On the computation of angular distributions of radiation in planetary atmospheres.* https://www.sciencedirect.com/science/article/pii/0022407382900966.
|
|
110
108
|
|
|
111
|
-
12)
|
|
109
|
+
12) T. Nakajima and M. Tanaka. 1988. *Algorithms for radiative intensity calculations in moderately thick atmospheres using a truncation approximation.* https://www.sciencedirect.com/science/article/pii/0022407388900313.
|
|
110
|
+
|
|
111
|
+
13) Connour, Kyle and Wolff, Michael. 2020. *pyRT_DISORT: A pre-processing front-end to help make DISORT simulations easier in Python.* https://github.com/kconnour/pyRT_DISORT.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
PythonicDISORT/__init__.py,sha256=V1obNzaFgqInxqYJ5h_r6JHbZRxx4VM5VgzCIS6EEzI,84
|
|
2
|
+
PythonicDISORT/_assemble_intensity_and_fluxes.py,sha256=2PsN9GNVXo-rpoDF1YjyxkoZUKL8VPlX8qCc4yKaHMg,27075
|
|
3
|
+
PythonicDISORT/_solve_for_coeffs.py,sha256=PJhm_IpZp_D8-QVo4JBWtD6WPeiLDvcu23FP8BPlIj8,19168
|
|
4
|
+
PythonicDISORT/_solve_for_gen_and_part_sols.py,sha256=Y0wbBPSIDcZrBoAbBNbt4W7L0QZ5nXwkqe-cizzGUNA,12979
|
|
5
|
+
PythonicDISORT/pydisort.py,sha256=nqBCMtiWSMwJ7fMF-yE1PJCytpgXWjgmtpN0MxXLaok,33214
|
|
6
|
+
PythonicDISORT/subroutines.py,sha256=y6VL4Nalc3qTTMP7jojArXes8wKMKjpYCj-HELhSOjw,16824
|
|
7
|
+
PythonicDISORT-0.8.0.dist-info/LICENSE.md,sha256=q1i1QVh0OLzK0fj6kaNRNWsM_KZca66JwWgWwbuCPlA,1092
|
|
8
|
+
PythonicDISORT-0.8.0.dist-info/METADATA,sha256=r_pZL1wsPn2MoRwIYF_X3uXYaUON99uKn7gUGV1yMfM,7029
|
|
9
|
+
PythonicDISORT-0.8.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
10
|
+
PythonicDISORT-0.8.0.dist-info/top_level.txt,sha256=aX6kCeI1E7naZz3xfw4_mIbWh5KBh9dmF3FIvgP5m3Y,15
|
|
11
|
+
PythonicDISORT-0.8.0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
PythonicDISORT/__init__.py,sha256=V1obNzaFgqInxqYJ5h_r6JHbZRxx4VM5VgzCIS6EEzI,84
|
|
2
|
-
PythonicDISORT/_assemble_intensity_and_fluxes.py,sha256=IH1OYHfMLh1LrNiwSCnaJduELvHpStJgXqTycQ869X8,20410
|
|
3
|
-
PythonicDISORT/_solve_for_coeffs.py,sha256=8x7bDARYjS_fnoFGt5LRnm6yUtjyPa_YQ2Mj0LA2AFY,19162
|
|
4
|
-
PythonicDISORT/_solve_for_gen_and_part_sols.py,sha256=okJFq60712DN48-jdodipvP5S11yYK_yobDVpg0kTi8,12841
|
|
5
|
-
PythonicDISORT/pydisort.py,sha256=xjhiRnwmVIPGKJqEuapwLwGLicL3mjizO-w3r5kaP1M,27880
|
|
6
|
-
PythonicDISORT/subroutines.py,sha256=oqPIluJaFF88d7N7iS72wFOKfiYAmT3uA33tpPjuLP0,15857
|
|
7
|
-
PythonicDISORT-0.7.0.dist-info/LICENSE.md,sha256=q1i1QVh0OLzK0fj6kaNRNWsM_KZca66JwWgWwbuCPlA,1092
|
|
8
|
-
PythonicDISORT-0.7.0.dist-info/METADATA,sha256=1V3vyKC8Qa9uEH_WvCfdUnpU28HqOEnb3PdPCIR7Ij4,7230
|
|
9
|
-
PythonicDISORT-0.7.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
10
|
-
PythonicDISORT-0.7.0.dist-info/top_level.txt,sha256=aX6kCeI1E7naZz3xfw4_mIbWh5KBh9dmF3FIvgP5m3Y,15
|
|
11
|
-
PythonicDISORT-0.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|