Lightweight xarray wrapper for tsam time series aggregation
Project description
tsam_xarray
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.cluster_representatives # (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.cluster_representatives # (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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tsam_xarray-0.3.1.tar.gz.
File metadata
- Download URL: tsam_xarray-0.3.1.tar.gz
- Upload date:
- Size: 41.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eedbef38309b4397d0cc65efdaafe8563cf147714d95287ab425abf6ec516e01
|
|
| MD5 |
36d63efb77d727665ed399a9bcc9ca4f
|
|
| BLAKE2b-256 |
0e059a6f0851018134cccacdeef12f76377eae56efab22cb14b350e89b31f0c4
|
Provenance
The following attestation bundles were made for tsam_xarray-0.3.1.tar.gz:
Publisher:
publish.yaml on FBumann/tsam_xarray
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tsam_xarray-0.3.1.tar.gz -
Subject digest:
eedbef38309b4397d0cc65efdaafe8563cf147714d95287ab425abf6ec516e01 - Sigstore transparency entry: 1202794244
- Sigstore integration time:
-
Permalink:
FBumann/tsam_xarray@3444342f7847777c72c6b7a5781fe44cd0886518 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/FBumann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@3444342f7847777c72c6b7a5781fe44cd0886518 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tsam_xarray-0.3.1-py3-none-any.whl.
File metadata
- Download URL: tsam_xarray-0.3.1-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
797a027c15fe11f7ca2531b865c637ac6828d4765d1847bf3e63ed1bb7f89961
|
|
| MD5 |
6374681f408959896fff81a63f3759cd
|
|
| BLAKE2b-256 |
a9d881aafb98df1e5a5b598c274e3954a48ef143d7d4f1e3891c8b85ecbff663
|
Provenance
The following attestation bundles were made for tsam_xarray-0.3.1-py3-none-any.whl:
Publisher:
publish.yaml on FBumann/tsam_xarray
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tsam_xarray-0.3.1-py3-none-any.whl -
Subject digest:
797a027c15fe11f7ca2531b865c637ac6828d4765d1847bf3e63ed1bb7f89961 - Sigstore transparency entry: 1202794247
- Sigstore integration time:
-
Permalink:
FBumann/tsam_xarray@3444342f7847777c72c6b7a5781fe44cd0886518 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/FBumann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@3444342f7847777c72c6b7a5781fe44cd0886518 -
Trigger Event:
push
-
Statement type: