Skip to main content

pyxarr

image image image image

This is a package which provides a minimal and light-weight class to work with multi-dimensional labeled arrays.

Description

The software of pyxarr is written from scratch. I have tried to mimic the classes DataArray, Dataset and Coords from xarray. My main goal is to keep the code light and fast.

Installation

Pyxarr is available as pyxarr on PyPI. To install it use pip:

$ pip install pyxarr

The module pyxarr requires Python3.10+ and Python modules: h5py, numpy.

Usage

Working with pyxarr DataArray:

import numpy as np
from pyxarr import DataArray

xda = DataArray()
bool(xda) # will return False, thus if xda: ... will work
len(xda)  # will return 0

rng = np.random.default_rng()
xda = DataArray(
   rng.random((120, 11, 17)),
   dims=("time", "y", "x"),
   coords=(
      np.arange("2025-02-24T14:32:00", "2025-02-24T15:32:00", 30, dtype="datetime64[s]"),
      list(range(11)),
      np.arange(17),
   ),
   attrs={
      "long_name": "noisy signal",
      "units": "1",
   },
)
bool(xda)  # returns True
len(xda)   # returns 120
xda.shape  # returns (120, 11, 17)
xda.size   # returns 22440
"x" in xda.coords  # returns True
xda[4, :, :]  # slicing works
xda.coords += ("orbit", list(range(500, 620))  # will add an auxiliary coordinate
xda.swap_dims("orbit", "time")  # will make the auxiliary coordinate the dimension coordinate and visa versa
xda.mean("time")  # will return a new DataArray averaged over the time axis
xda + xda2  # will return a new DataArray with the sum of the data of both arrays, other supported operators are sub, div and mul.

Working with pyxarr Dataset:

from pyxarr import Dataset

xds = Dataset()
bool(xds)  # will return False, thus if xds: ... will work
len(xds)   # will return 0

xds["foo"] = xda  # adding data to a dataset all dimensions will be added as coordinates
xds.attrs["title"] = "test example"  # adding attributes to a dataset

Working with pyxarr Coords:

import numpy as np
from pyxarr import Coords

coords = Coords()
bool(coords)  # will return False, thus if xds: ... will work
len(coords)   # will return 0

coords += ("time", np.arange("2025-07-01", "2025-08-01", dtype="datetime64[D]))
coords += ("column", np.arange(31))  # adding coordinates

coords = {
   "time": np.arange("2025-07-01", "2025-08-01", dtype="datetime64[D]),
   "column": np.arange(31),
}  # using a dictionary to define the coordinates

coords = [
   ("time", np.arange("2025-07-28T12:43:00", "2025-07-28T12:58:00", dtype="datetime64[s])),
   ("column", np.arange(1000)),
   ("row", np.arange(256)),
]  # using a list of tuples to define the coordinates

Time coordinates

Using the CF convensions described in section 4.4, we can define a simple time-coordinate variable as:

 double time(time) ;
   time:axis = "T" ;
   time:standard_name = "time" ;
   time:units = "days since 2024-01-01" ; // defaults to UTC

or

 double time(time) ;
   time:long_time = "sample time" ;
   time:axis = "T" ;
   time:standard_name = "time" ;
   time:units = "seconds since 2024-01-01 00:00:00" ; // defaults to UTC
   time:calendar = "proleptic_gregorian" ; // or utc, tai, etc.
   time:valid_min = 0. ;
   time:valid_max = 172800. ;

You can store any time-coordinate with all its attributes into an pyxarr Coords. However, often it handy to have the data read into a numpy.datetime64, this is an option which is offered in the pyxarr tools: dest_from_h5 and dest_to_h5. Both tools will only perform the conversion when the precision (level of detail or granularity present) is specified. This can be: days, hours, minutes, seconds, milli-seconds, micro-seconds, or nano-seconds.

TBW

Authors and acknowledgment

The code is developed by R.M. van Hees (SRON)

License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyxarr-0.5.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyxarr-0.5.0-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file pyxarr-0.5.0.tar.gz.

File metadata

  • Download URL: pyxarr-0.5.0.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pyxarr-0.5.0.tar.gz
Algorithm Hash digest
SHA256 63976c41a279793dd3fe7aa450d2b2ed3e3e4ee838009a31a47dba4f92288b11
MD5 ac4fce3b3ed325b5aecda5fe51184e0c
BLAKE2b-256 28fea64b16c85f5d061c0b4d14529bf4868f4eaa314f5c7952e2eb3517bc324b

See more details on using hashes here.

File details

Details for the file pyxarr-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pyxarr-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pyxarr-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d7ff72926c5000e584e571468b5cf442501e035623b305b46715feb5895fe40
MD5 0d73dabce8966941d82a05920058a4af
BLAKE2b-256 61f20d73b345d864c278795ee1724147e2c790b933a0d8817605250c7e305352

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.1

2 files

This release

0.5.0 This release

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 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