diff --git a/features/ambient.py b/features/ambient.py index b72a53d..7a9e8e3 100644 --- a/features/ambient.py +++ b/features/ambient.py @@ -12,6 +12,10 @@ from config.models import ( ) from setup import db_engine, session +MINIMUM_PRESSURE_MB = 870 +# The lowest measurable sea-level pressure is found at the centers of tropical cyclones and tornadoes, +# with a record low of 870 mbar (87 kPa; 26 inHg). + def get_ambient_data(usernames: Collection, sensor=None) -> pd.DataFrame: """ @@ -57,10 +61,31 @@ def get_ambient_data(usernames: Collection, sensor=None) -> pd.DataFrame: ) else: raise KeyError( - "Specify one of the ambient sensors: barometer, barometer_sensor, light, temperature, or temperature_sensor." + "Specify one of the ambient sensors: " + "barometer, barometer_sensor, light, temperature, or temperature_sensor." ) query_ambient = query_ambient.filter(Participant.username.in_(usernames)) with db_engine.connect() as connection: df_ambient = pd.read_sql(query_ambient.statement, connection) return df_ambient + + +def clean_pressure(df_ambient: pd.DataFrame) -> pd.DataFrame: + """ + Simply removes values lower than MINIMUM_PRESSURE_MB (lowest measured pressure). + + Parameters + ---------- + df_ambient: pd.DataFrame + A dataframe of barometer data, which includes measured pressure in double_values_0. + + Returns + ------- + df_ambient: pd.DataFrame + The same dataframe with rows with low values of pressure removed. + """ + if "double_values_0" not in df_ambient: + raise KeyError("The DF does not seem to hold barometer data.") + df_ambient = df_ambient[df_ambient["double_values_0"] > MINIMUM_PRESSURE_MB] + return df_ambient