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 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 main(): start_year = 1980 end_year = 2003 months_of_obs = [12, 1, 2, 3, 4, 5] r_config = RunConfig( data_path="/RESCUE/skynet3_rech1/huziy/hdf_store/quebec_0.1_crcm5-hcd-rl.hdf5", start_year=start_year, end_year=end_year, label="ERAI-CRCM5-L" ) var_name = "LC" bmp_info = analysis.get_basemap_info(r_config=r_config) lkid_to_mask = get_lake_masks(bmp_info.lons, bmp_info.lats) cell_area_m2 = analysis.get_array_from_file(path=r_config.data_path, var_name="cell_area_m2") # read the model data lkid_to_ts_model = {} for lkid, the_mask in lkid_to_mask.items(): lkid_to_ts_model[lkid] = analysis.get_area_mean_timeseries(r_config.data_path, var_name=var_name, the_mask=the_mask * cell_area_m2, start_year=start_year, end_year=end_year) df = lkid_to_ts_model[lkid] # remove the last December df = df.select(lambda d: not (d.year == end_year and d.month == 12)) # remove the first Jan and Feb df = df.select(lambda d: not (d.year == start_year and d.month in [1, 2])) # remove the Feb 29th df = df.select(lambda d: not (d.month == 2 and d.day == 29)) # select months of interest df = df.select(lambda d: d.month in months_of_obs) # calculate the climatology df = df.groupby(lambda d: datetime(2001 if d.month == 12 else 2002, d.month, d.day)).mean() df.sort_index(inplace=True) lkid_to_ts_model[lkid] = df * 100 # read obs data and calculate climatology lkid_to_ts_obs = {} for lkid in LAKE_IDS: lkid_to_ts_obs[lkid] = GL_obs_timeseries.get_ts_from_file(path=os.path.join(OBS_DATA_FOLDER, "{}-30x.TXT".format(lkid)), start_year=start_year, end_year=end_year - 1) # get the climatology dfm = lkid_to_ts_obs[lkid].mean(axis=1) dfm.index = [datetime(2001, 1, 1) + timedelta(days=int(jd - 1)) for jd in dfm.index] lkid_to_ts_obs[lkid] = dfm # plotting plot_utils.apply_plot_params(font_size=10) fig = plt.figure() gs = GridSpec(nrows=len(lkid_to_ts_model), ncols=2) for row, lkid in enumerate(lkid_to_ts_model): ax = fig.add_subplot(gs[row, 0]) mod = lkid_to_ts_model[lkid] obs = lkid_to_ts_obs[lkid] print(obs.index) print(obs.values) ax.plot(mod.index, mod.values, label=r_config.label, color="r", lw=2) ax.plot(obs.index, obs.values, label="NOAA NIC/CIS", color="k", lw=2) if row == 0: ax.legend() ax.set_title(lkid) ax.xaxis.set_major_formatter(DateFormatter("%b")) fig.tight_layout() fig.savefig(os.path.join(img_folder, "GL_ice-cover-validation.png"), bbox_inches="tight", dpi=common_plot_params.FIG_SAVE_DPI)