def plot_matrix(self, detector_nr): plt.rcParams.update({'font.size': 22}) detector_view = self.geo_matrix[detector_nr].reshape( (self.pre_pixel_nr, self.pre_pixel_nr)) print(detector_view[0, 0].shape) print(detector_view.flatten()[25]) # plt.imshow(detector_view, cmap=get_cmap()) plt.imshow(detector_view, norm=matplotlib.colors.SymLogNorm(1e-14), cmap=get_cmap()) cbar = plt.colorbar() # format='%.0e') cbar.ax.set_ylabel('Influence ($m^3$)', rotation=90, fontsize=22) plt.xlabel("#pixel x") plt.ylabel("#pixel z")
import numpy as np import sys import grid_from_lat_lon from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import cmap brcmap = cmap.get_cmap() warm_dict = np.load('PIAI_12.npy', allow_pickle=True, encoding='bytes').item() model_colors = ['#20ab2e', '#4042c7', '#bc87e8', '#ab2020'] models = list(warm_dict.keys()) model_names = ['Random Forest', 'SGB', 'MVLR', 'XGBoost'] regions = warm_dict[models[0]].keys() areas = [str(b)[2:-1] for b in regions] differences = {} for model in models: differences[model] = [] for model in models: for area in regions: differences[model].append( np.nanmean(warm_dict[model][area][b'values']) * 100) for i, model in enumerate(differences.keys()): grid, lats, lons = grid_from_lat_lon.make_grid(differences[model], areas) m = Basemap(projection='cyl', llcrnrlat=-90, urcrnrlat=90, llcrnrlon=-180,
yslice = 0 xx,zz = np.meshgrid(x1,(z1-zhub),indexing='ij') j = np.argmin(np.abs(yslice-y1)) u0=u0[:,j,:] u = u[:,j,:] w = w[:,j,:] return xx,zz,u0,u,w # --- fig,ax = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True, figsize=(16,8)) #cmap = 'magma' cmap,valuesOri=get_cmap(0,1.05) levelsLines = np.sort([1.05,1.0,0.99,0.98,0.95,0.9,0.8,0.7,0.6,0.5,0.4,0.3,0.2,0.1,0]) for irow,suffix in enumerate(suffixlist): for icol,CT in enumerate(CTlist): xAD,zAD,uAD,wAD = loadAD(CT=CT) xGP,zGP,u0,uGP,wGP = loadGP(CT=CT,suffix=suffix) cm = ax[irow,icol].contourf(xAD,zAD,uAD,levels=levelsLines,cmap=cmap) cnt = ax[irow,icol].contour(xAD,zAD,uAD,levels=levelsLines, colors='k',linewidths=0.5) cnt2 = ax[irow,icol].contour(xGP,zGP,uGP,levels=levelsLines, colors='k',linewidths=0.5,linestyles='--') txt = ax[irow,icol].text(0.025,0.95,suffix, horizontalalignment='left', verticalalignment='top', transform=ax[irow,icol].transAxes)
def plot_year(predictor, X_vars, y_var, year, GCM=False): global year_dir import datetime if GCM: year_data = hadgem_comp.get_hadgem() y_var = 'cf' year = 1850 else: year_data = np.load(year_dir + str(year) + '.npy', allow_pickle=True).item() pred_y = np.zeros(year_data[y_var][0].shape) ssims = [] mean_diffs = [] for month in range(len(year_data['sst']))[10:]: date = datetime.date(month=month + 1, year=year, day=1) print(date.strftime('%B'), 'date') for lat_row in range(len(year_data['sst'][month])): for lon_tile in range(len(year_data['sst'][month][lat_row])): xai = [] for var in X_vars: xai.append(year_data[var][month][lat_row][lon_tile]) if True in np.isnan(xai): pred_y[lat_row][lon_tile] = np.nan else: pred_y[lat_row][lon_tile] = predictor.predict([xai])[0] print(xai) land = np.isnan(pred_y) year_data[y_var][month][land] = np.nan over = (pred_y > np.max(year_data[y_var][month])) pred_y[over] = np.max(year_data[y_var][month]) print(np.nanmean(pred_y), 'predicted mean') print(np.nanmean(year_data[y_var][month]), 'actual mean') mean_diffs.append( np.nanmean(pred_y) - np.nanmean(year_data['cf'][month])) plot_max = max([np.nanmax(pred_y), np.nanmax(year_data[y_var][month])]) plot_min = min([np.nanmin(pred_y), np.nanmin(year_data[y_var][month])]) plt.pcolormesh(pred_y) plt.colorbar() plt.show() plt.subplot(121) plt.pcolormesh(year_data['longitudes'], year_data['latitudes'], pred_y, cmap='cividis', vmin=plot_min, vmax=plot_max) plt.title('Predicted CF') plt.colorbar() plt.subplot(122) plt.pcolormesh(year_data['longitudes'], year_data['latitudes'], pred_y - year_data[y_var][month], cmap=cmap.get_cmap()) plt.title('Differenced CF') plt.colorbar() plt.suptitle('{} {}'.format(date.strftime('%B'), date.strftime('%Y'))) plt.savefig('GCM Test') plt.show() pred_y[np.isnan(pred_y)] = 0. year_data[y_var][month][np.isnan(year_data[y_var][month])] = 0. sys.exit() similarity = ssim( pred_y, year_data[y_var][month], data_range=max([np.amax(pred_y), np.amax(year_data[y_var][month])])) print(similarity) ssims.append(similarity) return ssims, mean_diffs