Skip to content

utils

extract_windows(seq, window_size, dilation=1, mode='memory')

Extract sliding windows from a sequence.

The step size is considered to be one, which results in len(seq) - window_size + 1 extracted windows. The resulting array has the shape [num_windows, window_size, num_channels].

If dilation is set to a value greater than one, the window will not contain consecutive time steps. Instead, the time steps are spaced by the dilation value. In this case, the number of extracted windows is len(seq) - (window_size - 1) * dilation.

Parameters:

Name Type Description Default
seq ndarray

sequence to extract windows from

required
window_size int

length of the sliding window

required
dilation int

dilation of the sliding window

1
mode Literal['memory', 'memmap']

create windows either in memory or on disk

'memory'

Returns:

Type Description
ndarray

array of sliding windows

feature_to_tensor(features, dtype=torch.float32, copy=False)

Convert a numpy array to a torch tensor of dtype and swap the last dimensions.

The function assumes that the last dimension of the numpy array is the channel dimension, and the second to last is the time dimension. All preceding dimensions are considered to be batch dimensions.

Parameters:

Name Type Description Default
features ndarray

numpy array to convert

required
dtype dtype

dtype of the resulting tensor

float32
copy bool

whether to copy the array before converting it

False

get_files_in_path(path, condition=None)

Return the paths of all files in a path that satisfy a condition in alphabetical
order.

If the condition is `None` all files are returned.

Args:
    path: the path to look into
    condition: the include-condition for files

Returns:

Type Description
List[str]

all files that satisfy the condition in alphabetical order

get_targets_from_file_paths(file_paths, timestep_from_file_path)

Create the RUL targets based on the file paths of the feature files.

The function extracts the feature file path from each path. The supplied conversion function extracts the time step from it. Afterwards the RUL is calculated by subtracting each time step from the maximum time step plus 1.

Parameters:

Name Type Description Default
file_paths Dict[int, List[str]]

runs represented as dict of feature file paths

required
timestep_from_file_path Callable

Function to convert a feature file path to a time step

required

Returns:

Type Description
Dict[int, ndarray]

A list of RUL target arrays for each run