if 'ERA5_metOcean_atm' in file_nc: data_fromnc_x_1D = get_ncmodeldata(file_nc=file_nc, varname='longitude') data_fromnc_y_1D = get_ncmodeldata(file_nc=file_nc, varname='latitude') data_fromnc_x, data_fromnc_y = np.meshgrid(data_fromnc_x_1D, data_fromnc_y_1D) else: data_fromnc_x = get_ncmodeldata(file_nc=file_nc, varname='x') data_fromnc_y = get_ncmodeldata(file_nc=file_nc, varname='y') vars_pd, dims_pd = get_ncvardimlist(file_nc=file_nc) x_cen_withbnd = center2corner(data_fromnc_x) y_cen_withbnd = center2corner(data_fromnc_y) grid_verts = meshgridxy2verts(x_cen_withbnd, y_cen_withbnd) fig, axs = plt.subplots(2,1, figsize=(10,9)) ax = axs[0] ax.set_title('xy center data converted to xy corners') ax.plot(data_fromnc_x,data_fromnc_y, linewidth=0.5, color='blue') ax.plot(data_fromnc_x.T,data_fromnc_y.T, linewidth=0.5, color='blue') ax.plot(x_cen_withbnd,y_cen_withbnd, linewidth=0.5, color='crimson') ax.plot(x_cen_withbnd.T,y_cen_withbnd.T, linewidth=0.5, color='crimson') ax.set_aspect('equal') ax = axs[1] ax.set_title('xy corner data converted to vertices (useful for map plotting)') plot_netmapdata(grid_verts, values=None, ax=ax, linewidth=0.5, color='crimson', facecolor='None') ax.set_aspect('equal') fig.tight_layout() plt.savefig(os.path.join(dir_output,'%s_grid'%(os.path.basename(file_nc).replace('.',''))))
val_ylim = None clim_bl = [-10, 10] #optimize_dist = 150 else: raise Exception('ERROR: no settings provided for this mapfile') ugrid = get_netdata(file_nc=file_nc, multipart=multipart) #get bedlevel and create plot with ugrid and cross section line data_frommap_bl = get_ncmodeldata(file_nc=file_nc, varname='mesh2d_flowelem_bl', multipart=multipart) fig, ax_input = plt.subplots() pc = plot_netmapdata(ugrid.verts, values=data_frommap_bl, ax=ax_input, linewidth=0.5, edgecolors='face', cmap='jet') #, color='crimson', facecolor="None") pc.set_clim(clim_bl) fig.colorbar(pc, ax=ax_input) ax_input.set_aspect('equal') if 0: #click interactive polygon #pol_frominput = Polygon.frominteractive(ax) #this is old, does not work, use code below line, = ax_input.plot([], [], 'o-') # empty line linebuilder = LineBuilder( line) #after this click your line and then run the line below line_array = linebuilder.line_array ax_input.plot(line_array[0, 0], line_array[0, 1], 'bx', linewidth=3,
file = 'p:\\1221207-kuweit-iczm-marshlands\\02_Marshlands\\task_5D_-_Water_Quality\\02_modelSetup\\03_loads\\UAE_diffuse_loads.def' grd = 'p:\\1221207-kuweit-iczm-marshlands\\02_Marshlands\\task_5C_-_Sediment_Transport\\model_setup\\coupling\\final\\aggregations\\7_zones_4x4\\7_zones_4x4_waqgeom.nc' #grd = r'p:\1221207-kuweit-iczm-marshlands\02_Marshlands\task_5D_-_Water_Quality\02_modelSetup\T04\7_zones_4x4_waqgeom.nc' segs = dict() with open(file, 'r') as def_file: lines = def_file.readlines() for line in lines: if "'" in line: tmp = line.split(' ') segs[tmp[2]] = int(tmp[0]) fig, ax = plt.subplots() ugrid = get_netdata(grd) pc = plot_netmapdata(ugrid.verts, values=None, ax=None, linewidth=0.5, color="crimson", facecolor="None") ax.set_aspect(1./np.cos(np.mean(ax.get_ylim())/180*np.pi),adjustable='box') # see Matlab axislat() show_waq_segment(grd, 8, segs) grd = 'p:\\11202512-h2020_impaqt\\03_waterquality\\03_baseCase\\RT_spin\\NZB_waqgeom_UGRID.nc' segs = {'module_1 (11)': 448023, 'module_1 (12)': 491961, 'module_1 (13)': 535899} fig, ax = plt.subplots() ugrid = get_netdata(grd) pc = plot_netmapdata(ugrid.verts, values=None, ax=None, linewidth=0.5, color="crimson", facecolor="None") show_waq_segment(grd, 20, segs)
for iP, station in enumerate(data_fromhis_wl.var_stations['station_name']): ax.plot(data_fromhis_wl.var_times, data_fromhis_wl[:, iP], '-', label=station) ax.legend() ax.set_ylabel( '%s (%s)' % (data_fromhis_wl.var_varname, data_fromhis_wl.var_ncvarobject.units)) #plot net/grid ugrid_all = get_netdata(file_nc=file_nc_map) #,multipart=False) fig, ax = plt.subplots() pc = plot_netmapdata(ugrid_all.verts, values=None, ax=None, linewidth=0.5, color="crimson", facecolor="None") ax.set_aspect('equal') #plot water level on map data_frommap_wl = get_ncmodeldata(file_nc=file_nc_map, varname='mesh2d_s1', timestep=3) #, multipart=False) fig, ax = plt.subplots() pc = plot_netmapdata(ugrid_all.verts, values=data_frommap_wl[0, :], ax=None, linewidth=0.5, cmap="jet") pc.set_clim([-0.5, 1])
facey = get_ncmodeldata(file_nc=file_nc, varname='mesh2d_face_y') X, Y, U = scatter_to_regulargrid(xcoords=facex, ycoords=facey, ncellx=60, ncelly=35, values=ux_mean) X, Y, V = scatter_to_regulargrid(xcoords=facex, ycoords=facey, ncellx=60, ncelly=35, values=uy_mean) #thinning = 3 fig1, ax1 = plt.subplots(figsize=(9, 5)) pc1 = plot_netmapdata(ugrid_all.verts, magn_mean, edgecolor='face') #ax1.quiver(facex[::thinning], facey[::thinning], ux_mean[::thinning], uy_mean[::thinning], color='w',scale=20)#,width=0.005)#, edgecolor='face', cmap='jet') ax1.quiver(X, Y, U, V, color='w', scale=5) #,width=0.005)#, edgecolor='face', cmap='jet') pc1.set_clim([0, 0.10]) #ax1.set_title('sqrt(x^2+y^2)\nx=%s\ny=%s'%(ux_mean.var_ncvarobject.long_name,uy_mean.var_ncvarobject.long_name)) ax1.set_aspect('equal') ax1.set_xlabel('RD x [m]') ax1.set_ylabel('RD y [m]') cbar = fig1.colorbar(pc1) cbar.set_label('residuele stroming [m/s]') fig1.tight_layout() fig1.savefig( os.path.join(dir_output, os.path.basename(file_nc).replace('.', '')))
file_nc= 'C:\\Users\\backeber\\OneDrive - Stichting Deltares\\Desktop\\Project-D-HYDRO-Phase-4\\dflowfm\\dflowfm_serial\\DFM_OUTPUT_oceaneddy_expt00\\oceaneddy_expt00_map.nc' ) #ugrid_all = get_netdata(file_nc=fname) ds = xr.open_dataset(fname) ssh = get_ncmodeldata(file_nc=fname, varname='s1', timestep=0) # find location of max ssh to add to plot maxi = np.argmax(ssh) fig, ax = plt.subplots() #(figsize=(15, 10)) pc = plot_netmapdata(ugrid_all.verts, values=ssh[0, :], ax=ax, linewidth=0.5, cmap="jet") #pc.set_clim([0, 0.05]) x, y = ugrid_all.verts[maxi, :, :].mean(axis=0) ax.plot(x, y, 'wx') ax.set_title('%s (%s)' % (ds.s1.long_name, ds.s1.units)) ax.set_aspect('equal') fig.colorbar(pc, ax=ax) xticks = np.linspace(np.min(ds.FlowElem_xzw.data), np.max(ds.FlowElem_xzw.data), num=5, endpoint=True) yticks = np.linspace(np.min(ds.FlowElem_yzw.data), np.max(ds.FlowElem_yzw.data), num=5,
import matplotlib.pyplot as plt plt.close('all') from dfm_tools.get_nc import get_netdata, get_ncmodeldata, plot_netmapdata dir_testinput = r'c:\DATA\dfm_tools_testdata' file_nc = os.path.join(dir_testinput,'oost_tracer_2_map.nc') ugrid = get_netdata(file_nc=file_nc) print('plot grid and values from mapdata (constantvalue, 1 dim)') if 'oost_tracer_map' in file_nc: var_names = ['FColi1','HIWAI1','mspaf1','Pharma1'] #nieuwe file, te veel dimensies var_clims = [None,[0,100000000000],None,[0,10000]] elif 'oost_tracer_2_map' in file_nc: var_names = ['mesh2d_FColi','mesh2d_HIWAI','mesh2d_Pharma'] #oude file var_clims = [None,[0,100000000000],[0,10000]] else: raise Exception('ERROR: no settings provided for this mapfile') for var_name, var_clim in zip(var_names, var_clims): fig, ax = plt.subplots() data_frommap = get_ncmodeldata(file_nc=file_nc, varname=var_name)#, multipart=False) pc = plot_netmapdata(ugrid.verts, values=data_frommap, ax=None, linewidth=0.5, cmap="jet") if var_clim != None: pc.set_clim(var_clim) fig.colorbar(pc, ax=ax) ax.set_aspect('equal') ax.set_xlabel(var_name) plt.savefig('%s_%s'%(os.path.basename(file_nc).replace('.',''),var_name))
ugrid = get_netdata(file_nc=file_nc) varname = 'mesh2d_mor_bl' var_clims = [-50, 0] var_longname = vars_pd['long_name'][vars_pd['nc_varkeys'] == varname].iloc[0] fig, axs = plt.subplots(3, 1, figsize=(6, 9)) fig.suptitle('%s (%s)' % (varname, var_longname)) ax = axs[0] data_frommap_0 = get_ncmodeldata(file_nc=file_nc, varname=varname, timestep=0, get_linkedgridinfo=True) pc = plot_netmapdata(ugrid.verts, values=data_frommap_0.flatten(), ax=ax, linewidth=0.5, cmap='jet', clim=var_clims) cbar = fig.colorbar(pc, ax=ax) cbar.set_label( '%s (%s)' % (data_frommap_0.var_varname, data_frommap_0.var_ncattrs['units'])) ax.set_title('t=0 (%s)' % (data_frommap_0.var_times.iloc[0])) ax = axs[1] data_frommap_end = get_ncmodeldata(file_nc=file_nc, varname=varname, timestep=-1) pc = plot_netmapdata(ugrid.verts, values=data_frommap_end.flatten(), ax=ax,
) ugrid = get_netdata(file_nc=file_nc_map) data_frommap_bl = get_ncmodeldata(file_nc=file_nc_map, varname='mesh2d_flowelem_bl') source_list = [ ctx.providers.Stamen.Terrain, #default source ctx.providers.Esri.WorldImagery, ctx.providers.CartoDB.Voyager, #ctx.providers.NASAGIBS.ViirsEarthAtNight2012, ctx.providers.Stamen.Watercolor ] for source_ctx in source_list: source_name = source_ctx['name'].replace('.', '_') fig, ax = plt.subplots(1, 1, figsize=(10, 6)) pc = plot_netmapdata(ugrid.verts, values=data_frommap_bl, ax=ax, linewidth=0.5, cmap='jet') fig.colorbar(pc, ax=ax) fig.tight_layout() ctx.add_basemap(ax, source=source_ctx, crs="EPSG:28992", attribution_size=5) fig.savefig( os.path.join(dir_output, 'contextily_grevelingen_RD_%s' % (source_name)))
ssh12 = ds12.mesh2d_s1.data[i, :] ssh13 = ds13.mesh2d_s1.data[i, :] ssh14 = ds14.s1.data[i, :] maxi11 = np.argmax(ssh11) maxi12 = np.argmax(ssh12) maxi13 = np.argmax(ssh13) maxi14 = np.argmax(ssh14) x11[i], y11[i] = ugrid_all11.verts[maxi11, :, :].mean(axis=0) x12[i], y12[i] = ugrid_all12.verts[maxi12, :, :].mean(axis=0) x13[i], y13[i] = ugrid_all13.verts[maxi13, :, :].mean(axis=0) x14[i], y14[i] = ugrid_all14.verts[maxi14, :, :].mean(axis=0) fig, axs = plt.subplots(1, 2, figsize=(15, 5)) pc = plot_netmapdata(ugrid_all11.verts, values=None, ax=axs[0], linewidth=0.1, color="gray", facecolor="None") axs[0].set_aspect('equal') axs[0].plot(x11, y11, '-', label='Expt 11') axs[0].set_title('Beta plane expt') xticks = np.linspace(np.min(ds11.mesh2d_node_x.data), np.max(ds11.mesh2d_node_x.data), num=5, endpoint=True) yticks = np.linspace(np.min(ds11.mesh2d_node_y.data), np.max(ds11.mesh2d_node_y.data), num=5, endpoint=True) axs[0].set_xticks(xticks) axs[0].set_xlabel('%s (%s)' %
clim_bl = [-10, 10] clim_wl = [-2, 2] clim_sal = None clim_tem = None else: raise Exception('ERROR: no settings provided for this mapfile') vars_pd, dims_pd = get_ncvardimlist(file_nc=file_nc) #PLOT GRID print('plot only grid from mapdata') ugrid_all = get_netdata(file_nc=file_nc) #,multipart=False) fig, ax = plt.subplots() pc = plot_netmapdata(ugrid_all.verts, values=None, ax=None, linewidth=0.5, color="crimson", facecolor="None") ax.set_xlabel('x-direction') ax.set_ylabel('y-direction') ax.set_aspect('equal') fig.tight_layout() fig.savefig( os.path.join(dir_output, '%s_grid' % (os.path.basename(file_nc).replace('.', '')))) #PLOT bedlevel if not 'cb_3d_map' in file_nc: print('plot grid and values from mapdata (constantvalue, 1 dim)') ugrid = get_netdata(file_nc=file_nc) #,multipart=False) #iT = 3 #for iT in range(10):