Skip to content
Snippets Groups Projects
Commit 90b40081 authored by Alexander Hinz's avatar Alexander Hinz
Browse files

dendro: adjust grouper function

parent 2b19809f
No related branches found
No related tags found
3 merge requests!31Dendro,!28Dendro,!23Major rework of the entire pipeline
This commit is part of merge request !28. Comments created here will be created in the context of that merge request.
......@@ -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])
......@@ -177,7 +182,7 @@ def main(station, device, start_date, end_date, debug):
# 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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment