Esempio n. 1
0
def zonal_mean_column(num_lat=90,
                      num_lev=30,
                      water_depth=10.,
                      lat=None,
                      lev=None,
                      **kwargs):
    if lat is None:
        latax = Axis(axis_type='lat', num_points=num_lat)
    elif isinstance(lat, Axis):
        latax = lat
    else:
        try:
            latax = Axis(axis_type='lat', points=lat)
        except:
            raise ValueError('lat must be Axis object or latitude array')
    if lev is None:
        levax = Axis(axis_type='lev', num_points=num_lev)
    elif isinstance(lev, Axis):
        levax = lev
    else:
        try:
            levax = Axis(axis_type='lev', points=lev)
        except:
            raise ValueError('lev must be Axis object or pressure array')

    depthax = Axis(axis_type='depth', bounds=[water_depth, 0.])
    #axes = {'depth': depthax, 'lat': latax, 'lev': levax}
    slab = SlabOcean(axes={'lat': latax, 'depth': depthax}, **kwargs)
    atm = Atmosphere(axes={'lat': latax, 'lev': levax}, **kwargs)
    return slab, atm
Esempio n. 2
0
def single_column(num_lev=30, water_depth=1., lev=None, **kwargs):
    '''Convenience method to create domains for a single column of atmosphere
    overlying a slab of water.
    
    num_lev is the number of pressure levels (evenly spaced from surface to TOA)
    water_depth is the depth of the slab.
    
    Returns a list of 2 Domain objects (slab ocean, atmosphere)
    
    Usage:
    sfc, atm = domain.single_column()
        or
    sfc, atm = domain.single_column(num_lev=2, water_depth=10.)
    print sfc, atm
    
    Can also pass a pressure array or pressure level axis object
    '''
    if lev is None:
        levax = Axis(axis_type='lev', num_points=num_lev)
    elif isinstance(lev, Axis):
        levax = lev
    else:
        try:
            levax = Axis(axis_type='lev', points=lev)
        except:
            raise ValueError('lev must be Axis object or pressure array')
    depthax = Axis(axis_type='depth', bounds=[water_depth, 0.])
    slab = SlabOcean(axes=depthax, **kwargs)
    atm = Atmosphere(axes=levax, **kwargs)
    return slab, atm
Esempio n. 3
0
def surface_2D(num_lat=90,
               num_lon=180,
               water_depth=10.,
               lon=None,
               lat=None,
               **kwargs):
    """Creates a 2D slab ocean Domain in latitude and longitude with uniform water depth.

    Domain has a single heat capacity according to the specified water depth.

    **Function-call argument** \n

    :param int num_lat:         number of latitude points [default: 90]
    :param int num_lon:         number of longitude points [default: 180]
    :param float water_depth:   depth of the slab ocean in meters [default: 10.]
    :param lat:                 specification for latitude axis (optional)
    :type lat:                  :class:`~climlab.domain.axis.Axis` or latitude array
    :param lon:                 specification for longitude axis (optional)
    :type lon:                  :class:`~climlab.domain.axis.Axis` or longitude array
    :raises: :exc:`ValueError`  if `lat` is given but neither Axis nor latitude array.
    :raises: :exc:`ValueError`  if `lon` is given but neither Axis nor longitude array.
    :returns:                   surface domain
    :rtype:                     :class:`SlabOcean`

    :Example:

        ::

            >>> from climlab import domain
            >>> sfc = domain.surface_2D(num_lat=36, num_lat=72)

            >>> print sfc
            climlab Domain object with domain_type=ocean and shape=(36, 72, 1)

    """
    if lat is None:
        latax = Axis(axis_type='lat', num_points=num_lat)
    elif isinstance(lat, Axis):
        latax = lat
    else:
        try:
            latax = Axis(axis_type='lat', points=lat)
        except:
            raise ValueError('lat must be Axis object or latitude array')
    if lon is None:
        lonax = Axis(axis_type='lon', num_points=num_lon)
    elif isinstance(lon, Axis):
        lonax = lon
    else:
        try:
            lonax = Axis(axis_type='lon', points=lon)
        except:
            raise ValueError('lon must be Axis object or longitude array')
    depthax = Axis(axis_type='depth', bounds=[water_depth, 0.])
    axes = {'lat': latax, 'lon': lonax, 'depth': depthax}
    slab = SlabOcean(axes=axes, **kwargs)
    return slab
