Skip to content
Snippets Groups Projects

Dendro

Merged Alexander Hinz requested to merge hinza/data_progs:dendro into meteo
All threads resolved!
1 file
+ 11
6
Compare changes
  • Side-by-side
  • Inline
@@ -25,16 +25,21 @@ def filter(data, flags):
return data[data.columns[data.columns.str.match(".*dendro(?!.*r)")]]
def grouper(n, df, fillvalue=None):
# the customized grouper function split a dataframe, so that the output is a n columns long dataframe
# in the dendro calculation, one tree correspond to one dendrometer
# this consist of 3 columns: the calculated value, the manually read value and the flag
def grouper(df, n, fillvalue=None):
"""
This grouper function splits a pd.DataFrame into pd.DataFrames with `n` columns.
Background: Every dendrometer (i.e one tree) is represented by three columns:
1. calculated value
2. manually read value
3. quality flag
"""
args = [iter(df)] * n
return zip_longest(fillvalue=fillvalue, *args)
def fillNa(df):
for bhd_value, bhd_manu, flag in grouper(3, df):
for bhd_value, bhd_manu, flag in grouper(df, n=3):
# setting 91 flag on all values, where calculated value is nan
df.loc[df[bhd_value].isna(), flag] = 91
df[bhd_value] = df[bhd_value].fillna(df[bhd_manu])
@@ -139,7+144,7 @@
start_date=device.start_date,
end_date=device.end_date,
reindex=True, fill=True)
manflags = device.getManualFlags()
if df.empty or manflags.empty:
logger.info(f"{device}: no data found for period - skipping")
@@ -177,7+182,7 @@
# corrections in index Order and not setted flags
final = final.sort_index()
for a, b, c in grouper(3, final):
for a, b, c in grouper(final, n=3):
final = final.fillna({a: NODATA, b: NODATA, c: 92})
writeData(final, device)
Loading