Ejemplo n.º 1
0
 def _compute_fixed(self):
     '''Recompute any fixed quantities after a change in parameters'''
     phi = np.deg2rad(self.lat)
     try:
         albedo = self.a0 + self.a2 * P2(np.sin(phi))
     except:
         albedo = np.zeros_like(phi)
     # make sure that the diagnostic has the correct field dimensions.
     dom = self.domains['default']
     self.albedo = Field(albedo, domain=dom)
Ejemplo n.º 2
0
 def _compute_fixed(self):
     phi = np.deg2rad(self.lat)
     #  Why is there a silent fail here? Should get rid of this.
     try:
         insolation = self.S0 / 4 * (1. + self.s2 * P2(np.sin(phi)))
         # make sure that the diagnostic has the correct field dimensions.
         dom = self.domains['default']
         #self.insolation = Field(insolation, domain=dom)
         self.insolation[:] = Field(insolation, domain=dom)
     except:
         pass
Ejemplo n.º 3
0
 def _compute_fixed(self):
     #lat = self.domains['default'].axes['lat'].points 
     lat = self.lat
     phi = np.deg2rad(lat)
     try:
         insolation = self.S0 / 4 * (1. + self.s2 * P2(np.sin(phi)))
         # make sure that the diagnostic has the correct field dimensions.
         dom = self.domains['default']
         self.diagnostics['insolation'] = Field(insolation, domain=dom)
     except:
         pass
Ejemplo n.º 4
0
 def _compute_fixed(self):
     '''Recompute any fixed quantities after a change in parameters'''
     try:
         lon, lat = np.meshgrid(self.lon, self.lat)
     except:
         lat = self.lat
     phi = np.deg2rad(lat)
     try:
         albedo = self.a0 + self.a2 * P2(np.sin(phi))
     except:
         albedo = np.zeros_like(phi)
     # make sure that the diagnostic has the correct field dimensions.
     #dom = self.domains['default']
     #  this is a more robust way to get the single value from dictionary:
     dom = next(iter(self.domains.values()))
     self.albedo = Field(albedo, domain=dom)
Ejemplo n.º 5
0
 def _compute_fixed(self):
     phi = np.deg2rad(self.lat)
     #  Why is there a silent fail here? Should get rid of this.
     try:
         insolation = self.S0 / 4 * (1. + self.s2 * P2(np.sin(phi)))
         dom = self.domains['default']
         try:
             insolation = to_latlon(insolation, domain=dom)
             self.insolation[:] = insolation
         except:
             self.insolation[:] = Field(insolation, domain=dom)
         # make sure that the diagnostic has the correct field dimensions.
         #self.insolation = Field(insolation, domain=dom)
         self.insolation[:] = Field(insolation, domain=dom)
         self.coszen[:] = self._coszen_from_insolation()
     #  Silent fail only for attribute error: _s2 is not an attribute of self
     #  but s2 parameter is being stored in self._s2
     except AttributeError:
         pass
Ejemplo n.º 6
0
def test_analytical():
    '''Check to see if the the numerical solution converges to the analytical
    steady-state solution of the simple EBM with constant albedo'''
    param = {
        'a0': 0.3,
        'a2': 0.,
        'ai': 0.3,
        's2': -0.48,
        'S0': 1360.,
        'A': 210.,
        'B': 2.,
        'D': 0.55,
        'Tf': -1000.,  # effectively makes albedo constant
    }
    m = climlab.EBM(**param)
    m.integrate_years(5)
    Tnumerical = np.squeeze(m.Ts)
    delta = param['D'] / param['B']
    x = np.sin(np.deg2rad(m.lat))
    Tanalytical = ((1 - param['a0']) * param['S0'] / 4 *
                   (1 + param['s2'] * P2(x) /
                    (1 + 6 * delta)) - param['A']) / param['B']
    assert Tnumerical == pytest.approx(Tanalytical, abs=2E-2)
from climlab import domain
from climlab.domain import field
from climlab.utils.legendre import P2
import numpy as np
import matplotlib.pyplot as plt

# create domain
sfc = domain.zonal_mean_surface(num_lat=36)

lat = sfc.lat.points
lat_rad = np.deg2rad(lat)

# define initial temperature distribution
T0 = 15.
T2 = -20.
Ts = field.Field(T0 + T2 * P2(np.sin(lat_rad)), domain=sfc)

# create budyko transport process
budyko_transp = BudykoTransport(b=4., state=Ts)

### Integrate & Plot ###

fig = plt.figure()
ax = fig.add_subplot(111)

for i in np.arange(0, 3, 1):
    ax.plot(lat, budyko_transp.default, label='day %s' % (i * 40))
    budyko_transp.integrate_days(40.)

ax.set_title('Standalone Budyko Transport')
ax.set_xlabel('latitude')