src/pys5p/lib/plotlib.py
def data_for_trend2d(data_in, dims=None, delta_time=None):
    """
    Prepare data to display the averaged column/row as function of time

    Parameters
    ----------
    data :  numpy.ndarray or xarray.DataArray
       Object holding measurement data and attributes
    dims :  list of strings
       Names for the dataset dimensions
       Required when data is a numpy array (otherwise ignored)
    delta_time : int, optional
       Expected resolution of the time-axis.
       Defined in whole seconds or number of orbit revolutions.
    missing_data: 'NaN' or 'previous'
       Default: NaN

    Returns
    -------
    xarray.DataArray
    """
    try:
        check_data2d('data', data_in)
    except Exception as exc:
        raise RuntimeError('invalid input-data provided') from exc

    if isinstance(data_in, np.ndarray):
        if dims is None:
            raise KeyError('a list with dimensions names should be provided')
        msm = data_to_xr(data_in, dims=dims)
    else:
        msm = data_in

    # determine time-axis
    (ylabel, xlabel) = msm.coords._fields
    if ylabel in ('orbit', 'time'):
        time_axis = 0
        time_data = msm.coords[0]
    elif xlabel in ('orbit', 'time'):
        time_axis = 1
        time_data = msm.coords[1]
    else:
        raise RuntimeError('can not find the time-axis')

    if not np.issubdtype(time_data.dtype, np.integer):
        raise ValueError('time-coordinate not of type integer')
    if not np.all(time_data[1:] > time_data[:-1]):
        indx = (time_data[1:] <= time_data[:-1]).nonzero()[0]
        raise ValueError(f'time-coordinate not increasing at {indx}')

    # determine delta_time with greatest common divisor (numpy v1.15+)
    if delta_time is None:
        delta_time = np.gcd.reduce(np.diff(time_data))

    time_dim = 1 + (time_data.max() - time_data.min()) // delta_time
    if time_dim == time_data.size:
        return msm

    time_data_full = np.arange(time_data.min(),
                               time_data.max() + delta_time,
                               delta_time)
    mask = np.in1d(time_data_full, time_data)
    if time_axis == 0:
        data_full = np.empty((time_dim, msm.coords[msm.dims[1]].size),
                             dtype=msm.dtype)
        data_full[mask, :] = msm.values
        for ii in (~mask).nonzero()[0]:
            data_full[ii, :] = data_full[ii-1, :]
    else:
        data_full = np.empty((msm.coords[msm.dims[0]].size, time_dim),
                             dtype=msm.dtype)
        data_full[:, mask] = msm.values
        for ii in (~mask).nonzero()[0]:
            data_full[ii, :] = data_full[ii-1, :]

    msm.values = data_full
    return msm

    Prepare data to display the averaged column/row as function of time

    Parameters
    ----------
    data :  numpy.ndarray or xarray.DataArray
       Object holding measurement data and attributes
    dims :  list of strings
       Names for the dataset dimensions
       Required when data is a numpy array (otherwise ignored)
    delta_time : int, optional
       Expected resolution of the time-axis.
       Defined in whole seconds or number of orbit revolutions.
    missing_data: 'NaN' or 'previous'
       Default: NaN

    Returns
    -------
    xarray.DataArray
    
Prepare data to display the averaged column/row as function of time
Parameters

data :  numpy.ndarray or xarray.DataArray
Object holding measurement data and attributes
dims :  list of strings
Names for the dataset dimensions
Required when data is a numpy array (otherwise ignored)
delta_time : int, optional
Expected resolution of the time-axis.
Defined in whole seconds or number of orbit revolutions.

Returns


