PyTorch-compatible wrapper for Era5
Project description
ERA5-Torch
This repository provides a wrapper around ERA5 files that is compatible with PyTorch.
Installation
Install the requirements via pip install -r requirements.txt
.
Usage Examples
The main functionality is exposed through the Era5 class, which is a valid PyTorch Dataset and can thus be used with standard PyTorch dataloaders.
Assume that you have downloaded some NetCDF files (for example, follow this tutorial containing the temperature ("t") and your data lives at path/to/dataset.nc
. You can then load the data with:
from era5_torch import Era5
ds = Era5("/path/to/dataset.nc", "t", normalize=False)
ds[0]
which returns a single sample of the temperature values with shape (1, num_lat, num_long)
. By default, the samples are all located at a single point in time and a single pressure level.
If your model uses coordinate information, you can pass in the coordinates desired coordinates to the dataset class, which are appended in the passed order to the first axis of the return sample:
from era5_torch import Era5, Coordinate
ds = Era5("/path/to/dataset.nc", "t", normalize=False, normalize_coords=True, coords=[Coordinate.X, Coordinate.Y, Coordinate.Z])
ds[0]
which returns a sample with shape (4, num_lat, num_long)
, and ds[0][0]
is the temperature, ds[0][1]
the x-values of the temperature, et cetera.
To access the dataset in different ways (for example with 3D chunks of shape (time, lat, long)
), we provide the Chunker class. This can be passed to the Era5 class.
from era5_torch import Era5, Coordinate, ContinuousChunker
ds = Era5("/Users/almico/datasets/era5_temperatures_2008.nc", "t", normalize=False,chunker=ContinuousChunker((3,3,3)))
ds[0]
Returns a sample of shape (3,3,3)
with values varying over (time, lat, long)
. Alternatively, to get patches, you can also create a Chunker with ContinuousChunker((3,3))
. All chunkers have different behaviour, the ContinuousChunker
for example returns chunks starting from the first position in the dataset (usually the (0,0) coordinate) and creates as many chunks in an orderly manner as possible by traversing the coordinates one after another. Refer to the documentation of the Chunkers to get more information.# era5_torch
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file era5_torch-0.1.1.tar.gz
.
File metadata
- Download URL: era5_torch-0.1.1.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 878d9fa13dd9ecbe0fe7ce33820212e8e2976fae0d688cba1fa5d0b8b1a3667f |
|
MD5 | 8bba28039b5a639764849fa4659e361f |
|
BLAKE2b-256 | e01af8b7165000ed2577470ba7e912d978e884e43109e520068df690e32a3da8 |
File details
Details for the file era5_torch-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: era5_torch-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c63945166112a7d02363293b978219b073825bf6a9f684eb91878189f5b23218 |
|
MD5 | 95d32449da5500cd7d1aaf8547ed26dd |
|
BLAKE2b-256 | de6250f8df2f30b6f355d2bf0b5a554f464dc21eaae145b1bc4facd1ad6fb894 |