I first downloaded NetCDF4 data from this website. Now, I wanted to make the file more cloud friendly so I converted it into CSV. After that, my rows and columns in the CSV looked like this.
Now, I want to make a plot which will plot an image which will be similar to the earth plot in this link. The only difference is that they are plotting the plot directly from the netCDF4 file without converting it into CSV but I am trying to plot it after converting to CSV. I want to show the TLML values in the Earth plot.
If anyone is interested, this is how I converted my netCDF4 file into CSV.
import xarray as xr
file = "C:/Users/xyz/plotting-try/MERRA2_400.inst1_2d_lfo_Nx.20220203.nc4"
nc = xr.open_dataset(file)
nc.TLML[1,:,:].to_dataframe().to_csv('T2M.csv')
Can anyone help me on the plotting part? As mentioned, I want to plot it similar to how it was shown in the above link, just that I want to plot it using my CSV file.
If you want to download the netCDF4 file on your system, you can download it here. However, you'll first need to create an account on the Nasa website.
Edit: I have tried the below code but it isn't working.
df = pd.read_csv('T2M.csv')
lat = df['lat']
lon = df['lon']
time = df['time']
T2M = df['TLML']
fig = plt.figure(figsize=(8,4))
ax = plt.axes(projection=ccrs.Robinson())
ax.set_global()
ax.coastlines(resolution="110m",linewidth=1)
ax.gridlines(linestyle='--',color='black')
clevs = np.arange(576,361,24)
plt.contourf(lon, lat, T2M, clevs, transform=ccrs.PlateCarree(),cmap=plt.cm.jet)
plt.title('MERRA-2 Air Temperature at 2m, January 2010', size=14)
cb = plt.colorbar(ax=ax, orientation="vertical", pad=0.02, aspect=16, shrink=0.8)
cb.set_label('K',size=12,rotation=0,labelpad=15)
cb.ax.tick_params(labelsize=10)
fig.savefig('MERRA2_t2m.png', format='png', dpi=360)
This throws an error that TypeError: Input z must be 2D, not 1D
. And it throws on this line: plt.contourf(lon, lat, T2M, clevs, transform=ccrs.PlateCarree(),cmap=plt.cm.jet)
I'm not even sure whether the conversion into CSV format is done correctly. Anyone who has an experience working with these kind of files, please help me on this.