-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for CNRFC Deterministic Stage Forecasts #76
base: main
Are you sure you want to change the base?
Conversation
collect/cnrfc/cnrfc.py
Outdated
@@ -150,7 +150,7 @@ def get_water_year_trend_tabular(cnrfc_id, water_year): | |||
'downloaded': dt.datetime.now().strftime('%Y-%m-%d %H:%M')}} | |||
|
|||
|
|||
def get_deterministic_forecast(cnrfc_id, truncate_historical=False, release=False): | |||
def get_deterministic_forecast(cnrfc_id, truncate_historical=False, release=False, stage=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, could we just always return both flow and stage? Would definitely make sense to change the units either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how would you do the split between the forecast and historical? this way seems easiest to me for backwards compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay I added support so it will always return flow and stage (if they exist) 9237178
it does the split on the forecast/historical based on the first existing variable (checking for flow first)
collect/cnrfc/cnrfc.py
Outdated
if keep_stage: | ||
# parse forecast data from CSV | ||
df = pd.read_csv(csvdata, | ||
header=[0, 1], | ||
parse_dates=True, | ||
index_col=0, | ||
float_precision='high', | ||
dtype={'GMT': str}) | ||
|
||
else: | ||
# parse forecast data from CSV | ||
df = pd.read_csv(csvdata, | ||
header=0, | ||
skiprows=[1,], | ||
parse_dates=True, | ||
index_col=0, | ||
float_precision='high', | ||
dtype={'GMT': str}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you refactor for both options so that we use header=[0, 1],
? Might change things downstream a little, but this is probably what we * should * have been doing all along, and is less modification when we want to send the result over to S3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored but preserved the normal single row column header as the default de8208f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
70e87ba renamed the argument to multiindex
collect/cnrfc/cnrfc.py
Outdated
if keep_stage: | ||
filter_columns = [x for x in df.columns if x[1] != 'SSTG'] | ||
df[filter_columns] = df[filter_columns] * 1000.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this filter work for both cases if we keep the multi-level header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this works de8208f
70e87ba
to
05b7f03
Compare
05b7f03
to
408f61e
Compare
get stage data from cnrfc deterministic add keep_stage option for deterministic forecasts: fix up deterministic remove other changes' remove extra change remove print statements fix default string fix up stage data pull rename argument to multiindex and add assertion
408f61e
to
39a7590
Compare
@@ -234,11 +238,11 @@ def get_deterministic_forecast(cnrfc_id, truncate_historical=False, release=Fals | |||
'first_ordinate': first_ordinate.strftime('%Y-%m-%d %H:%M'), | |||
'issue_time': time_issued.strftime('%Y-%m-%d %H:%M'), | |||
'next_issue': next_issue_time.strftime('%Y-%m-%d %H:%M'), | |||
'units': 'cfs', | |||
# 'units': units, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good q. I think it's important in the case where we convert kcfs to cfs and/or kcfs to acre-feet, but I see how that's a bit sticky here
# convert kcfs/day to cfs/day | ||
df = df * 1000.0 | ||
# convert kcfs/day to cfs/day (unless stage data) | ||
filter_columns = [x for x in df.columns if x[1] != 'SSTG'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a helper function that records the units for the different forecast codes. CNRFC added these helpful notes to https://www.cnrfc.noaa.gov/deterministicHourlyProductCSV.php
Note 1: Data columns labeled QINE and SQIN in the files represent flows in kcfs (thousands of cubic feet per second).
Note 2: Data columns labeled SSTG in the files represent stages in feet.
Closes #75
For the current deterministic stage forecast:
For the watershed deterministic forecast with stage data: