====== ENVI-met powered by python ====== Visualizing netCDF outputs in python offers a quick and flexible solution for exploring ENVI-met's model output files. By using python libraries such as matplotlib, you can seamlessly load and display netCDF files. Here is some sample code: import matplotlib.pyplot as plt import netCDF4 def plot_map(netCDFfile, varName): nc = netCDF4.Dataset(netCDFfile) # path to your ENVI-met netCDF output file e.g. "T:/enviprojects/Berlin/output/NetCDF/Berlin_12.5_AT_2021-07-07_06.00.01.nc" print(nc.variables.keys()) # shows all available variables e.g. "Potential_Air_Temperature", "Relative_Humidity" print(len(nc.variables['Time'])) # shows how many timesteps are inside the netCDF output dataAr = nc.variables[varName][5][1][:][:] # first index is the output timestep (here 5), second index is the height level (here 1) gridJAr = nc.variables['GridsJ'][:] gridIAr = nc.variables['GridsI'][:] fig, ax = plt.subplots(figsize=(10*len(gridIAr) / len(gridJAr), 10)) # determines the resolution of the figure ax.set_aspect(1) # scales the aspect ratio contour = plt.contourf(gridIAr, gridJAr, dataAr, cmap=twilight_shifted, levels=100) # cmap defines the colorramp, levels defines the number of color gradients plt.colorbar(contour, ax=ax, label=varName, location='right', shrink=0.4) # defines the legend plt.title('ENVI-met powered by python') # adds a title plt.xlabel('meters') # adds the x label plt.ylabel('meters') # adds the y label #plt.figtext(0.5, 0.01, 'footnote center', ha='center', va='center', fontsize='small') # option to add a centered footnote #plt.figtext(0.98, 0.02, 'footnote right', ha='right', va='bottom', fontsize='small') # option to add a footnote on the lower right corner # Show the plot plt.show() # shows the plot #plt.savefig('D:/_images/' + varName + '.png', bbox_inches=0) # option to save the figure #plt.close()