def main(): # Show selected domains, basins, and/or flow directions or flow accumulations mh_gc044 = default_domains.gc_cordex_na_044.subgrid(20, 60, di=130, dj=110) mh_gc022 = mh_gc044.double_resolution_keep_free_domain_same() test_bc_011 = default_domains.gc_cordex_na_011.subgrid(12, 244, di=404, dj=380) test_bc_044 = test_bc_011.decrease_resolution_keep_free_domain_same(4) print(test_bc_044) plot_utils.apply_plot_params() # show_domain(mh_gc044) # show_domain(mh_gc022) # show_domain(mh_gc011) print(test_bc_011) # fig, ax, bmp = show_domain(default_domains.gc_cordex_011, draw_rivers=False) # show_domain(test_bc_011, draw_rivers=False, show_GRDC_basins=True) # show_domain(test_bc_044, draw_rivers=False, show_GRDC_basins=True) show_domain(default_domains.bc_mh_044, show_GRDC_basins=True, show_Churchil_Nelson_basins=False) # show_domain(default_domains.bc_mh_011) plt.show()
def main(): grid_config_to_dir_file = OrderedDict([ #(default_domains.bc_mh_044, Path("/RESCUE/skynet3_rech1/huziy/directions_for_ManitobaHydro/directions_mh_0.44deg.nc")), (default_domains.bc_mh_022, Path("/RESCUE/skynet3_rech1/huziy/directions_for_ManitobaHydro/directions_mh_0.22deg.nc")), # (default_domains.bc_mh_011, Path("/RESCUE/skynet3_rech1/huziy/directions_for_ManitobaHydro/directions_bc-mh_0.11deg_new.nc")), ]) stations = stfl_stations.load_stations_from_csv(selected_ids=None) print(stations) gs = GridSpec(1, len(grid_config_to_dir_file)) plot_utils.apply_plot_params(width_cm=25, height_cm=20, font_size=8) fig = plt.figure() for col, (grid_config, dir_path) in enumerate(grid_config_to_dir_file.items()): ax = fig.add_subplot(gs[0, col]) plot_station_positions(directions_file_path=dir_path, stations=stations, ax=ax, grid_config=grid_config) img_file = img_folder / "{}_{}.png".format("mh", "_".join([str(gc.dx) for gc in grid_config_to_dir_file])) fig.savefig(str(img_file), bbox_inches="tight", dpi=300)
def plot_alt_for_different_e_scenarios(): labels = ("E1", "E2", "E3", "E4") p_format = "pmNorthAmerica_0.44deg_CanHistoE{0}" prefixes = [p_format.format(x) for x in range(1, 5)] b, lons2d, lats2d = draw_regions.get_basemap_and_coords(llcrnrlat=40.0, llcrnrlon=-145, urcrnrlon=-10) x, y = b(lons2d, lats2d) permafrost_mask = draw_regions.get_permafrost_mask(lons2d, lats2d) dm = CRCMDataManager(data_folder="data/CORDEX") # needed here only for verticla levels plot_utils.apply_plot_params(width_pt=None, height_cm=12, width_cm=16, font_size=12) fig = plt.figure() gs = gridspec.GridSpec(2, 2) scen_index = 0 for row in range(2): for col in range(2): sc = labels[scen_index] ax = fig.add_subplot(gs[row, col]) h = dm.get_alt_using_files_in(folder="data/CORDEX/na/means_month", file_name_prefix=prefixes[scen_index]) h = np.ma.masked_where((permafrost_mask == 0) | (permafrost_mask >= 3) | (h < 0), h) plot_for_scenario(sc, ax, basemap=b, x=x, y=y, alt=h, permafrost_mask=permafrost_mask, start_year=1950, end_year=1954 ) scen_index += 1 gs.tight_layout(fig, h_pad=0.9, w_pad=16) fig.savefig("alt_diff_scenarios.png") pass
def validate_seasonal_mean_atm_fields(): plot_utils.apply_plot_params(font_size=10, width_pt=None, width_cm=20, height_cm=20) from crcm5.analyse_hdf import validate_model_fields p = Process(target=validate_model_fields.do_4_seasons, kwargs=dict( start_year=1980, end_year=2010)) p.start()
def main(): plot_utils.apply_plot_params() diag_folder = "/RECH2/huziy/BC-MH/bc_mh_044deg/Diagnostics" gc = default_domains.bc_mh_044 plot_monthly_clim_in_a_panel(diag_folder=diag_folder, grid_config=gc, basins_of_interest_shp=default_domains.MH_BASINS_PATH)
def main(): plot_utils.apply_plot_params(width_cm=20, height_cm=20, font_size=10) high_hles_years = [1993, 1995, 1998] low_hles_years = [1997, 2001, 2006] data_path = "/BIG1/skynet1_rech1/diro/sample_obsdata/eraint/eraint_uvslp_years_198111_201102_NDJmean_ts.nc" with xr.open_dataset(data_path) as ds: print(ds) u = get_composit_for_name(ds, "u10", high_years_list=high_hles_years, low_years_list=low_hles_years) v = get_composit_for_name(ds, "v10", high_years_list=high_hles_years, low_years_list=low_hles_years) msl = get_composit_for_name(ds, "msl", high_years_list=high_hles_years, low_years_list=low_hles_years) lons = ds["longitude"].values lats = ds["latitude"].values print(lats) print(msl.shape) print(lons.shape, lats.shape) lons2d, lats2d = np.meshgrid(lons, lats) fig = plt.figure() map = Basemap(llcrnrlon=-130, llcrnrlat=22, urcrnrlon=-28, urcrnrlat=65, projection='lcc', lat_1=33, lat_2=45, lon_0=-95, resolution='i', area_thresh=10000) clevs = np.arange(-11.5, 12, 1) cmap = cm.get_cmap("bwr", len(clevs) - 1) bn = BoundaryNorm(clevs, len(clevs) - 1) x, y = map(lons2d, lats2d) im = map.contourf(x, y, msl / 100, levels=clevs, norm=bn, cmap=cmap) # convert to mb (i.e hpa) map.colorbar(im) stride = 2 ux, vy = map.rotate_vector(u, v, lons2d, lats2d) qk = map.quiver(x[::stride, ::stride], y[::stride, ::stride], ux[::stride, ::stride], vy[::stride, ::stride], scale=10, width=0.01, units="inches") plt.quiverkey(qk, 0.5, -0.1, 2, "2 m/s", coordinates="axes") map.drawcoastlines(linewidth=0.5) map.drawcountries() map.drawstates() #plt.show() fig.savefig("hles_wind_compoosits.png", bbox_inches="tight", dpi=300)
def main(): plot_utils.apply_plot_params(font_size=20, width_pt=None, width_cm=20, height_cm=20) i_start, j_start = 0, 0 i_end, j_end = -1, -1 print(get_section_hor_indices(i_start=5, j_start = 0, i_end = 10, j_end = 20)) # #Superior # params = dict( # i_start = 25, j_start = 65, # i_end = 70, j_end = 65, # var_name = "votemper" # # ) # plot_cross_section_for_seasons(data_path=T_FILE_PATH, **params) # # #Michigan # params = dict( # i_start = 55, j_start = 55, # i_end = 55, j_end = 5, # var_name = "votemper" # # ) # plot_cross_section_for_seasons(data_path=T_FILE_PATH, **params) #Huron params = dict( i_start = 10, j_start = 30, i_end = 30, j_end = 10, var_name = "votemper" ) plot_cross_section_for_seasons(data_path=T_FILE_PATH, **params) plt.show()
def plot_comparisons_of_seasonal_sst_with_homa_obs(self, start_year=None, end_year=None, season_to_months=None, exp_label=""): model_data = self.get_seasonal_mean_lst(season_to_months=season_to_months, start_year=start_year, end_year=end_year) obs_sst_path = os.path.expanduser("~/skynet3_rech1/nemo_obs_for_validation/GreatLakes_2003_5km-2/sst-glk.nc") obs_data = self.read_and_interpolate_homa_data(path=obs_sst_path, start_year=start_year, end_year=end_year, season_to_months=season_to_months) plot_utils.apply_plot_params(font_size=10, width_pt=None, width_cm=20, height_cm=10) # calculate climatologic differences diff = {} for season in list(season_to_months.keys()): diff[season] = np.mean( [model_data[y][season] - obs_data[y][season] for y in range(start_year, end_year + 1)], axis=0) diff[season] = np.ma.masked_where(~self.lake_mask, diff[season]) the_field = diff[season] print("diff stats({}): min={}; max={}; avg={}".format( season, the_field.min(), the_field.max(), the_field.mean())) # plot seasonal biases xx, yy = self.basemap(self.lons.copy(), self.lats.copy()) # calculate difference ranges diff_max = 0 for season, the_diff in diff.items(): diff_max = max(np.percentile(np.abs(the_diff[~the_diff.mask]), 90), diff_max) diff_max = 5 locator = MaxNLocator(nbins=12, symmetric=True) bounds = locator.tick_values(-diff_max, diff_max) bn = BoundaryNorm(bounds, len(bounds) - 1) cmap = cm.get_cmap("RdBu_r", len(bounds) - 1) im = None fig = plt.figure() ncols = 2 # fig.suptitle(r"LST $\left({\rm ^\circ C}\right)$", font_properties=FontProperties(weight="bold")) gs = GridSpec(len(season_to_months) // ncols, ncols + 1, width_ratios=[1.0, ] * ncols + [0.05, ]) for i, season in enumerate(season_to_months.keys()): ax = fig.add_subplot(gs[i // ncols, i % ncols]) im = self.basemap.pcolormesh(xx, yy, diff[season][:], ax=ax, cmap=cmap, norm=bn) ax.set_title(season) self.basemap.drawcoastlines(ax=ax, linewidth=0.5) if not i: ax.set_ylabel("NEMO - Obs") cb = plt.colorbar(im, ticks=locator, cax=fig.add_subplot(gs[:, -1]), extend="both") nemo_img_dir = "nemo" if not os.path.isdir(nemo_img_dir): os.mkdir(nemo_img_dir) plt.tight_layout() fig.savefig(os.path.join(nemo_img_dir, "sst_homa_validation_{}.pdf".format(exp_label))) plt.show()
def main(): dh = DataHolder(var_name = "tos") plot_utils.apply_plot_params(width_pt=None, font_size=9) current_start_date = datetime(1970,1,1) current_end_date = datetime(1999,12,31) future_start_date = datetime( 2041, 1, 1 ) future_end_date = datetime( 2070, 12, 31) plt.subplot(2,1,1) plt.title("SST: current CV") cv = dh.get_cv_for_seasonal_mean(start_date = current_start_date, end_date = current_end_date, months=range(3,8)) dh.plot_2d_field(field_2d= cv, color_levels=np.arange(0, 0.001, 0.0001) ) plt.subplot(2,1,2) plt.title("SST: future CV") cv = dh.get_cv_for_seasonal_mean(current = False, start_date=future_start_date, end_date = future_end_date, months=range(3,8)) dh.plot_2d_field(field_2d = cv, color_levels=np.arange(0, 0.001, 0.0001) ) plt.savefig("sst_cv.png") pass
def plot_alt_from_monthly_climatologies(): plot_utils.apply_plot_params(width_pt=None, height_cm=20, width_cm=16, font_size=12) figure = plt.figure() b, lons2d, lats2d = draw_regions.get_basemap_and_coords(llcrnrlat=40.0, llcrnrlon=-145, urcrnrlon=-10) x, y = b(lons2d, lats2d) permafrost_mask = draw_regions.get_permafrost_mask(lons2d, lats2d) dm = CRCMDataManager(data_folder="data/CORDEX") year_ranges = [list(range(1981, 1985)), list(range(2041, 2045)), list(range(2071, 2075))] gs = gridspec.GridSpec(len(year_ranges), 1) pf_mask = (permafrost_mask == 1) | (permafrost_mask == 2) pf_mask = ~pf_mask permafrost_mask = np.ma.masked_where(permafrost_mask <= 0, permafrost_mask) for i, year_range in enumerate(year_ranges): ax = figure.add_subplot(gs[i, 0]) alt = dm.get_alt_using_monthly_mean_climatology(year_range) alt = np.ma.masked_where(pf_mask, alt) img = b.contourf(x, y, alt, levels=range(11), cmap=cm.get_cmap("jet", ), ax=ax) divider = make_axes_locatable(ax) cax = divider.append_axes("right", "5%", pad="3%") cb = plt.colorbar(img, cax=cax) b.contour(x, y, permafrost_mask, levels=range(5), linewidth=0.1, colors="k", ax=ax) b.drawcoastlines(ax=ax, linewidth=0.5) ax.set_title("period: {0} - {1}".format(year_range[0], year_range[-1])) plt.savefig("alt_from_clim.png")
def plot_point_positions_with_upstream_areas(processed_stations, processed_model_points, basemap, cell_manager, lake_fraction_field=None): # plot point positions with upstream areas # TODO: plot zonal average lake fractions and plot it at the side of the map rc_params_backup = plt.rcParams.copy() plot_utils.apply_plot_params(font_size=10, width_pt=None, width_cm=18, height_cm=8) fig = plt.figure() gs = gridspec.GridSpec(1, 1, width_ratios=[1, 1], wspace=0.01) ax = fig.add_subplot(gs[0, 0]) plot_positions_of_station_list(ax, processed_stations, processed_model_points, basemap, cell_manager) # ax.set_aspect("auto") # ax = fig.add_subplot(gs[0, 1]) # ydata = range(lake_fraction_field.shape[1]) # ax.plot(lake_fraction_field.mean(axis=0) * 100, ydata, lw=2) # ax.set_xlabel("%") # ax.set_ylim(min(ydata), max(ydata)) for tl in ax.yaxis.get_ticklabels(): tl.set_visible(False) impath = os.path.join(images_folder, "station_positions.png") fig.savefig(impath, bbox_inches="tight", dpi=cpp.FIG_SAVE_DPI, transparent=True) plt.close(fig) plt.rcParams.update(rc_params_backup)
def plot_temperature_biases(): seasons = ["(a) Annual", " (b) Winter (DJF)", "(c) Spring (MAM)", "(d) Summer (JJA)", "(e) Fall (SON)"] months = [range(1, 13), [12, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11] ] season_to_months = dict(zip(seasons, months)) cru_var_name = "tmp" cru_data_store, crcm4_data_store = _get_comparison_data(cru_var_name= cru_var_name, season_to_months=season_to_months) x, y = polar_stereographic.xs, polar_stereographic.ys i_array, j_array = _get_routing_indices() x_min, x_max, y_min, y_max = plot_utils.get_ranges(x[i_array, j_array], y[i_array, j_array]) plot_utils.apply_plot_params(width_pt= None, font_size=9, aspect_ratio=2.5) fig = plt.figure() assert isinstance(fig, Figure) basemap = polar_stereographic.basemap assert isinstance(basemap, Basemap) gs = gridspec.GridSpec(3,2) color_map = my_cm.get_red_blue_colormap(ncolors = 14, reversed=True) clevels = xrange(-8, 9, 2) all_plot_axes = [] for i, season in enumerate(seasons): if not i: ax = fig.add_subplot(gs[0,:]) else: row, col = (i - 1) // 2 + 1, (i - 1) % 2 ax = fig.add_subplot(gs[row, col]) all_plot_axes.append(ax) assert isinstance(ax, Axes) delta = crcm4_data_store[season] - cru_data_store[season] if cru_var_name == "tmp": delta -= 273.15 #delta = maskoceans(polar_stereographic.lons, polar_stereographic.lats, delta) save = delta[i_array, j_array] delta[:, :] = np.ma.masked delta[i_array, j_array] = save img = basemap.pcolormesh(x, y, delta, cmap = color_map, vmin = -7, vmax = 7) divider = make_axes_locatable(ax) cax = divider.append_axes("right", "8%", pad="3%") int_ticker = LinearLocator(numticks = color_map.N + 1) fig.colorbar(img, cax = cax, ticks = MultipleLocator(base = 2)) ax.set_title(season) for the_ax in all_plot_axes: the_ax.set_xlim(x_min, x_max) the_ax.set_ylim(y_min, y_max) basemap.drawcoastlines(ax = the_ax, linewidth = 0.1) plot_utils.draw_meridians_and_parallels(basemap, step_degrees=30.0, ax = the_ax) plot_basin_boundaries_from_shape(basemap, axes = the_ax, linewidth=0.4) put_selected_stations(the_ax, basemap, i_array, j_array) #gs.tight_layout(fig) fig.suptitle("T(2m), degrees, CRCM4 - CRU") fig.savefig("seasonal_{0}_ccc.png".format(cru_var_name))
def compare_averages_over_basins(): print getBasinNames() plot_utils.apply_plot_params(width_pt = 400, font_size = 15) basinNames = getSelectedBasinNames() for basinName in basinNames: compare_means(basinName = basinName) print basinName
def main(): season_to_months = DEFAULT_SEASON_TO_MONTHS r_config = RunConfig( data_path="/RESCUE/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl.hdf5", start_year=1980, end_year=2009, label="CRCM5-L" ) # Number of points for aggregation nx_agg = 5 ny_agg = 5 bmp_info = analysis.get_basemap_info_from_hdf(file_path=r_config.data_path) bmp_info_agg = bmp_info.get_aggregated(nagg_x=nx_agg, nagg_y=ny_agg) # Validate temperature and precip model_vars = ["TT", "PR"] obs_vars = ["tmp", "pre"] obs_paths = [ "/HOME/data/Validation/CRU_TS_3.1/Original_files_gzipped/cru_ts_3_10.1901.2009.tmp.dat.nc", "/HOME/data/Validation/CRU_TS_3.1/Original_files_gzipped/cru_ts_3_10.1901.2009.pre.dat.nc" ] plot_all_vars_in_one_fig = True fig = None gs = None row_axes = None ncols = None if plot_all_vars_in_one_fig: plot_utils.apply_plot_params(font_size=12, width_pt=None, width_cm=25, height_cm=12) fig = plt.figure() ncols = len(season_to_months) + 1 gs = GridSpec(len(model_vars), ncols, width_ratios=(ncols - 1) * [1., ] + [0.05, ]) else: plot_utils.apply_plot_params(font_size=12, width_pt=None, width_cm=25, height_cm=25) row = 0 for mname, oname, opath in zip(model_vars, obs_vars, obs_paths): if plot_all_vars_in_one_fig: row_axes = [fig.add_subplot(gs[row, col]) for col in range(ncols)] compare_vars(vname_model=mname, vname_obs=oname, r_config=r_config, season_to_months=season_to_months, nx_agg=nx_agg, ny_agg=ny_agg, bmp_info_agg=bmp_info_agg, obs_path=opath, diff_axes_list=row_axes) row += 1 # Save the figure if necessary if plot_all_vars_in_one_fig: fig_path = img_folder.joinpath("{}.png".format("_".join(model_vars))) with fig_path.open("wb") as figfile: fig.savefig(figfile, format="png", bbox_inches="tight") plt.close(fig)
def prepare(): import application_properties application_properties.set_current_directory() if not img_folder.is_dir(): img_folder.mkdir(parents=True) plot_utils.apply_plot_params(font_size=10, width_cm=20, height_cm=18)
def main(): import application_properties application_properties.set_current_directory() plot_utils.apply_plot_params(font_size=12, width_cm=25, height_cm=25) # Create folder for output images if not img_folder.is_dir(): img_folder.mkdir(parents=True) with_lakes_c_path = "/skynet3_rech1/huziy/hdf_store/cc-canesm2-driven/quebec_0.1_crcm5-hcd-rl-cc-canesm2-1980-2010.hdf5" with_lakes_label = "CRCM5-L" no_lakes_c_path = "/skynet3_rech1/huziy/hdf_store/cc-canesm2-driven/quebec_0.1_crcm5-r-cc-canesm2-1980-2010.hdf5" no_lakes_label = "CRCM5-NL" start_year_c = 1980 end_year_c = 2010 varname = "STFL" nyears_to_future = 75 with_lakes_config_c = RunConfig(data_path=with_lakes_c_path, start_year=start_year_c, end_year=end_year_c, label=with_lakes_label) with_lakes_config_f = with_lakes_config_c.get_shifted_config( nyears_to_future) no_lakes_config_c = RunConfig(data_path=no_lakes_c_path, start_year=start_year_c, end_year=end_year_c, label=no_lakes_label) no_lakes_config_f = no_lakes_config_c.get_shifted_config(nyears_to_future) bmp_info = analysis.get_basemap_info_from_hdf(file_path=with_lakes_c_path) # Calculate daily climatologic fields with_lakes_c_daily = analysis.get_daily_climatology_for_rconf( with_lakes_config_c, var_name=varname, level=0) with_lakes_f_daily = analysis.get_daily_climatology_for_rconf( with_lakes_config_f, var_name=varname, level=0) no_lakes_c_daily = analysis.get_daily_climatology_for_rconf( no_lakes_config_c, var_name=varname, level=0) no_lakes_f_daily = analysis.get_daily_climatology_for_rconf( no_lakes_config_f, var_name=varname, level=0) configs = DataConfig(bmp_info, no_lakes_config_c, no_lakes_config_f, with_lakes_config_c, with_lakes_config_f) args = (no_lakes_c_daily, no_lakes_f_daily, with_lakes_c_daily, with_lakes_f_daily) data = Data(*[arg[1] for arg in args]) plot_comparison_std(configs, data, varname=varname)
def main(): # directions_file_path = "/RESCUE/skynet3_rech1/huziy/Netbeans Projects/Java/DDM/directions_bc-mh_0.44deg.nc" # plot_directions(nc_path_to_directions=directions_file_path, # grid_config=default_domains.bc_mh_044, # shape_path_to_focus_polygons=default_domains.MH_BASINS_PATH) # # vname = "accumulation_area" vname = FACC basin_border_width = 0.5 plot_utils.apply_plot_params(width_cm=28, height_cm=10, font_size=8) img_folder_path = Path(img_folder) dir_file_to_domain_config = OrderedDict([ ("/RESCUE/skynet3_rech1/huziy/Netbeans Projects/Java/DDM/directions_bc-mh_0.44deg_new_hsfix.nc", default_domains.bc_mh_044), ("/RESCUE/skynet3_rech1/huziy/Netbeans Projects/Java/DDM/directions_bc-mh_0.22deg_new_hsfix.nc", default_domains.bc_mh_022), ("/RESCUE/skynet3_rech1/huziy/Netbeans Projects/Java/DDM/directions_bc-mh_0.11deg_new_hsfix.nc", default_domains.bc_mh_011) ]) fig1 = plt.figure() gs = GridSpec(2, len(dir_file_to_domain_config), wspace=0.1, hspace=0.0, height_ratios=[1, 0.04]) for col, (dir_file, domain_config) in enumerate(dir_file_to_domain_config.items()): ax = fig1.add_subplot(gs[0, col]) print("Processing {} for {}".format(dir_file, domain_config)) im = show_domain(domain_config, draw_rivers=True, ax=ax, path_to_shape_with_focus_polygons=default_domains.MH_BASINS_PATH, include_buffer=False, directions_file=dir_file, clevels=vname_to_clevs[vname], draw_colorbar=False, basin_border_width=basin_border_width, nc_varname_to_show=vname) cbax = fig1.add_subplot(gs[1,:]) cbax.set_aspect(1.0 / 20.0) plt.colorbar(im, cax=cbax, orientation="horizontal", ticks=vname_to_cbar_ticks[vname], format=vname_to_cbar_format[vname]) cbax.set_xlabel(vname_to_units[vname]) if not img_folder.exists(): img_folder.mkdir() # fig1.tight_layout() fig1.savefig(str(img_folder_path.joinpath("bc_mh_011_022_044_{}.png".format(vname))), bbox_inches="tight", dpi=300, transparent=True) plt.close(fig1)
def plot_seasonal_circulation_as_subplots(start_year=1995, end_year=2010, data_dir="/HOME/huziy/skynet3_rech1/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_30min", season_to_months=None, level_index=0): # get the data lons, lats, season_to_fields = get_seasonal_flows(data_dir=data_dir, start_year=start_year, end_year=end_year, season_to_months=season_to_months, level=level_index) img_folder = Path("nemo/circulation_plots/" + Path(data_dir).name) if not img_folder.exists(): img_folder.mkdir(parents=True) img_name = "circ_{}-{}_lev{}.png".format(start_year, end_year, level_index) nrows = 3 nsubplots = len(season_to_months) ncols = ceil(nsubplots / (nrows - 1)) gs = GridSpec(nrows, ncols, wspace=0.01, hspace=0, height_ratios=[1,] * (nrows - 1) + [0.05, ]) plot_utils.apply_plot_params(font_size=8, width_cm=8 * ncols, height_cm=min(4.5 * (nrows - 1), 25)) fig = plt.figure() plot_ind = 0 for season in season_to_months: row = plot_ind // ncols col = plot_ind % ncols uu, vv = season_to_fields[season] flow_speed = (uu ** 2 + vv ** 2) ** 0.5 uu1, vv1 = uu / flow_speed, vv / flow_speed ax = fig.add_subplot(gs[row, col]) assert isinstance(ax, Axes) ax.set_frame_on(False) ax.text(0.01, 0.1, season, va="bottom", ha="left", fontsize=12, transform=ax.transAxes) im = plot_flow_vectors_basemap(lons=lons, lats=lats, uu=uu1, vv=vv1, flow_speed=flow_speed, ax=ax, draw_colorbar=(col == 0) and (row == nrows - 2), streamplot=False) plot_ind += 1 # plt.colorbar(im, cax=fig.add_subplot(gs[nrows - 1, 0]), orientation="horizontal") img_path = img_folder / img_name fig.savefig(str(img_path), bbox_inches="tight", dpi=300)
def main_for_cc_paper(start_date=None, end_date=None): # Station ids to get from the CEHQ database ids_with_lakes_upstream = [ "104001", "093806", "093801", "081002", "081007", "080718" ] # for a presentation # ids_with_lakes_upstream = [ # "104001", "093806", "081002", "081007", # ] selected_ids = ids_with_lakes_upstream sim_labels = [ # "CRCM5-R", # "CRCM5-L2", "ERAI-CRCM5-L", "CanESM2-CRCM5-L" # "CRCM5-HCD-RL-INTF-a" ] sim_file_names = [ "/RESCUE/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl.hdf5", "/RESCUE/skynet3_rech1/huziy/hdf_store/cc-canesm2-driven/quebec_0.1_crcm5-hcd-rl-cc-canesm2-1980-2010.hdf5" ] color_list = ["dodgerblue", "r", "g"] sim_name_to_color = OrderedDict([ ("Obs.", "k") ]) for sim_name, the_color in zip(sim_labels, color_list): sim_name_to_color[sim_name] = the_color sim_name_to_file_name = OrderedDict(zip(sim_labels, sim_file_names)) # Get the list of stations to do the comparison with stations = cehq_station.read_station_data( start_date=start_date, end_date=end_date, selected_ids=selected_ids ) print("Initial list of stations:") for s in stations: print("{0}".format(s)) plot_utils.apply_plot_params(font_size=16, width_pt=None, width_cm=25, height_cm=12) draw_model_comparison(model_points=None, sim_name_to_file_name=sim_name_to_file_name, hdf_folder=None, start_year=start_date.year, end_year=end_date.year, stations=stations, stfl_name="STFL", drainage_area_reldiff_min=0.1, plot_upstream_area_averaged=False, sim_name_to_color=sim_name_to_color)
def plot_comparison_hydrographs(basin_name_to_out_indices_map, rea_config=None, gcm_config=None): """ :type basin_name_to_out_indices_map: dict """ assert isinstance(rea_config, RunConfig) assert isinstance(gcm_config, RunConfig) assert hasattr(rea_config, "data_daily") assert hasattr(gcm_config, "data_daily") bname_to_indices = OrderedDict([item for item in sorted(basin_name_to_out_indices_map.items(), key=lambda item: item[1][1], reverse=True)]) print(bname_to_indices) plot_utils.apply_plot_params(font_size=12, width_pt=None, width_cm=25, height_cm=12) fig = plt.figure() ncols = 3 nrows = len(bname_to_indices) // ncols + int(len(bname_to_indices) % ncols != 0) gs = GridSpec(nrows, ncols) ax_last = None for pl_index, (bname, (i, j)) in enumerate(bname_to_indices.items()): row = pl_index // ncols col = pl_index % ncols ax = fig.add_subplot(gs[row, col]) ax.plot(rea_config.data_daily[0], rea_config.data_daily[1][:, i, j], color="b", lw=2, label=rea_config.label) ax.plot(gcm_config.data_daily[0], gcm_config.data_daily[1][:, i, j], color="r", lw=2, label=gcm_config.label) ax.xaxis.set_major_locator(MonthLocator()) ax.xaxis.set_minor_locator(MonthLocator(bymonthday=15)) ax.xaxis.set_minor_formatter(FuncFormatter(lambda d, pos: num2date(d).strftime("%b")[0])) plt.setp(ax.xaxis.get_majorticklabels(), visible=False) ax.grid() sfmt = ScalarFormatter(useMathText=True) sfmt.set_powerlimits([-2, 2]) ax.yaxis.set_major_formatter(sfmt) bbox_props = dict(boxstyle="round,pad=0.3", fc="cyan", ec="b", lw=1, alpha=0.5) ax.annotate(bname, (0.9, 0.1), xycoords="axes fraction", bbox=bbox_props, zorder=10, alpha=0.5, horizontalalignment="right", verticalalignment="bottom") ax_last = ax ax_last.legend(loc="upper right", bbox_to_anchor=(1, -0.2), borderaxespad=0, ncol=2) img_file = img_folder.joinpath("bfe_hydrographs.eps") with img_file.open("wb") as f: fig.tight_layout() fig.savefig(f, bbox_inches="tight", format="eps")
def plot_area_avg(data_dict: dict, bias_dict:dict, img_dir: Path, obs_label_hint="DAYMET", panel_titles=()): img_dir.mkdir(parents=True, exist_ok=True) # calculate are avg ar_avgs = {} ar_avg_bias = {} times = None for data_key, data in data_dict.items(): if times is None: times = data.coords["t"].values times = dates.date2num(pd.to_datetime(times).to_pydatetime()) good_i, good_j = np.where(~data[0].to_masked_array().mask) ar_avgs[data_key] = data.values[:, good_i, good_j].mean(axis=1) if obs_label_hint not in data_key: ar_avg_bias[data_key] = bias_dict[data_key].values[:, good_i, good_j].mean(axis=1) # plotting plot_utils.apply_plot_params(font_size=14) fig = plt.figure() ax_list = [] gs = GridSpec(2, 1) ax = fig.add_subplot(gs[0, 0]) for data_key, data in ar_avgs.items(): ax.plot(times, data, label=data_key.split("_ndrw")[0]) ax_list.append(ax) if len(panel_titles) > 0: ax.set_title(panel_titles[0]) ax = fig.add_subplot(gs[1, 0]) for data_key, data in ar_avgs.items(): if obs_label_hint in data_key: continue ax.plot(times, ar_avg_bias[data_key], label="$\Delta$" + data_key.split("_ndrw")[0]) ax_list.append(ax) for pt, ax in zip(panel_titles, ax_list): ax.set_title(pt) for ax in ax_list: ax.xaxis.set_major_formatter(DateFormatter("%b")) ax.xaxis.set_major_locator(MonthLocator(bymonthday=1)) ax.legend() imfile = img_dir / ("_".join([dl for dl in data_dict if obs_label_hint not in dl]) + ".png") fig.savefig(str(imfile), dpi=400, bbox_inches="tight") plt.close(fig)
def compare_obs_and_model_lake_levels_at_points(): from crcm5.analyse_hdf import compare_lake_levels_with_obs plot_utils.apply_plot_params(font_size=14, width_pt=None, width_cm=25, height_cm=18) start_date = datetime(1980, 1, 1) end_date = datetime(2010, 12, 31) compare_lake_levels_with_obs.main(start_date=start_date, end_date=end_date) configure()
def validate_seasonal_mean_atm_fields(): plot_utils.apply_plot_params(font_size=10, width_pt=None, width_cm=20, height_cm=20) from crcm5.analyse_hdf import validate_model_fields p = Process(target=validate_model_fields.do_4_seasons, kwargs=dict(start_year=1980, end_year=2010)) p.start()
def validate_forcing_temp_and_precip_with_cru(): """ Compare DFS temperature (K) and precip, with the ones from the CRU data set """ from .forcing import compare_forcing_clim_with_CRU plot_utils.apply_plot_params(font_size=18, width_pt=None, width_cm=13, height_cm=25) compare_forcing_clim_with_CRU.main() compare_forcing_clim_with_CRU.main(dfs_var_name="precip", cru_var_name="pre", cru_file="data/cru_data/CRUTS3.1/cru_ts_3_10.1901.2009.pre.dat.nc")
def main(): plot_utils.apply_plot_params() diag_folder = "/RECH2/huziy/BC-MH/bc_mh_044deg/Diagnostics" gc = default_domains.bc_mh_044 plot_monthly_clim_in_a_panel( diag_folder=diag_folder, grid_config=gc, basins_of_interest_shp=default_domains.MH_BASINS_PATH)
def plot_area_avg_CMOS_poster(data_dict: dict, bias_dict: dict, img_dir: Path, obs_label_hint="DAYMET", panel_titles=(), plot_legend=True): img_dir.mkdir(parents=True, exist_ok=True) # calculate are avg ar_avgs = {} ar_avg_bias = {} times = None for data_key, data in data_dict.items(): if times is None: times = data.coords["t"].values times = dates.date2num(pd.to_datetime(times).to_pydatetime()) good_i, good_j = np.where(~data[0].to_masked_array().mask) ar_avgs[data_key] = data.values[:, good_i, good_j].mean(axis=1) if obs_label_hint not in data_key: ar_avg_bias[data_key] = bias_dict[data_key].values[:, good_i, good_j].mean(axis=1) plot_utils.apply_plot_params(font_size=8, width_cm=20, height_cm=5) fig = plt.figure() ax_list = [] gs = GridSpec(1, 1) # ax = fig.add_subplot(gs[0, 0]) # for data_key, data in ar_avgs.items(): # ax.plot(times, data, label=data_key.split("_ndrw")[0]) # # # ax_list.append(ax) # # if len(panel_titles) > 0: # ax.set_title(panel_titles[0]) ax = fig.add_subplot(gs[0, 0]) for data_key, data in ar_avgs.items(): if obs_label_hint in data_key: continue ax.plot(times, ar_avg_bias[data_key], label="$\Delta$" + data_key.split("_ndrw")[0], lw=2) ax_list.append(ax) for pt, ax in zip(panel_titles, ax_list): ax.set_title(pt) for ax in ax_list: ax.xaxis.set_major_formatter(DateFormatter("%b")) ax.xaxis.set_major_locator(MonthLocator(bymonthday=1)) if plot_legend: ax.legend() ax.grid(True, linestyle="--") imfile = img_dir / ("_".join([dl for dl in data_dict if obs_label_hint not in dl]) + "_CMOS_poster.png") fig.savefig(str(imfile), dpi=300, bbox_inches="tight") plt.close(fig)
def main(): print("start") import application_properties application_properties.set_current_directory() from util import plot_utils print("finished imports and set ups") plot_utils.apply_plot_params(width_pt=None, width_cm=15, height_cm=15, font_size=16) validate_daily_climatology() pass
def plot_hydrographs(): plot_utils.apply_plot_params(font_size=14, width_pt=None, width_cm=20, height_cm=20) start_year = 1980 end_year = 2010 varname = "STFL" base_config = RunConfig(start_year=start_year, end_year=end_year, data_path="/RESCUE/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl.hdf5", label="NI") modif_config = RunConfig(start_year=start_year, end_year=end_year, data_path="/RESCUE/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl-intfl_ITFS.hdf5", label="WI") r_obj = RPN(GEO_DATA_FILE) facc = r_obj.get_first_record_for_name("FAA") fldr = r_obj.get_first_record_for_name("FLDR") lons, lats, bmp = analysis.get_basemap_from_hdf(file_path=base_config.data_path) basin_name_to_out_indices_map, basin_name_to_basin_mask = get_basin_to_outlet_indices_map(lons=lons, lats=lats, accumulation_areas=facc, directions=fldr) # Calculate the daily mean fields dates, stf_base = analysis.get_daily_climatology_for_rconf(base_config, var_name=varname, level=0) _, stf_modif = analysis.get_daily_climatology_for_rconf(modif_config, var_name=varname, level=0) for bname, (i_out, j_out) in basin_name_to_out_indices_map.items(): print(bname, i_out, j_out) fig = plt.figure() gs = GridSpec(2, 1, height_ratios=[1, 0.5], hspace=0.1) ax = fig.add_subplot(gs[0, 0]) ax.plot(dates, stf_base[:, i_out, j_out], "b", lw=2, label=base_config.label) ax.plot(dates, stf_modif[:, i_out, j_out], "r", lw=2, label=modif_config.label) ax.set_title(bname) format_axis(ax) # Hide the tick labels from the x-axis of the upper plot for tl in ax.xaxis.get_ticklabels(): tl.set_visible(False) ax = fig.add_subplot(gs[1, 0]) ax.plot(dates, stf_modif[:, i_out, j_out] - stf_base[:, i_out, j_out], "k", lw=2, label="{}-{}".format(modif_config.label, base_config.label)) format_axis(ax) fig.savefig(str(IMG_FOLDER.joinpath("{}_{}-{}.png".format(bname, start_year, end_year)))) plt.close(fig)
def explore_seasonal_interflow(): from . import explore_interflow_field plot_utils.apply_plot_params(font_size=10, width_pt=None, width_cm=17, height_cm=17) # hdf_path = "/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl-intfl_do_not_discard_small.hdf" # hdf_path = "/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl-intfl_sani-10000.hdf" hdf_path = "/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl-intfl_sani-10000_not_care_about_thfc.hdf" explore_interflow_field.calculate_and_plot_seasonal_means( hdf_path=hdf_path, start_year=1979, end_year=1980)
def main(): bathymetry_path = "" topo_path = "/RECH2/huziy/coupling/coupled-GL-NEMO1h_30min/geophys_452x260_directions_new_452x260_GL+NENA_0.1deg_SAND_CLAY_LDPT_DPTH.fst" plot_utils.apply_plot_params() with RPN(topo_path) as r: assert isinstance(r, RPN) topo = r.get_first_record_for_name("ME") lons, lats = r.get_longitudes_and_latitudes_for_the_last_read_rec() print(lons.shape) prj_params = r.get_proj_parameters_for_the_last_read_rec() rll = RotatedLatLon(**prj_params) bmap = rll.get_basemap_object_for_lons_lats(lons2d=lons, lats2d=lats, resolution="i") xx, yy = bmap(lons, lats) plt.figure() ax = plt.gca() lons1 = np.where(lons <= 180, lons, lons - 360) topo = maskoceans(lons1, lats, topo) topo_clevs = [0, 100, 200, 300, 400, 500, 600, 800, 1000, 1200] # bn = BoundaryNorm(topo_clevs, len(topo_clevs) - 1) cmap = cm.get_cmap("terrain") ocean_color = cmap(0.18) cmap, norm = colors.from_levels_and_colors(topo_clevs, cmap(np.linspace(0.3, 1, len(topo_clevs) - 1))) add_rectangle(ax, xx, yy, margin=20, edge_style="solid") add_rectangle(ax, xx, yy, margin=10, edge_style="dashed") im = bmap.pcolormesh(xx, yy, topo, cmap=cmap, norm=norm) bmap.colorbar(im, ticks=topo_clevs) bmap.drawcoastlines(linewidth=0.3) bmap.drawmapboundary(fill_color=ocean_color) bmap.drawparallels(np.arange(-90, 90, 10), labels=[1, 0, 0, 1], color="0.3") bmap.drawmeridians(np.arange(-180, 190, 10), labels=[1, 0, 0, 1], color="0.3") plt.savefig("GL_452x260_0.1deg_domain.png", dpi=300, bbox_inches="tight")
def validate_areaavg_annual_max(nemo_configs:dict, obs_manager:CisNicIceManager, start_year=-np.Inf, end_year=np.Inf, season_month_start=11, season_month_count=5, mask_shape_file=""): """ the year of the start of the season corresonds to the aggregated value for the season, i.e. if season starts in Oct 2009 and ends in March 2010, then the maximum value for the season would correspond to 2009 :param nemo_configs: :param obs_manager: :param start_year: :param end_year: """ lake_mask_obs = get_mask(obs_manager.lons, obs_manager.lats, shp_path=mask_shape_file) > 0.5 icefr_obs = obs_manager.get_area_avg_ts(lake_mask_obs, start_year=start_year, end_year=end_year) plot_utils.apply_plot_params(width_cm=10, height_cm=8, font_size=8) fig = plt.figure() icefr_obs_ann_max = icefr_obs.groupby(lambda d: __map_date_to_seasonyear(d, season_month_start, season_month_count)).max().drop(-1) ax = icefr_obs_ann_max.plot(label="Obs.", marker="o", markersize=0.5, linewidth=0.5) label_to_nemo_ts = OrderedDict() for label, nemo_config in nemo_configs.items(): assert isinstance(nemo_config, NemoYearlyFilesManager) lake_mask_mod = get_mask(nemo_config.lons, nemo_config.lats, shp_path=mask_shape_file) > 0.5 label_to_nemo_ts[label] = nemo_config.get_area_avg_ts(lake_mask_mod, start_year=start_year, end_year=end_year, ) annual_max = label_to_nemo_ts[label].groupby(lambda d: __map_date_to_seasonyear(d, season_month_start, season_month_count)).max().drop(-1) assert isinstance(annual_max, pd.Series) annual_max.plot( ax=ax, label=label + " (R = {:.2f})".format(annual_max.corr(icefr_obs_ann_max)), marker="o", markersize=0.5, linewidth=0.5) ax.legend() ax.grid(True, linewidth=0.2, linestyle="dashed") ax.set_ylim([0, 1]) img_file = img_folder.joinpath("icefr_area_avg_max_{}-{}.png".format(start_year, end_year)) fig.savefig(str(img_file), bbox_inches="tight", dpi=300) plt.close(fig)
def compare_obs_and_model_at_points(): plot_utils.apply_plot_params(font_size=14, width_pt=None, width_cm=20) from crcm5.analyse_hdf import compare_streamflow_with_obs start_date = datetime(1980, 1, 1) end_date = datetime(2010, 12, 31) # compare_streamflow_with_obs.main(start_date=start_date, end_date=end_date) compare_streamflow_with_obs.main_for_cc_paper(start_date=start_date, end_date=end_date) # reset back plot parameters to the default ones configure()
def main(): shape_path = default_domains.MH_BASINS_PATH label_to_sim_path = OrderedDict( [("0.11", "/RESCUE/skynet3_rech1/huziy/water_route_mh_bc_011deg_wc/discharge_1980_01_01_12_00.nc"), ("0.44", "/RESCUE/skynet3_rech1/huziy/water_route_mh_bc_044deg_wc/discharge_1980_01_01_12_00.nc")] ) label_to_gridconfig = { "0.11": default_domains.bc_mh_011, "0.44": default_domains.gc_cordex_na_044 } label_to_infocell = { "0.11": "/RESCUE/skynet3_rech1/huziy/water_route_mh_bc_011deg_wc/infocell.nc", "0.44": "/RESCUE/skynet3_rech1/huziy/water_route_mh_bc_044deg_wc/infocell.nc" } # setup subplots plot_utils.apply_plot_params() nrows = 1 ncols = len(label_to_sim_path) gs = GridSpec(nrows=nrows, ncols=ncols) fig = plt.figure() clevs = [0, 20, 50, 100, 200, 500, 1000, 1500, 3000, 4500, 5000, 7000, 9000] bn = BoundaryNorm(clevs, len(clevs) - 1) cmap = cm.get_cmap("jet", len(clevs) - 1) for col, (label, the_path) in enumerate(label_to_sim_path.items()): ax = fig.add_subplot(gs[0, col]) ax.set_title(label) with Dataset(the_path) as ds: data, x_index, y_index = [ds.variables[k][:] for k in ["water_discharge", "x_index", "y_index"]] with Dataset(label_to_infocell[label]) as ds: lon, lat = [ds.variables[k][:] for k in ["lon", "lat"]] gc = label_to_gridconfig[label] # get the basemap object bmp, data_mask = gc.get_basemap_using_shape_with_polygons_of_interest( lon, lat, shp_path=shape_path, mask_margin=5) plot_annual_mean(ax, bmp, lons=lon, lats=lat, data=data, x_index=x_index, y_index=y_index, norm=bn, colormap=cmap) fig.savefig("mh/offline_route_annual_mean_comparison.png", bbox_inches="tight")
def compare_2d_seasonal_means_from_simulations(): from crcm5.analyse_hdf import compare_modelled_2d_fields as comp # varnames = ["STFA", "TT", "PR", "AV", "AH", "TRAF", "TDRA", "I5", "IMAV", "I0", "I1", "AS"] # varnames = ["AB", "AU", "AR", "AI", "AD"] # varnames = ["AD-AI", "AD", "AR"] # varnames = ["STFA"] # varnames = ["RH", "AV", "AH", "TT", "I1", "I0", "PR", "TRAF", "STFA", "STFL", "AS", "IMAV"] # varnames = ["TT", "TRAF"] # levels = len(varnames) * [0, ] # varnames = ["AD", "STFA", "AV", "AH", "I0", "I1", "TT", "PR", "TRAF"] # These are actually 0-based level indices # levels = [None, None, None, None, 1, 1, None, None, 0] varnames = [ "STFA", ] levels = [ 0, ] # Used to plot control and differences season_to_months = OrderedDict([("Winter", [12, 1, 2]), ("Spring", list(range(3, 6))), ("Summer", list(range(6, 9))), ("Fall", list(range(9, 12)))]) # season_to_months = OrderedDict([ # ("May", [5, ]), # ("June", [6, ]), # ("July", [7, ]), # ("August", [8, ]) # ]) start_year = 1991 end_year = 2010 plot_utils.apply_plot_params(font_size=10, width_pt=None, width_cm=20, height_cm=10) comp.plot_control_and_differences_in_one_panel_for_all_seasons( varnames=varnames, levels=levels, season_to_months=season_to_months, start_year=start_year, end_year=end_year)
def main(): bathymetry_path = "" topo_path = "/RECH2/huziy/coupling/coupled-GL-NEMO1h_30min/geophys_452x260_directions_new_452x260_GL+NENA_0.1deg_SAND_CLAY_LDPT_DPTH.fst" plot_utils.apply_plot_params() with RPN(topo_path) as r: assert isinstance(r, RPN) topo = r.get_first_record_for_name("ME") lons, lats = r.get_longitudes_and_latitudes_for_the_last_read_rec() print(lons.shape) prj_params = r.get_proj_parameters_for_the_last_read_rec() rll = RotatedLatLon(**prj_params) bmap = rll.get_basemap_object_for_lons_lats(lons2d=lons, lats2d=lats, resolution="i") xx, yy = bmap(lons, lats) plt.figure() ax = plt.gca() lons1 = np.where(lons <= 180, lons, lons - 360) topo = maskoceans(lons1, lats, topo) topo_clevs = [0, 100, 200, 300, 400, 500, 600, 800, 1000, 1200] # bn = BoundaryNorm(topo_clevs, len(topo_clevs) - 1) cmap = cm.get_cmap("terrain") ocean_color = cmap(0.18) cmap, norm = colors.from_levels_and_colors( topo_clevs, cmap(np.linspace(0.3, 1, len(topo_clevs) - 1))) add_rectangle(ax, xx, yy, margin=20, edge_style="solid") add_rectangle(ax, xx, yy, margin=10, edge_style="dashed") im = bmap.pcolormesh(xx, yy, topo, cmap=cmap, norm=norm) bmap.colorbar(im, ticks=topo_clevs) bmap.drawcoastlines(linewidth=0.3) bmap.drawmapboundary(fill_color=ocean_color) bmap.drawparallels(np.arange(-90, 90, 10), labels=[1, 0, 0, 1], color="0.3") bmap.drawmeridians(np.arange(-180, 190, 10), labels=[1, 0, 0, 1], color="0.3") plt.savefig("GL_452x260_0.1deg_domain.png", dpi=300, bbox_inches="tight")
def entry_for_cc_canesm2_gl(): """ for CanESM2 driven CRCM5_NEMO simulation """ data_root = common_params.data_root label_to_datapath = OrderedDict([ (common_params.crcm_nemo_cur_label, data_root / "lake_effect_analysis_CRCM5_NEMO_CanESM2_RCP85_1989-2010_1989-2010/merged/" ), (common_params.crcm_nemo_fut_label, data_root / "lake_effect_analysis_CRCM5_NEMO_CanESM2_RCP85_2079-2100_2079-2100/merged/" ), ]) cur_st_date = datetime(1989, 1, 1) cur_en_date = datetime(2011, 1, 1) # end date not inclusive fut_st_date = datetime(2079, 1, 1) fut_en_date = datetime(2101, 1, 1) # end date not inclusive cur_period = Period(cur_st_date, cur_en_date) fut_period = Period(fut_st_date, fut_en_date) periods_info = CcPeriodsInfo(cur_period=cur_period, fut_period=fut_period) season_to_months = OrderedDict([("ND", [11, 12]), ("JF", [1, 2]), ("MA", [3, 4])]) var_pairs = [("hles_snow", "TT"), ("hles_snow", "PR"), ("hles_snow", "lake_ice_fraction")] var_display_names = { "hles_snow": "HLES", "lake_ice_fraction": "Mean Lake ice \nfraction", "TT": "2m air\n temperature", "PR": "total\nprecipitation" } plot_utils.apply_plot_params(width_cm=25, height_cm=25, font_size=8) gl_mask = get_gl_mask(label_to_datapath[common_params.crcm_nemo_cur_label]) hles_region_mask = get_mask_of_points_near_lakes(gl_mask, npoints_radius=20) main(label_to_data_path=label_to_datapath, var_pairs=var_pairs, periods_info=periods_info, vname_display_names=var_display_names, season_to_months=season_to_months, hles_region_mask=hles_region_mask, lakes_mask=gl_mask)
def compare_and_plot(path_to_folder = 'data/streamflows/hydrosheds_euler9'): """ Calculates interannual variability (standard ceviations) for each pair of members and plots their ratios create annual mean matrices -> calculate standard deviations for future and current climate, plot ratios of variations for memebers and the std for the control run, """ member_to_path = get_member_to_path_mapping(path_to_folder) plot_utils.apply_plot_params(aspect_ratio = 1.5) plt.figure() plot_marks = ['a', 'b', 'c', 'd', 'e'] subplot_count = 1 for current_id, plot_mark in zip(members.current_ids, plot_marks): future_id = members.current2future[current_id] path_c = member_to_path[current_id] path_f = member_to_path[future_id] stfl_c, times_c, i_indices, j_indices = data_select.get_data_from_file(path_c) stfl_f, times_f, i_indices, j_indices = data_select.get_data_from_file(path_f) means_c = calculate_annual_means(times_c, stfl_c) means_f = calculate_annual_means(times_f, stfl_f) std_c = np.std(means_c, axis = 0) std_f = np.std(means_f, axis = 0) f_values = std_f / std_c plt.subplot(3, 2, subplot_count) plot_subplot(i_indices, j_indices, f_values, mark = plot_mark) subplot_count += 1 #plot variance for the control simulation plt.subplot(3,2, subplot_count) stfl_c, times_c, i_indices, j_indices = data_select.get_data_from_file(path_c) means_c = calculate_annual_means(times_c, stfl_c) std_c = np.std(means_c, axis = 0) plot_subplot(i_indices, j_indices, std_c, mark = 'f') super_title = 'a-e: Changes in interannual variability ($\\sigma_{\\rm future}/ \\sigma_{\\rm current}$). \n' super_title += 'f: Interannual variability of the control simulation' plt.suptitle(super_title) plt.show()
def validate_forcing_temp_and_precip_with_cru(): """ Compare DFS temperature (K) and precip, with the ones from the CRU data set """ from .forcing import compare_forcing_clim_with_CRU plot_utils.apply_plot_params(font_size=18, width_pt=None, width_cm=13, height_cm=25) compare_forcing_clim_with_CRU.main() compare_forcing_clim_with_CRU.main( dfs_var_name="precip", cru_var_name="pre", cru_file="data/cru_data/CRUTS3.1/cru_ts_3_10.1901.2009.pre.dat.nc")
def plot_all(cv_current, cv_future): plot_utils.apply_plot_params(width_pt=None, font_size=9) fig = plt.figure() ps = map_parameters.polar_stereographic x = ps.lons y = ps.lats basemap = Basemap(projection="npstere", boundinglat = 20, lon_0=-115) [x, y] = basemap(x, y) x_min, x_max = x.min(), x.max() y_min, y_max = y.min(), y.max() all_axes = [] all_images = [] gs = gridspec.GridSpec(2,2) ax1 = fig.add_subplot(gs[0,0]) all_axes.append(ax1) ax1.set_title("SST: CV current") image = basemap.pcolormesh(x, y, cv_current, ax = ax1) all_images.append(image) ax2 = fig.add_subplot(gs[0, 1]) all_axes.append(ax2) ax2.set_title("SST: CV future") image = basemap.pcolormesh(x, y, cv_current, ax = ax2) all_images.append(image) ax3 = fig.add_subplot(gs[1, :]) all_axes.append(ax3) ax3.set_title("SST: CV future - CV current") cMap = my_colormaps.get_red_blue_colormap(ncolors=10) image = basemap.pcolormesh(x, y, cv_future - cv_current, ax = ax3, cmap = cMap, vmin = -0.004, vmax = 0.004 ) all_images.append(image) for the_ax, image in zip( all_axes, all_images): divider = make_axes_locatable(the_ax) the_ax.set_xlim(x_min, x_max) the_ax.set_ylim(y_min, y_max) cax = divider.append_axes("right", "8%", pad="3%") cb = fig.colorbar(image, cax = cax, ax = the_ax) cb.outline.set_visible(False) basemap.drawcoastlines(ax = the_ax) fig.tight_layout() fig.savefig("crcm4_sst_cv.png")
def plot_alt_from_monthly_climatologies(): plot_utils.apply_plot_params(width_pt=None, height_cm=20, width_cm=16, font_size=12) figure = plt.figure() b, lons2d, lats2d = draw_regions.get_basemap_and_coords(llcrnrlat=40.0, llcrnrlon=-145, urcrnrlon=-10) x, y = b(lons2d, lats2d) permafrost_mask = draw_regions.get_permafrost_mask(lons2d, lats2d) dm = CRCMDataManager(data_folder="data/CORDEX") year_ranges = [ list(range(1981, 1985)), list(range(2041, 2045)), list(range(2071, 2075)) ] gs = gridspec.GridSpec(len(year_ranges), 1) pf_mask = (permafrost_mask == 1) | (permafrost_mask == 2) pf_mask = ~pf_mask permafrost_mask = np.ma.masked_where(permafrost_mask <= 0, permafrost_mask) for i, year_range in enumerate(year_ranges): ax = figure.add_subplot(gs[i, 0]) alt = dm.get_alt_using_monthly_mean_climatology(year_range) alt = np.ma.masked_where(pf_mask, alt) img = b.contourf(x, y, alt, levels=range(11), cmap=cm.get_cmap("jet", ), ax=ax) divider = make_axes_locatable(ax) cax = divider.append_axes("right", "5%", pad="3%") cb = plt.colorbar(img, cax=cax) b.contour(x, y, permafrost_mask, levels=range(5), linewidth=0.1, colors="k", ax=ax) b.drawcoastlines(ax=ax, linewidth=0.5) ax.set_title("period: {0} - {1}".format(year_range[0], year_range[-1])) plt.savefig("alt_from_clim.png")
def compare_simulations_differences(): """ Plot changes for different variables for different seasons for 2 simulations """ from crcm5.analyse_hdf import compare_modelled_2d_fields_increments_only as comp_incrs # varnames = ["STFA", "TT", "PR", "AV", "AH", "TRAF", "TDRA", "I5", "IMAV", "I0", "I1", "AS"] # varnames = ["TT", "TRAF", "I1", "PR", "TDRA", "AV"] # varnames = ["AV", "AH", "TT", "I1", "I0", "PR", "TRAF", "STFA", "STFL", "AS", "IMAV"] # varnames = ["TT", "TRAF"] varnames = ["STFA", "TRAF", "I1", "PR", "TDRA", "AV"] levels = len(varnames) * [ 0, ] # varnames = ["AS", "STFA", "AV", "AH", "I0", "I1", "TT", "PR"] # levels = [None, None, None, None, 1, 1, None, None] # Used to plot control and differences season_to_months = OrderedDict([("Winter", [12, 1, 2]), ("Spring", list(range(3, 6))), ("Summer", list(range(6, 9))), ("Fall", list(range(9, 12)))]) # season_to_months = OrderedDict([ # ("May", [5, ]), # ("June", [6, ]), # ("July", [7, ]), # ("August", [8, ]) # ]) start_year = 1991 end_year = 2010 plot_utils.apply_plot_params(font_size=10, width_pt=None, width_cm=20, height_cm=30) comp_incrs.plot_control_and_differences_in_one_panel_for_all_seasons_for_all_vars( varnames=varnames, levels=levels, season_to_months=season_to_months, start_year=start_year, end_year=end_year)
def main_bak(): dirpath = "/HOME/huziy/skynet3_rech1/NEMO_OFFICIAL/dev_v3_4_STABLE_2012/NEMOGCM/CONFIG/GLK_LIM3/EXP_GLK_LIM3_1980/zdf_gls_dt_and_sbc_30min" dirpath = Path(dirpath) nemo_manager = NemoYearlyFilesManager(folder=str(dirpath)) plot_utils.apply_plot_params(width_cm=20, font_size=10) lons, lats, uu1, vv1, flow_speed = get_annual_mean_flow(nemo_manager, start_year=1998, end_year=1998, level=0) lons[lons < 0] += 360 plot_flow_vectors_basemap(lons, lats, uu1, vv1, flow_speed) lons[lons > 180] -= 360
def plot_alt_for_different_e_scenarios(): labels = ("E1", "E2", "E3", "E4") p_format = "pmNorthAmerica_0.44deg_CanHistoE{0}" prefixes = [p_format.format(x) for x in range(1, 5)] b, lons2d, lats2d = draw_regions.get_basemap_and_coords(llcrnrlat=40.0, llcrnrlon=-145, urcrnrlon=-10) x, y = b(lons2d, lats2d) permafrost_mask = draw_regions.get_permafrost_mask(lons2d, lats2d) dm = CRCMDataManager( data_folder="data/CORDEX") # needed here only for verticla levels plot_utils.apply_plot_params(width_pt=None, height_cm=12, width_cm=16, font_size=12) fig = plt.figure() gs = gridspec.GridSpec(2, 2) scen_index = 0 for row in range(2): for col in range(2): sc = labels[scen_index] ax = fig.add_subplot(gs[row, col]) h = dm.get_alt_using_files_in( folder="data/CORDEX/na/means_month", file_name_prefix=prefixes[scen_index]) h = np.ma.masked_where( (permafrost_mask == 0) | (permafrost_mask >= 3) | (h < 0), h) plot_for_scenario(sc, ax, basemap=b, x=x, y=y, alt=h, permafrost_mask=permafrost_mask, start_year=1950, end_year=1954) scen_index += 1 gs.tight_layout(fig, h_pad=0.9, w_pad=16) fig.savefig("alt_diff_scenarios.png") pass
def main(): pf_mask_file = "pf_mask_qc0.1deg.220x220.nc" if not os.path.isfile(pf_mask_file): path_to_rpn_with_targ_grid = "/RESCUE/skynet3_rech1/huziy/from_guillimin/new_outputs/current_climate_30_yr_sims/quebec_0.1_crcm5-hcd-rl-intfl_ITFS/Samples/quebec_crcm5-hcd-rl-intfl_197901/pm1979010100_00008928p" save_pf_mask_to_netcdf(pf_mask_file, path_to_rpn_with_target_grid=path_to_rpn_with_targ_grid) with Dataset(pf_mask_file) as ds: pf_mask = ds.variables["pf_type"][:] print(ds.variables.keys()) lay_widths = qc01deg_sim_layer_widths data_path = "/RESCUE/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl-intfl_ITFS.hdf5" start_year = 1990 end_year = 1990 alt_field = do_calculations(data_path=data_path, lay_widths=lay_widths, start_year=start_year, end_year=end_year) alt_field = np.ma.masked_where((alt_field < 0) | (alt_field > 8), alt_field) # do the plotting plot_utils.apply_plot_params() fig = plt.figure() bmp_info = analysis.get_basemap_info_from_hdf(file_path=data_path) # Mask oceans alt_field = maskoceans(bmp_info.lons, bmp_info.lats, alt_field) alt_field = np.ma.masked_where((pf_mask > 2) | (pf_mask < 1), alt_field) alt_field[(pf_mask == 2) & (~alt_field.mask)] = 5.5 xx, yy = bmp_info.get_proj_xy() img = bmp_info.basemap.contourf(xx, yy, alt_field, extend="both") bmp_info.basemap.colorbar(img) bmp_info.basemap.drawcoastlines() plt.contour(xx, yy, pf_mask, levels=[1, 2, 3], colors="k", linewidth=2) fig_path = "{}_alt_{}-{}.png".format(data_path[:-5], start_year, end_year) fig.savefig(fig_path, transparent=True, dpi=common_plot_params.FIG_SAVE_DPI, bbox_inches="tight") print("Saving the plot to {}".format(fig_path)) plt.show()
def main(): data_dir = "data/cehq_data/MontrealFlood2017_station_data/streamflow/daily" basin_shapes = [ "/RESCUE/skynet3_rech1/huziy/Netbeans Projects/Python/RPN/data/shp/mtl_flood_2017_basins/02JKL_SDA_Ottawa.shp", #"/RESCUE/skynet3_rech1/huziy/Netbeans Projects/Python/RPN/data/shp/mtl_flood_2017_basins/02MOP_SDA_St_Lawrence.shp", # "/RESCUE/skynet3_rech1/huziy/Netbeans Projects/Python/RPN/data/shp/mtl_flood_2017_basins/02N_SDA_St_Maurice.shp" ] selected_ids = [""] excluded_ids = ["120201"] start_date = datetime(1980, 1, 1) end_date = datetime(2017, 6, 1) stations = cehq_station.read_station_data(start_date=start_date, end_date=end_date, folder=data_dir, min_number_of_complete_years=0, only_natural=None) for s in stations: assert isinstance(s, Station) print(s) print(s.get_list_of_complete_years()) stations = [s for s in stations if s.id not in excluded_ids] plot_utils.apply_plot_params(font_size=10) img_file = "stfl_station_positions.png" img_file = commons.img_folder / img_file plot_station_positions(stations, img_file=str(img_file), shp_paths=basin_shapes, min_lon=-81.5, max_lon=-70, min_lat=43.5, max_lat=49) pass
def main(): data_path = "/RESCUE/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl-intfl_ITFS.hdf5" start_year = 1980 end_year = 2010 vname = "TRAF" level_index = 0 fldr = analysis.get_array_from_file(data_path, var_name="flow_direction") lkfr = analysis.get_array_from_file(data_path, var_name="lake_fraction") the_mask = np.ma.masked_all_like(fldr) the_mask[fldr > 0] = (1 - lkfr)[fldr > 0] ser = analysis.get_area_mean_timeseries(hdf_path=data_path, var_name=vname, level_index=level_index, start_year=start_year, end_year=end_year, the_mask=the_mask) monthly_ser = ser.groupby(lambda d: datetime(d.year, d.month, 15)).mean() # do the plotting plot_utils.apply_plot_params() fig = plt.figure() monthly_ser = monthly_ser * 24 * 3600 # convert to mm/day monthly_ser.groupby(lambda d: d.month).plot() ax = plt.gca() assert isinstance(ax, Axes) ax.grid() fig.savefig(data_path[:-5] + "_{}_level_index_{}_{}-{}_timeseries.png".format( vname, level_index, start_year, end_year), transparent=True, dpi=common_plot_params.FIG_SAVE_DPI, bbox_inches="tight") plt.show()
def plot_correlations_for_seasons_as_subplots(): plot_utils.apply_plot_params(font_size=14, width_pt=None, width_cm=30, height_cm=10) start_year = 1991 end_year = 2010 fig = plt.figure() ncols = 5 gs = GridSpec(2, ncols + 1, width_ratios=[1.0, ] * ncols + [0.05, ]) # Winter row = 0 # months = [12, 1, 2] # main(start_year=start_year, end_year=end_year, months=months, ylabel="Winter", # fig=fig, current_row=row, gs=gs) # row += 1 # Spring months = list(range(3, 6)) main(start_year=start_year, end_year=end_year, months=months, ylabel="Spring", fig=fig, current_row=row, gs=gs) row += 1 # Summer months = list(range(6, 9)) img, imfolder = main(start_year=start_year, end_year=end_year, months=months, ylabel="Summer", fig=fig, current_row=row, gs=gs) row += 1 # Fall # months = list(range(9, 12)) # img, imfolder = main(start_year=start_year, end_year=end_year, months=months, ylabel="Fall", # fig=fig, current_row=row, gs=gs) # row += 1 plt.colorbar(cax=fig.add_subplot(gs[:, -1])) plt.tight_layout() fig.savefig(os.path.join(imfolder, "corr_all_seasons_separately.png"))
def main(): """ Launch all the validators in parallel """ plot_utils.apply_plot_params(width_pt=None, width_cm=27, height_cm=40, font_size=25) p1 = Process(target=tmp_val.validate_using_monthly_diagnostics) p1.start() p2 = Process(target=swe_val.validate_using_monthly_diagnostics) p2.start() p3 = Process(target=alt_val.plot_current_alts) p3.start() p1.join() p2.join() p3.join() pass
def main(): plot_utils.apply_plot_params(font_size=20, width_pt=None, width_cm=20, height_cm=20) i_start, j_start = 0, 0 i_end, j_end = -1, -1 print(get_section_hor_indices(i_start=5, j_start=0, i_end=10, j_end=20)) # #Superior # params = dict( # i_start = 25, j_start = 65, # i_end = 70, j_end = 65, # var_name = "votemper" # # ) # plot_cross_section_for_seasons(data_path=T_FILE_PATH, **params) # # #Michigan # params = dict( # i_start = 55, j_start = 55, # i_end = 55, j_end = 5, # var_name = "votemper" # # ) # plot_cross_section_for_seasons(data_path=T_FILE_PATH, **params) #Huron params = dict(i_start=10, j_start=30, i_end=30, j_end=10, var_name="votemper") plot_cross_section_for_seasons(data_path=T_FILE_PATH, **params) plt.show()
plt.savefig("offline_validation.png", dpi=400) plt.close(fig) r = RPN( "/RESCUE/skynet3_rech1/huziy/CNRCWP/C3/Depth_to_bedrock_WestNA_0.25") r.get_first_record_for_name("8L") proj_params = r.get_proj_parameters_for_the_last_read_rec() lons, lats = r.get_longitudes_and_latitudes_for_the_last_read_rec() bsmp = RotatedLatLon(**proj_params).get_basemap_object_for_lons_lats( lons2d=lons, lats2d=lats) plot_utils.apply_plot_params(width_pt=None, width_cm=19, height_cm=19, font_size=12) plot_station_positions(manager=None, station_list=stations, bsmp=bsmp) if __name__ == "__main__": import application_properties application_properties.set_current_directory() from util import plot_utils plot_utils.apply_plot_params(width_pt=None, width_cm=19, height_cm=40, font_size=22) main() print("Hello world")
def main(): start_year = 1979 end_year = 1981 HL_LABEL = "CRCM5_HL" NEMO_LABEL = "CRCM5_NEMO" sim_label_to_path = OrderedDict([ (HL_LABEL, "/RESCUE/skynet3_rech1/huziy/CNRCWP/C5/2016/2-year-runs/coupled-GL+stfl_oneway/Samples" ), (NEMO_LABEL, "/HOME/huziy/skynet3_rech1/CNRCWP/C5/2016/2-year-runs/coupled-GL+stfl/Samples" ) ]) var_name_list = ["TT", "LC", "HU", "AV", "AL"] vname_to_level = { "TT": 1, "PR": -1, "SN": -1, "LC": -1, "HR": 1, "HU": 1, "AV": -1, "I5": -1, "AL": -1 } vname_to_level_kind = { "TT": level_kinds.HYBRID, "PR": level_kinds.ARBITRARY, "SN": level_kinds.ARBITRARY, "LC": level_kinds.ARBITRARY, "HR": level_kinds.HYBRID, "HU": level_kinds.HYBRID, "AV": level_kinds.ARBITRARY, "I5": level_kinds.ARBITRARY, "AL": level_kinds.ARBITRARY, "J8": level_kinds.ARBITRARY } vname_to_file_prefix = { "TT": "dm", "PR": "pm", "SN": "pm", "LC": "pm", "HR": "dm", "HU": "dm", "AV": "pm", "I5": "pm", "AL": "pm", "J8": "pm" } # ---> ----> avg_mask = get_nemo_lakes_mask(samples_dir=sim_label_to_path[NEMO_LABEL]) current_label = HL_LABEL vname_to_ts = OrderedDict() for vname in var_name_list: common_params = dict(start_year=start_year, end_year=end_year, filename_prefix=vname_to_file_prefix[vname], level=vname_to_level[vname], level_kind=vname_to_level_kind[vname], varname=vname, mask=avg_mask) ts = get_area_avg_timeseries(sim_label_to_path[current_label], **common_params) vname_to_ts[vname] = ts plot_utils.apply_plot_params(font_size=10, width_cm=20, height_cm=20) fig = plt.figure() gs = GridSpec(len(vname_to_ts), 1) row = 0 for vname, ts in vname_to_ts.items(): ax = fig.add_subplot(gs[row, 0]) ts.plot(lw=2, color="k", ax=ax) ax.set_ylabel(vname) row += 1 if not os.path.isdir(img_folder): os.mkdir(img_folder) fig.tight_layout() fig.savefig(os.path.join( img_folder, "{}_lakeand_air_props_ts_over_GL_{}-{}.png".format( current_label, start_year, end_year)), dpi=commons.dpi, transparent=True)
def main(): img_folder = Path("nei_validation") img_folder.mkdir(parents=True, exist_ok=True) var_names = ["TT", "PR"] seasons = OrderedDict([ ("DJF", MonthPeriod(12, 3)), ("MAM", MonthPeriod(3, 3)), ("JJA", MonthPeriod(6, 3)), ("SON", MonthPeriod(9, 3)), ]) sim_paths = OrderedDict() start_year = 1980 end_year = 2008 sim_paths["WC_0.44deg_default"] = Path \ ("/HOME/huziy/skynet3_rech1/CRCM5_outputs/NEI/diags/NEI_WC0.44deg_default/Diagnostics") sim_paths["WC_0.44deg_ctem+frsoil+dyngla"] = Path \ ("/HOME/huziy/skynet3_rech1/CRCM5_outputs/NEI/diags/debug_NEI_WC0.44deg_Crr1/Diagnostics") sim_paths["WC_0.11deg_ctem+frsoil+dyngla"] = Path( "/snow3/huziy/NEI/WC/NEI_WC0.11deg_Crr1/Diagnostics") cru_vname_to_path = { "pre": "/HOME/data/Validation/CRU_TS_3.1/Original_files_gzipped/cru_ts_3_10.1901.2009.pre.dat.nc", "tmp": "/HOME/data/Validation/CRU_TS_3.1/Original_files_gzipped/cru_ts_3_10.1901.2009.tmp.dat.nc" } plot_cru_data = True plot_model_data = True plot_naobs_data = True plot_daymet_data = True plot_utils.apply_plot_params(font_size=14) basemap_for_obs = None # plot simulation data for sim_label, sim_path in sim_paths.items(): manager = DiagCrcmManager(data_dir=sim_path) # get the basemap to be reused for plotting observation data if basemap_for_obs is None: basemap_for_obs = manager.get_basemap(resolution="i", area_thresh=area_thresh_km2) if not plot_model_data: break for vname in var_names: seas_to_clim = manager.get_seasonal_means_with_ttest_stats( season_to_monthperiod=seasons, start_year=start_year, end_year=end_year, vname=vname, vertical_level=var_name_to_level[vname], data_file_prefix=var_name_to_file_prefix[vname]) _plot_seasonal_data( seas_data=seas_to_clim, data_label="{}_{}-{}".format(sim_label, start_year, end_year), img_dir=img_folder, map=manager.get_basemap(resolution="i", area_thresh=area_thresh_km2), lons=manager.lons, lats=manager.lats, vname=vname) assert basemap_for_obs is not None # plot obs data # -- CRU for vname in var_names: if not plot_cru_data: break cru_vname = var_name_to_cru_name[vname] manager = CRUDataManager(path=cru_vname_to_path[cru_vname], var_name=cru_vname) seas_to_clim = manager.get_seasonal_means_with_ttest_stats( season_to_monthperiod=seasons, start_year=start_year, end_year=end_year) manager.close() _plot_seasonal_data(seas_data=seas_to_clim, data_label="{}_{}-{}".format( "CRU", start_year, end_year), img_dir=img_folder, map=basemap_for_obs, lons=manager.lons2d, lats=manager.lats2d, vname=vname, var_name_to_mul={ "TT": 1, "PR": 1 }) # -- NAOBS naobs_vname_to_path = { "TT": "/HOME/huziy/skynet3_rech1/obs_data/anuspl_uw_0.11_wc_domain/anusplin+_interpolated_tt_pr.nc", "PR": "/HOME/huziy/skynet3_rech1/obs_data/anuspl_uw_0.11_wc_domain/anusplin+_interpolated_tt_pr.nc" } for vname in var_names: if not plot_naobs_data: break manager = CRUDataManager(path=naobs_vname_to_path[vname], var_name=vname) seas_to_clim = manager.get_seasonal_means_with_ttest_stats( season_to_monthperiod=seasons, start_year=start_year, end_year=end_year) # mask no data points for s, data in seas_to_clim.items(): for i in [0, 1]: data[i] = np.ma.masked_where(manager.lats2d > 60, data[i]) data[i] = np.ma.masked_where(manager.lons2d < -150, data[i]) data[i] = maskoceans(manager.lons2d, manager.lats2d, datain=data[i]) _plot_seasonal_data(seas_data=seas_to_clim, data_label="{}_{}-{}".format( "NAOBS", start_year, end_year), img_dir=img_folder, map=basemap_for_obs, lons=manager.lons2d, lats=manager.lats2d, vname=vname) manager.close() # -- daymet monthly daymet_vname_to_path = { "prcp": "/HOME/data/Validation/Daymet/Monthly_means/NetCDF/daymet_v3_prcp_monttl_*_na.nc4", "tavg": "/HOME/huziy/skynet3_rech1/obs_data/daymet_tavg_monthly/daymet_v3_tavg_monavg_*_na_nc4classic.nc4" } vname_to_daymet_vname = {"PR": "prcp", "TT": "tavg"} for vname in var_names: if not plot_daymet_data: break daymet_vname = vname_to_daymet_vname[vname] manager = HighResDataManager(path=daymet_vname_to_path[daymet_vname], vname=daymet_vname) seas_to_clim = manager.get_seasonal_means_with_ttest_stats_dask( season_to_monthperiod=seasons, start_year=start_year, end_year=end_year, convert_monthly_accumulators_to_daily=(vname == "PR")) _plot_seasonal_data(seas_data=seas_to_clim, data_label="{}_{}-{}".format( "DAYMET", start_year, end_year), img_dir=img_folder, map=basemap_for_obs, lons=manager.lons, lats=manager.lats, vname=vname, var_name_to_mul={ "PR": 1, "TT": 1 }) manager.close()