Exemple #1
0
def create_frvect(timeseries):
    """Create a `~frameCPP.FrVect` from a `TimeSeries`

    This method is primarily designed to make writing data to GWF files a
    bit easier.

    Parameters
    ----------
    timeseries : `TimeSeries`
        the input `TimeSeries`

    Returns
    -------
    frvect : `~frameCPP.FrVect`
        the output `FrVect`
    """
    # create timing dimension
    dims = frameCPP.Dimension(timeseries.size, timeseries.dx.value,
                              str(timeseries.dx.unit), 0)
    # create FrVect
    vect = frameCPP.FrVect(timeseries.name or '',
                           FRVECT_TYPE_FROM_NUMPY[timeseries.dtype.type], 1,
                           dims, str(timeseries.unit))
    # populate FrVect and return
    vect.GetDataArray()[:] = numpy.require(timeseries.value,
                                           requirements=['C'])
    return vect
Exemple #2
0
def create_frvect(series):
    """Create a `~frameCPP.FrVect` from a `~gwpy.types.Series`

    .. note::

       Currently this method is restricted to 1-dimensional arrays.

    Parameters
    ----------
    series : `~gwpy.types.Series`
        the input data array to store

    Returns
    -------
    frvect : `~frameCPP.FrVect`
        the newly created data vector
    """
    from LDAStools import frameCPP
    from ._framecpp import FrVectType

    # create dimensions
    dims = frameCPP.Dimension(
        series.shape[0],  # num elements
        series.dx.value,  # step size
        str(series.dx.unit),  # unit
        0,  # starting value
    )

    # create FrVect
    vect = frameCPP.FrVect(
        _series_name(series),  # name
        int(FrVectType.find(series.dtype)),  # data type enum
        series.ndim,  # num dimensions
        dims,  # dimension object
        str(series.unit),  # unit
    )

    # populate FrVect
    vect.GetDataArray()[:] = numpy.require(series.value, requirements=['C'])

    return vect