Ejemplo n.º 1
0
def test_contains_cftime_datetimes_non_cftimes_dask(non_cftime_data):
    assert not contains_cftime_datetimes(non_cftime_data.chunk())
Ejemplo n.º 2
0
def test_contains_cftime_datetimes_dask_3d(times_3d):
    assert contains_cftime_datetimes(times_3d.chunk())
Ejemplo n.º 3
0
def test_contains_cftime_datetimes_non_cftimes(non_cftime_data):
    assert not contains_cftime_datetimes(non_cftime_data)
Ejemplo n.º 4
0
def test_contains_cftime_datetimes_dask_1d(data):
    assert contains_cftime_datetimes(data.time.chunk())
Ejemplo n.º 5
0
def test_contains_cftime_datetimes_3d(times_3d):
    assert contains_cftime_datetimes(times_3d)
Ejemplo n.º 6
0
 def is_cftime_like(self):
     if (self.is_temporal) and (contains_cftime_datetimes(self._obj)):
         return True
     else:
         return False
Ejemplo n.º 7
0
def test_contains_cftime_datetimes_1d(data):
    assert contains_cftime_datetimes(data.time)
Ejemplo n.º 8
0
def test_contains_cftime_datetimes_non_cftimes_dask(non_cftime_data):
    assert not contains_cftime_datetimes(non_cftime_data.chunk())
Ejemplo n.º 9
0
def plot(darray,
         row=None,
         col=None,
         col_wrap=None,
         ax=None,
         hue=None,
         rtol=0.01,
         subplot_kws=None,
         **kwargs):
    """
    Default plot of DataArray using matplotlib.pyplot.

    Calls xarray plotting function based on the dimensions of
    darray.squeeze()

    =============== ===========================
    Dimensions      Plotting function
    --------------- ---------------------------
    1               :py:func:`xarray.plot.line`
    2               :py:func:`xarray.plot.pcolormesh`
    Anything else   :py:func:`xarray.plot.hist`
    =============== ===========================

    Parameters
    ----------
    darray : DataArray
    row : string, optional
        If passed, make row faceted plots on this dimension name
    col : string, optional
        If passed, make column faceted plots on this dimension name
    hue : string, optional
        If passed, make faceted line plots with hue on this dimension name
    col_wrap : integer, optional
        Use together with ``col`` to wrap faceted plots
    ax : matplotlib axes, optional
        If None, uses the current axis. Not applicable when using facets.
    rtol : number, optional
        Relative tolerance used to determine if the indexes
        are uniformly spaced. Usually a small positive number.
    subplot_kws : dict, optional
        Dictionary of keyword arguments for matplotlib subplots. Only applies
        to FacetGrid plotting.
    **kwargs : optional
        Additional keyword arguments to matplotlib

    """
    darray = darray.squeeze()

    if contains_cftime_datetimes(darray):
        raise NotImplementedError(
            'Built-in plotting of arrays of cftime.datetime objects or arrays '
            'indexed by cftime.datetime objects is currently not implemented '
            'within xarray. A possible workaround is to use the '
            'nc-time-axis package '
            '(https://github.com/SciTools/nc-time-axis) to convert the dates '
            'to a plottable type and plot your data directly with matplotlib.')

    plot_dims = set(darray.dims)
    plot_dims.discard(row)
    plot_dims.discard(col)
    plot_dims.discard(hue)

    ndims = len(plot_dims)

    error_msg = ('Only 1d and 2d plots are supported for facets in xarray. '
                 'See the package `Seaborn` for more options.')

    if ndims in [1, 2]:
        if row or col:
            kwargs['row'] = row
            kwargs['col'] = col
            kwargs['col_wrap'] = col_wrap
            kwargs['subplot_kws'] = subplot_kws
        if ndims == 1:
            plotfunc = line
            kwargs['hue'] = hue
        elif ndims == 2:
            if hue:
                plotfunc = line
                kwargs['hue'] = hue
            else:
                plotfunc = pcolormesh
    else:
        if row or col or hue:
            raise ValueError(error_msg)
        plotfunc = hist

    kwargs['ax'] = ax

    return plotfunc(darray, **kwargs)
