Skip to main content

unidas logo

coverage PyPI Version Licence

A DAS compatibility package.

There is an increasing number of open-source libraries for working with distributed acoustic sensing (DAS) data. Each of these has its own strengths and weaknesses, and often it is desirable to use features from multiple libraries in research workflows. Moreover, creators of DAS packages which perform specific operations (e.g., machine learning for phase picking) currently have to choose a single DAS library to support, or undertake writing conversion codes on their own.

Unidas solves these problems by providing simple ways to interoperate between DAS libraries.

Usage

There are two ways to use unidas. First, the adapter decorator allows a function to simply declare which library's data structure to use.

import unidas


@unidas.adapter("daspy.Section")
def daspy_function(sec, **kwargs):
    """A useful daspy function"""
    # Regardless of the actual input type, adapter will convert it to a daspy section
    # then convert it back after the return.
    return sec


import dascore as dc

patch = dc.get_example_patch()
# even though we call a daspy function, the input/output is a dascore patch.
out = daspy_function(patch)
assert isinstance(out, dc.Patch)

By default the first argument is converted. Use arg to name a different one, either by position or by parameter name.

@unidas.adapter("daspy.Section", arg="sec")
def daspy_function(reference, sec):
    """Only sec is converted to a daspy section."""
    return sec

You can also use adapter to wrap un-wrapped functions.

import dascore as dc
import unidas
from xdas.signal import hilbert

dascore_hilbert = unidas.adapter("xdas.DataArray")(hilbert)
patch = dc.get_example_patch()

patch_hilberto = dascore_hilbert(patch)

The convert function converts from one library's data structure to another library's data structure.

import daspy
import unidas

# Use lightguide's afk filter with a daspy section. 
sec = daspy.read()
blast = unidas.convert(sec, to="lightguide.Blast")
blast.afk_filter(exponent=0.8)
sec_out = unidas.convert(blast, to='daspy.Section')

Xarray DataArrays work with both APIs:

import dascore as dc
import unidas

patch = dc.get_example_patch()
data_array = unidas.convert(patch, to="xarray.DataArray")

@unidas.adapter("xarray.DataArray")
def first_ten_samples(data_array):
    return data_array.isel(time=slice(0, 10))

trimmed_patch = first_ten_samples(patch)

Installation

Unidas requires Python 3.11 or newer. Simply install unidas with pip or mamba:

pip install unidas 
mamba install unidas

By design, unidas has no hard dependencies other than numpy, but an ImportError will be raised if the libraries needed to perform a requested conversion are not installed.

To install the supported DAS libraries with unidas:

pip install "unidas[extras]"

Some optional libraries lag new Python releases. The complete unidas[extras] set currently targets Python 3.11 and 3.12. On Python 3.13 and newer, the extra installs xarray; install the other optional DAS libraries directly once they publish compatible wheels. Xarray can also be installed separately with pip install xarray.

For development and testing:

pip install "unidas[dev]"

Unidas is single file (src/unidas.py) so it can also be vendored (copied directly into your project). If you do this, please consider sharing any improvements so the entire community can benefit.

Guidance for package developers

If you are creating/maintaining a library for doing some kind of specialized DAS processing in python, we recommend you do two things:

  1. Pick the DAS library you prefer and use it internally.
  2. Apply the adapter decorator to your project's API.

Doing so will make your project easily accessible by users of all the libraries supported by unidas.

For example:

import unidas

@unidas.adapter("daspy.Section")
def fancy_machine_learning_function(sec):
    """Cutting edge machine learning DAS research function."""
    # Here we will use daspy internally, but the function accepts 
    # data structures from other libraries with no additional effort
    # because of the adapter decorator. 
    
    ...  # Fancy stuff goes here.
    
    return sec

Adding support for new libraries to unidas

To add support for a new data structure/library, you need to do two things:

  1. Create a subclass of Converter which has (at least) a conversion method to unidas' BaseDAS.
  2. Add a conversion method to UnidasBaseDASConverter to convert from unidas' BaseDAS back to your data structure.
  3. Write a test in test/test_unidas.py (this is important for maintainability).

Feel free to open a discussion if you need help.

Supported libraries (in alphabetical order)

Compatibility notes

DASPy sections and Lightguide blasts require time and distance coordinates, evenly sampled coordinates, and an absolute datetime time coordinate. Objects with relative, numeric, or uneven time/distance coordinates may still convert to other formats, but will raise a ValueError when converting to daspy.Section or lightguide.Blast.

Xarray conversion through unidas' internal representation preserves the array name, data, dimension order, coordinates (including scalar and multidimensional auxiliary coordinates), attributes, and coordinate metadata such as units. On this internal round-trip, dimensions without coordinate labels remain unlabeled. DASCore may replace missing labels with placeholder coordinates. Other formats retain only the structures and metadata they support; unsupported coordinate layouts raise an error identifying the target and coordinate. For example, XDAS supports scalar coordinates but does not support multidimensional coordinates. Some DASCore versions cannot construct scalar or multidimensional coordinates. DASCore coordinate units become portable strings in xarray attributes.

DASPy sampling fields are derived from coordinates and take precedence over conflicting attributes such as fs or dx. Lightguide represents distance using integer channel indices and rounds the starting distance to the nearest channel when it is not an integer multiple of the spacing.

Xarray Dataset objects, storage encoding (including CF time-unit conventions), and reconstruction of custom indexes are not supported. Data is not explicitly computed on the xarray–internal representation path, but other libraries may require eager arrays.

Making releases

To publish a release, bump __version__ in src/unidas.py, merge the change to main, create a version tag such as v0.1.0, then publish a GitHub Release from that tag. Publishing the GitHub Release triggers the PyPI upload workflow.

Metadata

Release files for unidas 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unidas 0.1.4
File Size Uploaded
unidas-0.1.4.tar.gz 25.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unidas 0.1.4
File Interpreter ABI Platform
unidas-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 40.7 kB

Release files / unidas-0.1.4.tar.gz

Download URL unidas-0.1.4.tar.gz
Size 25.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2057960d4526e106b4d452de0a62847d7289ff9ef94822376d92573fc08e5f7c
BLAKE2b-256 checksum
How to use checksums
2a99522344fdb47ec6e3e492957f372b565e3b5c7c8c1dd888f455223c12a881
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / unidas-0.1.4-py3-none-any.whl

Download URL unidas-0.1.4-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3588bb8b5b35982fa8dd64a17d1abeafda6fa089f1da531bc35b949cd56e94e
BLAKE2b-256 checksum
How to use checksums
da6a01e4c38fd6efe13b17a0c620a06fa2f5718c81bfc047825357bddb0a8914
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

This release

0.1.4 This release

2 release files

0.1.2

2 release files

0.1.0

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page