Commit 95b51930 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

Picarro. Clock shift correction.

parent 83d776be
Pipeline #154211 passed with stages
in 1 minute and 36 seconds
"""
The picarro processor module provides functions to manipulate picarro's raw data.
"""
import numpy as np
import pandas as pd
def clock_shift_correction(picarro_df: pd.DataFrame,
reference_df: pd.DataFrame = None,
first_datetime: pd.Timestamp = None,
last_datetime: pd.Timestamp = None) -> pd.DataFrame:
"""Correct the Picarro's data time shift which occurs when the Picarro's PC clock is not NTP-synchronized.
The data recorded in `PICARRO_periodic` are timestamped with Picarro's PC time, not the CFA's main PC time.
Parameters
----------
picarro_df: pd.Dataframe
Picarro's data.
reference_df: pd.Dataframe, optional
Reference dataframe, whose first and last index's datetime is used to determine the "real" moment the Picarro
started/finished to record.
first_datetime: pd.Timestamp, optional
Reference start point for the first Picarro point. If not set, `reference_df` should be set.
last_datetime: pd.Timestamp, optional
Reference end point for the last Picarro point. If not set, `reference_df` should be set.
Returns
-------
pd.Dataframe
Same as input's `picarro_df`, with datetime index rescaled.
"""
if first_datetime is None or last_datetime is None:
first_datetime = reference_df.index[0]
last_datetime = reference_df.index[-1]
start_shift = picarro_df.index[0] - first_datetime
picarro_df.index = picarro_df.index - start_shift
inline_lag = picarro_df.index[-1] - last_datetime
inline_lag_sec = inline_lag.total_seconds()
lag_per_sample = inline_lag_sec / len(picarro_df.index)
lag_per_sample_vector = np.arange(0, inline_lag_sec, lag_per_sample)
lag_per_sample_timedelta = pd.to_timedelta(lag_per_sample_vector, unit="s")
picarro_df.index = picarro_df.index - lag_per_sample_timedelta
return picarro_df
if __name__ == '__main__':
from cfatools.logreader.dataset import DatasetReader
log = DatasetReader("/homel/ojossoud/_temp/data_cfa", "20210826_ASUMA2016_6-1_sq")
picarro_df = log.get_timeseries("PICARRO_periodic", "Delta_18_16")
encoder_df = log.get_timeseries("ENCODER_periodic")
clock_shift_correction(picarro_df, encoder_df)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment