Patch Conversions

Although DASCore provides a lot of the functionality needed for DFOS processing, is not intended to do absolutely everything, and some other libraries might be better suited for a particular task. In addition to making it simple to access the underlying data as shown in the patch tutorial, DASCore provides convenience functions to convert data to formats used by other libraries. Here are a few examples:

Pandas

import dascore as dc

patch = dc.get_example_patch()

# Convert to a dataframe
df = patch.io.to_dataframe()

# Convert a dataframe to a patch
patch_from_df = dc.io.dataframe_to_patch(df)

Xarray

import dascore as dc

patch = dc.get_example_patch()

# Convert to xarray's DataArray
dar = patch.io.to_xarray()

# Convert a DataArray to a patch
patch_from_dar = dc.io.xarray_to_patch(dar)

ObsPy

import dascore as dc

patch = dc.get_example_patch()

# Convert the patch to an ObsPy Stream
stream = patch.io.to_obspy()

# Convert an ObsPy Stream to a patch
patch_from_dar = dc.io.obspy_to_patch(stream)
Note

As explained in the obspy_to_patch docs, there must be a value in the stats dict which indicates values for a non-time dimension. For example, each trace might have a ‘distance’ key in its stats dict which DASCore uses to construct the distance dimensional coordinate.