pept.base.IterableSamples#

class pept.base.IterableSamples(data, sample_size=None, overlap=None, columns=[], **kwargs)[source]#

Bases: PEPTObject, Collection

An class for iterating through an array (or array-like) in samples with potential overlap.

This class can be used to access samples of data of an adaptive sample_size and overlap without requiring additional storage.

The samples from the underlying data can be accessed using both indexing (samples[0]) and iteration (for sample in samples: ...).

Particular cases:
  1. If sample_size == 0, all data_samples is returned as one single sample.

  2. If overlap >= sample_size, an error is raised.

  3. If overlap < 0, lines are skipped between samples.

Raises
ValueError

If overlap >= sample_size unless sample_size is 0. Overlap must be smaller than sample_size. Note that it can also be negative.

See also

pept.LineData

Encapsulate LoRs for ease of iteration and plotting.

pept.PointData

Encapsulate points for ease of iteration and plotting.

Attributes
dataiterable that supports slicing

An iterable (e.g. numpy array) that supports slicing syntax (data[5:7]) storing the data that will be iterated over in samples.

sample_sizeint

The number of rows in data to be returned in a single sample. A sample_size of 0 yields all the data as a single sample.

overlapint

The number of overlapping rows from data between two consecutive samples. An overlap of 0 implies consecutive samples, while an overlap of (sample_size - 1) means incrementing the samples by one. A negative overlap implies skipping values between samples.

__init__(data, sample_size=None, overlap=None, columns=[], **kwargs)[source]#

IterableSamples class constructor.

Parameters
dataiterable

The data that will be iterated over in samples; most commonly a NumPy array.

sample_sizeint or Iterable[Int], optional

The number of rows in data to be returned in a single sample. A sample_size of 0 yields all the data as a single sample.

overlapint, optional

The number of overlapping rows from data between two consecutive samples. An overlap of 0 implies consecutive samples, while an overlap of (sample_size - 1) means incrementing the samples by one. A negative overlap implies skipping values between samples.

Methods

__init__(data[, sample_size, overlap, columns])

IterableSamples class constructor.

copy([deep, data, extra, hidden])

Construct a similar object, optionally with different data.

extra_attrs()

hidden_attrs()

load(filepath)

Load a saved / pickled PEPTObject object from filepath.

save(filepath)

Save a PEPTObject instance as a binary pickle object.

Attributes

attrs

columns

data

overlap

sample_size

samples_indices

property data#
property columns#
property attrs#
extra_attrs()[source]#
hidden_attrs()[source]#
property samples_indices#
property sample_size#
property overlap#
copy(deep=True, data=None, extra=True, hidden=True, **attrs)[source]#

Construct a similar object, optionally with different data. If extra, extra attributes are propagated; same for hidden.

static load(filepath)#

Load a saved / pickled PEPTObject object from filepath.

Most often the full object state was saved using the .save method.

Parameters
filepathfilename or file handle

If filepath is a path (rather than file handle), it is relative to where python is called.

Returns
pept.PEPTObject subclass instance

The loaded object.

Examples

Save a LineData instance, then load it back:

>>> lines = pept.LineData([[1, 2, 3, 4, 5, 6, 7]])
>>> lines.save("lines.pickle")
>>> lines_reloaded = pept.LineData.load("lines.pickle")
save(filepath)#

Save a PEPTObject instance as a binary pickle object.

Saves the full object state, including inner attributes, in a portable binary format. Load back the object using the load method.

Parameters
filepathfilename or file handle

If filepath is a path (rather than file handle), it is relative to where python is called.

Examples

Save a LineData instance, then load it back:

>>> lines = pept.LineData([[1, 2, 3, 4, 5, 6, 7]])
>>> lines.save("lines.pickle")
>>> lines_reloaded = pept.LineData.load("lines.pickle")