I have been working on radar data file with netcdf as file format, the file is structured such that within the year directory is the month directory and within it is the day directory, and within the day directory are the files with inconsistent time increment of scan. I want to get the hourly average reflectivity and is using the glob to scan through the directories and list the files and filter it with the second elevation volume scan of the horizontal reflectivity. below is the code i'm working on:
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