我一直在尝试找到一种使用Python自动执行MODIS Aqua SST 2级产品的方法。我已经编写了一个代码,该代码将分别遍历每个文件并生成我想要的最终产品,但这非常耗费人工,因为我必须手动将不同的文件名放入代码中:
data_path_windows = "EUMETSAT\\False_Bay" #where my data is
input_root = "G:\EUMETSAT\False_Bay\MODIS_Aqua\SST" #where my data is
file_variables = "A2015121125000.L2_LAC_SST_Var.nc" #first file
file_crds = "A2015121125000.L2_LAC_SST_Var.nc"
SST_file = nc.Dataset(os.path.join(data_path_windows,input_root,file_variables),'r')
GEO_file = nc.Dataset(os.path.join(data_path_windows,input_root,file_crds), 'r')
SST = SST_file.variables['sst'][:].data #variable
FLAG= SST_file.variables['l2_flags']
fillval = SST_file.variables['sst']._FillValue
SST[SST == fillval] = np.nan
file_name_geo = "A2015121125000.L2_LAC_SST_Var.nc" #lat, lon subsetting
LAT = GEO_file.variables['latitude'][:]
LON = GEO_file.variables['longitude'][:]
x = LON
y = LAT
m = Basemap(projection='gall',llcrnrlat=-34.5,urcrnrlat=-34,llcrnrlon=18.25,urcrnrlon=19,resolution='h')
x, y = m(LON, LAT)
fig = plt.figure(figsize= (17, 10), dpi=300)
m.fillcontinents(color='gray',lake_color='gray')
m.drawcoastlines()
parallels = np.arange(-34.5,-34.,.1) #grid lines
m.drawparallels(parallels,labels=[False,True,True,False], fontsize=20)
meridians = np.arange(18.,19.,.1) #grid lines
m.drawmeridians(meridians,labels=[True,False,False,True], fontsize=20)
f1=m.contourf(x,y,np.ma.masked_invalid(SST),np.arange(8,25,2), vmin=8,
vmax=25,cmap=cm.viridis)
cbar = m.colorbar(f1,"bottom",size="5%",pad="7%")
cbar.set_label('Sea Surface Temperature, $^{o}$ C', fontsize=10) #labels color bar
plt.title('May 1, 2015 SST', fontsize =10) #title of the plot
plt.savefig('SST_MODIS_2015_5_1.png', dip=1000) #daily output for SST
然后通过更改以下变量来每天重复。...
file_variables = "A2015122115500.L2_LAC_SST_Var.nc"
file_crds = "A2015122115500.L2_LAC_SST_Var.nc"
...
file_name_geo = "A2015122115500.L2_LAC_SST_Var.nc"
...
plt.title('May 2, 2015 SST', fontsize =10) #title of the plot
plt.savefig('SST_MODIS_2015_5_2.png', dip=1000)
依此类推。
是否可以让代码自动调用列表中的下一个文件以生成第二天的子文件?
我知道在Matlab中我可以循环代码进行分析,但是仍然不确定在Python中如何生成每日值和图像。任何使该过程更加简化和自动化的建议将不胜感激。谢谢。