def plt_brom_ersem_wod(save=False): dss = xr.open_dataset(brom_path) #levels = sorted(dss.depth.values) levels = sorted(dss.z.values) fig = plt.figure(figsize=(7, 5.5), dpi=100) ''' Data from World Ocean Database https://www.nodc.noaa.gov/OC5/WOD/datageo.html ''' ncfile = (wod_path) vars = ['Oxygen', 'po4', 'si', 'no3'] titles = ['O$_2', 'PO$_4', 'Si $', 'NO$_3'] axes = [] cols = 2 gs = gridspec.GridSpec(len(vars) // cols, cols) gs.update(hspace=0.3, wspace=0.3, top=0.92, bottom=0.02, right=0.97) x_text, y_text = -0.05, 1.1 labels = ('A) ', 'B) ', 'C) ', 'D) ') interps = [1, 3, 10, 3] #levels of interpolation for n in range(0, 4): row = (n // cols) col = n % cols axes.append(fig.add_subplot(gs[row, col])) add_brom_plot(dss, axes[n], vars[n]) add_amk(axes[n], vars[n]) plot_data_wod(ncfile, vars[n], True, True, levels, axes[n], interps[n], double_int=True, only_clima_mean=True) axes[n].set_ylim(90, 0) axes[n].xaxis.set_ticks_position('top') axes[n].set_ylabel('depth, m') axes[n].set_title(r'{}\ \mu M$'.format(titles[n]), y=1.1) axes[n].text(x_text, y_text, labels[n], transform=axes[n].transAxes, fontsize=14, fontweight='bold', va='top', ha='right') if save == True: #plt.savefig('Fig/Figure6_WOD_vs_BROM.pdf', # format = 'pdf', # transparent = False) plt.savefig('Fig/Figure6_WOD_vs_BROM.png', format='png', transparent=False) else: plt.show()
def plot_roms_average_year(var,title,cmap = 'gist',vmax = None,vmin = None) : ds = xr.open_dataset('Data\ROMS_Laptev_Sea_NETCDF3_CLASSIC_east_var2.nc') ds = ds.where((ds['time.year'] >= 1989), drop=True) d = ds.depth.values ds_1990 = ds.where((ds['time.year'] < 1992), drop=True) ds_2002= ds.where((ds['time.year'] >= 2002), drop=True) arr = ds[var].to_pandas().sort_index() arr = arr.resample('D').ffill() t = arr.index.dayofyear arr['dayofyear'] = t arr = arr.pivot_table(arr,index = 'dayofyear', aggfunc=np.median).T.sort_index() #columns = 'depth', X,Y = np.meshgrid(arr.columns,arr.index) fig = plt.figure(figsize=(8,9), dpi=100 ) fig.suptitle(title) gs = gridspec.GridSpec(3,1) gs.update(hspace=0.35,top = 0.95,bottom = 0.05, right = 1.05,left = 0.1) ax = fig.add_subplot(gs[0]) ax1 = fig.add_subplot(gs[1]) ax2 = fig.add_subplot(gs[2]) ax2.set_title('Average year') ds_1990[var].plot(ax=ax, x = 'time',y = 'depth',cmap=plt.get_cmap(cmap),vmax = vmax,vmin = vmin) ds_2002[var].plot(ax=ax1, x = 'time',y = 'depth',cmap=plt.get_cmap(cmap),vmax = vmax,vmin = vmin) cs = ax2.pcolormesh(X,Y,arr,cmap=plt.get_cmap(cmap),vmax = vmax,vmin = vmin) plt.colorbar(cs, ax = ax2) for axis in (ax,ax1,ax2): axis.set_ylabel('depth, m') axis.set_ylim(80,0) start = datetime.datetime(1989, 1, 1, 23, 59) end = datetime.datetime(2014, 1, 1, 23, 59) rng = pd.date_range(start, end, freq='A-DEC') ax.vlines(rng,0,80,linestyle = '--', lw = 0.5) ax1.vlines(rng,0,80,linestyle = '--', lw = 0.5) ax2.set_xlabel('number of day in a year') #plt.savefig(r'C:\Users\elp\OneDrive\Python_workspace\arctic2030\Data\mean_roms_{}.png'.format(var)) plt.show() plt.clf()
sub_second = int(round((start_time - int(start_time)) * 100)) timestamp = "%d-%02d-%02d %02d:%02d:%02d.%02d UT" % ( srt_time[0], srt_time[1], srt_time[2], srt_time[3], srt_time[4], srt_time[5], sub_second) # add and modify aspects of plot post-plotting f.suptitle('%s %s %4.2f MHz' % (title, timestamp, cfreq / 1E6), fontsize=10) ax.set_xlabel('time (UTC)', fontsize=8) tl = ax.get_xticklabels() for tk in tl: tk.set_size(8) del tl tl = ax.get_yticklabels() for tk in tl: tk.set_size(8) del tl gridspec.update() f.tight_layout() f.subplots_adjust(top=0.95, right=0.88) cax = f.add_axes([0.9, 0.12, 0.02, 0.80]) f.colorbar(im, cax=cax) # save and show plot matplotlib.pyplot.savefig(dir_plot) #matplotlib.pyplot.show()
from make_movie_strip import process_fp from make_movie_strip import process_phase from make_movie_strip import add_no_over import figure_util import data.bio_film_data.strainmap as strainmaper plt.style.use('../figstyle.mpl') figall = plt.figure() #gs = gs.GridSpec(2, 3, width_ratios=[0.4, 0.25, 0.25]) #plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1 ) gs = gs.GridSpec(2, 4, height_ratios=[0.7, 0.3]) #gs.update(left=0.05, right=0.95, wspace=0.15, hspace=0.00) gs.update(left=0.06, right=0.98, wspace=0.15, hspace=0.05) aximgr = plt.subplot(gs[0, 0:2]) aximgr.grid(False) aximgr.axis('off') aximgy = plt.subplot(gs[0, 2:4]) aximgy.grid(False) aximgy.axis('off') axall = [plt.subplot(gs[1, i]) for i in range(4)] yticks = mticker.MaxNLocator(nbins=4) ## Images """ path = "movie_strip/sigB_biofilmpad6-O001_3-{0}-{1:03d}.tif" image_num = 31
print("Loading data...") x_test, _, _, _ = load_data(env['test_data_file']) print("Initializing VIN...") VIN = create_VIN( env['input_image_shape'], n_hidden_filters=150, n_state_filters=10, k=env['k'], ) print("Loading pre-trained VIN parameterss...") storage.load(VIN, env['pretrained_network_file']) plt.figure(figsize=(8, 8)) gridspec = gridspec.GridSpec(5, 4, height_ratios=[0, 2, 2, 2, 2]) gridspec.update(wspace=0.1, hspace=0.1) plt.suptitle('Trajectories between two points predicted by VIN ') plt.subplot(gridspec[0, :]) plt.legend( handles=[ mpatches.Patch(color='#A71C1B', label='Start'), mpatches.Patch(color='#F35D47', label='Trajectory'), mpatches.Patch(color='#007035', label='Goal'), ], loc=3, ncol=3, mode="expand", borderaxespad=0., bbox_to_anchor=(0., 1.02, 1., .102),
def for_2d_interpolation(ncfile, varname, file, max_depth, kxy=1): fig = plt.figure(figsize=(6, 9), dpi=100) gs = gridspec.GridSpec(3, 1) gs.update(left=0.07, right=0.99, hspace=0.4, wspace=0.05, bottom=0.05, top=0.95) axis = fig.add_subplot(gs[0]) axis2 = fig.add_subplot(gs[1]) axis3 = fig.add_subplot(gs[2]) #axis4 = fig.add_subplot(gs[3]) ds = xr.open_dataset(ncfile) df = ds.to_dataframe() df = df[[ 'date_time', 'var1', 'var2', 'var3', 'var4', 'var5', 'var6', 'var7', 'var9', 'var10', 'var12' ]] df.columns = [ 'date_time', 'var1', 'temp', 'sal', 'Oxygen', 'po4', 'si', 'no3', 'pH', 'chl', 'alk' ] cmap = plt.get_cmap('rainbow') # get colormap # Write name of variable to the text file with statistics file.write('\n{}'.format(varname)) # Data cleaning! Different for each case df['no3'] = df['no3'][df['no3'] < 17] df['po4'] = df['po4'][df['po4'] < 2.5] df['Oxygen'] = df['Oxygen'] * 44.6 df['alk'] = df['alk'] * 1000 df['Oxygen'] = df['Oxygen'][df['Oxygen'] > 200] df = df[df.date_time.dt.year > 1950] df['Date_of_year'] = df.date_time.dt.dayofyear.values # crate the 1d array with numbers of days in a year day_of_year = (np.array(df.date_time.dt.dayofyear.values)).flatten() #day = (np.array(df.date_time.dt.date.values)).flatten() depth2 = (np.array(df['var1'])).flatten() var2 = (np.array(df[varname])).flatten() # specify steps for interpolations for different vars steps = { 'Oxygen': 1, 'si': 0.1, 'alk': 1, 'chl': 0.01, 'po4': 0.5, 'no3': 0.1, 'pH': 0.01 } step = steps[varname] #Remove nans depth2_nan = depth2[~np.isnan(depth2)] var2_nan = var2[~np.isnan(depth2)] day_of_year_nan = day_of_year[~np.isnan(depth2)] depth2_nan = depth2_nan[~np.isnan(var2_nan)] var2_nan2 = var2_nan[~np.isnan(var2_nan)] day_of_year_nan = day_of_year_nan[~np.isnan(var2_nan)] vmax = np.nanmax(var2_nan2) vmin = np.nanmin(var2_nan2) file.write('\nMax over the whole period = {}'.format(vmax)) file.write('\nMin over the whole period = {}'.format(vmin)) # Create grid for linear 2d interpolation gridsize = 1 xi = np.arange(0, 366, gridsize) if varname == 'chl': yi = np.arange(0, max_depth, gridsize) else: yi = np.arange(0, max_depth, gridsize) z_griddata = griddata((day_of_year_nan, depth2_nan), var2_nan2, (xi[None, :], yi[:, None]), method='linear') #Create 2d arrays with new x,y for plotting X, Y = np.meshgrid(xi, yi) # Interpolation 1 way ##f_int2d = interpolate.interp2d(day_of_year_nan,depth2_nan,var2_nan2) ###zi_int2d = np.transpose(f_int2d(xi,yi)) # Interpolate with bivariate spline. kxy = level of int. 1 linear, 3 cubic f_biv_spline = interpolate.SmoothBivariateSpline(day_of_year_nan, depth2_nan, var2_nan2, kx=kxy, ky=kxy) z_biv_spline = np.transpose(f_biv_spline(xi, yi)) levels = np.arange(vmin, vmax - 1, step) axis.set_title('Long-term variability, raw data') for tick in axis.get_xticklabels(): tick.set_rotation(45) CS = axis.scatter(df.date_time.dt.date.values, depth2, c=var2, alpha=1, cmap=cmap, s=5) axis2.set_title('Seasonal variability, raw data') CS2 = axis2.scatter(day_of_year_nan, depth2_nan, c=var2_nan2, alpha=1, cmap=cmap, s=5, vmin=vmin, vmax=vmax) axis3.set_title('Seasonal variability, griddata') CS3 = axis3.scatter(X, Y, c=z_griddata, alpha=1, s=2, cmap=cmap) #,vmin = vmin, vmax = vmax) #CS3 = axis3.contourf(xi, yi,z_griddata,levels = levels ,cmap = cmap,vmin = vmin, vmax = vmax) # Different options to plot interpolated data #axis4.set_title('Seasonal variability, SmoothBivariateSpline') #CS4 = axis4.contourf(xi,yi,z_biv_spline, cmap= cmap) #,vmin = vmin,vmax = vmax) #CS4 = axis4.pcolormesh(xi,yi,z_griddata, cmap= cmap) #,vmin = vmin,vmax = vmax) if varname == 'pH': fig.suptitle(r'{}'.format(varname), y=0.995, size=14) else: fig.suptitle(r'{} $\mu M$'.format(varname), y=0.995, size=14) plt.colorbar(CS2, ax=axis2) plt.colorbar(CS, ax=axis) plt.colorbar(CS3, ax=axis3) #plt.colorbar(CS4, ax=axis4) for axis in (axis, axis2, axis3): #,axis4): axis.set_ylim(max_depth, 0) for axis in (axis2, axis3): #,axis4): axis.set_xlim(0, 365) axis.set_xlabel('Day in a year') fig.savefig('data/smeaheia_wod_2d_3{}.png'.format(varname)) #plt.show() plt.clf()
print "Received ->", recv_msg break return recv_msg if __name__ == "__main__": UDPServer = UDPServer() #recv_msg = UDPServer.tcpServer() #print "main recv_msg", recv_msg recv_msg = "2" plt.figure(num=None, figsize=(8, 6), dpi=100, facecolor='w', edgecolor='k') gs = gs.GridSpec(1, 1) gs.update(left=0.05, right=0.98, hspace=0.3) leftArm = plt.subplot(gs[:-1, -1]) leftArm.axis('scaled') plt.xticks(np.arange(0,80,20)) plt.xlim(0,80) plt.ylim(-80,80) leftArm.set_title('leftArm') larm = arm.arm_class(leftArm) plt.ion() plt.show() if recv_msg == "2": print "2" larm.arm_angle()