Ejemplo n.º 10
0
def test_contains_cftime_datetimes_dask_3d(times_3d):
    assert contains_cftime_datetimes(times_3d.chunk())
Ejemplo n.º 11
0
def test_contains_cftime_datetimes_non_cftimes(non_cftime_data):
    assert not contains_cftime_datetimes(non_cftime_data)
Ejemplo n.º 12
0
def test_contains_cftime_datetimes_3d(times_3d):
    assert contains_cftime_datetimes(times_3d)
Ejemplo n.º 13
0
def test_contains_cftime_datetimes_dask_1d(data):
    assert contains_cftime_datetimes(data.time.chunk())
Ejemplo n.º 14
0
def test_contains_cftime_datetimes_1d(data):
    assert contains_cftime_datetimes(data.time)
Ejemplo n.º 15
0
def plot(darray, row=None, col=None, col_wrap=None, ax=None, rtol=0.01,
         subplot_kws=None, **kwargs):
    """
    Default plot of DataArray using matplotlib.pyplot.

    Calls xarray plotting function based on the dimensions of
    darray.squeeze()

    =============== ===========================
    Dimensions      Plotting function
    --------------- ---------------------------
    1               :py:func:`xarray.plot.line`
    2               :py:func:`xarray.plot.pcolormesh`
    Anything else   :py:func:`xarray.plot.hist`
    =============== ===========================

    Parameters
    ----------
    darray : DataArray
    row : string, optional
        If passed, make row faceted plots on this dimension name
    col : string, optional
        If passed, make column faceted plots on this dimension name
    col_wrap : integer, optional
        Use together with ``col`` to wrap faceted plots
    ax : matplotlib axes, optional
        If None, uses the current axis. Not applicable when using facets.
    rtol : number, optional
        Relative tolerance used to determine if the indexes
        are uniformly spaced. Usually a small positive number.
    subplot_kws : dict, optional
        Dictionary of keyword arguments for matplotlib subplots. Only applies
        to FacetGrid plotting.
    **kwargs : optional
        Additional keyword arguments to matplotlib

    """
    darray = darray.squeeze()

    if contains_cftime_datetimes(darray):
        raise NotImplementedError('Plotting arrays of cftime.datetime objects '
                                  'is currently not possible.')

    plot_dims = set(darray.dims)
    plot_dims.discard(row)
    plot_dims.discard(col)

    ndims = len(plot_dims)

    error_msg = ('Only 2d plots are supported for facets in xarray. '
                 'See the package `Seaborn` for more options.')

    if ndims == 1:
        if row or col:
            raise ValueError(error_msg)
        plotfunc = line
    elif ndims == 2:
        # Only 2d can FacetGrid
        kwargs['row'] = row
        kwargs['col'] = col
        kwargs['col_wrap'] = col_wrap
        kwargs['subplot_kws'] = subplot_kws

        plotfunc = pcolormesh
    else:
        if row or col:
            raise ValueError(error_msg)
        plotfunc = hist

    kwargs['ax'] = ax

    return plotfunc(darray, **kwargs)
Ejemplo n.º 16
0
Archivo: plot.py Proyecto: rth/xarray
def plot(darray,
         row=None,
         col=None,
         col_wrap=None,
         ax=None,
         rtol=0.01,
         subplot_kws=None,
         **kwargs):
    """
    Default plot of DataArray using matplotlib.pyplot.

    Calls xarray plotting function based on the dimensions of
    darray.squeeze()

    =============== ===========================
    Dimensions      Plotting function
    --------------- ---------------------------
    1               :py:func:`xarray.plot.line`
    2               :py:func:`xarray.plot.pcolormesh`
    Anything else   :py:func:`xarray.plot.hist`
    =============== ===========================

    Parameters
    ----------
    darray : DataArray
    row : string, optional
        If passed, make row faceted plots on this dimension name
    col : string, optional
        If passed, make column faceted plots on this dimension name
    col_wrap : integer, optional
        Use together with ``col`` to wrap faceted plots
    ax : matplotlib axes, optional
        If None, uses the current axis. Not applicable when using facets.
    rtol : number, optional
        Relative tolerance used to determine if the indexes
        are uniformly spaced. Usually a small positive number.
    subplot_kws : dict, optional
        Dictionary of keyword arguments for matplotlib subplots. Only applies
        to FacetGrid plotting.
    **kwargs : optional
        Additional keyword arguments to matplotlib

    """
    darray = darray.squeeze()

    if contains_cftime_datetimes(darray):
        raise NotImplementedError('Plotting arrays of cftime.datetime objects '
                                  'is currently not possible.')

    plot_dims = set(darray.dims)
    plot_dims.discard(row)
    plot_dims.discard(col)

    ndims = len(plot_dims)

    error_msg = ('Only 2d plots are supported for facets in xarray. '
                 'See the package `Seaborn` for more options.')

    if ndims == 1:
        if row or col:
            raise ValueError(error_msg)
        plotfunc = line
    elif ndims == 2:
        # Only 2d can FacetGrid
        kwargs['row'] = row
        kwargs['col'] = col
        kwargs['col_wrap'] = col_wrap
        kwargs['subplot_kws'] = subplot_kws

        plotfunc = pcolormesh
    else:
        if row or col:
            raise ValueError(error_msg)
        plotfunc = hist

    kwargs['ax'] = ax

    return plotfunc(darray, **kwargs)
