def single_location_comparison(location=[31.65, 77.34], station='Banjar', min_year=2000, max_year=2011): """Plot model outputs for given coordinates over time.""" aphro_ds = aphrodite.collect_APHRO(location, minyear=min_year, maxyear=max_year) cru_ds = cru.collect_CRU(location, minyear=min_year, maxyear=max_year) era5_ds = era5.collect_ERA5(location, minyear=min_year, maxyear=max_year) gpm_ds = gpm.collect_GPM(location, minyear=min_year, maxyear=max_year) wrf_ds = beas_sutlej_wrf.collect_BC_WRF(location, minyear=min_year, maxyear=max_year) gauge_ds = beas_sutlej_gauges.gauge_download(station, minyear=min_year, maxyear=max_year) # cmip_ds = cmip5.collect_CMIP5() # cordex_ds = cordex.collect_CORDEX() # model_ts = model_prep([lat, lon], data_filepath='single_loc_test.csv', \ # model_filepath=model_filepath) timeseries = [gauge_ds, gpm_ds, era5_ds, wrf_ds, aphro_ds, cru_ds] tims.benchmarking_subplots(timeseries, reference_dataset=gauge_ds) dataset_stats(timeseries, ref_ds=gauge_ds)
def multi_location_comparison(): """Plot model outputs for multiple locations over time.""" gauge_ds = beas_sutlej_gauges.all_gauge_data(minyear=2000, maxyear=2011, threshold=3653) locations = [[31.424, 76.417], [31.357, 76.878], [31.52, 77.22], [31.67, 77.06], [31.454, 77.644], [31.238, 77.108], [31.65, 77.34], [31.88, 77.15], [31.77, 77.31], [31.80, 77.19]] aphro_sets = [] cru_sets = [] era5_sets = [] gpm_sets = [] wrf_sets = [] for loc in locations: aphro_ds = aphrodite.collect_APHRO(loc, minyear=2000, maxyear=2011) aphro_sets.append(aphro_ds.tp) cru_ds = cru.collect_CRU(loc, minyear=2000, maxyear=2011) cru_sets.append(cru_ds.tp) era5_ds = era5.collect_ERA5(loc, minyear=2000, maxyear=2011) era5_sets.append(era5_ds.tp) gpm_ds = gpm.collect_GPM(loc, minyear=2000, maxyear=2011) gpm_sets.append(gpm_ds.tp) wrf_ds = beas_sutlej_wrf.collect_BC_WRF(loc, minyear=2000, maxyear=2011) wrf_sets.append(wrf_ds.tp) # Merge datasets aphro_mer_ds = xr.concat(aphro_sets, dim='lon') aphro_mer_ds.attrs['plot_legend'] = 'APHRODITE' cru_mer_ds = xr.concat(cru_sets, dim='lon') cru_mer_ds.attrs['plot_legend'] = 'CRU' era5_mer_ds = xr.concat(era5_sets, dim='lon') era5_mer_ds.attrs['plot_legend'] = 'ERA5' gpm_mer_ds = xr.concat(gpm_sets, dim='lon') gpm_mer_ds.attrs['plot_legend'] = 'TRMM' wrf_mer_ds = xr.concat(wrf_sets, dim='lon') wrf_mer_ds.attrs['plot_legend'] = 'BC WRF' timeseries = [ gpm_mer_ds, era5_mer_ds, wrf_mer_ds, aphro_mer_ds, cru_mer_ds ] pdf.mult_gauge_loc_plot(gauge_ds, timeseries)
def gauge_stats(): """Print mean, standard deviations and slope for datasets.""" bs_station_df = pd.read_csv('_Data/bs_only_gauge_info.csv') ''' mlm_val_stations = ['Bhakra', 'Suni' 'Pandoh', 'Janjehl', 'Bhuntar', 'Rampur'] val_stations = ['Banjar', 'Larji', 'Bhuntar', 'Sainj', 'Bhakra', 'Kasol', 'Suni', 'Pandoh', 'Janjehl', 'Rampur'] ''' r2_list = [] rmse_list = [] for s in tqdm(bs_station_df): gauge_ds = beas_sutlej_gauges.gauge_download(s, minyear=2000, maxyear=2011) gauge_maxy = gauge_ds.time.max().values gauge_miny = gauge_ds.time.min().values miny = gauge_miny - 0.0001 maxy = gauge_maxy + 0.0001 location = bs_station_df[s].values aphro_ds = aphrodite.collect_APHRO(location, minyear=miny, maxyear=maxy) cru_ds = cru.collect_CRU(location, minyear=miny, maxyear=maxy) era5_ds = era5.collect_ERA5(location, minyear=miny, maxyear=maxy) gpm_ds = gpm.collect_GPM(location, minyear=miny, maxyear=maxy) wrf_ds = beas_sutlej_wrf.collect_BC_WRF(location, minyear=miny, maxyear=maxy) timeseries = [era5_ds, gpm_ds, aphro_ds, cru_ds, wrf_ds] r2s, rmses = dataset_stats(timeseries, ref_ds=gauge_ds, ret=True) r2_list.append(r2s) rmse_list.append(rmses) avg_r2 = np.array(r2_list).mean(axis=0) avg_rmse = np.array(rmse_list).mean(axis=0) return avg_r2, avg_rmse
def basin_comparison(model_filepath, location): """ Plot model outputs for given basin over time.""" aphro_ds = aphrodite.collect_APHRO(location, minyear=2000, maxyear=2011) cru_ds = cru.collect_CRU(location, minyear=2000, maxyear=2011) era5_ds = era5.collect_ERA5(location, minyear=2000, maxyear=2011) gpm_ds = gpm.collect_GPM(location, minyear=2000, maxyear=2011) wrf_ds = beas_sutlej_wrf.collect_BC_WRF(location, minyear=2000, maxyear=2011) # cmip_ds = cmip5.collect_CMIP5() # cordex_ds = cordex.collect_CORDEX() # cmip_bs = select_basin(cmip_ds, location) # cordex_bs = select_basin(cordex_ds, location) # model_bs = model_prep(location, model_filepath) basins = [aphro_ds, cru_ds, era5_ds, gpm_ds, wrf_ds] dataset_stats(basins)
def multi_dataset_map(location, seasonal=False): """ Create maps of raw values from multiple datasets - ERA5 - GPM PR - APHRODITE - CRU - Bannister corrected WRF """ # Load data aphro_ds = aphrodite.collect_APHRO(location, minyear=2000, maxyear=2011) cru_ds = cru.collect_CRU(location, minyear=2000, maxyear=2011) era5_ds = era5.collect_ERA5(location, minyear=2000, maxyear=2011) gpm_ds = gpm.collect_GPM(location, minyear=2000, maxyear=2011) wrf_ds = beas_sutlej_wrf.collect_BC_WRF(location, minyear=2000, maxyear=2011) dataset_list = [gpm_ds, era5_ds, wrf_ds, aphro_ds, cru_ds] # Slice and take averages avg_list = [] for ds in dataset_list: ds_avg = ds.tp.mean(dim='time') if seasonal is True: ds_annual_avg = ds_avg ds_jun = ds.tp[5::12] ds_jul = ds.tp[6::12] ds_aug = ds.tp[7::12] ds_sep = ds.tp[8::12] ds_monsoon = xr.merge([ds_jun, ds_jul, ds_aug, ds_sep]) ds_monsoon_avg = ds_monsoon.tp.mean(dim='time') ds_dec = ds.tp[11::12] ds_jan = ds.tp[0::12] ds_feb = ds.tp[1::12] ds_mar = ds.tp[2::12] ds_west = xr.merge([ds_dec, ds_jan, ds_feb, ds_mar]) ds_west_avg = ds_west.tp.mean(dim='time') ds_avg = xr.concat( [ds_annual_avg, ds_monsoon_avg, ds_west_avg], pd.Index(["Annual", "Monsoon (JJAS)", "Winter (DJFM)"], name='t')) avg_list.append(ds_avg) datasets = xr.concat( avg_list, pd.Index(["TRMM", "ERA5", "BC_WRF", "APHRO", "CRU"], name="Dataset")) # Plot maps g = datasets.plot(x="lon", y="lat", col="t", row="Dataset", cbar_kwargs={"label": "Total precipitation (mm/day)"}, cmap="YlGnBu", subplot_kws={"projection": ccrs.PlateCarree()}) for ax in g.axes.flat: ax.coastlines() gl = ax.gridlines(draw_labels=True) gl.top_labels = False gl.right_labels = False ax.set_extent([75, 83.5, 29, 34]) ax.add_feature(cf.BORDERS) ax.set_xlabel("Longitude") ax.set_ylabel("Latitude") plt.show()