Esempio n. 4
0
def zonal_mean_surface(num_lat=90, water_depth=10., lat=None, **kwargs):
    if lat is None:
        latax = Axis(axis_type='lat', num_points=num_lat)
    elif isinstance(lat, Axis):
        latax = lat
    else:
        try:
            latax = Axis(axis_type='lat', points=lat)
        except:
            raise ValueError('lat must be Axis object or latitude array')
    depthax = Axis(axis_type='depth', bounds=[water_depth, 0.])
    axes = {'depth': depthax, 'lat': latax}
    slab = SlabOcean(axes=axes, **kwargs)
    return slab
Esempio n. 5
0
def single_column(num_lev=30, water_depth=1., lev=None, **kwargs):
    """Creates domains for a single column of atmosphere overlying a slab of water.

    Can also pass a pressure array or pressure level axis object specified in ``lev``.

    If argument ``lev`` is not ``None`` then function tries to build a level axis
    and ``num_lev`` is ignored.

    **Function-call argument** \n

    :param int num_lev:         number of pressure levels
                                (evenly spaced from surface to TOA) [default: 30]
    :param float water_depth:   depth of the ocean slab [default: 1.]
    :param lev:                 specification for height axis (optional)
    :type lev:                  :class:`~climlab.domain.axis.Axis` or pressure array
    :raises: :exc:`ValueError`  if `lev` is given but neither Axis
                                nor pressure array.
    :returns:                   a list of 2 Domain objects (slab ocean, atmosphere)
    :rtype:                     :py:class:`list` of :class:`SlabOcean`, :class:`SlabAtmosphere`

    :Example:

        ::

            >>> from climlab import domain

            >>> sfc, atm = domain.single_column(num_lev=2, water_depth=10.)

            >>> print sfc
            climlab Domain object with domain_type=ocean and shape=(1,)

            >>> print atm
            climlab Domain object with domain_type=atm and shape=(2,)

    """
    if lev is None:
        levax = Axis(axis_type='lev', num_points=num_lev)
    elif isinstance(lev, Axis):
        levax = lev
    else:
        try:
            levax = Axis(axis_type='lev', points=lev)
        except:
            raise ValueError('lev must be Axis object or pressure array')
    depthax = Axis(axis_type='depth', bounds=[water_depth, 0.])
    slab = SlabOcean(axes=depthax, **kwargs)
    atm = Atmosphere(axes=levax, **kwargs)
    return slab, atm
Esempio n. 6
0
def make_slabatm_axis(num_points=1):
    """Convenience method to create a simple axis for a slab atmosphere.

    **Function-call argument** \n

    :param int num_points:   number of points for the slabatmosphere Axis [default: 1]
    :returns:               an Axis with ``axis_type='lev'`` and ``num_points=num_points``
    :rtype:                 :class:`~climlab.domain.axis.Axis`

    :Example:

        ::

            >>> import climlab
            >>> slab_atm_axis = climlab.domain.make_slabatm_axis()

            >>> print slab_atm_axis
            Axis of type lev with 1 points.

            >>> slab_atm_axis.axis_type
            'lev'

            >>> slab_atm_axis.bounds
            array([    0.,  1000.])

            >>> slab_atm_axis.units
            'mb'

    """
    depthax = Axis(axis_type='lev', num_points=num_points)
    return depthax
