Flags
- flags.apply_automatic_flags(df: DataFrame, automatic_flags: list) DataFrame
Apply automatic flags to a DataFrame based on specified conditions.
- Parameters:
df (pd.DataFrame) – DataFrame to which the flags will be applied.
automatic_flags (list) –
List of conditions to apply the flags, for example: [
”row[‘CavityTemp’] < 44.98”, “any(row[value] == 0 for value in [‘CO2’, ‘CO2_dry’, ‘CH4’, ‘CH4_dry’])”
]
- Returns:
DataFrame with the ‘FA’ column updated with automatic flags. ‘FA’ column values:
1: Condition is true (flag is applied)
0: Condition is false (flag is not applied)
- Return type:
pd.DataFrame
Notes
The conditions in automatic_flags must be strings evaluable as Python expressions that return boolean values.
The parameter automatic_flags may be defined in the campaign config file.
- flags.apply_calibration_flags(df: DataFrame, calibration_periods: list) DataFrame
Apply calibration flags to a DataFrame.
The function iterates through df rows and applies calibration flags and ID based on the specified calibration_periods. It also handles cases where ‘FM’ (manual flags) invalidate the calibration flags (‘CAL’).
- Parameters:
df (pd.DataFrame) – DataFrame with calibration data.
calibration_periods (list) –
List of calibration periods, each represented as a list with the format: [start_time, end_time, value, id, method]. Example: [
[“2020-12-18 16:00”, “2021-10-25 15:00”, 4, “D311113”, “solenoid_valves”], [“2021-10-25 19:00”, “2022-10-05”, 4, “D289341”, “solenoid_valves”], [“2021-10-18 19:00”, “2022-10-05”, 5, “CC339517”, “solenoid_valves”], [“2022-10-13”, “”, 4, “CC339517”, “MPVPosition”]
]
- Returns:
DataFrame with applied calibration flags and ID: - ‘CAL’: Calibration flag (1 for calibration periods, 0 otherwise). - ‘CAL_ID’: ID of the gas tank used during calibration periods.
- Return type:
pd.DataFrame
Notes
The parameter calibration_periods may be defined in the campaign config file.
Requires a column ‘FM’ (manual flags) in df. If ‘FM’ == 1, ‘CAL’ is set to 0.
- flags.apply_manual_calibration_flags(df: DataFrame, database_path: str, logbook_name: str) DataFrame
- flags.apply_manual_flags(df: DataFrame, database_path: str, logbook_name: str) DataFrame
Applies manual flags to a DataFrame based on events from a database.
- Parameters:
df (pd.DataFrame) – DataFrame to which the manual flags will be applied.
database_path (str) – Path to the SQLite database containing event data.
logbook_name (str) – Name or identifier of the logbook events to consider.
- Returns:
- DataFrame with the ‘FM’ column updated with manual flags:
1: Data point falls within a logged event period
0: Data point does not fall within any logged event period
- Return type:
pd.DataFrame
Notes
The parameters database_path and logbook_name may be defined in the campaign config file.
Only events that invalidate data (where invalid=True) are considered.
Date intervals are closed on both sides.