Skip to main content

xgrads

DOI GitHub Documentation Status PyPI version Publish to PyPI pytest Build Status Codacy Badge

3D plot

1. Introduction

The Grid Analysis and Display System (GrADS or OpenGrADS) is a widely used software for easy access, manipulation, and visualization of earth science data. It uses a descriptor (or control) file with a suffix .ctl to describe a raw binary 4D dataset. The ctl file is similar to the header information of a NetCDF file, containing all the information about dimensions, attributes, and variables except for the variable data.

This python package xgrads is designed for parse and read the .ctl file commonly used by GrADS. Right now it can parse various kinds of .ctl files. However, only the commonly used raw binary 4D datasets can be read using dask and return as a xarray.Dataset Other types of binary data, like dtype is station orgrib, may be supported in the future.


2. How to install

Requirements xgrads supports Python 3.9 through 3.13 and depends on recent versions of NumPy, xarray, dask, pyproj, and numba. Exact compatibility depends on the installed dependency versions.

Install via pip

pip install xgrads

Install via conda

conda install -c conda-forge xgrads

Install from github

git clone https://github.com/miniufo/xgrads.git
cd xgrads
python -m pip install .

3. Examples

3.1 Parse a .ctl file

Parsing a .ctl file is pretty simple using the following code:

from xgrads import CtlDescriptor

ctl = CtlDescriptor(file='test.ctl')

# print all the info in ctl file
print(ctl)

If you have already load the ASCII content in the .ctl file, you can do it as:

content = \
    "dset ^binary.dat\n" \
    "* this is a comment line\n" \
    "title 10-deg resolution model\n" \
    "undef -9.99e8\n" \
    "xdef 36 linear   0 10\n" \
    "ydef 19 linear -90 10\n" \
    "zdef  1 linear   0  1\n" \
    "tdef  1 linear 00z01Jan2000 1dy\n" \
    "vars  1\n" \
    "test  1 99 test variable\n" \
    "endvars\n"

ctl = CtlDescriptor(content=content)

# print all the info
print(ctl)

3.2 Read binary data into a xarray.Dataset

Reading a .ctl related binary data file is also pretty simple using the following code:

from xgrads import open_CtlDataset

dset = open_CtlDataset('test.ctl')

# print all the info in ctl file
print(dset)

Then you have the dset as a xarray.Dataset. This is similar to xarray.open_dataset that use dask to chunk (buffer) parts of the whole dataset in physical memory if the whole dataset is too large to fit in.

If there are many .ctl files in a folder, we can also open all of them in a single call of open_mfdataset as:

from xgrads import open_mfdataset

dset = open_mfdataset('./folder/*.ctl')

# print all the info in ctl file
print(dset)

assuming that every .ctl file has similar data structure except the time step is different. This is similar to xarray.open_mfdataset.


3.3 Convert a GrADS dataset to a NetCDF dataset

With the above functionality, it is easy to convert a .ctl (GrADS) dataset to a .nc (NetCDF) dataset:

from xgrads import open_CtlDataset

open_CtlDataset('input.ctl').to_netcdf('output.nc')

Metadata

Release files for xgrads 0.2.9

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

Source distribution (sdist)

Source distribution for xgrads 0.2.9
File Size Uploaded
xgrads-0.2.9.tar.gz 27.3 kB Details

Built distribution (wheel)

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

Total release size: 50.7 kB

Release files / xgrads-0.2.9.tar.gz

Download URL xgrads-0.2.9.tar.gz
Size 27.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cf12e4f7390989c1be9990096308ed85d29efd3945d7d1d8c071ca593a35ffe6
BLAKE2b-256 checksum
How to use checksums
c3426a6e3c596642b1a6304e78b7aad6b5970c7d15c73f6f83f9bcb64b96272f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xgrads-0.2.9-py3-none-any.whl

Download URL xgrads-0.2.9-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b3e3967fa489efd36200a2e8e4a6eb66c35c09891b966d28bfdacd4b48c7640
BLAKE2b-256 checksum
How to use checksums
8739b19a1996a024e4de148fc8f60b97752d3110df636689e4e60190e3864492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.2.9 This release

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.0

1 release file

0.1.82

1 release file

0.1.81

1 release file

0.1.8

1 release file

0.1.7

2 release files

0.1.6

1 release file

0.1.5

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