Размещать данные NETCDF только для области интереса в python? - PullRequest
1 голос
/ 23 января 2020

ниже - мой код для вывода данных из файла netcdf. Тем не менее, я могу нанести данные с помощью базовой карты для всего мира. Я вставляю шейп-файл xxxxxx через модуль базовой карты, и моя цель состоит в том, чтобы нанести на указанную c область

### Import libraries###

import matplotlib.pyplot as plt 
from mpl_toolkits.basemap import Basemap
from netCDF4 import Dataset
import numpy as np


### opening NETCDF dataset MERRA###

file = 'C:.../Python_Notebook/NETCDF/MERRA2_400.statD_2d_slv_Nx.20190101.nc4'
fh = Dataset(file, mode = 'r')


### Get variables ###
# Read in 'T2M' 2-meter air temperature variable.
lons = fh.variables['lon'][:] # get longitude variables
lats = fh.variables['lat'][:] # get latitude variables
tmean = fh.variables['T2MMEAN'][:,:,:] - 273.15 # get tmean variable with conversion K for °C 

### meshgrid ###

m=Basemap(projection='cyl',llcrnrlat=-20,urcrnrlat=-5,llcrnrlon=-63,urcrnrlon=-48)
lon, lat = np.meshgrid(lons, lats) # create a matrix of coordinates
xi, yi = m(lon, lat)

# Plot Data

fig,ax=plt.subplots(figsize=(20,10))
cs = m.contourf(xi,yi,np.squeeze(tmean),  cmap='rainbow') 

### Draw ### 
m.readshapefile(MTshp, name="Mt") # draw shapefile State of Mato Grosso Brazil
#m.drawcoastlines()
#m.drawcountries()
#m.drawstates()

### Draw Coordinates ###

m.drawparallels(np.arange(-80, 80, 5), labels=[1,0,0,0]) # draw parallels
m.drawmeridians(np.arange(-180, 180, 5), labels=[0,0,0,1]) # draw meridians

# Add Colorbar
cbar = m.colorbar(cs, location='right', pad="15%")
cbar.set_label('°C') # tmean units

### Labels ###
plt.xlabel('Longitude', fontweight='bold', labelpad=15)
plt.ylabel('Latitude', fontweight='bold', labelpad=25)

### Add Title ###
plt.title('01-01-2019 Mean Temperature', fontweight='bold', fontsize=12)

# Show the plot
plt.show()

, что я должен сделать, чтобы построить данные netcdf только в моем шейп-файле? какую процедуру я должен сделать? можешь помочь мне? пожалуйста? Я благодарю вас за понимание

...