这里可能会遇到问题,这里有可能有两种问题,一个是C语言编译器的问题,下载安装Microsoft Visual Studio Community 2017然后再运行一下这句话就好了;另一种就是GDAL的问题。
GDAL(Geospatial Data Abstraction Library)是一个在X/MIT许可协议下的开源栅格空间数据转换库,可以参考大佬翻译的这份中文教程https://www.osgeo.cn/python_gdal_utah_tutorial/index.html来学习一下。之前电脑上没有安装过python相关的东西的话一般不会遇到这个问题。如果你是在windows平台,那么我推荐你来安装OSGeo4W来搞定这个问题https://trac.osgeo.org/osgeo4w/;除此之外,还有两种方法,一个是你重新搞个环境,不要加入之前的包再来安装一次,另一个是下载whl文件来安装。
import netCDF4 as nc4 import numpy as np from collections import OrderedDict from geo_Collection import geo_web as gs from QAAV6 import QAAv6 minlat = 32.5 minlon = 130.5 maxlat = 35 maxlon = 136 # area of full seto-inland sea x = np.arange(minlon, maxlon, 0.01) # 1 km grid, y = np.arange(maxlat, minlat, -0.01) nc_file = nc4.Dataset(filename, 'r') lon = nc_file.groups['navigation_data'].variables['longitude'][:] lat = nc_file.groups['navigation_data'].variables['latitude'][:] variables = nc_file.groups['geophysical_data'].variables for i in variables: var = variables[i][:] np.where(var <= 0, var, np.nan) if i != 'l2_flags': var_re, grid = gs.swath_resampling(var, lon, lat, x, y, 5000) # 1 km grid # var_re=var_re.filled() if np.ma.is_mask(var_re): var_re.mask=np.ma.nomask var_re[var_re==-32767.0]=np.nan variables[i] = var_re else: # var_re = var_re.filled() variables[i] = var lons = grid.lons lats = grid.lats #以叶绿素为例 chl = variables['chlor_a'] plot_geo_image(chl, lon, lat, label='CHL [mg/m$^3$]', title=os.path.basename(file)) ncfile.close()#一定要记得这句
import pyresample import numpy as np from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt from matplotlib import colors import math from scipy.interpolate import RectSphereBivariateSpline from matplotlib.colors import LogNorm #from deco import * defswath_resampling(src_data: np.ma.array, src_lon: np.array, src_lat: np.array, trg_lon: np.array, trg_lat: np.array, search_radius: float): iflen(trg_lon.shape) == 1: grid_def = pyresample.geometry.SwathDefinition(*np.meshgrid(trg_lon, trg_lat)) else: grid_def = pyresample.geometry.SwathDefinition(lons=trg_lon, lats=trg_lat)
#source grid with original swath data # if len(src_lon.shape) == 1: # swath_def = pyresample.geometry.SwathDefinition(*np.meshgrid(src_lon, src_lat,sparse=True)) # else: # swath_def = pyresample.geometry.SwathDefinition(lons=src_lon, lats=src_lat)
swath_def = pyresample.geometry.SwathDefinition(lons=src_lon, lats=src_lat) # resample (here we use nearest. Bilinear, gaussian and custom defined methods are available) # for more, visit https://pyresample.readthedocs.io/en/latest/ result = pyresample.kd_tree.resample_nearest(swath_def, src_data, grid_def, epsilon=0.5, fill_value=np.nan, radius_of_influence=search_radius) return result, grid_def
#@concurrent defplot_geo_image(sds: np.ma.array, lon: np.ndarray, lat: np.ndarray, log10: bool = True, title: str = None, label: str = None, caxis: list = None, lon_range: list = None, lat_range: list = None, save_image: str = None, dpi: int = 400): iflen(lon.shape) == 1: print('MeshGridding...') lon, lat = np.meshgrid(lon, lat)
cb = m.colorbar(p,location="right",size="5%",pad=0.1) # draw colorbar #if label is not None: # cb.set_label("%s" % label) # plt.sca(ax) # make the original axes current again # plt.clim(cmn, cmx) #unit='Elevation to the sea level' #cb.set_label(unit, rotation=270, labelpad=10.0, fontsize=10) cb.ax.tick_params(labelsize=10)
if save_image isnotNone: plt.savefig(save_image, dpi=dpi, facecolor='w', edgecolor='w', orientation='portrait') plt.show() plt.close()
defcreategrid(min_lon, max_lon, min_lat, max_lat, cell_size_deg, mesh=False): #Output grid within geobounds and specifice cell size #cell_size_deg should be in decimal degrees’’’
# source /Users/zhenjia/.bash_profile #先运行上面这个文件来搞定全局变量 #Example script to process L1A files up to L2, put in same directory as # your L1A files # Run script by typing on Terminal Command Line: # bash l1a_to_l2.sh input.txt # input.txt contains list of files [ create by: ls -1 *L1A_LAC* > input.txt ]
LIST=$1 if [ -z "$LIST" ] then echo"No input file list supplied" exit 1 fi
if [[ ! -a $LIST ]]; then echo"$LIST does not exist!" exit 1 fi