Code Monkey home page Code Monkey logo

ldeo-crew / pythonic-disort Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 2.0 4.6 MB

Discrete Ordinates Solver for the (1D) Radiative Transfer Equation in a single or multi-layer plane-parallel atmosphere. Coded entirely in Python 3. Based on Stamnes' FORTRAN DISORT (see references in the Jupyter Notebook) and has its main features.

Home Page: https://pythonic-disort.readthedocs.io/en/latest/

License: MIT License

Python 46.61% Jupyter Notebook 53.39%
atmospheric-modelling discrete-ordinates-method disort python radiative-transfer radiative-transfer-models

pythonic-disort's Introduction

Introduction

The PythonicDISORT package is a Discrete Ordinates Solver for the (1D) Radiative Transfer Equation in a plane-parallel, horizontally homogeneous atmosphere. It is coded entirely in Python 3 and is a reimplementation instead of a wrapper. While PythonicDISORT has been optimized for speed, it will naturally be slower than similar FORTRAN algorithms. On the other hand, PythonicDISORT should be easier to install, use, and modify than FORTRAN-based Discrete Ordinates Solvers.

PythonicDISORT is based on Stamnes' FORTRAN DISORT (see References, in particular [2, 3, 8]) and has its main features: multi-layer solver, delta-M scaling, Nakajima-Tanaka (NT) corrections, only flux option, direct beam source, isotropic internal source (blackbody emission), Dirichlet boundary conditions (diffuse flux boundary sources), Bi-Directional Reflectance Function (BDRF) for surface reflection, interpolation with respect to polar angle and more. In addition, we added a subroutine to calculate actinic fluxes to satisfy a user request, and integration with respect to tau was also added. Further feature requests as well as feedback are welcome.

You may contact me, Dion, through [email protected].

The GitHub repository is https://github.com/LDEO-CREW/Pythonic-DISORT.

Documentation

https://pythonic-disort.readthedocs.io/en/latest/

Also see the accompanying Jupyter Notebook Pythonic-DISORT.ipynb in the docs directory of our GitHub repository. This Jupyter Notebook provides comprehensive documentation, suggested inputs, explanations, mathematical derivations and verification tests. It is highly recommended that new users read the non-optional parts of sections 1 and 2.

PyTest and examples of how to use PythonicDISORT

Not only are there verification tests in Pythonic-DISORT.ipynb, most of the test problems in Stamnes' disotest.f90 (download DISORT 4.0.99 from http://www.rtatmocn.com/disort/) have also been recreated. In these tests, the solutions from PythonicDISORT are compared against solutions 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 in the pydisotest directory to run these tests. The pydisotest directory also contains Jupyter Notebooks to show the implementation of each test. These notebooks double up as examples of how to use PythonicDISORT.

Installation

  • From PyPI: pip install PythonicDISORT
  • From Conda-forge: (TODO: need to first publish on Conda-forge)
  • 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)

Requirements to run PythonicDISORT

  • Python 3.8+
  • numpy >= 1.8.0
  • scipy >= 1.8.0
  • (OPTIONAL) pytest >= 6.2.5 (Required to use the command pytest, see PyTest and examples of how to use PythonicDISORT)

(OPTIONAL) Additional requirements to run the Jupyter Notebook

  • autograd >= 1.5
  • jupyter > 1.0.0
  • notebook > 6.5.2
  • matplotlib >= 3.6.0

In addition, a F2PY-wrapped Stamnes' DISORT, or equivalent, is required to properly run the last section (section 6).

Compatibility

The PythonicDISORT package should be system agnostic given its minimal dependencies and pure Python code. Everything in the repository was built and tested on Windows 11.

Acknowledgements

