# Path: atmos/constants.py

# 
# Path: atmos/data.py
# def get_coord(data, coord_name, return_type='values'):
#     """Return values, name or dimension of coordinate in DataArray.
# 
#     Parameters
#     ----------
#     data : xray.DataArray
#         Data array to search for latitude coords.
#     coord_name : str
#         Coordinate to extract.  Can be the exact ID of the variable or
#         a generic ID ('lat', 'lon', 'plev', 'time', 'day', 'year').
#         If a generic ID is provided then lists of common names for that ID
#         will be searched for a match.
#     return_type : {'values', 'name', 'dim'}, optional
#         'values' : Return an array of coordinate values.
#         'name' : Return the name of the coordinate.
#         'dim' : Return the dimension of the coordinate.
# 
#     Returns
#     -------
#     output : ndarray, string or int
# 
#     The generic coordinate names searched through are:
#     'lat' : ['lats', 'latitude', 'YDim','Y', 'y']
#     'lon' : ['long', 'lons', 'longitude', 'XDim', 'X', 'x']
#     'plev' : ['plevel', 'plevels', 'lev', 'level',
#               'levels', 'Height']
#     as well as capitalization options for coord_name (.upper(),
#     .lower(), .capitalize())
#     """
# 
#     def name_options(nm):
#         opts = {'lat' : ['lats', 'latitude', 'YDim','Y', 'y'],
#                 'lon' : ['long', 'lons', 'longitude', 'XDim', 'X', 'x'],
#                 'plev' : ['plevel', 'plevels', 'lev', 'level', 'levels',
#                           'Height']}
# 
#         nms = list(set([nm, nm.lower(), nm.upper(), nm.capitalize()]))
#         if opts.get(nm) is not None:
#             nms = list(nms) + opts[nm]
#         return nms
# 
#     names = name_options(coord_name)
# 
#     # Look in list of common coordinate names
#     if coord_name not in data.coords:
#         found = [i for i, s in enumerate(names) if s in data.coords]
# 
#         if len(found) == 0:
#             raise ValueError("Can't find coordinate name in data coords %s" %
#                              data.coords.keys())
#         if len(found) > 1:
#             raise ValueError('Conflicting possible coord names in coords %s'
#                 % data.coords.keys())
#         else:
#             coord_name = names[found[0]]
# 
#     if return_type == 'values':
#         output = data[coord_name].values.copy()
#     elif return_type == 'name':
#         output = coord_name
#     elif return_type == 'dim':
#         output = data.dims.index(coord_name)
#     else:
#         raise ValueError('Invalid return_type ' + return_type)
# 
#     return output


