Remove low values of pressure.

ambient
junos 2021-10-22 18:09:17 +02:00
parent 92fbda242b
commit 6fc0d962ae
1 changed files with 26 additions and 1 deletions

View File

@ -12,6 +12,10 @@ from config.models import (
) )
from setup import db_engine, session 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: 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: else:
raise KeyError( 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)) query_ambient = query_ambient.filter(Participant.username.in_(usernames))
with db_engine.connect() as connection: with db_engine.connect() as connection:
df_ambient = pd.read_sql(query_ambient.statement, connection) df_ambient = pd.read_sql(query_ambient.statement, connection)
return df_ambient 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