PythonicDISORT 0.7.0__tar.gz → 0.9.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PythonicDISORT
3
- Version: 0.7.0
3
+ Version: 0.9.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,45 @@ Requires-Dist: jupyter>1.0.0; extra == "notebook-dependencies"
20
20
  Requires-Dist: notebook>6.5.2; extra == "notebook-dependencies"
21
21
 
22
22
  # Introduction
23
- The PythonicDISORT package is a Discrete Ordinates Solver for the (1D) Radiative Transfer Equation in a single or multi-layer plane-parallel atmosphere.
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 sources (thermal sources),
30
- Dirichlet boundary conditions (diffuse flux boundary sources), Bi-Directional Reflectance Function (BDRF) for surface reflection, and more.
31
- In addition, upon the request of a user, we added a subroutine to calculate actinic fluxes and we are open to further feature requests as well as feedback.
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),
31
+ Dirichlet boundary conditions (diffuse flux boundary sources), Bi-Directional Reflectance Function (BDRF) for surface reflection,
32
+ interpolation with respect to polar angle and more.
33
+ In addition, we added a subroutine to calculate actinic fluxes to satisfy a user request, and integration with respect to tau was also added.
34
+ Further feature requests as well as feedback are welcome.
32
35
 
33
36
  You may contact me, Dion, through dh3065@columbia.edu.
34
37
 
35
- Our **GitHub repository:** https://github.com/LDEO-CREW/Pythonic-DISORT also includes our F2PY-wrapped Stamnes DISORT (version 4.0.99) in the `disort4.0.99_f2py` directory.
36
- The original was downloaded from http://www.rtatmocn.com/disort/. The wrapper is inspired by https://github.com/kconnour/pyRT_DISORT.
38
+ The **GitHub repository** is https://github.com/LDEO-CREW/Pythonic-DISORT.
37
39
 
38
40
  # Documentation
39
41
  https://pythonic-disort.readthedocs.io/en/latest/
40
42
 
41
43
  Also see the accompanying Jupyter Notebook `Pythonic-DISORT.ipynb` in the `docs` directory
42
44
  of our GitHub repository.
43
- The Jupyter Notebook provides comprehensive documentation, suggested inputs, explanations,
45
+ This Jupyter Notebook provides comprehensive documentation, suggested inputs, explanations,
44
46
  mathematical derivations and verification tests.
45
- We highly recommend reading the non-optional parts of sections 1 and 2 before use.
47
+ It is highly recommended that new users read the non-optional parts of sections 1 and 2.
46
48
 
47
49
  ## PyTest and examples of how to use PythonicDISORT
48
50
 
