def band_fraction(self, value): self.num_channels = value.size # abstract axis for channels ax = axis.Axis(num_points=self.num_channels) self.channel_ax = {'channel': ax} dom = domain._Domain(axes=self.channel_ax) # fraction of the total solar flux in each band: self._band_fraction = field.Field(value, domain=dom)
def _compute_absorptivity(self): # assume that the water vapor etc is current optical_path = self._compute_optical_path() # account for finite layer depth absorptivity = 1. - np.exp(-optical_path) axes = copy(self.Tatm.domain.axes) # add these to the dictionary of axes axes.update(self.channel_ax) dom = domain.Atmosphere(axes=axes) self.absorptivity = field.Field(absorptivity, domain=dom)
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')
## NEED TO FIX THE PASSING OF INITIAL PARAMETERS # especially timestep # how easy is to implement the Stommel 1961 box model in climlab? # currently... it still requires a fair bit of code: import numpy as np from climlab.process.time_dependent_process import TimeDependentProcess from climlab.domain import domain, field box = domain.box_model_domain() print box.shape # initial condition x = field.Field([1., 0.], domain=box) y = field.Field([1., 1.], domain=box) state = {'x': x, 'y': y} # define the process class StommelBox(TimeDependentProcess): def compute(self): x = self.state['x'] y = self.state['y'] term = np.abs(-y + self.param['R'] * x) / self.param['lam'] self.tendencies['y'] = (1 - y - y * term) self.tendencies['x'] = (self.param['delta'] * (1 - x) - x * term) # make a parameter dictionary param = {'R': 2., 'lam': 1., 'delta': 1., 'timestep': 0.01} # instantiate the process