Clip time series¶
Description¶
Clip time series bases
Parameters¶
- base:
Base
The input base.
- base:
- time_variable:
str
, default='time'
The name of the time variable.
- time_variable:
- strategy:
str
, default='min_max'
The strategy used to clip the time series. Two values are accepted:
'min_max'
: Clip the time series using a minimum and maximum value (see min_max_range keyword).'common_window'
: Clip the time series in such a way that all instants have the same initial and final time.
- strategy:
- min_max_range:
list(float)
, default=[None, None]
When using strategy
'min_max'
, define the time range as a list of two floats specifying the minimum and maximum values. Either value can be set toNone
to indicate that there is no bound in that direction.
- min_max_range:
- min_max_exclusive:
bool
, default=False
If
True
, the limits of the time range are excluded from the output base.
- min_max_exclusive:
- memory_mode:
bool
, default=False
If
True
the instants and zones of the input base are deleted progressively.
- memory_mode:
Preconditions¶
The base can have multiple zones and multiple instants. Each instant is considered as a distinct time series and it must have the time_variable as variable, either inherited through the share instant or as an instant variable. The time_variable is assumed to be sorted.
Postconditions¶
The output base will retain the same structure as the input base
Usage¶
treatment = antares.Treatment('cliptimeseries')
treatment['base'] = base
treatment['strategy'] = 'min_max'
treatment['time_range'] = [0.5, 1.5]
treatment['min_max_exclusive'] = True
treatment['memory_mode'] = False
clip_base = treatment.execute()
Example¶
import os
import numpy as np
import antares
output_folder = os.path.join("OUTPUT", "TreatmentClipTimeSeries")
os.makedirs(output_folder, exist_ok=True)
base = antares.Base()
base["0000"] = antares.Zone()
# Create a first instant with time data from 0 to 10 seconds and a linear
# variable
base["0000"]["0000"] = antares.Instant()
base[0][0]['t'] = np.linspace(0, 10, 100)
base[0][0]['myvar'] = 10*base[0][0]['t'] + 3
# Create a second instant with time data from 2 to 7 seconds and a quadratic
# variable
base["0000"]["0001"] = antares.Instant()
base[0][1]['t'] = np.linspace(2, 7, 100)
base[0][1]['myvar'] = base[0][0]['t']**2
# Plot original base
plot = antares.Treatment('plot1d')
plot['bases'] = [base]
plot['x_var'] = 't'
plot['overlap_vars'] = True
plot['overlap_instants'] = True
plot['title'] = 'Base before clipping'
plot['legend_label'] = '{instant}'
plot['show'] = False
plot['output_file'] = os.path.join(output_folder, "input.jpeg")
plot['figure_kwargs'] = {'dpi': 300}
plot.execute()
# Clip base keeping only the common window between all time series
clip = antares.Treatment('cliptimeseries')
clip['base'] = base
clip['time_variable'] = 't'
clip['strategy'] = 'common_window'
output_base = clip.execute()
# Plot output base
plot = antares.Treatment('plot1d')
plot['bases'] = [output_base]
plot['x_var'] = 't'
plot['overlap_vars'] = True
plot['overlap_instants'] = True
plot['title'] = 'Base after clipping'
plot['legend_label'] = '{instant}'
plot['show'] = False
plot['output_file'] = os.path.join(output_folder, "output.jpeg")
plot['figure_kwargs'] = {'dpi': 300}
plot.execute()