49
- Not only do we have verification tests in the Jupyter Notebook, we have also recreated most of the test problems in Stamnes' `disotest.f90`;
50
- `disotest.f90` is included in the `disort4.0.99_f2py` directory of our GitHub repository. In these tests, the solutions from PythonicDISORT are compared
51
- against solutions from our F2PY-wrapped Stamnes' DISORT (version 4.0.99). With PyTest installed, execute the console command `pytest`
52
- in the `pydisotest` directory to run these tests. The `pydisotest` directory also contains Jupyter Notebooks, one for each test,
53
- to show how the tests were implemented. These notebooks double up as examples of how to use PythonicDISORT.
51
+ Not only are there verification tests in `Pythonic-DISORT.ipynb`,
52
+ most of the test problems in Stamnes' `disotest.f90` (download DISORT 4.0.99 from http://www.rtatmocn.com/disort/) have also been recreated.
53
+ In these tests, the solutions from PythonicDISORT are compared against solutions
54
+ 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`
55
+ in the `pydisotest` directory to run these tests. The `pydisotest` directory also contains Jupyter Notebooks to show the implementation of each test.
56
+ These notebooks double up as examples of how to use PythonicDISORT.
54
57
 
55
58
  # Installation
56
59
 
57
60
  * From PyPI: `pip install PythonicDISORT`
58
- * From Conda-forge: (TODO: we need to first publish on Conda-forge)
61
+ * From Conda-forge: (TODO: need to first publish on Conda-forge)
59
62
  * 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
63
 
61
64
  ## Requirements to run PythonicDISORT
@@ -64,21 +67,18 @@ to show how the tests were implemented. These notebooks double up as examples of
64
67
  * `scipy >= 1.8.0`
65
68
  * (OPTIONAL) `pytest >= 6.2.5` (Required to use the command `pytest`, see *PyTest and examples of how to use PythonicDISORT*)
66
69
 
67
- ## Additional requirements to run the Jupyter Notebook
70
+ ## (OPTIONAL) Additional requirements to run the Jupyter Notebook
68
71
  * `autograd >= 1.5`
69
72
  * `jupyter > 1.0.0`
70
73
  * `notebook > 6.5.2`
74
+ * `matplotlib >= 3.6.0`
71
75
 
72
- In addition, our F2PY-wrapped Stamnes' DISORT (in the `disort4.0.99_f2py` directory), or equivalent,
73
- must be set up to run the last section (section 6).
76
+ In addition, a F2PY-wrapped Stamnes' DISORT, or equivalent, is required to properly run the last section (section 6).
74
77
 
75
78
  ## Compatibility
76
79
 
77
- The PythonicDISORT package *should* be system agnostic given its minimal dependencies and pure Python code.
78
- We do not guarantee that our Jupyter Notebook and F2PY-wrapped Stamnes' DISORT will work on other systems though.
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.
80
+ The PythonicDISORT package should be system agnostic given its minimal dependencies and pure Python code.
81
+ Everything in the repository was built and tested on Windows 11.
82
82
 
83
83
  # Acknowledgements
84
84
 
@@ -106,6 +106,8 @@ Science and Technology Center (STC) (Award #2019625) under which this package wa
106
106
 
107
107
  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
108
 
109
- 11) 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.
109
+ 11) Knut Stamnes. 1982. *On the computation of angular distributions of radiation in planetary atmospheres.* https://www.sciencedirect.com/science/article/pii/0022407382900966.
110
110
 
111
- 12) K. Connour and A. Stcherbinine. 2022. *pyRT_DISORT.* https://github.com/kconnour/pyRT_DISORT.
111
+ 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.
112
+
113
+ 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.
@@ -1,40 +1,43 @@
1
1
  # Introduction
2
- The PythonicDISORT package is a Discrete Ordinates Solver for the (1D) Radiative Transfer Equation in a single or multi-layer plane-parallel atmosphere.
2
+ The PythonicDISORT package is a Discrete Ordinates Solver for the (1D) Radiative Transfer Equation
3
+ in a plane-parallel, horizontally homogeneous atmosphere.
3
4
  It is coded entirely in Python 3 and is a reimplementation instead of a wrapper.
4
5
  While PythonicDISORT has been optimized for speed, it will naturally be slower than similar FORTRAN algorithms.
5
6
  On the other hand, PythonicDISORT should be easier to install, use, and modify than FORTRAN-based Discrete Ordinates Solvers.
6
7
 
7
- PythonicDISORT is based on Stamnes' FORTRAN DISORT (see References, in particular [2, 3, 8]) and has its main features:
8
- delta-M scaling, Nakajima-Tanaka (NT) corrections, only flux option, isotropic internal sources (thermal sources),
9
- Dirichlet boundary conditions (diffuse flux boundary sources), Bi-Directional Reflectance Function (BDRF) for surface reflection, and more.
10
- In addition, upon the request of a user, we added a subroutine to calculate actinic fluxes and we are open to further feature requests as well as feedback.
8
+ PythonicDISORT is based on Stamnes' FORTRAN DISORT (see References, in particular [2, 3, 8]) and has its main features: multi-layer solver,
9
+ delta-M scaling, Nakajima-Tanaka (NT) corrections, only flux option, direct beam source, isotropic internal source (blackbody emission),
10
+ Dirichlet boundary conditions (diffuse flux boundary sources), Bi-Directional Reflectance Function (BDRF) for surface reflection,
11
+ interpolation with respect to polar angle and more.
12
+ In addition, we added a subroutine to calculate actinic fluxes to satisfy a user request, and integration with respect to tau was also added.
13
+ Further feature requests as well as feedback are welcome.
11
14
 
12
15
  You may contact me, Dion, through dh3065@columbia.edu.
13
16
 
14
- Our **GitHub repository:** https://github.com/LDEO-CREW/Pythonic-DISORT also includes our F2PY-wrapped Stamnes DISORT (version 4.0.99) in the `disort4.0.99_f2py` directory.
15
- The original was downloaded from http://www.rtatmocn.com/disort/. The wrapper is inspired by https://github.com/kconnour/pyRT_DISORT.
17
+ The **GitHub repository** is https://github.com/LDEO-CREW/Pythonic-DISORT.
16
18
 
17
19
  # Documentation
18
20
  https://pythonic-disort.readthedocs.io/en/latest/
19
21
 
20
22
  Also see the accompanying Jupyter Notebook `Pythonic-DISORT.ipynb` in the `docs` directory
21
23
  of our GitHub repository.
22
- The Jupyter Notebook provides comprehensive documentation, suggested inputs, explanations,
24
+ This Jupyter Notebook provides comprehensive documentation, suggested inputs, explanations,
23
25
  mathematical derivations and verification tests.
24
- We highly recommend reading the non-optional parts of sections 1 and 2 before use.
26
+ It is highly recommended that new users read the non-optional parts of sections 1 and 2.
25
27
 
26
28
  ## PyTest and examples of how to use PythonicDISORT
27
29
 
28
- Not only do we have verification tests in the Jupyter Notebook, we have also recreated most of the test problems in Stamnes' `disotest.f90`;
29
- `disotest.f90` is included in the `disort4.0.99_f2py` directory of our GitHub repository. In these tests, the solutions from PythonicDISORT are compared
30
- against solutions from our F2PY-wrapped Stamnes' DISORT (version 4.0.99). With PyTest installed, execute the console command `pytest`
31
- in the `pydisotest` directory to run these tests. The `pydisotest` directory also contains Jupyter Notebooks, one for each test,
32
- to show how the tests were implemented. These notebooks double up as examples of how to use PythonicDISORT.
30
+ Not only are there verification tests in `Pythonic-DISORT.ipynb`,
31
+ most of the test problems in Stamnes' `disotest.f90` (download DISORT 4.0.99 from http://www.rtatmocn.com/disort/) have also been recreated.
32
+ In these tests, the solutions from PythonicDISORT are compared against solutions
33
+ 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`
34
+ in the `pydisotest` directory to run these tests. The `pydisotest` directory also contains Jupyter Notebooks to show the implementation of each test.
35
+ These notebooks double up as examples of how to use PythonicDISORT.
33
36
 
