def random_xy(namelist_wps_filename, domain_number): ## Initialize the grid wps = nplt.wps_info(namelist_wps_filename) plt_idx = wps.plot_domain_number(domain_number) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x, length_y = wps.calc_wps_domain_info( ) ulat = corner_lat_full[plt_idx, 3] llat = corner_lat_full[plt_idx, 0] rlon = corner_lon_full[plt_idx, 3] llon = corner_lon_full[plt_idx, 0] # =========================TEST==================================================== #ulat= (45 + 0 / 60.0 + 0 / 3600.0) #*degrad #llat= (41 + 0 / 60.0 + 0 / 3600.0) #*degrad #rlon= (-1. * (104 + 0 / 60.0 + 0 / 3600.0) ) #*degrad #llon= ( -1. * (111 + 0 / 60.0 + 0 / 3600.0) ) #*degrad # ============================================================================= Latitude = [random.uniform(llat, ulat) for x in range(n)] Latitude = [l * degrad for l in Latitude] # put in radians for law of cosine Longitude = [random.uniform(llon, rlon) for x in range(n)] Longitude = [ll * degrad for ll in Longitude] # put in radians for law of cosine return Longitude, Latitude
def make_interp_grid(namelist_wps_filename, plot_domain_number): """ Use namelist file to recreate the grid and store it. returns ny by nx array for Latitude and Longitude at every gridpoint. returns the domain information in wps and the plt_idx or specific grid being used. """ wps = nplt.wps_info(namelist_wps_filename) plt_idx = wps.plot_domain_number(plot_domain_number) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x, length_y = wps.calc_wps_domain_info( ) corner_x, corner_y = nplt.wps_info.reproject_corners( corner_lon_full[plt_idx, :], corner_lat_full[plt_idx, :], wpsproj, latlonproj) nplt.wps_info.print_info() nx = wps.e_we[ plt_idx] # x direction #nx = 256 #% Number of grid points in the x direction ny = wps.e_sn[ plt_idx] # y direction #ny = 256 #%*2; % Number of grid points in the y direction print() n = int(ny * nx) grid_y = np.empty(n) grid_x = np.empty(n) print("nx: ", nx, " by ny: ", ny) count1 = 0 for i in range(ny): for j in range(nx): # x [grid_y[count1],grid_x[count1]] = wrf.xy_to_ll_proj(j, i, meta=False, map_proj=1, truelat1=wps.truelat1, truelat2=wps.truelat1, stand_lon=wps.stand_lon,\ ref_lat=wps.ref_lat, ref_lon=wps.ref_lon, pole_lat=wps.pole_lat, pole_lon=wps.pole_lon, known_x=wps.ref_x, known_y=wps.ref_y, dx=wps.dx[plt_idx], dy=wps.dy[plt_idx]) #Lat/Lon count1 += 1 # Reshape the lat/lon newLon = np.reshape(grid_x, [ny, nx]) #ROW BY COLUMN... ROW = Constant Lat newLat = np.reshape(grid_y, [ny, nx]) # Row By column.... Row = Changing Lon. return newLon, newLat, wps, plt_idx
def main(): """TEST CODE""" outdir = os.getcwd() + "/" #%% SAMPLE 1 - Plot All Domains print("Sample 1") # Include the directory/path is file located outside the working directory infile = 'namelist_THESIS.wps' wps = nplt.wps_info(infile) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x,\ length_y = wps.calc_wps_domain_info() ## SET UP PLOT fig1 = plt.figure(figsize=(10, 10)) ax1 = plt.axes(projection=wpsproj) #PLOT ALL DOMAINS nplt.wps_info.plot_all_domains(ax1, fig1, wps.max_dom, wpsproj, latlonproj,\ corner_lat_full, corner_lon_full, length_x, length_y) ax1.set_title('WRF 3-Nested Domain', size=20) fig1.savefig(outdir + 'WRF_DOMAIN_PLOT_THESIS.png', dpi=600) #plt.show() plt.close() #%% ## SAMPLE 2 - Plot a Single Domain print("Sample 2") ## SET INPUT DATA wpsfile = 'namelist_THESIS.wps' plot_domains = 3 ## GET/STORE WPS Data, Print Data, Get Plot Domain, Calculate Domain Info wps = nplt.wps_info(wpsfile) #wps.print_info() plt_idx = wps.plot_domain_number(plot_domains) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x,\ length_y = wps.calc_wps_domain_info() ## SET UP PLOT fig2 = plt.figure(figsize=(10, 10)) ax2 = plt.axes(projection=wpsproj) ## ADDING FEATURES ax2.coastlines('10m', 'black') ax2.add_feature(cartopy.feature.STATES.with_scale('10m')) ## REPORJECT corner_x, corner_y = nplt.wps_info.reproject_corners(corner_lon_full[plt_idx, :],\ corner_lat_full[plt_idx, :], wpsproj, latlonproj) ### ZOOM FUNCTION ns_zoom = 0 we_zoom = 0 corner_x, corner_y = nplt.wps_info.plot_zoom_in(corner_x, corner_y, ns_zoom, we_zoom) ######## ## SET DOMAIN LIMITS TO ZOOM ax2.set_xlim([corner_x[0], corner_x[3]]) ax2.set_ylim([corner_y[0], corner_y[3]]) #print(list(ax2.get_extent(cartopy.crs.PlateCarree()))) nplt.wps_info.set_lambert_ticks(ax2, xskip=1., yskip=1., x_thickness=14, y_thickness=14) ax2.set_title("WRF domain " + str(plot_domains), size=20) fig2.savefig(outdir + 'WRF_THESIS_PLOT.png', dpi=600) plt.close() #plt.show() #print("I'm not sure why the xtick and yticks aren't labeled.") #%% SAMPLE 3 - ZOOM IN ON A SINGLE DOMAIN print("Sample 3") plt_idx = wps.plot_domain_number(plot_domains) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x,\ length_y = wps.calc_wps_domain_info() ## SET UP PLOT #fig3 = plt.figure(figsize=(10, 10)) ax3 = plt.axes(projection=wpsproj) ## ADDING FEATURES ax3.coastlines('10m', 'black') ax3.add_feature(cartopy.feature.STATES.with_scale('10m')) ## REPORJECT corner_x, corner_y = nplt.wps_info.reproject_corners(corner_lon_full[plt_idx, :],\ corner_lat_full[plt_idx, :], wpsproj, latlonproj) ### ZOOM FUNCTION ns_zoom = 25 we_zoom = 40 corner_x, corner_y = nplt.wps_info.plot_zoom_in(corner_x, corner_y, ns_zoom, we_zoom) ######## ## SET DOMAIN LIMITS TO ZOOM ax3.set_xlim([corner_x[0], corner_x[3]]) ax3.set_ylim([corner_y[0], corner_y[3]]) ax3.set_title("WRF Domain " + str(plot_domains) + " Zoom In", size=20) #fig3.savefig('WRF_SAMPLE_SINGLE_DOMAIN_ZOOM_IN_PLOT.png', dpi=600) plt.show() plt.close() #%% SAMPLE 4 - ZOOM OUT ON A SINGLE DOMAIN print("Sample 4") plt_idx = wps.plot_domain_number(plot_domains) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x,\ length_y = wps.calc_wps_domain_info() ## SET UP PLOT #fig4 = plt.figure(figsize=(10, 10)) ax4 = plt.axes(projection=wpsproj) ## ADDING FEATURES ax4.coastlines('10m', 'black') ax4.add_feature(cartopy.feature.STATES.with_scale('10m')) ## REPORJECT corner_x, corner_y = nplt.wps_info.reproject_corners(corner_lon_full[plt_idx, :],\ corner_lat_full[plt_idx, :], wpsproj, latlonproj) ### ZOOM FUNCTION - FULL ZOOM OUT ns_zoom = 39 we_zoom = 39 corner_x, corner_y = nplt.wps_info.plot_zoom_out(corner_x, corner_y, ns_zoom, we_zoom) ax4 = nplt.wps_info.set_lambert_ticks(ax4, xskip=10., yskip=10.,\ x_thickness=14, y_thickness=14) ## SET DOMAIN LIMITS TO ZOOM ax4.set_xlim([corner_x[0], corner_x[3]]) ax4.set_ylim([corner_y[0], corner_y[3]]) ax4.set_title("WRF Domain " + str(plot_domains) + " Zoom Out", size=20) #fig4.savefig(outdir+'WRF_SAMPLE_SINGLE_DOMAIN_ZOOM_OUT_PLOT.png', dpi=600) plt.show() plt.close() #%% SAMPLE 5 - Not sure where I am going with this but showing how you can use the data print("Sample 5") wps = nplt.wps_info(wpsfile, True) #dx = wps.dx #% Distance between 2 points in x direction #dy = wps.dy #% Distance between 2 points in y direction n_xdir = np.empty(wps.max_dom) n_ydir = np.empty(wps.max_dom) for i in range(wps.max_dom): ### x direction #nx = 256 #% Number of grid points in the x direction n_xdir[i] = wps.e_we[i] - wps.j_parent_start[i] # y direction #ny = 256 #%*2; % Number of grid points in the y direction n_ydir[i] = wps.e_sn[i] - wps.i_parent_start[i] print() print() print("J Parents", wps.j_parent_start) print("I Parents", wps.i_parent_start) print("nx,ny: ", n_xdir, n_ydir) print() print() sys.exit(0) #%% SAMPLE 6 - Using an invalid namelist.wps name print("Sample 6 - Failure") infile = 'namelist.wps_failure' wps = nplt.wps_info(infile) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x,\ length_y = wps.calc_wps_domain_info()
FuniqueLat.append(float(CMLF_LAT[index2])) FuniqueLon.append(float(CMLF_LON[index2])) else: DuniqueName.append(stations[index]) DuniqueLat.append(float(lat[index])) DuniqueLon.append(float(lon[index])) #%% for isLabel in isLabelList: ## SET INPUT DATA wpsfile = 'namelist.wps' plot_domains = 3 ## GET/STORE WPS Data, Print Data, Get Plot Domain, Calculate Domain Info wps = nplt.wps_info(wpsfile) #wps.print_info() plt_idx = wps.plot_domain_number(plot_domains) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x, length_y = wps.calc_wps_domain_info( ) ## SET UP PLOT fig2 = plt.figure(figsize=(15, 20)) ax1 = plt.axes(projection=wpsproj) ## ADDING FEATURES ax1.coastlines('10m', 'black') ax1.add_feature(cartopy.feature.STATES.with_scale('10m')) ## REPORJECT corner_x, corner_y = nplt.wps_info.reproject_corners(
Is it possible to have gridlines and x/y ticks on increments of 1,5,10,etc. instead of based on the extent of the projection """ import namelist_plot as nplt #%% NOT USED DIRECTLY import numpy as np import cartopy from cartopy.feature import OCEAN, LAKES, LAND, NaturalEarthFeature import matplotlib.pyplot as plt #%% SAMPLE 1 - Plot All Domains print("Sample 1") # Include the directory/path is file located outside the working directory infile = 'namelist.wps' wps = nplt.wps_info(infile) wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x, length_y = wps.calc_wps_domain_info( ) ## SET UP PLOT fig1 = plt.figure(figsize=(10, 10)) ax1 = plt.axes(projection=wpsproj) #PLOT ALL DOMAINS nplt.wps_info.plot_all_domains(ax1, fig1, wps.max_dom, wpsproj, latlonproj, corner_lat_full, corner_lon_full, length_x, length_y) ax1.set_title('WRF 3-Nested Domain', size=20) fig1.savefig('WRF_DOMAIN_PLOT_COAWST.png', dpi=600) plt.show()