Coder Social home page Coder Social logo

danielkoll / pyrads Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 10.0 21.94 MB

A line-by-line longwave radiation code for planetary atmospheres.

License: MIT License

Python 14.65% Fortran 85.35%
two-stream longwave line-by-line radiative-transfer radiation atmosphere python olr planetary-atmospheres surface-temperature

pyrads's People

Contributors

andrewilwilliams avatar brian-rose avatar danielkoll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyrads's Issues

Packaging this nice package

PyRADS will be a lot more accessible to users if it is packaged with a standard setup.py file so it can be installed and imported like any other library.

It should also be possible to build and wrap the MTCKD code with f2py so it is callable from python without reading and writing to disk.

I'll submit some PRs when I have time.

Stratospheric water vapor inaccurate

Old calculation in verticalstructure.py

    # v1: pick highest pressure level in strat, assume q is uniform at that value
    # mask = T_adiabat < Tstrat
    # T = T_adiabat
    # T[mask] = Tstrat

    # q = q_adiabat
    # q[mask] = q_adiabat[p==(p[mask].max())]

New calculation in verticalstructure.py
# v2, more accurate: use interpolation to find p_trop, where T=Tstrat. Then compute q at that level.
# Note: at insufficient res, interpolation will produce p_trop=min(p)!
p_trop = np.interp(Tstrat,T_adiabat,p)
q_trop = get_q(Tstrat,p_trop,params,RH=RH) # analytically ..
mask = p<=p_trop

    T = T_adiabat
    T[mask] = Tstrat
    
    q = q_adiabat
    q[mask] = q_trop

Use numba to accelerate OpticalThickness calculation?

As noted in the examples/tests, most of the time taken to calculate the spectra is from the OpticalThickness.compute_tau calculation.

I've done a little bit of digging and it seems to me that the functions computeAbsorption_fixedCutoff()/computeAbsorption() (called by getKappa_HITRAN()) in pyrads/Absorption_Crosssections_HITRAN2016.py are the ones which cause this slowdown.

This is because in both functions there exists a very large loop over the wavenumbers:

for i in range(len(waveList)):
        n = waveList[i] # Wavenumber of the line
        #gam = gamList[i]*(p/1.013e5)*(296./T)**TExpList[i]  # DKOLL: old
        gam = getGamma(i)*(296./T)**TExpList[i]              # DKOLL: new. getGamma includes p-scaling
        #Temperature scaling of line strength

Given that there isn't anything particularly complex that happens inside this loop, I'm wondering whether it makes sense to try and accelerate this function using numba. I'm playing around with this idea a bit now and I think that it should be possible, but the code in Absorption_Crosssections_HITRAN2016.py will have to be tidied up a bit.

Specifically:

  • Remove global statements / make all function inputs explicit
  • Unpack class instances (eg. unpack everything in params) -- numba doesn't like classes at the moment

There might be more issues here, and I've only just started playing with the idea, but I'll try and keep a log here of what does/doesn't work.

Also tagging @hdrake and @brian-rose here too, in case anyone's interested / has any thoughts on this / has already tried it?!

Python 3 compatibility

Python 2.7 is very close to end-of-life. It's important to make PyRADS work on Python 3 if it's going to have any future.

I had a brief glance through the code. Converting to Python 3 may be as simple as replacing print statements with print() functions.

Numba causes silent errors for mixed-component atmospheres

The new numba capability reproduces pyrads results identically when I only use HITRAN data from a single species.

However, numba appears to fail silently when using line data from multiple HITRAN species, which requires repeated calls to Absorption_Crosssections_HITRAN2016_numba. Test03.runaway_with_co2 contains an example of calculations which use both H2O and CO2 data. In this case the optical thicknesses computed using numba don't match the results without numba anymore.

Adding isotopologues

By default, PyRADS only implements the dominant isotopologue of each gas. However, minor isotopologues have lines and bands in parts of the spectrum where the main isotopologue doesn't absorb much.

This could potentially affect CO2 forcing at intermediate/high CO2 levels -- currently unclear how big the effect is.

It seems that, by default, HITRAN data is already weighted by a 'representative' isotope ratio (https://hitran.org/docs/definitions-and-units). So necessary changes would be to update the HITRAN line data, plus the mean molecular mass of each gas assumed in the code (e.g., Absorption_Crosssections_HITRAN2016.py assumes a molecular weight of 44 g/mol for CO2).

Relaxing CO2 trace gas assumption in OpticalThickness.py ?

At the moment, compute_tau_H2ON2_CO2dilute assumes that CO2 is a trace gas and so doesn't include the partial pressure of CO2 in the calculation. I'm currently running PyRADS with CO2 values up to ~50,000ppmv and so this is a problem.

To fix this, is it sufficient to add in the partial pressure of CO2 and then just change the broadening to "mixed"?

i.e.

p_CO2 = pres * ppv_CO2
p_H2O = RH * params.esat(temp)  # ...

q_CO2 = convert_molar_to_mass_ratio(ppv_CO2,params.R_CO2,R_mean)

R_mean = q_H2O*params.Rv + q_CO2*params.R_CO2 + (1.-q_H2O - q_CO2)*params.R


kappaH2O = getKappa_HITRAN(grid.n,grid.n0,grid.n1,grid.dn, \
                           "H2O",press=pres,press_self=p_H2O, \
                           temp=temp,broadening="mixed", lineWid=25., \
                           cutoff_option="fixed",remove_plinth=True)

kappaCO2 = getKappa_HITRAN(grid.n,grid.n0,grid.n1,grid.dn, \
                           "CO2",press=pres,press_self=p_CO2, \
                           temp=temp,broadening="mixed", lineWid=25., \
                           cutoff_option="fixed",remove_plinth=False)

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.