34
37
  # Installation
35
38
 
36
39
  * From PyPI: `pip install PythonicDISORT`
37
- * From Conda-forge: (TODO: we need to first publish on Conda-forge)
40
+ * From Conda-forge: (TODO: need to first publish on Conda-forge)
38
41
  * 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*)
39
42
 
40
43
  ## Requirements to run PythonicDISORT
@@ -43,21 +46,18 @@ to show how the tests were implemented. These notebooks double up as examples of
43
46
  * `scipy >= 1.8.0`
44
47
  * (OPTIONAL) `pytest >= 6.2.5` (Required to use the command `pytest`, see *PyTest and examples of how to use PythonicDISORT*)
45
48
 
46
- ## Additional requirements to run the Jupyter Notebook
49
+ ## (OPTIONAL) Additional requirements to run the Jupyter Notebook
47
50
  * `autograd >= 1.5`
48
51
  * `jupyter > 1.0.0`
49
52
  * `notebook > 6.5.2`
53
+ * `matplotlib >= 3.6.0`
50
54
 
51
- In addition, our F2PY-wrapped Stamnes' DISORT (in the `disort4.0.99_f2py` directory), or equivalent,
52
- must be set up to run the last section (section 6).
55
+ In addition, a F2PY-wrapped Stamnes' DISORT, or equivalent, is required to properly run the last section (section 6).
53
56
 
54
57
  ## Compatibility
55
58
 
56
- The PythonicDISORT package *should* be system agnostic given its minimal dependencies and pure Python code.
57
- We do not guarantee that our Jupyter Notebook and F2PY-wrapped Stamnes' DISORT will work on other systems though.
58
- The latter will almost certainly need user edits to work and in any case it requires FORTRAN compilers which
59
- are not included in our GitHub repository. Everything in the repository was built and tested on Windows 11 but
60
- not yet tested on other systems.
59
+ The PythonicDISORT package should be system agnostic given its minimal dependencies and pure Python code.
60
+ Everything in the repository was built and tested on Windows 11.
61
61
 
