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.0.tar.gz (8.5 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.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tsloader-3.0.0.tar.gz
Algorithm Hash digest
SHA256 58a8f5fb484b2914a288d1f3b626681876d9a8efb9083f2cd27baa7ef38dfeb5
MD5 e1a948fc0ead17360b5c3fab2b73c2e1
BLAKE2b-256 b8cbb3ecadf74171bc3749f8931d78957e761e90ec7e7cd5445db4dc99fec7aa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tsloader-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 403debef62d243c041fcafcbe228243185a943d4dbd783f9d69c19c40f104cff
MD5 18955807a2e950f00c4601071831f5e7
BLAKE2b-256 96140f44e97e604371f7a8957e709d6e16ccdb1f164bc00df5c5b40f321107c2

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