def surface_state(num_lat=90, water_depth=10., T0=12., T2=-40.): '''Set up a state variable dictionary for a zonal-mean surface model (e.g. basic EBM). There is a single state variable `Ts`, the temperature of the surface mixed layer. ''' sfc = domain.zonal_mean_surface(num_lat=num_lat, water_depth=water_depth) sinphi = np.sin(np.deg2rad(sfc.axes['lat'].points)) initial = T0 + T2 * legendre.P2(sinphi) Ts = Field(initial, domain=sfc) state = AttrDict() state['Ts'] = Ts return state
def surface_state(num_lat=90, water_depth=10.0, T0=12.0, T2=-40.0): """Set up a state variable dictionary for a zonal-mean surface model (e.g. basic EBM). There is a single state variable `Ts`, the temperature of the surface mixed layer. """ sfc = domain.zonal_mean_surface(num_lat=num_lat, water_depth=water_depth) sinphi = np.sin(np.deg2rad(sfc.axes["lat"].points)) initial = T0 + T2 * legendre.P2(sinphi) Ts = Field(initial, domain=sfc) state = AttrDict() state["Ts"] = Ts return state
def __init__(self, name='Untitled', state=None, domains=None, subprocess=None, lat=None, lev=None, num_lat=None, num_levels=None, input=None, verbose=True, **kwargs): # verbose flag used to control text output at process creation time self.verbose = verbose self.name = name # dictionary of domains. Keys are the domain names self.domains = _make_dict(domains, _Domain) # If lat is given, create a simple domains if lat is not None: sfc = zonal_mean_surface() self.domains.update({'default': sfc}) # dictionary of state variables (all of type Field) self.state = attr_dict.AttrDict() states = _make_dict(state, Field) for name, value in states.items(): self.set_state(name, value) # dictionary of model parameters self.param = kwargs # dictionary of diagnostic quantities #self.diagnostics = attr_dict.AttrDict() #self._diag_vars = frozenset() self._diag_vars = [] # dictionary of input quantities #self.input = _make_dict(input, Field) if input is None: #self._input_vars = frozenset() self._input_vars = [] else: self.add_input(list(input.keys())) for name, var in input: self.__dict__[name] = var self.creation_date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.localtime()) # subprocess is a dictionary of any sub-processes self.subprocess = attr_dict.AttrDict() if subprocess is not None: self.add_subprocesses(subprocess)
def __init__( self, num_lat=90, S0=const.S0, A=210., B=2., D=0.555, # in W / m^2 / degC, same as B water_depth=10.0, Tf=-10., a0=0.3, a2=0.078, ai=0.62, timestep=const.seconds_per_year / 90., T_init_0=12., T_init_P2=-40., **kwargs): super(EBM, self).__init__(timestep=timestep, **kwargs) if not self.domains and not self.state: # no state vars or domains yet sfc = domain.zonal_mean_surface(num_lat=num_lat, water_depth=water_depth) lat = sfc.axes['lat'].points initial = T_init_0 + T_init_P2 * legendre.P2( np.sin(np.deg2rad(lat))) self.set_state('Ts', Field(initial, domain=sfc)) self.param['S0'] = S0 self.param['A'] = A self.param['B'] = B self.param['D'] = D self.param['Tf'] = Tf self.param['water_depth'] = water_depth self.param['a0'] = a0 self.param['a2'] = a2 self.param['ai'] = ai # create sub-models self.add_subprocess('LW', AplusBT(state=self.state, **self.param)) self.add_subprocess('insolation', P2Insolation(domains=sfc, **self.param)) self.add_subprocess( 'albedo', albedo.StepFunctionAlbedo(state=self.state, **self.param)) # diffusivity in units of 1/s K = self.param['D'] / self.domains['Ts'].heat_capacity self.add_subprocess( 'diffusion', MeridionalDiffusion(state=self.state, K=K, **self.param)) self.topdown = False # call subprocess compute methods first
def __init__(self, num_lat=90, S0=const.S0, A=210., B=2., D=0.555, # in W / m^2 / degC, same as B water_depth=10.0, Tf=-10., a0=0.3, a2=0.078, ai=0.62, timestep=const.seconds_per_year/90., T_init_0 = 12., T_init_P2 = -40., **kwargs): super(EBM, self).__init__(timestep=timestep, **kwargs) if not self.domains and not self.state: # no state vars or domains yet sfc = domain.zonal_mean_surface(num_lat=num_lat, water_depth=water_depth) lat = sfc.axes['lat'].points initial = T_init_0 + T_init_P2 * legendre.P2(np.sin(np.deg2rad(lat))) self.set_state('Ts', Field(initial, domain=sfc)) self.param['S0'] = S0 self.param['A'] = A self.param['B'] = B self.param['D'] = D self.param['Tf'] = Tf self.param['water_depth'] = water_depth self.param['a0'] = a0 self.param['a2'] = a2 self.param['ai'] = ai # create sub-models self.add_subprocess('LW', AplusBT(state=self.state, **self.param)) self.add_subprocess('insolation', P2Insolation(domains=sfc, **self.param)) self.add_subprocess('albedo', albedo.StepFunctionAlbedo(state=self.state, **self.param)) # diffusivity in units of 1/s K = self.param['D'] / self.domains['Ts'].heat_capacity self.add_subprocess('diffusion', MeridionalDiffusion(state=self.state, K=K, **self.param)) self.topdown = False # call subprocess compute methods first
def __init__( self, state=None, domains=None, subprocess=None, lat=None, lev=None, num_lat=None, num_levels=None, input=None, **kwargs ): # dictionary of domains. Keys are the domain names self.domains = _make_dict(domains, _Domain) # If lat is given, create a simple domains if lat is not None: sfc = zonal_mean_surface() self.domains.update({"default": sfc}) # dictionary of state variables (all of type Field) self.state = attr_dict.AttrDict() states = _make_dict(state, Field) for name, value in states.iteritems(): self.set_state(name, value) # dictionary of model parameters self.param = kwargs # dictionary of diagnostic quantities self.diagnostics = attr_dict.AttrDict() # dictionary of input quantities # self.input = _make_dict(input, Field) if input is None: self._input_vars = frozenset() else: self.add_input(input.keys()) for name, var in input: self.__dict__[name] = var self.creation_date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.localtime()) # subprocess is a dictionary of any sub-processes if subprocess is None: # self.subprocess = {} # a dictionary whose items can be accessed as attributes self.subprocess = attr_dict.AttrDict() else: self.add_subprocesses(subprocess)
def __init__(self, name='Untitled', state=None, domains=None, subprocess=None, lat=None, lev=None, num_lat=None, num_levels=None, input=None, verbose=True, **kwargs): # verbose flag used to control text output at process creation time self.verbose = verbose self.name = name # dictionary of domains. Keys are the domain names self.domains = _make_dict(domains, _Domain) # If lat is given, create a simple domains if lat is not None: sfc = zonal_mean_surface() self.domains.update({'default': sfc}) # dictionary of state variables (all of type Field) self.state = AttrDict() states = _make_dict(state, Field) for name, value in states.items(): self.set_state(name, value) # dictionary of model parameters self.param = kwargs # dictionary of diagnostic quantities #self.diagnostics = AttrDict() #self._diag_vars = frozenset() self._diag_vars = [] # dictionary of input quantities #self.input = _make_dict(input, Field) if input is None: #self._input_vars = frozenset() self._input_vars = [] else: self.add_input(list(input.keys())) for name, var in input: self.__dict__[name] = var self.creation_date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.localtime()) # subprocess is a dictionary of any sub-processes self.subprocess = AttrDict() if subprocess is not None: self.add_subprocesses(subprocess)
def surface_state(num_lat=90, num_lon=None, water_depth=10., T0=12., T2=-40.): """Sets up a state variable dictionary for a surface model (e.g. :class:`~climlab.model.ebm.EBM`) with a uniform slab ocean depth. The domain is either 1D (latitude) or 2D (latitude, longitude) depending on whether the input argument num_lon is supplied. Returns a single state variable `Ts`, the temperature of the surface mixed layer (slab ocean). The temperature is initialized to a smooth equator-to-pole shape given by .. math:: T(\phi) = T_0 + T_2 P_2(\sin\phi) where :math:`\phi` is latitude, and :math:`P_2` is the second Legendre polynomial :class:`~climlab.utils.legendre.P2`. **Function-call arguments** \n :param int num_lat: number of latitude points [default: 90] :param int num_lat: (optional) number of longitude points [default: None] :param float water_depth: depth of the slab ocean in meters [default: 10.] :param float T0: global-mean initial temperature in :math:`^{\circ} \\textrm{C}` [default: 12.] :param float T2: 2nd Legendre coefficient for equator-to-pole gradient in initial temperature, in :math:`^{\circ} \\textrm{C}` [default: -40.] :returns: dictionary with temperature :class:`~climlab.domain.field.Field` for surface mixed layer ``Ts`` :rtype: dict :Example: :: >>> from climlab.domain import initial >>> import numpy as np >>> T_dict = initial.surface_state(num_lat=36) >>> print np.squeeze(T_dict['Ts']) [-27.88584094 -26.97777479 -25.18923361 -22.57456133 -19.21320344 -15.20729309 -10.67854785 -5.76457135 -0.61467228 4.61467228 9.76457135 14.67854785 19.20729309 23.21320344 26.57456133 29.18923361 30.97777479 31.88584094 31.88584094 30.97777479 29.18923361 26.57456133 23.21320344 19.20729309 14.67854785 9.76457135 4.61467228 -0.61467228 -5.76457135 -10.67854785 -15.20729309 -19.21320344 -22.57456133 -25.18923361 -26.97777479 -27.88584094] """ if num_lon is None: sfc = domain.zonal_mean_surface(num_lat=num_lat, water_depth=water_depth) else: sfc = domain.surface_2D(num_lat=num_lat, num_lon=num_lon, water_depth=water_depth) if 'lon' in sfc.axes: lon, lat = np.meshgrid(sfc.axes['lon'].points, sfc.axes['lat'].points) else: lat = sfc.axes['lat'].points sinphi = np.sin(np.deg2rad(lat)) initial = T0 + T2 * legendre.P2(sinphi) Ts = Field(initial, domain=sfc) #if num_lon is None: # Ts = Field(initial, domain=sfc) #else: # Ts = Field([[initial for k in range(num_lon)]], domain=sfc) state = AttrDict() state['Ts'] = Ts return state