Skip to main content

das3py

Das servers typically provide data relevant to space plasma and magnetospheric physics research. To retrieve data, an HTTP GET request is posted to a das server by a client program and a self-describing stream of data values covering the requested time range, at the requested time resolution, is provided in the response body. This package, das3py, provides an efficient space physics data client for python. It reads both das2 and das3 streams, and das2 streams will be supported indefinitely. Streams are parsed and stored as NumPy arrays using a C extension, avoiding data copies and conversions.

das3py was published as das2py through version 3.0.4. See Upgrading from das2py below.

Installing from PyPI

python -m pip install das3py

The PyPI packages are pre-built for:

  • Linux on x86_64, for Python 2.7 and 3.9 through 3.15. They need glibc 2.26 or newer (RHEL 8, Ubuntu 18.04 and later) and pip 20.3 or newer. The 2.7 package is for UCS-4 builds of Python, as Linux distributions ship; a 2.7 built from source needs --enable-unicode=ucs4.

  • Windows on 64-bit x86, for Python 3.9 through 3.13. Nothing else has to be installed.

If pip is older than 20.3, upgrade it first:

python -m pip install -U pip

On other Linux systems, build from source as described in Building and Installing from Source on Linux below. For macOS, see Windows and macOS.

To check the install, run one of the examples. It needs matplotlib and an internet connection:

python -m pip install matplotlib
curl -O https://raw.githubusercontent.com/das-developers/das3py/main/examples/ex02_galileo_pws_spectra.py
python ex02_galileo_pws_spectra.py

On Windows type curl.exe in place of curl. In Windows PowerShell, curl alone is a different command.

It writes ex02_galileo_pws_spectra.png, which should look like this:

First program

The following small program demonstrates how to query for data and generate a plot using das3py.

Query a URI for reduced resolution data

import das3
src = das3.get_source( 'tag:das2.org,2012:site:/uiowa/cassini/rpws/survey_keyparam/das2' )
header, datasets = src.get( {'time' : ('2017-09-02', '2017-09-03')} )
  • get() returns the stream header and a list of datasets. This source sends one: a day of Cassini RPWS electric field spectra, one spectrum a minute at 73 frequencies.
  • print(src.info()) lists the query parameters a source takes.
  • site:/... is short for tag:das2.org,2012:site:/....
  • Servers come and go. The federated catalog provides stability for application code by mapping URIs to data sources.
  • Browse for URIs using a das2 catalog browser, or using das3py to get the root node (see example 11).

Access quantities by physical dimensions

dataset = datasets[0]
print(dataset)

vX = dataset['time']['center']
vY = dataset['frequency']['center']
vZ = dataset['electric_specdens']['center']
  • Datasets contain dimensions. Dimensions contain variables. Each variable in a dimension serves a purpose, the most common is to define the center point of a coordinate or measurement.
  • Array dimensions are not confused with physical dimensions. Dataset meaning is not tied to any particular array morphology.

Use Matplotlib to generate an image

import das3.mpl   # das2 label formatting for matplotlib
import matplotlib.pyplot as pyplot
import matplotlib.colors as colors

fig, ax = pyplot.subplots()
im = ax.pcolormesh(vX.array, vY.array, vZ.array, norm=colors.LogNorm(), cmap='jet')
ax.set_yscale('log')
fig.colorbar(im, label=das3.mpl.label(dataset['electric_specdens'].props['label']))
fig.autofmt_xdate()

ax.set_title(das3.mpl.label(header['props']['title']))
ax.set_xlabel(das3.mpl.range_label(dataset['time']))
ax.set_ylabel(das3.mpl.label(dataset['frequency'].props['label']))
pyplot.show()
  • The title and axis labels come from the stream. das3.mpl.label() converts das2 formatting codes, such as !a for superscript, to matplotlib's, and das3.mpl.range_label() describes the time range.
  • Times arrive as NumPy datetime64 values, which matplotlib plots as dates.
  • Fill values arrive masked: vZ.array is a NumPy masked array.

Vectors and other composites

das3 streams can carry vectors, rotation matrices and other multi-part values as a single variable. This query gets eight minutes of TRACERS-2 magnetometer data:

src = das3.get_source('site:/uiowa/tracers/tracers-2/l2/mag_16sps_delta')
header, datasets = src.get( {'time' : ('2026-05-04T01:29:59', '2026-05-04T01:38:07')} )

dB = datasets[0]['ts2_l2_mag_16sps_fac_deltab']['center']

