A ML-oriented generic patcher for xarray data structures.
Project description
XRPatcher - A ML-Oriented Generic Patcher for xarray
Data Structures
- J. Emmanuel Johnson
- Quentin Febvre
About
This is a lightweight package to create patch items from xarray data structures. This makes it more compatible with machine learning datasets and dataloaders like PyTorch or TensorFlow. The user simply needs to define the patch dimensions and the stride dimensions and you are good to go! It also reconstructs (or unpatchifies) from arbitrary patches which allows for more robust inference procedures, e.g. to account for border effects from CNN models.
⏩ Examples
Quick Example
import xarray as xr
from xrpatcher import XRDAPatcher
# load demo dataset
data = xr.tutorial.load_dataset("eraint_uvz")
# extract demo dataarray
data = data.u[..., :240, :360]
# Instantiate the patching logic for training
patches = dict(longitude=30, latitude=30)
train_patcher = XRDAPatcher(
da=data,
patches=patches,
strides=patches, # No Overlap
check_full_scan=True # check no extra dimensions
)
# Instantiate the patching logic for testing
patches = dict(longitude=30, latitude=30)
strides = dict(longitude=5, latitude=5)
test_patcher = XRDAPatcher(
da=data,
patches=patches,
strides=strides, # Overlap
check_full_scan=True # check no extra dimensions
)
Extended Example
Example 1: Patching Crash Course
We have an extended example where we demonstrate some of the ways to do the reconstruction!
Example 2: PyTorch Integration
We have an extended example where we demonstrate some nifty PyTorch Integration.
🛠️ Installation
pip
We can directly install it via pip from the
pip install "git+https://github.com/jejjohnson/xrpatcher.git"
Cloning
We can also clone the git repository
git clone https://github.com/jejjohnson/xrpatcher.git
cd xrpatcher
Conda Environment (RECOMMENDED)
We use conda/mamba as our package manager. To install from the provided environment files run the following command.
mamba env create -n environment.yaml
poetry
The easiest way to get started is to simply use the poetry package which installs all necessary dev packages as well
poetry install
pip
We can also install via pip
as well
pip install .
Inspiration
There are a few other packages that gave us inspiration for this.
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 xrpatcher-0.0.1.tar.gz
.
File metadata
- Download URL: xrpatcher-0.0.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.9 Linux/5.19.0-43-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d98663430ee3070512e44ae65b2bc47b335e866a0d4a3ab864129c932a2ec97f |
|
MD5 | 96358ccb65c3c25ff7a96007fa751139 |
|
BLAKE2b-256 | c75322f1b7ce06c6d5b13660f384ad3838634cd4e1663c842c11e37f168a7a45 |
File details
Details for the file xrpatcher-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: xrpatcher-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.9 Linux/5.19.0-43-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba874b2f70320cce1f10a07ed7270814cee52987c9f1fff00bfa3335fd102019 |
|
MD5 | 723969e530e26e64544efe85198b1241 |
|
BLAKE2b-256 | 9fbb1772af46db80aba04acca6490163cbc7932b6f2faffd582d37c4010184ba |