Esempio n. 7
0
def box_model_domain(num_points=2, **kwargs):
    """Creates a box model domain (a single abstract axis).

    :param int num_points:      number of boxes [default: 2]
    :returns:                   Domain with single axis of type ``'abstract'``
                                and ``self.domain_type = 'box'``
    :rtype:                     :class:`_Domain`

    :Example:

        ::

            >>> from climlab import domain
            >>> box = domain.box_model_domain(num_points=2)

            >>> print box
            climlab Domain object with domain_type=box and shape=(2,)

    """
    ax = Axis(axis_type='abstract', num_points=num_points)
    boxes = _Domain(axes=ax, **kwargs)
    boxes.domain_type = 'box'
    return boxes
Esempio n. 8
0
def zonal_mean_column(num_lat=90,
                      num_lev=30,
                      water_depth=10.,
                      lat=None,
                      lev=None,
                      **kwargs):
    """Creates two Domains with one water cell, a latitude axis and
    a level/height axis.

        * SlabOcean:    one water cell and a latitude axis above
          (similar to :func:`zonal_mean_surface`)
        * Atmosphere: a latitude axis and a level/height axis (two dimensional)


    **Function-call argument** \n

    :param int num_lat:         number of latitude points on the axis
                                [default: 90]
    :param int num_lev:         number of pressure levels
                                (evenly spaced from surface to TOA) [default: 30]
    :param float water_depth:   depth of the water cell (slab ocean) [default: 10.]
    :param lat:                 specification for latitude axis (optional)
    :type lat:                  :class:`~climlab.domain.axis.Axis` or latitude array
    :param lev:                 specification for height axis (optional)
    :type lev:                  :class:`~climlab.domain.axis.Axis` or pressure array
    :raises: :exc:`ValueError`  if `lat` is given but neither Axis nor latitude array.
    :raises: :exc:`ValueError`  if `lev` is given but neither Axis nor pressure array.
    :returns:                   a list of 2 Domain objects (slab ocean, atmosphere)
    :rtype:                     :py:class:`list` of :class:`SlabOcean`, :class:`Atmosphere`

    :Example:

        ::

            >>> from climlab import domain
            >>> sfc, atm = domain.zonal_mean_column(num_lat=36,num_lev=10)

            >>> print sfc
            climlab Domain object with domain_type=ocean and shape=(36, 1)

            >>> print atm
            climlab Domain object with domain_type=atm and shape=(36, 10)


    """
    if lat is None:
        latax = Axis(axis_type='lat', num_points=num_lat)
    elif isinstance(lat, Axis):
        latax = lat
    else:
        try:
            latax = Axis(axis_type='lat', points=lat)
        except:
            raise ValueError('lat must be Axis object or latitude array')
    if lev is None:
        levax = Axis(axis_type='lev', num_points=num_lev)
    elif isinstance(lev, Axis):
        levax = lev
    else:
        try:
            levax = Axis(axis_type='lev', points=lev)
        except:
            raise ValueError('lev must be Axis object or pressure array')

    depthax = Axis(axis_type='depth', bounds=[water_depth, 0.])
    #axes = {'depth': depthax, 'lat': latax, 'lev': levax}
    slab = SlabOcean(axes={'lat': latax, 'depth': depthax}, **kwargs)
    atm = Atmosphere(axes={'lat': latax, 'lev': levax}, **kwargs)
    return slab, atm
Esempio n. 9
0
def make_slabocean_axis(num_points=1):
    '''Convenience method to create a simple axis for a slab ocean.'''
    depthax = Axis(axis_type='depth', num_points=num_points)
    return depthax
Esempio n. 10
0
def box_model_domain(num_points=2, **kwargs):
    '''Create a box model domain (a single abstract axis).'''
    ax = Axis(axis_type='abstract', num_points=num_points)
    boxes = _Domain(axes=ax, **kwargs)
    boxes.domain_type = 'box'
    return boxes
Esempio n. 11
0
def make_slabatm_axis(num_points=1):
    '''Convenience method to create a simple axis for a slab atmosphere.'''
    depthax = Axis(axis_type='lev', num_points=num_points)
    return depthax