Skip to main content

GHOST-xarray

GHOST-xarray provides helper functions to load output files from GHOST (the Geophysical High-Order Suite for Turbulence) into xarray labelled multidimensional arrays.

Installation

pip install ghost-xarray

Usage

GHOST-xarray provides 2 functions:

  • open_dataarray, which opens a single variable,
  • open_dataset, which opens multiple variables.

open_dataarray needs: a directory, a variable name, and its timestep dt, shape and datatype:

import ghost_xarray

vx = ghost_xarray.open_dataarray(
    "path/to/directory",
    "vx",
    dt=0.5,
    shape=(128, 128, 128),
    dtype=np.float32,
)
vx.isel(t=0, y=64).plot()  # isel selects by index position

A plot of the x-component of the velocity at t=0.

By default, it generates the corresponding coordinates from the shape parameter as np.linspace(0, 2 * np.pi, shape[i], endpoint=False). But shape can also be a dictionary of np.ndarray with explicit coordinates:

vx = ghost_xarray.open_dataarray(
    "path/to/directory",
    "vx",
    dt=0.5,
    shape=dict(x=np.linspace(0, 10, 64), y=np.linspace(0, 100, 11)),
    dtype=np.float32,
)
v_average = vx.isel(t=0).sel(y=50).mean(dim="x")  # sel selects by coordinate
v_average.compute()

All operations are lazy, until .compute() or .plot() are called. Hence, the above example only loads a single file to memory, instead of actually loading data for all times.

For a vector-valued variable, it adds an additional i dimension, corresponding to x, y[, z]:

v = ghost_xarray.open_dataarray(
    "path/to/directory",
    name="v",
    dt=0.5,
    coords=(128, 128, 128),
    dtype=np.float32,
)
v.isel(y=64).sel(t=1.5).plot(col="i")  # makes three 2D imshows, one for each component.

A plot for each component of the velocity.

Finally, open_dataset opens several variables into a xarray.Dataset, which provides a dict-like interface.

data = ghost_xarray.open_dataset(
    "path/to/directory/",
    names=["v", "w"],
    dt=0.5,
    coords=(128, 128, 128),
    dtype=np.float32,
)

h = (data.v * data.w).sum(dim="i")  # computes the sum along components (dimension "i").
h.isel(t=slice(0, 4), x=64).plot(col="t")  # plots the first 4 timepoints

Plot of the helicity for multiple timepoints.

Metadata

Release files for ghost-xarray 0.3.1

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

Source distribution (sdist)

Source distribution for ghost-xarray 0.3.1
File Size Uploaded Provenance Actions
ghost-xarray-0.3.1.tar.gz 193.3 kB Without provenance Details for ghost-xarray-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ghost-xarray 0.3.1
File Interpreter ABI Platform Actions
ghost_xarray-0.3.1-py3-none-any.whl Python 3 none any Details for ghost_xarray-0.3.1-py3-none-any.whl

Total release size: 200.4 kB

Release files / ghost-xarray-0.3.1.tar.gz

Download URL ghost-xarray-0.3.1.tar.gz
Size 193.3 kB
Tags Source
SHA-256 checksum
How to use checksums
06b843dff86d58ede9e9a2d63299b86c2caea7785691f4334624d1f1d4639856
BLAKE2b-256 checksum
How to use checksums
ea552c3b3c7be9f1f2d1810810229acbc69ed7fb7c36b4fff54e8f70e99e5628
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / ghost_xarray-0.3.1-py3-none-any.whl

Download URL ghost_xarray-0.3.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2eecd20df5b4ed4fa8868bb0c901b41d6af17f62bdd61117809b6392b7471ce3
BLAKE2b-256 checksum
How to use checksums
a8b1702dfc3e2b4a71190df4d3e1750a6b19b8b3c8aebabb2831ffef6bf68e30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Security for ghost-xarray 0.3.1

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