I acknowledge funding from NSF through the Learning the Earth with Artificial intelligence and Physics (LEAP) Science and Technology Center (STC) (Award #2019625) under which this package was initially created.

References

  1. S. Chandrasekhar. 1960. Radiative Transfer.

  2. Knut Stamnes and S-Chee Tsay and Warren Wiscombe and Kolf Jayaweera. 1988. Numerically stable algorithm for discrete-ordinate-method radiative transfer in multiple scattering and emitting layered media. http://opg.optica.org/ao/abstract.cfm?URI=ao-27-12-2502.

  3. Stamnes, S.. 1999. LLLab disort website. http://www.rtatmocn.com/disort/.

  4. Knut Stamnes and Paul Conklin. 1984. A new multi-layer discrete ordinate approach to radiative transfer in vertically inhomogeneous atmospheres. https://www.sciencedirect.com/science/article/pii/0022407384900311.

  5. W. J. Wiscombe. 1977. The Delta–M Method: Rapid Yet Accurate Radiative Flux Calculations for Strongly Asymmetric Phase Functions. https://journals.ametsoc.org/view/journals/atsc/34/9/1520-0469_1977_034_1408_tdmrya_2_0_co_2.xml.

  6. J. H. Joseph and W. J. Wiscombe and J. A. Weinman. 1976. The Delta-Eddington Approximation for Radiative Flux Transfer. https://journals.ametsoc.org/view/journals/atsc/33/12/1520-0469_1976_033_2452_tdeafr_2_0_co_2.xml.

  7. Sykes, J. B.. 1951. Approximate Integration of the Equation of Transfer. https://doi.org/10.1093/mnras/111.4.377.

  8. Stamnes, Knut and Tsay, Si-Chee and Wiscombe, Warren and Laszlo, Istvan and Einaudi, Franco. 2000. General Purpose Fortran Program for Discrete-Ordinate-Method Radiative Transfer in Scattering and Emitting Layered Media: An Update of DISORT.

  9. Z. Lin and S. Stamnes and Z. Jin and I. Laszlo and S.-C. Tsay and W.J. Wiscombe and K. Stamnes. 2015. Improved discrete ordinate solutions in the presence of an anisotropically reflecting lower boundary: Upgrades of the DISORT computational tool. https://www.sciencedirect.com/science/article/pii/S0022407315000679.

  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.

  11. Knut Stamnes. 1982. On the computation of angular distributions of radiation in planetary atmospheres. https://www.sciencedirect.com/science/article/pii/0022407382900966.

  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.

  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.

pythonic-disort's People

Contributors

dhjx1996 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pythonic-disort's Issues

Speed up the for-loops in PythonicDISORT using the fact that many np.linalg functions can act on a list of matrices

As of NumPy version 1.8.0 (remember to update requirements), np.linalg.eig([list of matrices]) will output a list of the eigenpairs for each matrix. This is much faster than using a python for-loop. This should work for many other np.linalg functions as well, see https://numpy.org/doc/stable/reference/routines.linalg.html#module-numpy.linalg.

PythonicDISORT will still require for-loops to assemble the various systems to be solved, but we can potentially speed the algorithm up greatly by using the above on the linear algebra operations which are the most expensive parts of each loop.

Use Jordan matrices and generalized eigenvectors to implement the solution when single-scattering albedo = 1.

If the single-scattering albedo equals $0$, the coefficient matrix will not be diagonalizable. It is still possible to express the coefficient matrix $A = G J G^{-1}$, but $J$ will be a Jordan matrix and we will need to use generalized eigenvectors to solve the system of ODEs. Currently, users may use single-scattering albedos that are close to $1$ to approximate conservative scattering and PythonicDISORT will warn if a single-scattering albedo is too close to $1$.

We would like PythonicDISORT to instead use the special case solution if the single-scattering albedo is too close to $1$. This may render the joblib parallelization obsolete.

Remove symmetry assumption in the BDRF

We assumed the BDRF to be spherically symmetric. This is false for many important BDRFs, in particular the four BDRFs in Stamnes' DISORT4: Hapke, Cox-Munk, RPV and Ross-Li. We can still assume that the BDRF is symmetric in the azimuthal angle, i.e. that it depends on $|\phi - \phi'|$ but not $\phi$ and $\phi'$ directly. We, however, need to let the BDRF depend on $\mu$ and $\mu'$ independently. Instead of an array of BDRF Legendre coefficients, the required BDRF input should now be a list of $\mu, \mu'$ dependent Fourier coefficient functions.

Make code citable

Add a CITATION.cff file; configure repository to publish releases to Zenodo and mint a DOI.

Unable to import distort

Hi, I'm a newbie and I'm learning the Pythonic-DISORT using Jupyter notebook. it's going fine for me but when I got to chapter 6;
"Comparisons against Stamnes’ DISORT", I was unable to import disort. I see disort4.0.99_f2py directory in your GitHub repository but don't know how to go about it.
any help will be greatly appreciated .

Implement Stamnes' "iteration of the source-function" interpolation method as a subroutine

While every $\mu$-interpolation of the discrete ordinates intensity function approximation will have caveats, Stamnes' "iteration of the source-function" interpolation method (see Sections 2.7 and 2.8 of Stamnes, Knut and Tsay, Si-Chee and Wiscombe, Warren and Laszlo, Istvan and Einaudi, Franco. 2000. General Purpose Fortran Program for Discrete-Ordinate-Method Radiative Transfer in Scattering and Emitting Layered Media: An Update of DISORT) is non-standard and performs uniquely well. Therefore, it should be implemented as a subroutine.

Cannot run the example/test notebooks

Hello,
I have installed Pythonic-DISORT by cloning the repo and running pip install -r all_optional_dependencies.txt

I then tried to run the example notebook 1a_test but get this error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 2
      1 import PythonicDISORT
----> 2 import disort
      3 import numpy as np
      4 import matplotlib.pyplot as plt

ModuleNotFoundError: No module named 'disort'

The installation went smoothly, so I am unsure why I get this ModuleNotFoundError. Could you please look into it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.