Skip to main content

XRPatcher - A ML-Oriented Generic Patcher for xarray Data Structures

Installation |Examples

pyver codestyle Open In Colab GitHub commit activity

  • 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 Open In Colab

We have an extended example where we demonstrate some of the ways to do the reconstruction!

Example 2: PyTorch Integration Open In Colab

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.

Metadata

Release files for xrpatcher 0.0.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 xrpatcher 0.0.1
File Size Uploaded
xrpatcher-0.0.1.tar.gz 11.7 kB Details

Built distribution (wheel)

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

Total release size: 23.3 kB

Release files / xrpatcher-0.0.1.tar.gz

Download URL xrpatcher-0.0.1.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d98663430ee3070512e44ae65b2bc47b335e866a0d4a3ab864129c932a2ec97f
BLAKE2b-256 checksum
How to use checksums
c75322f1b7ce06c6d5b13660f384ad3838634cd4e1663c842c11e37f168a7a45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.9 Linux/5.19.0-43-generic

Release files / xrpatcher-0.0.1-py3-none-any.whl

Download URL xrpatcher-0.0.1-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba874b2f70320cce1f10a07ed7270814cee52987c9f1fff00bfa3335fd102019
BLAKE2b-256 checksum
How to use checksums
9fbb1772af46db80aba04acca6490163cbc7932b6f2faffd582d37c4010184ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.9 Linux/5.19.0-43-generic

Release history Release notifications | RSS feed

This release

0.0.1 This release

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