flasc.data_processing.time_operations

flasc.data_processing.time_operations#

Time operations for data processing.

Functions

df_downsample

Downsample a dataframe to a average accounting for angular columns.

df_movingaverage

Compute a moving average of a dataframe with angular columns.

df_resample_by_interpolation

Resample a dataframe by interpolation onto a new time array.

flatten_cols

Flatten multi-level columns in a DataFrame.

flasc.data_processing.time_operations.df_movingaverage(df_in, cols_angular, window_width=datetime.timedelta(seconds=60), min_periods=1, center=True, calc_median_min_max_std=False)[source]#

Compute a moving average of a dataframe with angular columns.

Note that median, minimum, and maximum do not handle angular quantities and should be treated carefully. Standard deviation handles angular quantities.

Parameters:
  • df_in (pd.DataFrame | FlascDataFrame) -- Input dataframe.

  • cols_angular (list) -- List of angular columns.

  • window_width (timedelta) -- Width of the moving average window.

  • min_periods (int) -- Minimum number of periods to consider.

  • center (bool) -- Center the time index. Default is True.

  • calc_median_min_max_std (bool) -- Calculate median, min, max, and std. Default is False.

Returns:

Output dataframe with moving averages.

Return type:

pd.DataFrame

flasc.data_processing.time_operations.df_downsample(df_in, cols_angular, window_width=datetime.timedelta(seconds=60), min_periods=1, center=False, calc_median_min_max_std=False, return_index_mapping=False)[source]#

Downsample a dataframe to a average accounting for angular columns.

Parameters:
  • df_in (pd.DataFrame | FlascDataFrame) -- Input dataframe.

  • cols_angular (list) -- List of angular columns.

  • window_width (timedelta) -- Width of the average window.

  • min_periods (int) -- Minimum number of data points for a bin to be valid.

  • center (bool) -- Center the time index. Default is False.

  • calc_median_min_max_std (bool) -- Calculate median, min, max, and std. Default is False.

  • return_index_mapping (bool) -- Return index mapping. Default is False.

Returns:

A tuple (pd.DataFrame, np.ndarray) if return_index_mapping is True. Where

the DataFrame is the downsampled dataframe and the np.ndarray is the index mapping.

A pd.DataFrame | FlascDataFrame if return_index_mapping is False.

flasc.data_processing.time_operations.df_resample_by_interpolation(df, time_array, circular_cols, interp_method='linear', max_gap=None, verbose=True)[source]#

Resample a dataframe by interpolation onto a new time array.

Parameters:
  • df (pd.DataFrame | FlascDataFrame) -- Input dataframe.

  • time_array (np.array) -- New time array.

  • circular_cols (list) -- List of columns that are circular.

  • interp_method (str) -- Interpolation method. Default is "linear".

  • max_gap (float) -- Maximum gap for interpolation. Default is None. If None, will be set to 1.5 times the median timestep.

  • verbose (bool) -- Print information. Default is True.

Returns:

Resampled dataframe

Return type:

pd.DataFrame | FlascDataFrame

flasc.data_processing.time_operations.flatten_cols(df)[source]#

Flatten multi-level columns in a DataFrame.

Parameters:

df (pd.DataFrame | FlascDataFrame) -- Input DataFrame.

Returns:

Flattened DataFrame.

Return type:

pd.DataFrame | FlascDataFrame