brian-rose / ClimateLaboratoryBook

JupyterBook source for The Climate Laboratory
https://brian-rose.github.io/ClimateLaboratoryBook
Other
103 stars 45 forks source link

climlab does not import correctly in Google Colab #96

Closed jlpearso closed 1 year ago

jlpearso commented 1 year ago

Hello,

I have just installed climlab on Google Colab with no errors. However, upon import, I receive the following warnings:

/usr/local/lib/python3.9/dist-packages/climlab/radiation/cam3.py:46: 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.')
/usr/local/lib/python3.9/dist-packages/climlab/radiation/rrtm/rrtmg_lw.py:19: 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.')
/usr/local/lib/python3.9/dist-packages/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.')
/usr/local/lib/python3.9/dist-packages/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.')

Initializing a model is fine, but when I try to run the model forward in time I get the following error:


NameError                                 Traceback (most recent call last)
[<ipython-input-14-b960f8fe0eca>](https://773tncaih8g-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230322-060151-RC00_518525591#) in <module>
----> 1 radmodel.step_forward()

6 frames
[/usr/local/lib/python3.9/dist-packages/climlab/process/time_dependent_process.py](https://773tncaih8g-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230322-060151-RC00_518525591#) in step_forward(self)
    331 
    332         """
--> 333         tenddict = self.compute()
    334         #  Total tendency is applied as an explicit forward timestep
    335         # (already accounting properly for order of operations in compute() )

[/usr/local/lib/python3.9/dist-packages/climlab/process/time_dependent_process.py](https://773tncaih8g-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230322-060151-RC00_518525591#) in compute(self)
    211         tendencies = {}
    212         ignored = self._compute_type('diagnostic')
--> 213         tendencies['explicit'] = self._compute_type('explicit')
    214         #  Tendencies due to implicit and adjustment processes need to be
    215         #  calculated from a state that is already adjusted after explicit stuff

[/usr/local/lib/python3.9/dist-packages/climlab/process/time_dependent_process.py](https://773tncaih8g-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230322-060151-RC00_518525591#) in _compute_type(self, proctype)
    259             if self.time['steps'] % step_ratio == 0:
    260                 proc.time['active_now'] = True
--> 261                 tenddict = proc.compute()
    262             else:
    263                 # proc.tendencies is unchanged from last subprocess timestep if we didn't recompute it above

[/usr/local/lib/python3.9/dist-packages/climlab/process/time_dependent_process.py](https://773tncaih8g-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230322-060151-RC00_518525591#) in compute(self)
    233                 self.tendencies[varname] += tend
    234         # Finally compute my own tendencies, if any
--> 235         self_tend = self._compute()
    236         #  Adjustment processes _compute method returns absolute adjustment
    237         #  Needs to be converted to rate of change

[/usr/local/lib/python3.9/dist-packages/climlab/process/energy_budget.py](https://773tncaih8g-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230322-060151-RC00_518525591#) in _compute(self)
     70 
     71     def _compute(self):
---> 72         tendencies = self._temperature_tendencies()
     73         return tendencies
     74 

[/usr/local/lib/python3.9/dist-packages/climlab/process/energy_budget.py](https://773tncaih8g-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230322-060151-RC00_518525591#) in _temperature_tendencies(self)
     58 
     59     def _temperature_tendencies(self):
---> 60         self._compute_heating_rates()
     61         tendencies = {}
     62         for varname, value in self.state.items():

[/usr/local/lib/python3.9/dist-packages/climlab/radiation/rrtm/rrtmg_sw.py](https://773tncaih8g-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230322-060151-RC00_518525591#) in _compute_heating_rates(self)
    206             #  Call the Monte Carlo Independent Column Approximation (McICA, Pincus et al., JC, 2003)
    207             (cldfmcl, ciwpmcl, clwpmcl, reicmcl, relqmcl, taucmcl,
--> 208             ssacmcl, asmcmcl, fsfcmcl) = _rrtmg_sw.climlab_mcica_subcol_sw(
    209                             ncol, nlay, icld, permuteseed, irng, play,
    210                             cldfrac, ciwp, clwp, reic, relq, tauc, ssac, asmc, fsfc)

NameError: name '_rrtmg_sw' is not defined```

This seems similar to another issue still open here with regards to binder. 

Are there any workarounds? Thank you kindly.
jlpearso commented 1 year ago

sorry I realize now this should have been posted in the climlab repository, not the one for the book! The similar issue just popped up in my search. I will cross post there, please close this at your discretion.

brian-rose commented 1 year ago

Let's take care of this over at https://github.com/climlab/climlab/issues/175. I will close this.