# Path: indiff/_constants.py
# _RADEARTH = 6370997.
# 
# Path: indiff/utils.py
# def to_radians(arr, is_delta=False):
#     """Force data with units either degrees or radians to be radians."""
#     # Infer the units from embedded metadata, if it's there.
#     arr_out = arr
#     try:
#         units = arr_out.units
#     except AttributeError:
#         pass
#     else:
#         if units.lower().startswith('degrees'):
#             warn_msg = ("Conversion applied: degrees -> radians to arr_outay: "
#                         "{}".format(arr_out))
#             warnings.warn(warn_msg, UserWarning)
#             return np.deg2rad(arr_out)
#     # Otherwise, assume degrees if the values are sufficiently large.
#     threshold = 0.1*np.pi if is_delta else 4*np.pi
#     if np.max(np.abs(arr_out)) > threshold:
#         warn_msg = ("Conversion applied: degrees -> radians to arr_outay: "
#                     "{}".format(arr_out))
#         warnings.warn(warn_msg, UserWarning)
#         return np.deg2rad(arr_out)
#     return arr_out
# 
# Path: indiff/coord/coord.py
# class Coord(object):
#     """Generic base class for physical coordinates."""
#     _POSSIBLY_CYCLIC = True
# 
#     def _prep_dim(self, dim):
#         msg = ("Specified dim '{}' does not match any dim in self.arr.  "
#                "self.arr.dims: {}").format(dim, self.arr.dims)
#         if dim in self.arr.dims:
#             return dim
#         if dim is None:
#             if self.arr.shape == 1:
#                 return self.arr.dims[0]
#         raise ValueError(msg)
# 
#     def __init__(self, arr, dim=None, cyclic=False):
#         self.arr = arr
#         self.dim = self._prep_dim(dim)
#         if cyclic and not self._POSSIBLY_CYCLIC:
#             raise ValueError("The coordinate cannot be cyclic in a physically "
#                              "meaningful way.")
#         self.cyclic = cyclic
# 
#     def __getitem__(self, key):
#         return self.arr[key]
# 
#     def deriv_prefactor(self, *args, **kwargs):
#         raise NotImplementedError
# 
#     def deriv_factor(self, *args, **kwargs):
#         raise NotImplementedError


import numpy as np
from .._constants import _RADEARTH
from ..utils import to_radians
from . import Coord


class YCoord(HorizCoord):
    """Cartesian y horizontal coordinate."""
    def __init__(self, arr, dim=None, cyclic=False):
        super(YCoord, self).__init__(arr, dim=dim, cyclic=cyclic)

    def deriv_prefactor(self, *args, **kwargs):
        """Factor to multiply the result of derivatives along this coord."""
        return 1.

    def deriv_factor(self, *args, **kwargs):
        """Factor to multiply within a derivative along this coord."""
        return 1.


class Lon(XCoord):
    """Longitude spherical horizontal coordinate."""
    def __init__(self, lon, dim=None, cyclic=True, radius=_RADEARTH):
        super(Lon, self).__init__(lon, dim=dim, cyclic=cyclic)
        self.radius = radius

    def deriv_prefactor(self, lat):
        return 1. / (self.radius * np.cos(to_radians(lat)))


class Lat(YCoord):
    """Latitude spherical horizontal coordinate."""
    _POSSIBLY_CYCLIC = False


# Path: indiff/_constants.py
# _RADEARTH = 6370997.
# 
# Path: indiff/utils.py
# def to_radians(arr, is_delta=False):
#     """Force data with units either degrees or radians to be radians."""
#     # Infer the units from embedded metadata, if it's there.
#     arr_out = arr
#     try:
#         units = arr_out.units
#     except AttributeError:
#         pass
#     else:
#         if units.lower().startswith('degrees'):
#             warn_msg = ("Conversion applied: degrees -> radians to arr_outay: "
#                         "{}".format(arr_out))
#             warnings.warn(warn_msg, UserWarning)
#             return np.deg2rad(arr_out)
#     # Otherwise, assume degrees if the values are sufficiently large.
#     threshold = 0.1*np.pi if is_delta else 4*np.pi
#     if np.max(np.abs(arr_out)) > threshold:
#         warn_msg = ("Conversion applied: degrees -> radians to arr_outay: "
#                     "{}".format(arr_out))
#         warnings.warn(warn_msg, UserWarning)
#         return np.deg2rad(arr_out)
#     return arr_out
# 
# Path: indiff/coord/coord.py
# class Coord(object):
#     """Generic base class for physical coordinates."""
#     _POSSIBLY_CYCLIC = True
# 
#     def _prep_dim(self, dim):
#         msg = ("Specified dim '{}' does not match any dim in self.arr.  "
#                "self.arr.dims: {}").format(dim, self.arr.dims)
#         if dim in self.arr.dims:
#             return dim
#         if dim is None:
#             if self.arr.shape == 1:
#                 return self.arr.dims[0]
#         raise ValueError(msg)
# 
#     def __init__(self, arr, dim=None, cyclic=False):
#         self.arr = arr
#         self.dim = self._prep_dim(dim)
#         if cyclic and not self._POSSIBLY_CYCLIC:
#             raise ValueError("The coordinate cannot be cyclic in a physically "
#                              "meaningful way.")
#         self.cyclic = cyclic
# 
#     def __getitem__(self, key):
#         return self.arr[key]
# 
#     def deriv_prefactor(self, *args, **kwargs):
#         raise NotImplementedError
# 
#     def deriv_factor(self, *args, **kwargs):
#         raise NotImplementedError


# Path: indiff/coord/horiz.py
import numpy as np
from .._constants import _RADEARTH
from ..utils import to_radians
from . import Coord



class YCoord(HorizCoord):
    """Cartesian y horizontal coordinate."""
    def __init__(self, arr, dim=None, cyclic=False):
        super(YCoord, self).__init__(arr, dim=dim, cyclic=cyclic)

    def deriv_prefactor(self, *args, **kwargs):
        """Factor to multiply the result of derivatives along this coord."""
        return 1.

    def deriv_factor(self, *args, **kwargs):
        """Factor to multiply within a derivative along this coord."""
        return 1.


class Lon(XCoord):
    """Longitude spherical horizontal coordinate."""
    def __init__(self, lon, dim=None, cyclic=True, radius=_RADEARTH):
        super(Lon, self).__init__(lon, dim=dim, cyclic=cyclic)
        self.radius = radius

    def deriv_prefactor(self, lat):
        return 1. / (self.radius * np.cos(to_radians(lat)))


class Lat(YCoord):
    """Latitude spherical horizontal coordinate."""
    _POSSIBLY_CYCLIC = False


    def __init__(self, lat, dim=None, radius=_RADEARTH):