Skip to main content

xbootstrap

PyPI tests build codecov License: MIT Code style: black

xbootstrap is a simple package for performing nested* circular† block‡ bootstrapping of xarray objects.

  • Bootstrapping is random resampling with replacement.
  • ‡ Block boostrapping is a simple way to account for autocorrelation in the data being randomly resampled.
  • † Circular block bootstrapping avoids undersampling data values near the beginning and end of the dimension(s) being resampled. This is optional in xbootstrap.
  • * Here, nested bootstrapping means that, when multiple dimensions are specified, the first dimension is randomly resampled, then for each resampled element along that dimension the second dimension is randomly resampled, then for each resampled element along that dimension the third dimension is randomly resampled etc.

Installation

To install this package from PyPI:

pip install xbootstrap

Example usage

xbootstrap currently comprises a single function called block_bootstrap that can be used as follows:

import numpy as np
import xarray as xr
from xbootstrap import block_bootstrap

# Generate some example data
n_time = 100
n_ensemble = 10
ds1 = xr.DataArray(
    np.random.random((n_time, n_ensemble)),
    coords={"time": range(n_time), "ensemble": range(n_ensemble)},
)
ds2 = xr.DataArray(
    np.random.random((n_time, n_ensemble)),
    coords={"time": range(n_time), "ensemble": range(n_ensemble)},
)
ds3 = xr.DataArray(np.random.random((n_time)), coords={"time": range(n_time)})

# Create 1000 circularly bootstrapped resamples of ds1, ds2 and ds3
# using a blocksize of 5 for the time dimension and 1 for the ensemble
# dimension, and only bootstrapping the time dimension for ds2
ds1_bs, ds2_bs, ds3_bs = block_bootstrap(
    ds1,
    ds2,
    ds3,
    blocks={"time": 5, "ensemble": 1},
    n_iteration=1000,
    exclude_dims=[[], ["ensemble"], []],
    circular=True,
)

block_bootstrap also operates lazily with dask-backed xarray objects, but this requires dask to be installed:

ds1_bs, ds2_bs, ds3_bs = block_bootstrap(
    ds1.chunk(),
    ds2.chunk(),
    ds3.chunk(),
    blocks={"time": 5, "ensemble": 1},
    n_iteration=10,
    exclude_dims=[[], ["ensemble"], []],
    circular=True,
)

Contributing

Contributions are very welcome, particularly in the form of reporting bugs and writing tests. Please open an issue and check out the contributor guide.

References

Wilks, D.S., 2011. Statistical methods in the atmospheric sciences (Vol. 100). Academic press. (particularly Chapter 5.3)

Metadata

Release files for xbootstrap 0.0.6

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

Source distribution (sdist)

Source distribution for xbootstrap 0.0.6
File Size Uploaded
xbootstrap-0.0.6.tar.gz 29.1 kB Details

Built distribution (wheel)

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

Total release size: 39.4 kB

Release files / xbootstrap-0.0.6.tar.gz

Download URL xbootstrap-0.0.6.tar.gz
Size 29.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cee796f156a03fc970804a883a17a79f671b2d9cd7e36fb700007831de3226d4
BLAKE2b-256 checksum
How to use checksums
124b924a93cb77616b006d8d241b1d21d28986dc4945bf6a09e2d01e9a3124ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / xbootstrap-0.0.6-py3-none-any.whl

Download URL xbootstrap-0.0.6-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3be52ff2f49f247b3120eff831f27f0526024462ad173f7aa9b85259b3cb8961
BLAKE2b-256 checksum
How to use checksums
b99f42ecb57d6ea8fbe8e136be843f1e8eddccaaf3bdb224614979fd62c50761
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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