Skip to main content

Lightweight xarray wrapper for tsam time series aggregation

Project description

tsam_xarray

PyPI Python CI codecov License: MIT Docs

Lightweight xarray wrapper for tsam time series aggregation.

DataArray in, DataArray out — no manual DataFrame conversions, no MultiIndex wrangling, no loop-and-concat boilerplate.

Installation

pip install tsam_xarray

Quick start

import numpy as np
import pandas as pd
import xarray as xr
import tsam_xarray

# Create sample data: 30 days of hourly solar and wind data
time = pd.date_range("2020-01-01", periods=30 * 24, freq="h")
da = xr.DataArray(
    np.random.default_rng(42).random((len(time), 2)),
    dims=["time", "variable"],
    coords={"time": time, "variable": ["solar", "wind"]},
)

# Aggregate to 4 typical days
result = tsam_xarray.aggregate(
    da, time_dim="time", cluster_dim="variable", n_clusters=4,
)

result.typical_periods   # (cluster, timestep, variable)
result.cluster_weights   # (cluster,) — days each cluster represents
result.accuracy.rmse     # (variable,) — per-variable RMSE
result.reconstructed     # same shape as input

Multi-dimensional data

# Cluster variable x region together; scenario is sliced independently
result = tsam_xarray.aggregate(
    da,
    time_dim="time",
    cluster_dim=["variable", "region"],
    n_clusters=8,
)

result.typical_periods  # (scenario, cluster, timestep, variable, region)

Weights

# Single cluster_dim — simple dict
result = tsam_xarray.aggregate(
    da, time_dim="time", cluster_dim="variable", n_clusters=8,
    weights={"solar": 2.0, "wind": 1.0},
)

# Multiple cluster_dim — dict-of-dicts
result = tsam_xarray.aggregate(
    da, time_dim="time", cluster_dim=["variable", "region"], n_clusters=8,
    weights={"variable": {"solar": 2.0}, "region": {"north": 1.5}},
)

tsam passthrough

All tsam.aggregate() keyword arguments pass through:

from tsam import ClusterConfig, SegmentConfig

result = tsam_xarray.aggregate(
    da,
    time_dim="time",
    cluster_dim="variable",
    n_clusters=8,
    cluster=ClusterConfig(method="kmeans"),
    segments=SegmentConfig(n_segments=6),
)

Documentation

Full docs with interactive examples: tsam_xarray.readthedocs.io

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

tsam_xarray-0.0.3a0.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

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

tsam_xarray-0.0.3a0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file tsam_xarray-0.0.3a0.tar.gz.

File metadata

  • Download URL: tsam_xarray-0.0.3a0.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tsam_xarray-0.0.3a0.tar.gz
Algorithm Hash digest
SHA256 0714b4948211a7dc0458602743d6b70ab1d863a9147121639902973cad845291
MD5 f0f8f95950339cbfaf921c92e8745b9d
BLAKE2b-256 81e7ae3f1abd30e968ef162c58761d0847901d98f72cbb1a4d33c811c2cf51a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tsam_xarray-0.0.3a0.tar.gz:

Publisher: publish.yaml on FBumann/tsam_xarray

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tsam_xarray-0.0.3a0-py3-none-any.whl.

File metadata

  • Download URL: tsam_xarray-0.0.3a0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tsam_xarray-0.0.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 af6ff9b4261726db30f1a8db4b75be1cd0aee5a207d9e86635dc0bc4a343e718
MD5 0a4645deaa8140b1a0615c117cbe8844
BLAKE2b-256 50f94b0ac04323f63137d66a2f345d6eecfc152c66a46a204c957482a0d41e8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tsam_xarray-0.0.3a0-py3-none-any.whl:

Publisher: publish.yaml on FBumann/tsam_xarray

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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