From 5094fd8f7f79afcf9694ba155239a42003b75697 Mon Sep 17 00:00:00 2001 From: Amelia <30877272+amsnyder@users.noreply.github.com> Date: Tue, 18 Jan 2022 10:18:21 -0500 Subject: [PATCH] fix days of year for percent coverage --- data_exploration/src/gap_analysis.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/data_exploration/src/gap_analysis.py b/data_exploration/src/gap_analysis.py index a074be6..bb688a8 100644 --- a/data_exploration/src/gap_analysis.py +++ b/data_exploration/src/gap_analysis.py @@ -47,7 +47,11 @@ def gap_analysis_calc(source, var_dfs): for year in years: year_df = df[df.index.year==year][site] # year_df.dropna(inplace=True) - var_site_gap_df.loc[year, 'p_coverage'] = year_df.count()/365 + if year == datetime.datetime.today().year: + elapsed_days = datetime.datetime.today().timetuple().tm_yday + else: + elapsed_days = (datetime.datetime(year+1, 1, 1, 0, 0) - datetime.datetime(year, 1, 1, 0, 0)).days + var_site_gap_df.loc[year, 'p_coverage'] = year_df.count()/elapsed_days deltas = year_df.dropna().index.to_series().diff()[1:] gaps = deltas[deltas > dt.timedelta(days=1)] var_site_gap_df.loc[year, 'n_gaps'] = len(gaps)