print(dB.array.shape)   # (7808, 3)
print(dB.extShape())    # (7808,)  one value per record
print(dB.intrShape())   # (3,)     each value is a 3-vector
print(dB.labels)        # ['dBx', 'dBy', 'dBz']
print(dB.ops)           # {'kind': 'vector', 'frame': 'TS2_FAC', 'system': 'cartesian', ...}
  • The external shape counts records in the dataset. The internal shape is the shape of each value.
  • dB.ops says what the values are and which coordinate frame they are in.
  • The array is ordinary NumPy, so the field magnitude is numpy.linalg.norm(dB.array, axis=1).
  • Example 12 plots the three components.

Anaconda Package

A das3py conda package for Linux, Windows and macOS is planned. The dasdevelopers channel still has the older das2py 3.0.4.

What changed in 3.0

The short version, for people upgrading from 2.3:

  • The package is das3 now. It reads das3 streams as well as das2 streams. Code that says import das2 needs to say import das3. The pip name is now das3py. Python 2.7 and 3.x are both supported, das3 isn't a reference to the interpreter version.

  • Reads return the stream header too. Source.get() and the read_*() functions return a tuple, (stream_header, datasets), not just a list of datasets, so their call sites change.

  • Composite values. Vectors, rotation matrices, quaternions and complex pairs come through as one variable, with an internal shape. So a vector over N records is an (N, 3) array with the external shape (N,) in the dataset, and the internal shape (3,) within each value. These can be retrieved via var.extShape() and var.intrShape().

  • Mathematical Formalisms. Each variable is now tagged with metadata denoting which math operations it supports. For example a point variable supports subtraction (a point - point = length) but not addition. The dict var.ops provides information on operations.

  • Raw Storage. To get the compact raw storage for a variable, use var.storage(), which gives the values without the dataset's broadcast.

  • Sequences are materialized. A coordinate defined by a <sequence> in the stream header arrives as a real array.

  • Tidier names. dir(das3) shows the public API and nothing else. A few methods were renamed to match the rest: DasTime.fromString, DasTime.roundDoy, Dimension.hasProp and hasPropVal (replacing propEq) and Source.infoProto. The 2.3 names still work and warn. Quantity.to_value keeps its snake_case on purpose, since it's source compatible with AstroPy's Quantities.

  • das_verify checks more. Index counts against the dataset rank, one units= per composite, and <sequence> counts against the internal shape, none of which an XML schema can express.

  • Not yet: ragged arrays (variable length records) still don't convert to ndarrays. das2C reads them fully, but das3py stops at the conversion.

Upgrading from das2py

As of version 3.0 the package is das3, named for the das3 stream format it added, and as of 3.0.6 it is distributed as das3py. It still reads das2 streams, and runs on Python 2.7 and 3.x alike.

Most das2py code needs two changes:

  1. The module name. import das2 becomes import das3, and das2.DasTime becomes das3.DasTime, and so on. Don't change every "das2" in a file: catalog names such as 'tag:das2.org,2012:site:/...' and das2.org URLs stay as they are.

  2. Reading data returns the stream header too.

    ds_list = src.get()                 # das2py 2.3
    stream_hdr, ds_list = src.get()     # das3py
    

    The same goes for read_file(), read_http() and read_cmd(), which now raise an exception on failure instead of returning None.

Code written for the das2py 3.0.4 conda package needs only the first change.

A few 2.3 method names changed too. The old names still work, with a PendingDeprecationWarning that Python hides by default; see the CHANGELOG. To find them, run a script with the warning promoted to an error:

python -W error::PendingDeprecationWarning your_script.py

Data sources in the das catalog have also changed their query parameters since 2.3. print(src.info()) lists the ones a source takes now.

Note that das2py and das3py both include the das_verify command. If you uninstall das2py, reinstall das3py to replace it:

python -m pip install --force-reinstall --no-deps das3py

The old das2py releases stay on PyPI, so scripts that pin das2py<3 keep working.

Building and Installing from Source on Linux

Compilation and installation of das3py is regularly tested on Linux under both Python 2 (still) and Python 3. The following packages are required to build das3py and all dependencies:

  1. Get system software packages.

    Red Hat Enterprise Linux or compatible (Rocky, Alma)

    dnf install git gcc make curl expat-devel fftw-devel openssl-devel python3-devel
    

    Debian or compatible (Ubuntu)

    apt install gcc git make curl libexpat-dev libfftw3-dev libssl-dev python3-dev python3-venv
    
  2. Get the source, along with the pegged das2C version.

    git clone --recursive https://github.com/das-developers/das3py.git
    

    das2C is a git submodule in deps/das2C, pegged to the das2C release this das3py was written and tested against. If you cloned without --recursive that directory is empty, so fill it with git submodule update --init.

  3. Build and test sources against a specific version of python. The makefile will automatically find python if PY_BIN is not defined, but providing an explicit path avoids confusion down the road. For old Python2 builds, PY_BIN is required, as Python3 will be built by default.

    cd das3py
    make PY_BIN=/path/to/python           # See PY_BIN note above
    make PY_BIN=/path/to/python test      # optional, but recommended
    make PY_BIN=/path/to/python examples  # optional, needs network access
    

    The first make also builds the bundled das2C, which downloads the sources of NASA's CDF library. To use a CDF you already have, set CDF_INC and CDF_LIB as das2C's own build notes describe.

    To build against some other das2C, a development checkout for example, build that one yourself and reference it. das3py does not alter an external das2C build, it just uses it.

    make DAS2C=/path/to/das2C PY_BIN=/path/to/python
    
  4. Install into your desired python environment.

    /path/to/python -m pip install ./dist/das3py-*.whl
    
    # or
    
    make PY_BIN=/path/to/python install
    

The Linux PyPI packages are built in a manylinux container with make pypi. The Makefile explains what that needs.

Windows and macOS

The Windows PyPI packages are built with buildfiles\win_wheels.bat. It uses Visual Studio, vcpkg and das2C's nmake makefile, and the comments at the top of the file list what it needs.

das3py has been built on macOS before, and setup.py has a branch for it, but this release has not been tested there. If you need it on macOS, please ask on the issue tracker.

Licenses

das3py is under the MIT license. The PyPI packages also contain das2C and other libraries, compiled in. THIRD-PARTY.txt lists them and their licenses, and each package carries the license texts.

Reporting bugs

Please use the github.com issue tracker to report any problems with the library. If you've fixed a bug, thanks! Please send a pull request so that your fix can be merged into the main project.

Metadata

Release files for das3py 3.0.7

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

Built distributions (wheels)

Table of built distributions (wheels) for das3py 3.0.7
File Actions
das3py-3.0.7-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for das3py-3.0.7-cp313-cp313-win_amd64.whl
das3py-3.0.7-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for das3py-3.0.7-cp312-cp312-win_amd64.whl
das3py-3.0.7-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for das3py-3.0.7-cp311-cp311-win_amd64.whl
das3py-3.0.7-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for das3py-3.0.7-cp310-cp310-win_amd64.whl
das3py-3.0.7-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details for das3py-3.0.7-cp39-cp39-win_amd64.whl

Total release size: 14.1 MB

Release files / das3py-3.0.7-cp313-cp313-win_amd64.whl

Download URL das3py-3.0.7-cp313-cp313-win_amd64.whl
Size 2.8 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
bc987ece5b8e2c210ea2effc48f5940d534f98ee3bb4df25e16589a351480661
BLAKE2b-256 checksum
How to use checksums
8b1a2349ab4118e135ca629defd6cb0ce6da35088bff0b5c4c2cafa1b8f3c7c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / das3py-3.0.7-cp312-cp312-win_amd64.whl

Download URL das3py-3.0.7-cp312-cp312-win_amd64.whl
Size 2.8 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
66e2ecee28571011dc08e16d1c3a00983fdf1fe49d268634168bdae44cf8995b
BLAKE2b-256 checksum
How to use checksums
64c04f302402397530bee61dcd0f0de6c1b71924a67fd18185bdb2b2c7347c0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / das3py-3.0.7-cp311-cp311-win_amd64.whl

Download URL das3py-3.0.7-cp311-cp311-win_amd64.whl
Size 2.8 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
1a8ef8a44f6bbbe5ef5549ef644e58a0e58f87fbeb2f4f3b774cd3a5213e23cd
BLAKE2b-256 checksum
How to use checksums
22d1b0ab525eb68d9d52c535eca719fa68ac97f434e46cc332897acacc6d42eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / das3py-3.0.7-cp310-cp310-win_amd64.whl

Download URL das3py-3.0.7-cp310-cp310-win_amd64.whl
Size 2.8 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
c48074cad63144fcdf7c33f20e5065459f2461e35e2eba5b26dcf3561215341a
BLAKE2b-256 checksum
How to use checksums
5348616fd77c5d11203dd820c06a504964f11427dc202c3be198c1fb54b66214
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / das3py-3.0.7-cp39-cp39-win_amd64.whl

Download URL das3py-3.0.7-cp39-cp39-win_amd64.whl
Size 2.8 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
22c2f5b8f7e9a72bf1df5fcd86645cead5b94a1ecfbb0e3913fc3e2138ce666d
BLAKE2b-256 checksum
How to use checksums
087329b6cc761f6439a09a7bda5466f4081a609427f4d1e6b9c9a587abe13fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for das3py 3.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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