Code for mapping Spatial Distribution Average Daytime Temperature in Jupyter using WRF simulation (wrfout nc files)

32 views Asked by At

I would like to ask if anyone willing to share the coding for mapping the average daytime temperature using the output from wrfout (nc files) in jupyter.

I am using the xarray command to open the dataset and select the time that I needed.

nc = xr.open_dataset("D:/wrfout_d03_2010-06-30_00.00.00.nc") nc_temp = nc['T2'][40:209] #period of event in hourly (in total have 169 values of Time ~7dayx24hrs) My simulation have 229 values in total (considered as runtime). All values successfully

I am used to do the .sel or isel command but it is for one particular values. Same goes to the groupby and .mean and .loc command. How to manipulate this command to calculate average for daytime period (~12hrs) and plot the simulated as contour.

I am hoping to do the spatial average daytime temperature (~for example 3-day averaged or 7-day averaged, etc.).

Here is the command that I used to plot the simulated contour map for a particular time (in this case I choose 1500 LT). As mentioned, my intention is mapping the spatial average daytime temperature and produced the simulated contour map similar like this one.

##open the simulated model NETCDF file

nc = xr.open_dataset("D:/WRFSIM/WRFURBC1/yesSSTX/URB.nc")
nc_temp = nc['T2'][55,:,:] #2-m temp
deg_C = nc_temp - 273.15
print(deg_C.values)

nc_lat = nc['XLAT'][0,:,0]
nc_lon = nc['XLONG'][0,0,:]

#check the shape to know if we took out the correct data
print(nc_temp.shape)
print(nc_lat.shape)
print(nc_lon.shape)
    
X, Y = np.meshgrid(nc_lon, nc_lat)

#This section plot figure

from matplotlib.cm import get_cmap
cmap1 = get_cmap("Reds")
fig, ax = plt.subplots(figsize=(10,7))

#plot simulated (as contour)
cont = ax.contourf(X,Y, deg_C, cmap=cmap1, extend='both')
cbar = fig.colorbar(cont, ax=ax)
cbar.set_label('Temperature ($^\circ$C)', labelpad=+1, fontsize=14)
    
#add xlabel, title
ax.set_title('WRF Simulated 2-m Temp. at July 2, 2010 (1500LT)', fontsize=16)
ax.set_xlabel("Longitude", fontsize=14)
ax.set_ylabel("Latitude", fontsize=14)

#finally show the figure
print("max temp:", np.max(deg_C.values))
print("min temp:", np.min(deg_C.values))

plt.grid()
plt.tight_layout()
plt.show()

WRF Simulated 2-m Temp

Thank you in advanced.

0

There are 0 answers