Skip to main content

Load time series in pyTorch dataloaders.

Project description

Time Series Loader

Manage time series dataset to be served as torch dataloaders. The main features are:

  • Load a csv file into dataloaders
  • Handle train/val/test splits
  • Normalize and rescale each variable

Example usage

We first build a PyTorch Dataset, then a pytorch-lightning DataModule.

from tsloader import TimeSeriesDataset, TimeSeriesDataModule

class ETDataset(TimeSeriesDataset):
    columns_inputs = ["HUFL", "HULL", "MUFL", "MULL", "LUFL", "LULL"]
    columns_targets = ["OT"]

    train_start = datetime.datetime(year=2016, month=7, day=1)
    train_end = validation_start = datetime.datetime(year=2017, month=7, day=1)
    validation_end = test_start = validation_start + datetime.timedelta(days=28 * 4)
    test_end = test_start + datetime.timedelta(days=28 * 4)
    stride_size = 24

    def preprocess(self):
        self.df["datetime"] = self.df["date"].apply(pd.to_datetime)


class ETDataModule(TimeSeriesDataModule):
    Dataset = ETDataset


# Setup the datamodule
datamodule = ETDataModule(
    dataset_path="datasets/ett/ETTh1.csv", forecast_size=48, batch_size=4
)
datamodule.setup()
# Visualize the entire dataset
datamodule.visualize()
# Load a sample from the training dataloader
dataloader = datamodule.train_dataloader()
for commands, observations in dataloader:
    ...

Installation

Using pip, we can simply install the latest release. The main branch is considered stable.

$ pip install git+https://git.zagouri.org/max/tsloader

If you are from Accenta, then you probably want to install the Accenta-specific version of this package:

$ pip install git+https://git.zagouri.org/max-accenta/tsloader

Compiling the documentation

The required libraries for compiling the documentation are listed in docs/requirements.txt. Once installed, run the following command from the docs/ folder:

$ make html

The documentation is built to the folder docs/_build/html/, and can be viewed by moving inside the directory and launching a temporary http server (for instance python -m http.server).

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

tsloader-3.0.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

tsloader-3.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file tsloader-3.0.2.tar.gz.

File metadata

  • Download URL: tsloader-3.0.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for tsloader-3.0.2.tar.gz
Algorithm Hash digest
SHA256 b2249720a927586994528e0ca05aef223a4a4e0addb6ebafc944be4bfd1e0207
MD5 5cd1306281a5cc8006e27827e71a1a7b
BLAKE2b-256 67dfbf94b7bcd5d674f239631a85cf8f7d781eaafe6ead6fefcc8011ccdeb099

See more details on using hashes here.

File details

Details for the file tsloader-3.0.2-py3-none-any.whl.

File metadata

  • Download URL: tsloader-3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for tsloader-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ea986c1f937afcc34702d965dbac72e6bca6ec68755ddf6ccbdf60282a2b751d
MD5 a7ee1cbe2cd4be43cc28a75ff290b2b5
BLAKE2b-256 ec3c563e89a72505631af9f24b0f00cc626e07e4da65779296609be803d85dda

See more details on using hashes here.

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