62
62
  # Acknowledgements
63
63
 
@@ -85,6 +85,8 @@ Science and Technology Center (STC) (Award #2019625) under which this package wa
85
85
 
86
86
  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.
87
87
 
88
- 11) 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.
88
+ 11) Knut Stamnes. 1982. *On the computation of angular distributions of radiation in planetary atmospheres.* https://www.sciencedirect.com/science/article/pii/0022407382900966.
89
89
 
90
- 12) K. Connour and A. Stcherbinine. 2022. *pyRT_DISORT.* https://github.com/kconnour/pyRT_DISORT.
90
+ 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.
91
+
92
+ 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.
@@ -8,7 +8,7 @@ dependencies = [
8
8
  "scipy>=1.8.0",
9
9
  ]
10
10
  name = "PythonicDISORT"
11
- version = "0.7.0"
11
+ version = "0.9.0"
12
12
  authors = [
13
13
  { name="Dion HO Jia Xu", email="dh3065@columbia.edu" },
14
14
  ]
@@ -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
- """In this function the solution functions: intensity `u`, upward flux `flux_up`, downward flux `flux_down`
32
- are assembled from the eigenpairs and the coefficients which have been solved from the boundary conditions.
33
- These solution functions are then returned.
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
- if there_is_beam_source:
191
- um = np.einsum(
192
- "mtij, mtj -> mti", GC_collect[:, l, :, :], np.exp(exponent), optimize=True
193
- ) + B_collect[:, l, :] * np.exp(-scaled_tau[None, :, None] / mu0)
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
- um = np.einsum(
196
- "mtij, mtj -> mti", GC_collect[:, l, :, :], np.exp(exponent), optimize=True
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:
@@ -206,11 +233,15 @@ def _assemble_intensity_and_fluxes(
206
233
  K_collect_0,
207
234
  G_inv_collect_0,
208
235
  mu_arr,
209
- _autograd_compatible,
236
+ is_antiderivative_wrt_tau,
237
+ _autograd_compatible
210
238
  )
211
239
 
212
240
  if _autograd_compatible:
213
- um = um + np.concatenate((_mathscr_v_contribution.T, np.zeros((NFourier - 1, len(tau), NQuad))))
241
+ if NFourier == 1:
242
+ um = um + _mathscr_v_contribution.T
243
+ else:
244
+ um = um + np.concatenate((_mathscr_v_contribution.T, np.zeros((NFourier - 1, len(tau), NQuad))))
214
245
  else:
215
246
  um[0, :, :] += _mathscr_v_contribution.T
216
247
 
@@ -229,20 +260,43 @@ def _assemble_intensity_and_fluxes(
229
260
  ],
230
261
  axis=-1,
231
262
  )
232
- if there_is_beam_source:
233
- ulast = np.einsum(
234
- "tij, tj -> it", GC_collect[-1, l, :, :], np.exp(exponent), optimize=True
235
- ) + B_collect[-1, l, :].T * np.exp(-scaled_tau[None, :] / mu0)
263
+ if is_antiderivative_wrt_tau:
264
+ if there_is_beam_source:
265
+ ulast = np.einsum(
266
+ "tij, tj -> it",
267
+ GC_collect[-1, l, :, :],
268
+ np.exp(exponent) / (scale_tau[l, None] * K_collect[-1, l, :]),
269
+ optimize=True,
270
+ ) + B_collect[-1, l, :].T * np.exp(-scaled_tau[None, :] / mu0) / (
271
+ -scale_tau[None, l] / mu0
272
+ )
273
+ else:
274
+ ulast = np.einsum(
275
+ "tij, tj -> it",
276
+ GC_collect[-1, l, :, :],
277
+ np.exp(exponent) / (scale_tau[l, None] * K_collect[-1, l, :]),
278
+ optimize=True,
279
+ )
236
280
  else:
237
- ulast = np.einsum(
238
- "tij, tj -> it", GC_collect[-1, l, :, :], np.exp(exponent), optimize=True
239
- )
281
+ if there_is_beam_source:
282
+ ulast = np.einsum(
283
+ "tij, tj -> it", GC_collect[-1, l, :, :], np.exp(exponent), optimize=True
284
+ ) + B_collect[-1, l, :].T * np.exp(-scaled_tau[None, :] / mu0)
285
+ else:
286
+ ulast = np.einsum(
287
+ "tij, tj -> it", GC_collect[-1, l, :, :], np.exp(exponent), optimize=True
288
+ )
289
+
240
290
  intensities_abs = np.abs(intensities)
241
291
  Fourier_error = np.max(
242
- np.abs(ulast[:, :, None] * np.cos((NFourier - 1) * (phi0 - phi))[None, None, :]),
243
- intensities_abs,
244
- out=np.zeros_like(intensities_abs),
245
- where=intensities_abs > 1e-8,
292
+ np.divide(
293
+ np.abs(
294
+ ulast[:, :, None] * np.cos((NFourier - 1) * (phi0 - phi))[None, None, :]
295
+ ),
296
+ intensities_abs,
297
+ out=np.zeros_like(intensities_abs),
298
+ where=intensities_abs > 1e-8,
299
+ )
246
300
  )
247
301
  return I0_orig * np.squeeze(intensities), Fourier_error
248
302
  else:
@@ -251,7 +305,16 @@ def _assemble_intensity_and_fluxes(
251
305
 
252
306
  # Construct u0
253
307
  # --------------------------------------------------------------------------------------------------------------------------
254
- def u0(tau, return_act_dscale_reclassification=False):
308
+ def u0(tau, is_antiderivative_wrt_tau=False, _return_act_dscale_for_reclass=False):
309
+ """
310
+ Zeroth Fourier mode of the intensity with argument `tau` (type: array or float).
311
+ Returns an ndarray with axes corresponding to variation with `mu` and `tau` respectively.
312
+ This function is useful for calculating actinic fluxes and other quantities of interest,
313
+ but reclassification of delta-scaled flux and other corrections must be done manually
314
+ (for actinic flux `generate_diff_act_flux_funcs` will automatically perform the reclassification).
315
+ Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
316
+ to switch to an antiderivative of the function with respect to `tau`.
317
+ """
255
318
  tau = np.atleast_1d(tau)
256
319
  assert np.all(tau >= 0)
257
320
  assert np.all(tau <= tau_arr[-1])
@@ -268,11 +331,14 @@ def _assemble_intensity_and_fluxes(
268
331
  scaled_tau = scaled_tau_arr_l - scaled_tau_dist_from_top
269
332
  # The following complements the function `subroutines.generate_diff_act_flux_funcs`
270
333
  # in performing the reclassification of delta-scaled actinic flux
271
- if return_act_dscale_reclassification:
272
- act_dscale_reclassification = I0 * np.exp(-scaled_tau / mu0) - I0 * np.exp(-tau / mu0)
334
+ if _return_act_dscale_for_reclass:
335
+ if is_antiderivative_wrt_tau:
336
+ act_dscale_reclassification = I0 * np.exp(-scaled_tau / mu0) / (-scale_tau[l] / mu0) - I0 * np.exp(-tau / mu0) * -mu0
337
+ else:
338
+ act_dscale_reclassification = I0 * np.exp(-scaled_tau / mu0) - I0 * np.exp(-tau / mu0)
273
339
  else:
274
340
  scaled_tau = tau
275
- if return_act_dscale_reclassification:
341
+ if _return_act_dscale_for_reclass:
276
342
  act_dscale_reclassification = 0
277
343
 
278
344
  exponent = np.concatenate(
@@ -282,14 +348,33 @@ def _assemble_intensity_and_fluxes(
282
348
  ],
283
349
  axis=-1,
284
350
  )
285
- if there_is_beam_source:
286
- u0 = np.einsum(
287
- "tij, tj -> it", GC_collect_0[l, :, :], np.exp(exponent), optimize=True
288
- ) + B_collect_0[l, :].T * np.exp(-scaled_tau[None, :] / mu0)
351
+
352
+ if is_antiderivative_wrt_tau:
353
+ if there_is_beam_source:
354
+ u0 = np.einsum(
355
+ "tij, tj -> it",
356
+ GC_collect_0[l, :, :],
357
+ np.exp(exponent) / (scale_tau[l, None] * K_collect_0[l, :]),
358
+ optimize=True,
359
+ ) + B_collect_0[l, :].T * np.exp(-scaled_tau[None, :] / mu0) / (
360
+ -scale_tau[None, l] / mu0
361
+ )
362
+ else:
363
+ u0 = np.einsum(
364
+ "tij, tj -> it",
365
+ GC_collect_0[l, :, :],
366
+ np.exp(exponent) / (scale_tau[l, None] * K_collect_0[l, :]),
367
+ optimize=True,
368
+ )
289
369
  else:
290
- u0 = np.einsum(
291
- "tij, tj -> it", GC_collect_0[l, :, :], np.exp(exponent), optimize=True
292
- )
370
+ if there_is_beam_source:
371
+ u0 = np.einsum(
372
+ "tij, tj -> it", GC_collect_0[l, :, :], np.exp(exponent), optimize=True
373
+ ) + B_collect_0[l, :].T * np.exp(-scaled_tau[None, :] / mu0)
374
+ else:
375
+ u0 = np.einsum(
376
+ "tij, tj -> it", GC_collect_0[l, :, :], np.exp(exponent), optimize=True
377
+ )
293
378
 
294
379
  # Contribution from particular solution for isotropic internal sources
295
380
  if there_is_iso_source:
@@ -301,11 +386,12 @@ def _assemble_intensity_and_fluxes(
301
386
  K_collect_0,
302
387
  G_inv_collect_0,
303
388
  mu_arr,
304
- _autograd_compatible,
389
+ is_antiderivative_wrt_tau,
390
+ _autograd_compatible
305
391
  )
306
- u0 += _mathscr_v_contribution
392
+ u0 = u0 + _mathscr_v_contribution
307
393
 
308
- if return_act_dscale_reclassification:
394
+ if _return_act_dscale_for_reclass:
309
395
  return I0_orig * np.squeeze(u0), act_dscale_reclassification
310
396
  else:
311
397
  return I0_orig * np.squeeze(u0)
@@ -320,7 +406,13 @@ def _assemble_intensity_and_fluxes(
320
406
  B_neg = B_collect_0[:, N:].T
321
407
 
322
408
 
323
- def flux_up(tau):
409
+ def flux_up(tau, is_antiderivative_wrt_tau=False):
410
+ """
411
+ (Energetic) Flux function with argument `tau` (type: array or float) for positive (upward) `mu` values.
412
+ Returns the diffuse flux magnitudes (same type and size as `tau`).
413
+ Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
414
+ to switch to an antiderivative of the function with respect to `tau`.
415
+ """
324
416
  tau = np.atleast_1d(tau)
325
417
  assert np.all(tau >= 0)
326
418
  assert np.all(tau <= tau_arr[-1])
@@ -347,13 +439,19 @@ def _assemble_intensity_and_fluxes(
347
439
  K_collect_0,
348
440
  G_inv_collect_0,
349
441
  mu_arr,
350
- _autograd_compatible,
442
+ is_antiderivative_wrt_tau,
443
+ _autograd_compatible
351
444
  )[:N, :]
352
445
  else:
353
446
  _mathscr_v_contribution = 0
354
-
447
+
355
448
  if there_is_beam_source:
356
- direct_beam_contribution = B_pos[:, l] * np.exp(-scaled_tau[None, :] / mu0)
449
+ if is_antiderivative_wrt_tau:
450
+ direct_beam_contribution = (
451
+ B_pos[:, l] * np.exp(-scaled_tau[None, :] / mu0) / (-scale_tau[None, l] / mu0)
452
+ )
453
+ else:
454
+ direct_beam_contribution = B_pos[:, l] * np.exp(-scaled_tau[None, :] / mu0)
357
455
  else:
358
456
  direct_beam_contribution = 0
359
457
 
@@ -364,17 +462,36 @@ def _assemble_intensity_and_fluxes(
364
462
  ],
365
463
  axis=-1,
366
464
  )
367
- u0_pos = (
368
- np.einsum("tij, tj -> it", GC_pos[l, :, :], np.exp(exponent))
369
- + direct_beam_contribution
370
- + _mathscr_v_contribution
371
- )
465
+
466
+ if is_antiderivative_wrt_tau:
467
+ u0_pos = (
468
+ np.einsum(
469
+ "tij, tj -> it",
470
+ GC_pos[l, :, :],
471
+ np.exp(exponent) / (scale_tau[l, None] * K_collect_0[l, :]),
472
+ )
473
+ + direct_beam_contribution
474
+ + _mathscr_v_contribution
475
+ )
476
+ else:
477
+ u0_pos = (
478
+ np.einsum("tij, tj -> it", GC_pos[l, :, :], np.exp(exponent))
479
+ + direct_beam_contribution
480
+ + _mathscr_v_contribution
481
+ )
372
482
 
373
483
  flux = 2 * pi * (mu_arr_pos * W) @ u0_pos
374
484
  return I0_orig * np.squeeze(flux)[()]
375
485
 
376
486
 
377
- def flux_down(tau):
487
+ def flux_down(tau, is_antiderivative_wrt_tau=False):
488
+ """
489
+ (Energetic) Flux function with argument `tau` (type: array or float) for negative (downward) `mu` values.
490
+ Returns a tuple of the diffuse and direct flux magnitudes respectively where each entry is of the
491
+ same type and size as `tau`.
492
+ Pass `is_antiderivative_wrt_tau = True` (defaults to `False`)
493
+ to switch to an antiderivative of the function with respect to `tau`.
494
+ """
378
495
  tau = np.atleast_1d(tau)
379
496
  assert np.all(tau >= 0)
380
497
  assert np.all(tau <= tau_arr[-1])
@@ -401,15 +518,21 @@ def _assemble_intensity_and_fluxes(
401
518
  K_collect_0,
402
519
  G_inv_collect_0,
403
520
  mu_arr,
404
- _autograd_compatible,
521
+ is_antiderivative_wrt_tau,
522
+ _autograd_compatible
405
523
  )[N:, :]
406
524
  else:
407
525
  _mathscr_v_contribution = 0
408
526
 
409
527
  if there_is_beam_source:
410
- direct_beam_contribution = B_neg[:, l] * np.exp(-scaled_tau[None, :] / mu0)
411
- direct_beam = I0 * mu0 * np.exp(-tau / mu0)
412
- direct_beam_scaled = I0 * mu0 * np.exp(-scaled_tau / mu0)
528
+ if is_antiderivative_wrt_tau:
529
+ direct_beam_contribution = B_neg[:, l] * np.exp(-scaled_tau[None, :] / mu0) / (-scale_tau[None, l] / mu0)
530
+ direct_beam = I0 * mu0 * np.exp(-tau / mu0) * -mu0
531
+ direct_beam_scaled = I0 * mu0 * np.exp(-scaled_tau / mu0) / (-scale_tau[None, l] / mu0)
532
+ else:
533
+ direct_beam_contribution = B_neg[:, l] * np.exp(-scaled_tau[None, :] / mu0)
534
+ direct_beam = I0 * mu0 * np.exp(-tau / mu0)
535
+ direct_beam_scaled = I0 * mu0 * np.exp(-scaled_tau / mu0)
413
536
  else:
414
537
  direct_beam_contribution = 0
415
538
  direct_beam = 0
@@ -422,11 +545,19 @@ def _assemble_intensity_and_fluxes(
422
545
  ],
423
546
  axis=-1,
424
547
  )
425
- u0_neg = (
426
- np.einsum("tij, tj -> it", GC_neg[l, :, :], np.exp(exponent))
427
- + direct_beam_contribution
428
- + _mathscr_v_contribution
429
- )
548
+
549
+ if is_antiderivative_wrt_tau:
550
+ u0_neg = (
551
+ np.einsum("tij, tj -> it", GC_neg[l, :, :], np.exp(exponent) / (scale_tau[l, None] * K_collect_0[l, :]))
552
+ + direct_beam_contribution
553
+ + _mathscr_v_contribution
554
+ )
555
+ else:
556
+ u0_neg = (
557
+ np.einsum("tij, tj -> it", GC_neg[l, :, :], np.exp(exponent))
558
+ + direct_beam_contribution
559
+ + _mathscr_v_contribution
560
+ )
430
561
 
431
562
  diffuse_flux = 2 * pi * (mu_arr_pos * W) @ u0_neg + direct_beam_scaled - direct_beam
432
563
  return (