def run_clark2009(catchment, output_dem, hydro_year_to_take, met_inp_folder, catchment_shp_folder): """ wrapper to call the clark 2009 snow model for given area :param catchment: string giving catchment area to run model on :param output_dem: string identifying the grid to run model on :param hydro_year_to_take: integer specifying the hydrological year to run model over. 2001 = 1/4/2000 to 31/3/2001 :return: st_swe, st_melt, st_acc, out_dt, mask. daily grids of SWE at day's end, total melt and accumulation over the previous day, and datetimes of ouput """ print('loading met data') data_id = '{}_{}'.format(catchment, output_dem) inp_met = nc.Dataset( met_inp_folder + '/met_inp_{}_hy{}.nc'.format(data_id, hydro_year_to_take), 'r') inp_dt = nc.num2date(inp_met.variables['time'][:], inp_met.variables['time'].units) inp_doy = convert_date_hydro_DOY(inp_dt) inp_hourdec = [datt.hour for datt in inp_dt] inp_ta = inp_met.variables['temperature'][:] inp_precip = inp_met.variables['precipitation'][:] print('met data loaded') mask = create_mask_from_shpfile( inp_met.variables['lat'][:], inp_met.variables['lon'][:], catchment_shp_folder + '/{}.shp'.format(catchment)) # TODO: think about masking input data to speed up print('starting snow model') # start with no snow. # call main function once hourly/sub-hourly temp and precip data available. st_swe, st_melt, st_acc = snow_main_simple(inp_ta, inp_precip, inp_doy, inp_hourdec, dtstep=3600) out_dt = np.asarray( make_regular_timeseries(inp_dt[0], inp_dt[-1] + dt.timedelta(days=1), 86400)) print('snow model finished') # mask out values outside of catchment st_swe[:, mask == False] = np.nan st_melt[:, mask == False] = np.nan st_acc[:, mask == False] = np.nan return st_swe, st_melt, st_acc, out_dt, mask
ts_mb = plt.cumsum(mb_dat[:, 0]) np.where(np.asarray(mb_dt) == dt.datetime(2011, 5, 13, 00, 00)) ts_mb -= ts_mb[199] # init_swe = np.ones( inp_ta.shape[1:]) * 0 # give initial value of swe as starts in spring init_d_snow = np.ones( inp_ta.shape[1:]) * 30 # give initial value of days since snow # call main function once hourly/sub-hourly temp and precip data available. st_swe, st_melt, st_acc, st_alb = snow_main_simple(inp_ta, inp_precip, inp_doy, inp_hourdec, dtstep=1800, init_swe=init_swe, init_d_snow=init_d_snow, inp_sw=inp_sw, which_melt='clark2009', **config) st_swe1, st_melt1, st_acc1, st_alb1 = snow_main_simple(inp_ta, inp_precip, inp_doy, inp_hourdec, dtstep=1800, init_swe=init_swe, init_d_snow=init_d_snow, inp_sw=inp_sw, which_melt='dsc_snow', **config)
# plt.plot(plot_dt,inp_sw_obs/2, label = 'Observed radiation') # plt.plot(year_VC, rad_VC_year, label = 'VC rad') # plt.plot(year_VN, rad_VN_year, label = 'VN rad') # plt.gcf().autofmt_xdate() # months = mdates.MonthLocator() # every month # monthsFmt = mdates.DateFormatter('%b') # manager = plt.get_current_fig_manager() # manager.window.showMaximized() # plt.ylabel('radiations in W/m2') # plt.legend() # plt.show() # plt.close # call main function once hourly/sub-hourly temp and precip data available. try : st_swe, st_melt, st_acc, st_alb = snow_main_simple(inp_ta, inp_precip, inp_doy, inp_hourdec, dtstep=3600,init_swe=init_swe, init_d_snow=init_d_snow, inp_sw=inp_sw, which_melt='clark2009', **config) st_swe1, st_melt1, st_acc1, st_alb1 = snow_main_simple(inp_ta, inp_precip, inp_doy, inp_hourdec, dtstep=3600, init_swe=init_swe, init_d_snow=init_d_snow, inp_sw=inp_sw, which_melt='dsc_snow', **config) except : print('No VC data', year) try : st_swea, st_melta, st_acca, st_alba = snow_main_simple(inp_ta_VN, inp_precip, inp_doy, inp_hourdec, dtstep=3600,init_swe=init_swe, init_d_snow=init_d_snow, inp_sw=inp_sw_VN,which_melt='clark2009', **config) st_swe1a, st_melt1a, st_acc1a, st_alb1a = snow_main_simple(inp_ta_VN, inp_precip, inp_doy, inp_hourdec, dtstep=3600,init_swe=init_swe, init_d_snow=init_d_snow, inp_sw=inp_sw_VN,which_melt='dsc_snow', **config) except : print('No VN data', year) # MUELLER SWE csv file # csv_file = "C:/Users/Bonnamourar/OneDrive - NIWA/CSV SWE/Mueller SWE.csv" # MAHANGA SWE csv file
stor_dict = {} ii = 0 for i, tf in enumerate(tf_list): for j, tt in enumerate(tmelt_list): stor_dict[ii] = {} config['mf_mean'] = tf config['tmelt'] = tt # call main function once hourly/sub-hourly temp and precip data available. st_swe, st_melt, st_acc, st_alb = snow_main_simple( inp_ta, inp_precip, inp_doy, inp_hourdec, dtstep=3600, init_swe=init_swe, init_d_snow=init_d_snow, inp_sw=inp_sw, which_melt='clark2009', **config) run_dict = { 'timestamp': inp_dt, 'swe': np.squeeze(st_swe), 'melt': np.squeeze(st_melt), 'acc': np.squeeze(st_acc), 'alb': np.squeeze(st_alb) } run_df = pd.DataFrame.from_dict(run_dict) run_df.set_index('timestamp', inplace=True)