import numpy as np
import xarray as xray
import atmos.utils as utils
import atmos.data as dat
import atmos.xrhelper as xr
from atmos.constants import const as constants
from atmos.data import get_coord
        Array of latitude in degrees.  If omitted, lat is extracted
        from xray.DataArray input v.
    pres : ndarray, optional
        Pressures in Pa.  Can be a vector for pressure-level data, or
        a grid of pressures of the same shape as v.  If omitted, pres
        is extracted from xray.DataArray input v.
    pdim : {-3, -2}, optional
        Dimension of v corresponding to vertical levels.  Can be either
        the second-last or third-last dimension.  If omitted, pdim is
        extracted from xray.DataArray v.
    scale : float, optional
        Scale factor for output, e.g. 1e-9 to output streamfunction in
        10^9 kg/s.
    sector_scale : float, optional
        Scaling factor for the streamfunction over a sector lon1-lon2
        (i.e. should be set to (lon2 - lon1)/360.0 or None if full longitude
        range is going to be included).
    Returns
    -------
    psi : ndarray or xray.DataArray
        Eulerian mass stream function in units of 1/scale kg/s.
    """

    R = constants.radius_earth.values
    g = constants.g.values

    if isinstance(v, xray.DataArray):
        i_DataArray = True
        name, attrs, coords, _ = xr.meta(v)
        if lat is None:

# Path: atmos/constants.py

# 
# Path: atmos/data.py
# def get_coord(data, coord_name, return_type='values'):
#     """Return values, name or dimension of coordinate in DataArray.
# 
#     Parameters
#     ----------
#     data : xray.DataArray
#         Data array to search for latitude coords.
#     coord_name : str
#         Coordinate to extract.  Can be the exact ID of the variable or
#         a generic ID ('lat', 'lon', 'plev', 'time', 'day', 'year').
#         If a generic ID is provided then lists of common names for that ID
#         will be searched for a match.
#     return_type : {'values', 'name', 'dim'}, optional
#         'values' : Return an array of coordinate values.
#         'name' : Return the name of the coordinate.
#         'dim' : Return the dimension of the coordinate.
# 
#     Returns
#     -------
#     output : ndarray, string or int
# 
#     The generic coordinate names searched through are:
#     'lat' : ['lats', 'latitude', 'YDim','Y', 'y']
#     'lon' : ['long', 'lons', 'longitude', 'XDim', 'X', 'x']
#     'plev' : ['plevel', 'plevels', 'lev', 'level',
#               'levels', 'Height']
#     as well as capitalization options for coord_name (.upper(),
#     .lower(), .capitalize())
#     """
# 
#     def name_options(nm):
#         opts = {'lat' : ['lats', 'latitude', 'YDim','Y', 'y'],
#                 'lon' : ['long', 'lons', 'longitude', 'XDim', 'X', 'x'],
#                 'plev' : ['plevel', 'plevels', 'lev', 'level', 'levels',
#                           'Height']}
# 
#         nms = list(set([nm, nm.lower(), nm.upper(), nm.capitalize()]))
#         if opts.get(nm) is not None:
#             nms = list(nms) + opts[nm]
#         return nms
# 
#     names = name_options(coord_name)
# 
#     # Look in list of common coordinate names
#     if coord_name not in data.coords:
#         found = [i for i, s in enumerate(names) if s in data.coords]
# 
#         if len(found) == 0:
#             raise ValueError("Can't find coordinate name in data coords %s" %
#                              data.coords.keys())
#         if len(found) > 1:
#             raise ValueError('Conflicting possible coord names in coords %s'
#                 % data.coords.keys())
#         else:
#             coord_name = names[found[0]]
# 
#     if return_type == 'values':
#         output = data[coord_name].values.copy()
#     elif return_type == 'name':
#         output = coord_name
#     elif return_type == 'dim':
#         output = data.dims.index(coord_name)
#     else:
#         raise ValueError('Invalid return_type ' + return_type)
# 
#     return output


# Path: atmos/variables.py
import numpy as np
import xarray as xray
import atmos.utils as utils
import atmos.data as dat
import atmos.xrhelper as xr
from atmos.constants import const as constants
from atmos.data import get_coord

        Array of latitude in degrees.  If omitted, lat is extracted
        from xray.DataArray input v.
    pres : ndarray, optional
        Pressures in Pa.  Can be a vector for pressure-level data, or
        a grid of pressures of the same shape as v.  If omitted, pres
        is extracted from xray.DataArray input v.
    pdim : {-3, -2}, optional
        Dimension of v corresponding to vertical levels.  Can be either
        the second-last or third-last dimension.  If omitted, pdim is
        extracted from xray.DataArray v.
    scale : float, optional
        Scale factor for output, e.g. 1e-9 to output streamfunction in
        10^9 kg/s.
    sector_scale : float, optional
        Scaling factor for the streamfunction over a sector lon1-lon2
        (i.e. should be set to (lon2 - lon1)/360.0 or None if full longitude
        range is going to be included).
    Returns
    -------
    psi : ndarray or xray.DataArray
        Eulerian mass stream function in units of 1/scale kg/s.
    """

    R = constants.radius_earth.values
    g = constants.g.values

    if isinstance(v, xray.DataArray):
        i_DataArray = True
        name, attrs, coords, _ = xr.meta(v)
        if lat is None:

            lat = dat.get_coord(v, 'lat')