Ejemplo n.º 17
0
def plot(darray, row=None, col=None, col_wrap=None, ax=None, hue=None,
         rtol=0.01, subplot_kws=None, **kwargs):
    """
    Default plot of DataArray using matplotlib.pyplot.

    Calls xarray plotting function based on the dimensions of
    darray.squeeze()

    =============== ===========================
    Dimensions      Plotting function
    --------------- ---------------------------
    1               :py:func:`xarray.plot.line`
    2               :py:func:`xarray.plot.pcolormesh`
    Anything else   :py:func:`xarray.plot.hist`
    =============== ===========================

    Parameters
    ----------
    darray : DataArray
    row : string, optional
        If passed, make row faceted plots on this dimension name
    col : string, optional
        If passed, make column faceted plots on this dimension name
    hue : string, optional
        If passed, make faceted line plots with hue on this dimension name
    col_wrap : integer, optional
        Use together with ``col`` to wrap faceted plots
    ax : matplotlib axes, optional
        If None, uses the current axis. Not applicable when using facets.
    rtol : number, optional
        Relative tolerance used to determine if the indexes
        are uniformly spaced. Usually a small positive number.
    subplot_kws : dict, optional
        Dictionary of keyword arguments for matplotlib subplots. Only applies
        to FacetGrid plotting.
    **kwargs : optional
        Additional keyword arguments to matplotlib

    """
    darray = darray.squeeze()

    if contains_cftime_datetimes(darray):
        raise NotImplementedError(
            'Built-in plotting of arrays of cftime.datetime objects or arrays '
            'indexed by cftime.datetime objects is currently not implemented '
            'within xarray. A possible workaround is to use the '
            'nc-time-axis package '
            '(https://github.com/SciTools/nc-time-axis) to convert the dates '
            'to a plottable type and plot your data directly with matplotlib.')

    plot_dims = set(darray.dims)
    plot_dims.discard(row)
    plot_dims.discard(col)
    plot_dims.discard(hue)

    ndims = len(plot_dims)

    error_msg = ('Only 1d and 2d plots are supported for facets in xarray. '
                 'See the package `Seaborn` for more options.')

    if ndims in [1, 2]:
        if row or col:
            kwargs['row'] = row
            kwargs['col'] = col
            kwargs['col_wrap'] = col_wrap
            kwargs['subplot_kws'] = subplot_kws
        if ndims == 1:
            plotfunc = line
            kwargs['hue'] = hue
        elif ndims == 2:
            if hue:
                plotfunc = line
                kwargs['hue'] = hue
            else:
                plotfunc = pcolormesh
    else:
        if row or col or hue:
            raise ValueError(error_msg)
        plotfunc = hist

    kwargs['ax'] = ax

    return plotfunc(darray, **kwargs)
Ejemplo n.º 18
0
def contains_datetime_like_objects(var):
    """Check if a variable contains datetime like objects (either
    np.datetime64, np.timedelta64, or cftime.datetime)
    """
    return is_np_datetime_like(var.dtype) or contains_cftime_datetimes(var)