我一直在使用netcdf作为文件格式来处理雷达数据文件,该文件的结构使得在year目录内是month目录,在其内是day目录,在day目录内是时间不一致的文件扫描增量。我想获取每小时的平均反射率,并且正在使用glob扫描目录并列出文件,并使用水平反射率的第二次高程体积扫描对其进行过滤。 以下是我正在处理的代码:
import datetime as dt
import glob
import netCDF4 as nc
import numpy as np
startdate = dt.datetime(2015, 01, 01, 00, 00, 00)
enddate = dt.datetime(2015, 01, 02, 00, 00, 00)
interval = dt.timedelta(hours=1)
ctr = 0
sub_hour_ave = np.zeros((360,240))
while startdate != enddate:
for i in range(24):
denominator = 0
hourly_files = glob.glob('C:\\Users\\User\\Documents\\sample\\Subic\\'+str(startdate.year)+'\\'+\
str(startdate.month).zfill(2)+'\\'+str(startdate.day).zfill(2)+'\\SUB-'+str(startdate.year)+''\
+str(startdate.month).zfill(2)+''+str(startdate.day).zfill(2)+ "-" + str(i).zfill(2) + '*-02-ZH.nc')
for files in hourly_files:
sub_nc = nc.Dataset(files)
sub_data = np.array(sub_nc.variables['Filtered_Intensity(Horizontal)'])
sub_data[sub_data = -99900] = np.isnan()
sub_data += sub_data
denominator += 1
sub_hour_ave = sub_data/denominator
startdate += interval