Пример #1
0
 def plot_diff(self, gcdf_obj_comp):
     '''this one plots 3 col x [n] num_times: old mod, new mod, plus delta'''
     # gcdf_obj_comp = the object of comparison. obtained using getCDF i.e. __init__
     xlabel_hack = [
         'Modern Model', 'Hedrick WRR18', 'Diff (modern - WRR18)'
     ]
     num_times = self.num_times
     mat = np.empty([3 * num_times, self.nrows, self.ncols])
     im = [None] * num_times
     for i in range(num_times):
         im[i] = i * 3  #mat index
         mat_t = self.netCDF[self.string][self.idt[i]]
         mat_t[self.mask == False] = np.nan
         mat[im[i], :, :] = mat_t
         mat_t = gcdf_obj_comp.netCDF[gcdf_obj_comp.string][self.idt[i]]
         mat_t[self.mask == False] = np.nanplot_diff
         mat[im[i] + 1, :, :] = mat_t
         mat[im[i] +
             2, :, :] = mat[i, :, :] - mat[i + 1, :, :]  # difference mat
     pltz_obj = pltz.Plotables()
     # fig, axs = plt.subplots(nrows = num_times, ncols = 3, figsize = (8, math.ceil(10 * (num_times/3))), dpi = 180)
     fig, axs = plt.subplots(nrows=num_times,
                             ncols=3,
                             figsize=(12, 12),
                             dpi=180)
     ct = 0
     for i, row in enumerate(axs):
         for j, cell in enumerate(row):
             print(ct)
             mp = cell.imshow(mat[ct, :, :])
             pltz_obj.cb_readable(mat[ct, :, :], 4)
             cbar = fig.colorbar(mp,
                                 ax=cell,
                                 fraction=0.04,
                                 pad=0.04,
                                 orientation='vertical',
                                 extend='max',
                                 ticks=pltz_obj.cb_range)
             ct += 1
             # print(i,j)
             if i == len(axs) - 1:
                 # print(i)
                 cell.set_xlabel(xlabel_hack[j])
             if j == 0:
                 cell.set_ylabel(self.dt[self.idt[i]])
             cell.set_xticklabels([])
             cell.set_yticklabels([])
     # plt.subplot_tool()
     plt.savefig('Hedrick_Comparison_bets.png', dpi=180)
Пример #2
0
 def plot_CDF(self, img_str):
     ''' to be used with pull_times method. Not yet generalized '''
     pltz_obj = pltz.Plotables()
     pltz_obj.dist_subP(self.pds)
     ct, ct_in = 0, 0
     for i in range(len(pltz_obj.row)):
         fig, axs = plt.subplots(nrows=pltz_obj.row[i],
                                 ncols=pltz_obj.col[i],
                                 figsize=(6, 8),
                                 dpi=180)
         axs = axs.ravel()
         for j, axo in enumerate(axs):
             print(ct_in)
             if not (pltz_obj.panel_flag + (ct_in == self.pds)
                     == 2):  #funky way of saying BOTH need to be true
                 temp_daily = self.mat[ct:ct + self.hd * self.di, :, :]
                 time_avg = np.apply_along_axis(np.mean, 0, temp_daily)
                 pltz_obj.cb_readable(time_avg, 4)
                 ct += self.hd * self.di  #counter used to index
                 mp = axo.imshow(time_avg)
                 # cbar = fig.colorbar(mp, ax=axo, fraction=0.04, pad=0.04, orientation = 'horizontal',
                 #                     extend = 'max', format = '%.1f', ticks = pltz_obj.cb_range)
                 cbar = fig.colorbar(mp,
                                     ax=axo,
                                     fraction=0.04,
                                     pad=0.04,
                                     orientation='horizontal',
                                     extend='max',
                                     ticks=pltz_obj.cb_range)
                 mp.axes.get_xaxis().set_ticks([])
                 mp.axes.get_yaxis().set_ticks([])
                 mp.axes.set_title(self.dt_pds[ct_in])
                 ct_in += 1
             else:
                 pass
         str = img_str + '%r.png' % (i + 1)
         plt.tight_layout()
         plt.savefig(str, dpi=180)
