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
= dc.get_example_patch()
patch
# Convert to a dataframe
= patch.io.to_dataframe()
df
# Convert a dataframe to a patch
= dc.io.dataframe_to_patch(df) patch_from_df
Xarray
import dascore as dc
= dc.get_example_patch()
patch
# Convert to xarray's DataArray
= patch.io.to_xarray()
dar
# Convert a DataArray to a patch
= dc.io.xarray_to_patch(dar) patch_from_dar
ObsPy
import dascore as dc
= dc.get_example_patch()
patch
# Convert the patch to an ObsPy Stream
= patch.io.to_obspy()
stream
# Convert an ObsPy Stream to a patch
= dc.io.obspy_to_patch(stream) patch_from_dar
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.