Untitled
unknown
plain_text
a year ago
998 B
2
Indexable
Never
import xarray as xr import cartopy.crs as ccrs import matplotlib.pyplot as plt hdf_file = "/srv/ccrc/RegClim2/z3540003/Winter_School/MOD13Q1.A2023001.h31v11.006.2023018081419.hdf" data = xr.open_dataset(hdf_file, engine="netcdf4") # Extract the coordinates and data for the region with valid data valid_data = data["250m 16 days NDVI"] valid_data = valid_data.where(valid_data != -3000) # Assuming -3000 is the fill value # Get the region's coordinates x = valid_data.coords["XDim"].values y = valid_data.coords["YDim"].values # Create a figure and plot the data using PlateCarree projection fig = plt.figure(figsize=(8, 8)) ax = plt.axes(projection=ccrs.PlateCarree()) ax.coastlines() im = ax.imshow(valid_data, extent=(x.min(), x.max(), y.min(), y.max()), origin="upper", transform=ccrs.PlateCarree()) # Customize the plot plt.colorbar(im, ax=ax, label="NDVI") ax.set_title("MODIS NDVI for Region with Data") ax.set_xlabel("Longitude") ax.set_ylabel("Latitude") # Show the plot plt.show()