list_s_to_plot.append(df_to_plot.iloc[:, i]) # No NAN version df_to_plot_noNAN = df_to_plot.dropna() list_s_to_plot_noNAN = [] for i in range(cfg['INPUT_CONTROL']['n_ts']): # Loop over each time series list_s_to_plot_noNAN.append(df_to_plot_noNAN.iloc[:, i]) #======================================================== # Calculate weekly average (TVA weekly data week definition) #======================================================== # Has NAN version list_s_to_plot_weekly = [] for i, s_to_plot in enumerate(list_s_to_plot): s_to_plot_week = my_functions.calc_ts_stats_by_group(s_to_plot, by='TVA_week', stat='mean') list_s_to_plot_weekly.append(s_to_plot_week) df_to_plot_weekly = pd.concat(list_s_to_plot_weekly, axis=1) # No NAN version df_to_plot_weekly_noNAN = df_to_plot_weekly.dropna() list_s_to_plot_weekly_noNAN = [] for i in range(cfg['INPUT_CONTROL']['n_ts']): # Loop over each time series list_s_to_plot_weekly_noNAN.append(df_to_plot_weekly_noNAN.iloc[:, i]) #======================================================== # plot #======================================================== #============ Process "\n" in "model_info" ==================# model_info = cfg['PLOT_OPTIONS']['model_info'].replace("\\n", "\n")
for i in range(cfg['INPUT_CONTROL']['n_ts']): # Loop over each time series list_s_to_plot.append(df_to_plot.iloc[:,i]) # No NAN version df_to_plot_noNAN = df_to_plot.dropna() list_s_to_plot_noNAN = [] for i in range(cfg['INPUT_CONTROL']['n_ts']): # Loop over each time series list_s_to_plot_noNAN.append(df_to_plot_noNAN.iloc[:,i]) #======================================================== # Calculate weekly average (TVA weekly data week definition) #======================================================== # Has NAN version list_s_to_plot_weekly = [] for i, s_to_plot in enumerate(list_s_to_plot): s_to_plot_week = my_functions.calc_ts_stats_by_group(s_to_plot, by='TVA_week', stat='mean') list_s_to_plot_weekly.append(s_to_plot_week) df_to_plot_weekly = pd.concat(list_s_to_plot_weekly, axis=1) # No NAN version df_to_plot_weekly_noNAN = df_to_plot_weekly.dropna() list_s_to_plot_weekly_noNAN = [] for i in range(cfg['INPUT_CONTROL']['n_ts']): # Loop over each time series list_s_to_plot_weekly_noNAN.append(df_to_plot_weekly_noNAN.iloc[:,i]) #======================================================== # plot #======================================================== #============ Process "\n" in "model_info" ==================# model_info = cfg['PLOT_OPTIONS']['model_info'].replace("\\n", "\n")
s_rbm_mon = my_functions.calc_monthly_data(s_rbm_to_plot) # plot fig = plt.figure() ax = plt.axes() plt.plot_date(s_usgs_mon.index, s_usgs_mon, 'b-', label='USGS gauge') plt.plot_date(s_rbm_mon.index, s_rbm_mon, 'r--', label='Lohmann route') plt.ylabel('Flow (cfs)', fontsize=16) plt.title('Monthly, %s, %s' %(usgs_site_name, usgs_site_code), fontsize=16) plt.legend() my_functions.plot_date_format(ax, time_range=(plot_start_date, plot_end_date), locator=time_locator, time_format='%Y/%m') fig = plt.savefig('%s.flow.monthly.png' %output_plot_basename, format='png') #============== plot seasonal data ===============# # calculate s_usgs_seas = my_functions.calc_ts_stats_by_group(s_usgs_to_plot, 'month', 'mean') # index is 1-12 (month) s_rbm_seas = my_functions.calc_ts_stats_by_group(s_rbm_to_plot, 'month', 'mean') # index is 1-12 (month) # plot fig = plt.figure() ax = plt.axes() plt.plot_date(s_usgs_seas.index, s_usgs_seas, 'b-', label='USGS gauge') plt.plot_date(s_rbm_seas.index, s_rbm_seas, 'r--', label='Lohmann route') plt.ylabel('Flow (cfs)', fontsize=16) plt.title('%s, %s\nMonthly mean seasonality, water years %d - %d' %(usgs_site_name, usgs_site_code, plot_start_date.year+1, plot_end_date.year), fontsize=16) plt.legend() # formatting plt.xlim([1, 12]) tick_labels = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Nov','Oct','Nov','Dec'] my_functions.plot_format(ax, xtick_location=range(1,13), xtick_labels=tick_labels) fig = plt.savefig('%s.flow.season.png' %output_plot_basename, format='png')