Skip to main content

Lightweight xarray wrapper for tsam time series aggregation

Project description

tsam_xarray

Lightweight xarray wrapper for tsam time series aggregation.

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 represents
result.accuracy.rmse     # (variable,) — per-variable RMSE
result.reconstructed     # same shape as input

Multi-dimensional data

# 4D data: (time, variable, region, scenario)
da = xr.DataArray(...)

# Cluster variable × 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)

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),
)

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.1a0.tar.gz (20.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.1a0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tsam_xarray-0.0.1a0.tar.gz
  • Upload date:
  • Size: 20.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.1a0.tar.gz
Algorithm Hash digest
SHA256 a7e67b1757f6ce62dc8a10bd03af242b1205914c7feafe2ed863fed4f1d206ca
MD5 3f634c12ba4da4bc8ef49e91ac35e5e3
BLAKE2b-256 3064eb877d9250de638c59ee3f2827371a204875b99b592358dcad6c868a3786

See more details on using hashes here.

Provenance

The following attestation bundles were made for tsam_xarray-0.0.1a0.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.1a0-py3-none-any.whl.

File metadata

  • Download URL: tsam_xarray-0.0.1a0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 6899ccc4cfd371a3afdc5d23a29d265b0d319746dd8e0ca1cddea1f33daa1c8e
MD5 e1aa6e0c64f3480ef14886f39582bc93
BLAKE2b-256 f4ef7ec4bfe3e4c29e40f05bba3444c679251d338efa1eb97331ded94ba5953d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tsam_xarray-0.0.1a0-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