Prepare data to display the averaged column / row as function of time Parameters data : numpy . ndarray or xarray . DataArray Object holding measurement data and attributes dims : list of strings Names for the dataset dimensions Required when data is a numpy array ( otherwise ignored ) delta_time : int optional Expected resolution of the time - axis . Defined in whole seconds or number of orbit revolutions . Returns
def data_for_trend2d(data_in, dims=None, delta_time=None):
    try:
        check_data2d('data', data_in)
    except Exception as exc:
        raise RuntimeError('invalid input-data provided') from exc
    if isinstance(data_in, np.ndarray):
        if dims is None:
            raise KeyError('a list with dimensions names should be provided')
        msm = data_to_xr(data_in, dims=dims)
    else:
        msm = data_in
    (ylabel, xlabel) = msm.coords._fields
    if ylabel in ('orbit', 'time'):
        time_axis = 0
        time_data = msm.coords[0]
    elif xlabel in ('orbit', 'time'):
        time_axis = 1
        time_data = msm.coords[1]
    else:
        raise RuntimeError('can not find the time-axis')
    if not np.issubdtype(time_data.dtype, np.integer):
        raise ValueError('time-coordinate not of type integer')
    if not np.all(time_data[1:] > time_data[:-1]):
        indx = (time_data[1:] <= time_data[:-1]).nonzero()[0]
        raise ValueError(f'time-coordinate not increasing at {indx}')
    if delta_time is None:
        delta_time = np.gcd.reduce(np.diff(time_data))
    time_dim = 1 + (time_data.max() - time_data.min()) // delta_time
    if time_dim == time_data.size:
        return msm
    time_data_full = np.arange(time_data.min(),
                               time_data.max() + delta_time,
                               delta_time)
    mask = np.in1d(time_data_full, time_data)
    if time_axis == 0:
        data_full = np.empty((time_dim, msm.coords[msm.dims[1]].size),
                             dtype=msm.dtype)
        data_full[mask, :] = msm.values
        for ii in (~mask).nonzero()[0]:
            data_full[ii, :] = data_full[ii-1, :]
    else:
        data_full = np.empty((msm.coords[msm.dims[0]].size, time_dim),
                             dtype=msm.dtype)
        data_full[:, mask] = msm.values
        for ii in (~mask).nonzero()[0]:
            data_full[ii, :] = data_full[ii-1, :]
    msm.values = data_full
    return msm
def data_for_trend2d ( data_in , dims = None , delta_time = None ) : try : check_data2d ( 'data' , data_in ) except Exception as exc : raise RuntimeError ( 'invalid input-data provided' ) from exc if isinstance ( data_in , np . ndarray ) : if dims is None : raise KeyError ( 'a list with dimensions names should be provided' ) msm = data_to_xr ( data_in , dims = dims ) else : msm = data_in ( ylabel , xlabel ) = msm . coords . _fields if ylabel in ( 'orbit' , 'time' ) : time_axis = 0 time_data = msm . coords [ 0 ] elif xlabel in ( 'orbit' , 'time' ) : time_axis = 1 time_data = msm . coords [ 1 ] else : raise RuntimeError ( 'can not find the time-axis' ) if not np . issubdtype ( time_data . dtype , np . integer ) : raise ValueError ( 'time-coordinate not of type integer' ) if not np . all ( time_data [ 1 : ] > time_data [ : - 1 ] ) : indx = ( time_data [ 1 : ] <= time_data [ : - 1 ] ) . nonzero ( ) [ 0 ] raise ValueError ( f'time-coordinate not increasing at {indx}' ) if delta_time is None : delta_time = np . gcd . reduce ( np . diff ( time_data ) ) time_dim = 1 + ( time_data . max ( ) - time_data . min ( ) ) // delta_time if time_dim == time_data . size : return msm time_data_full = np . arange ( time_data . min ( ) , time_data . max ( ) + delta_time , delta_time ) mask = np . in1d ( time_data_full , time_data ) if time_axis == 0 : data_full = np . empty ( ( time_dim , msm . coords [ msm . dims [ 1 ] ] . size ) , dtype = msm . dtype ) data_full [ mask , : ] = msm . values for ii in ( ~ mask ) . nonzero ( ) [ 0 ] : data_full [ ii , : ] = data_full [ ii - 1 , : ] else : data_full = np . empty ( ( msm . coords [ msm . dims [ 0 ] ] . size , time_dim ) , dtype = msm . dtype ) data_full [ : , mask ] = msm . values for ii in ( ~ mask ) . nonzero ( ) [ 0 ] : data_full [ ii , : ] = data_full [ ii - 1 , : ] msm . values = data_full return msm
Prepare data to display the averaged column/row as function of time
Parameters
Prepare data to display the averaged column / row as function of time Parameters
"""
    Prepare data to display the averaged column/row as function of time

    Parameters
    ----------
    data :  numpy.ndarray or xarray.DataArray
       Object holding measurement data and attributes
    dims :  list of strings
       Names for the dataset dimensions
       Required when data is a numpy array (otherwise ignored)
    delta_time : int, optional
       Expected resolution of the time-axis.
       Defined in whole seconds or number of orbit revolutions.
    missing_data: 'NaN' or 'previous'
       Default: NaN

    Returns
    -------
    xarray.DataArray
    """ # determine time-axis # determine delta_time with greatest common divisor (numpy v1.15+)
data_in
dims
delta_time