Пример #3
0
 def plot_diff_simple(self, idi, img_str):
     '''Plots only the delta map in multipanels'''
     # idi options:  2 = diff, 1 = old, 0 = new  InDexIndex (idi)
     num_ticks = 3  # tick marks in colorbar
     fsize = 10  # base font size
     pltz_obj = pltz.Plotables()
     pltz_obj.dist_subP(self.num_times)
     print('num times = ', self.num_times)
     pltz_obj.marks_colors()
     idd = list(range(idi, idi + self.num_times * 3,
                      3))  #idi picks what to plot (new, old, delta)
     if idi == 2:
         col_lim_type = 'A'  #
     else:
         # Find min, max mat vals for all times
         vmn, vmx = 0, 0  # initiate vmx, vmn. WILL BREAK if min is pos or max negative
         for idd in idd:
             mat_d = self.diff_mat[idd, :, :]
             vmn = min(vmn, np.nanmin(mat_d))
             vmx = max(vmx, np.nanmax(mat_d))
         col_lim = [vmn, vmx]
         col_lim_type = 'L'
         pltz_obj.cb_readable(col_lim, col_lim_type, num_ticks)
     ct = 0
     for i in range(len(pltz_obj.row)):
         fig, axs = plt.subplots(nrows=pltz_obj.row[i],
                                 ncols=pltz_obj.col[i],
                                 figsize=(12, 12),
                                 dpi=180)
         axs = axs.ravel()
         for j, axo in enumerate(
                 axs
         ):  #Needs to be fixed HERE! will break if not 4 or multiples of 9. ZRU 6/6/19
             try:  #ensure no empty subplots
                 diff_mat = self.diff_mat[ct * 3 + idi, :, :]
                 if col_lim_type == 'A':
                     pltz_obj.cb_readable(diff_mat, col_lim_type, num_ticks)
                     mp = axo.imshow(diff_mat,
                                     cmap=pltz_obj.cmap,
                                     norm=MidpointNormalize(
                                         midpoint=0,
                                         vmin=pltz_obj.vmin,
                                         vmax=pltz_obj.vmax))
                     cbar = fig.colorbar(mp,
                                         ax=axo,
                                         fraction=0.04,
                                         pad=0.04,
                                         extend='max',
                                         ticks=pltz_obj.cb_range)
                     cbar.ax.tick_params(labelsize=fsize)
                     axo.set_title(self.dt[self.idt[j + i * 9]],
                                   fontsize=fsize + 4)
                 elif col_lim_type == 'L':
                     mp = axo.imshow(diff_mat,
                                     cmap=pltz_obj.cmap,
                                     norm=MidpointNormalize(
                                         midpoint=0,
                                         vmin=pltz_obj.vmin,
                                         vmax=pltz_obj.vmax))
                     cbar = fig.colorbar(mp,
                                         ax=axo,
                                         fraction=0.04,
                                         pad=0.04,
                                         orientation='horizontal',
                                         extend='max',
                                         ticks=pltz_obj.cb_range)
                     cbar.ax.tick_params(labelsize=fsize)
                 mp.axes.get_xaxis().set_ticks([])
                 mp.axes.get_yaxis().set_ticks([])
                 fig.suptitle(
                     'Specific Mass (mm) difference map (New Model - Old Model)',
                     fontsize=fsize + 8)
                 ct += 1
             except IndexError:  #ensure no empty subplots
                 axo.axis("off")
         str = img_str + '%r.png' % (
             i + 1
         )  # adds +1 to fig name if multi image (i.e. > 9 subplots)
         plt.savefig(str, dpi=180)
Пример #4
0
#                         acre_feet_change, pct_storage]),
#                 columns = ['mean sediment change (feet)', '0.01 quantile sediment change (feet)',
#                         '0.99 quantile sediment change (feet)', 'reservoir size (acres)',
#                         'reservoir depth (avg)', '2018 reservoir storage (acre-ft)',
#                         '2010 reservoir storage (acre-feet)','acre-feet change',
#                         'percent storage change'],
#                 index = reservoirs)
# print(df)
# pd.DataFrame.to_csv(df, os.path.join(utilities.get_path(22), 'sediment_summary_stats_all_openTopo.csv'))

# Figures
# replace nans with numpy nan value
arr = arr_copco_diff
mask = mask_copco
# in this version nans were wierd negative neglible vals
pltz_obj = pltz.Plotables(arr, mask)
pltz_obj.trim_extent_nan('array')
cbar_string = 'Elevation \u0394 (ft; 2018 minus 2002)'
reservoir = 'Copco'
suptitle_string = '{}: Sediment \u0394 2002 to 2018'.format(reservoir)
fp_out = os.path.join(
    utilities.get_path(22),
    'bathymetry_project/{}_Sediment_Change_2018_2002.png'.format(reservoir))
pltz_obj.basic_plot('mat_trimmed_nan_masked', cbar_string, suptitle_string,
                    fp_out)
#
# # fig, axes = plt.subplots(nrows = 1, ncols = 1)
# # # h = axes.imshow(diff_map, cmap = self.cmap_marks, norm=MidpointNormalize(midpoint = 0))
# # h = axes.imshow(arr_IG_10)
# # # IG lims
# # # h.set_clim(2170, 2330)
Пример #5
0
fp_d1_2 = '/mnt/snowpack/lidar/SanJoaquin/2019/aso/USCASJ20190614_SUPERsnow_depth_50p0m_agg.tif'
fp_d2_2 = '/mnt/snowpack/lidar/SanJoaquin/2019/aso/USCASJ20190704_SUPERsnow_depth_50p0m_agg.tif'

fp_out = '/home/zachuhlmann/projects/basin_masks/'



utils_obj = gdalUtils.GDAL_python_synergy(fp_d1, fp_d2, fp_out)
utils_obj.clip_extent_overlap()
utils_obj.make_diff_mat()
# utils_obj.basic_stats()

# # utils_obj.save_tiff('mat_diff_norm')
# # utils_obj.replace_qml()

pltz_obj = pltz.Plotables()
pltz_obj.set_zero_colors(1)
pltz_obj.marks_colors()

# MAPPING OUTLIERS
name = ['mat_clip1', 'mat_diff_norm', 'mat_clip2']
operator = [['lt', 'gt'], ['lt', 'gt']]  #display options
val = [[17, -0.01], [10, -1.01]]   #display options
histogram_mats = ['mat_clip1', 'mat_diff_norm']
bin_dims = (60, 200)
moving_window_size = 3
moving_window_name = 'bins'
threshold_histogram_space = [0,-0.9,(4/9)]

# mov_wind(config['bin']['wind_sz'])
# mov_wind(config['map']['wind_sz'])