match_sampling_rate
MatchSamplingRate(reference_feature_name, feature_interpolation_map, fill_strategy='both_ways')
Bases: Transform
Matches the sampling rate of all time series in the DataFrame.
Interpolates the time series to match the sampling rate of the reference
time series. The below example shows the usage of a MatchSamplingRate
transform in a run.py
file. Assuming the loaded data is
represented by the table:
| feature_a | feature_b | const |
| --- | --- | --- |
| list[struct[time,struct[]]] | list[struct[time,struct[]]] | int |
| --------------------------- | --------------------------- | ----- |
| [{12:26:01.0, {1.2}}, | [{12:26:00.0, {1.0}}, | 1 |
| {12:26:02.0, {2.4}}, | {12:26:05.0, {2.0}}] | |
| {12:26:03.0, {3.6}}, | | |
| {12:26:04.0, {4.8}}] | | |
The following transform can be used to match the sampling rate
of the time series feature_b
to the sampling rate
of the time series feature_a
.
...
environment.load()
data = environment.get_data()
transform = MatchSamplingRate(
reference_feature_name="feature_a",
feature_interpolation_map={
"feature_b": "linear",
},
)
transformed_data = transform.transform(data)
...
The resulting Dataframe after the transform is:
| feature_a | feature_b | const |
| --- | --- | --- |
| list[struct[time,struct[]]] | list[struct[time,struct[]]] | int |
| --------------------------- | --------------------------- | ----- |
| [{12:26:00.0, {1.2}}, | [{12:26:00.0, {1.2}}, | 1 |
| {12:26:01.0, {2.4}}, | {12:26:01.0, {1.4}}, | |
| {12:26:02.0, {3.6}}, | {12:26:02.0, {1.6}}, | |
| {12:26:03.0, {4.8}}] | {12:26:03.0, {1.8}}] | |
Initialize the transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference_feature_name
|
str
|
Reference timeseries feature. |
required |
feature_interpolation_map
|
dict[str, MatchSamplingRateMethod]
|
Key-value pairs of the timeseries features that are targeted in interpolation columns and the interpolation method to use. The interpolation method can be 'linear' or 'nearest'. |
required |
fill_strategy
|
FillStrategy
|
Strategy to fill missing values after interpolation. |
'both_ways'
|
Source code in src/flowcean/polars/transforms/match_sampling_rate.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
apply(data)
Transform the input DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
LazyFrame
|
Input DataFrame. |
required |
Returns:
Type | Description |
---|---|
LazyFrame
|
Transformed DataFrame. |
Source code in src/flowcean/polars/transforms/match_sampling_rate.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
FeatureNotFoundError(feature)
Bases: Exception
Feature not found in the DataFrame.
This exception is raised when a feature is not found in the DataFrame.
Source code in src/flowcean/polars/transforms/match_sampling_rate.py
277 278 |
|
interpolate_feature(target_feature_name, data, reference_feature, interpolation_method='linear', fill_strategy=None)
Interpolate a single time series feature using Polars expressions.
Source code in src/flowcean/polars/transforms/match_sampling_rate.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|