Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spectrally-resolved output from RRTMG_LW #137

Closed
AndrewILWilliams opened this issue Jan 6, 2021 · 5 comments · Fixed by #138
Closed

Spectrally-resolved output from RRTMG_LW #137

AndrewILWilliams opened this issue Jan 6, 2021 · 5 comments · Fixed by #138

Comments

@AndrewILWilliams
Copy link
Contributor

Following much Twitter conversation(!), I think it would be useful to try and code it such that the spectral band fluxes are outputted from RRTMG in addition to the total flux. I'm thinking particularly about the LW for now, but perhaps this could be expanded.

Currently, as pointed out by @brian-rose, climlab doesn't give these spectral diagnostics because they're not calculated in the fortran code. However, I think that it should be possible to get the OLR as a function of the wavenumber at band center without too much extra code.

I think that the relevant loop over bands occurs at this line in rrtm/_rrtmg_lw/rrtmg_lw_v4.85/gcm_model/src/rrtmg_lw_rtrnmc.f90:

igc = 1
! Loop over frequency bands.
do iband = istart, iend
...

Then later on in the loop, there's a bit of code which calculates the longwave diagnostics, eg totuflux.

So as far as I can tell, it's just a matter of adding a new variable like totuflux_sr (Spectrally Resolved) in this loop and then following that back through the code until you get to the Python interface.

I'm not great with fortran, but can start trying this today and see where I get...

@brian-rose
Copy link
Collaborator

Great, sounds like a good start. A couple things to note:

  • the code in climlab/radiation/rrtm/_rrtmg_lw/rrtmg_lw_v4.85/ should be kept "pure", i.e. an unmodified copy of RRTMG v4.85
  • when modifying the fortran, start by copying the relevant file to climlab/radiation/rrtm/_rrtmg_lw/sourcemods/ and work from that copy.
  • add your modified code file to the mod_src list in setup.py. The compiler should then pick up the modified version during the build

@brian-rose
Copy link
Collaborator

We'll also need to think about the user-facing part of the wrapper. What do you want the new diagnostic to look like?

I can imagine implementing a simple test to see if the spectrally decomposed TOA flux adds up to the OLR.

@AndrewILWilliams
Copy link
Contributor Author

AndrewILWilliams commented Jan 7, 2021

Thanks @brian-rose ! That's helpful and also sounds like a sensible test to implement.

I'm just putting together a PR now, but I'm having a bit of trouble building climlab. In the docs I read that I need to download some "SDK" file and put it at $HOME/opt/MacOSX10.9.sdk on my mac. However, even after doing this, when I try import climlab, the fortran extensions aren't working?

All of the tests pass fine

(test_env) Andrews-MacBook-Pro-2:climlab andrewwilliams$ python
Python 3.7.9 (default, Aug 31 2020, 07:22:35) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import climlab
/Users/andrewwilliams/Desktop/PhD/Projects/climlab/climlab/radiation/cam3/cam3.py:67: UserWarning: Cannot import and initialize compiled Fortran extension, CAM3 module will not be functional.
  warnings.warn('Cannot import and initialize compiled Fortran extension, CAM3 module will not be functional.')
/Users/andrewwilliams/Desktop/PhD/Projects/climlab/climlab/radiation/rrtm/rrtmg_lw.py:18: UserWarning: Cannot import and initialize compiled Fortran extension, RRTMG_LW module will not be functional.
  warnings.warn('Cannot import and initialize compiled Fortran extension, RRTMG_LW module will not be functional.')
/Users/andrewwilliams/Desktop/PhD/Projects/climlab/climlab/radiation/rrtm/rrtmg_sw.py:19: UserWarning: Cannot import and initialize compiled Fortran extension, RRTMG_SW module will not be functional.
  warnings.warn('Cannot import and initialize compiled Fortran extension, RRTMG_SW module will not be functional.')
/Users/andrewwilliams/Desktop/PhD/Projects/climlab/climlab/convection/emanuel_convection.py:14: UserWarning: Cannot import EmanuelConvection fortran extension, this module will not be functional.
  warnings.warn('Cannot import EmanuelConvection fortran extension, this module will not be functional.')
>>> 

@brian-rose
Copy link
Collaborator

This is expected if you import climlab from the root level of the source code repository, because Python will always prefer to import from the local path first.

If you import climlab from a different working directory, you will be importing the version of climlab installed in the current python environment. You will not see those warning messages. If you've already found that tests are passing, then you should have full functionality and be good to go.

@AndrewILWilliams
Copy link
Contributor Author

AndrewILWilliams commented Jan 7, 2021

Great! That works! :)

I'm just putting a test together then will submit a PR. Something is being outputted, and the sum(spectral_olr, )≈olr so that's good, just want to tidy up a bit

EDIT: I need to double check the sum(spectral_olr)=olr actually, I forgot that I need to account for the different band widths

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants