Skip to main content

Tools to read in CryoGrid MATLAB data to Python and create forcing data

Project description

CryoGrid-pyTools

Tools to read in CryoGrid MATLAB data to Python, includes forcing, outputs, DEMs, etc.

Feel free to use, modify, and distribute as you see fit.

Installation

pip install cryogrid_pytools

# OR for the very latest bleeeeding edge version
pip install "cryogrid-pytools[data,viz] @ git+https://github.com/lukegre/CryoGrid-pyTools.git"

However, I recommend using uv to manage your Python environments. This would be

uv add cryogrid-pytools[data,viz]

# OR
uv add "cryogrid-pytools[data,viz] @ git+https://github.com/lukegre/CryoGrid-pyTools.git"

Usage

This package can read in

  • CryoGrid output (from OUT_regridded_FCI2)
  • simple MATLAB struct files (not run_info.mat)
  • ERA5 forcing
  • excel run configuration files (experimental)

Basic examples are shown below for the first two items, but see demo.ipynb for more comprehensive examples.

Reading single CryoGrid output files

Currently, only output files from the calss OUT_regridded_FCI2 are supported. However, the majority of files you'll use follow this format.

import cryogrid_pytools as cgt

# a single file that should look something like this
fname = "results_from_RUN_SIMPLE/<project_name>_<YYYYMMDD>.mat"

# currently the only output from OUT_regridded_FCI2 is supported
dataset = cgt.read_OUT_regridded_FCI2_file(fname)

Reading multiple CryoGrid output files

If you're working with RUN_SPATIAL_SPINUP_CLUSTERING, you can read in multiple files at once. The data are returned as an xarray.Dataset with the dimensions: [gridcell, depth, time]

# path contains wildcards where cluster ID and date are respectively
fname = "results_from_RUN_SPATIAL_SPINUP_CLUSTERING/project_name_*_*.mat"

# deepest_point is the deepest point in the saved files
dataset = cgt.read_OUT_regridded_FCI2_clusters(fname, deepest_point=-5)

Reading struct files from MATLAB

TIP: In MATLAB, You need to add the `CryoGrid/source` directory to the MATLAB path before the file can be loaded properly.

Note that run_info.mat cannot be read as it contains special classes that are not supported by scipy.io.loadmat. To save parts of run_info, use the following code in MATLAB:

run_info_spatial = run_info.SPATIAL.STATVAR
save "run_info_spatial.mat" run_info_spatial

Then, in Python:

fname = 'path_to_file/run_spatial_statvar.mat'
spatial = cgt.read_mat_struct_as_dataset(fname, index=['Y', 'X'])

Project details


Download files

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

Source Distribution

cryogrid_pytools-0.3.14.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

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

cryogrid_pytools-0.3.14-py3-none-any.whl (53.2 kB view details)

Uploaded Python 3

File details

Details for the file cryogrid_pytools-0.3.14.tar.gz.

File metadata

  • Download URL: cryogrid_pytools-0.3.14.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for cryogrid_pytools-0.3.14.tar.gz
Algorithm Hash digest
SHA256 a72a223d0eca6db519f59e0ed96e55a8477e09d127dfd52049458a24d4c3d641
MD5 b18cada3a3780cbd7f5bb07fe5a70f53
BLAKE2b-256 5abd4bff74a0f36ad4ce0af3650176d7ffeec03815f20f180b27272bfa141a37

See more details on using hashes here.

File details

Details for the file cryogrid_pytools-0.3.14-py3-none-any.whl.

File metadata

File hashes

Hashes for cryogrid_pytools-0.3.14-py3-none-any.whl
Algorithm Hash digest
SHA256 fa5a6c4f1de0fd94b09c3db16ee3eada2fa0a8b3bbb44ac66e2c1aec094ace3a
MD5 1247df1c725c576abc8b126a53e6f345
BLAKE2b-256 b5fb356dad5932d1c95de540df8e651c1f07efe264595b646858ea3d434f5ce5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page