def read (files,save): """ ingest RWP NIMA processed Data from the NCAR NetCDFs each file here is a day, with times as an element! This will use for loops, and it will go slowly... """ # then create the new file unless save is a file handle, in which case just save to that doc = h5(save) # establish the hdf5 object. doc.create(wspd=38,wdir=38,height=38,wvert=38,u=38,v=38,w=38,snrw=38,sw=38,edr=38) print "Finding RWP Files"; for file_dir in sorted(files): fname = file_dir.split("/")[-1] if 'mom' in fname or 'rass' in fname: continue #rass and moment riffraf. print file_dir try: nc = ncf(file_dir) except: # something there did not work, either in the name, or in the netcdf reading in general continue # check to make sure this is the right kind of data, a full 38 obs l = nc.dimensions['height'] if l > 38: nc.close() continue begin = s2t(getattr(nc,'Data_start_time'),'%a %b %d %H:%M:%S %Y %Z') #should work for PCAPS data for t in range(len(nc.variables['time'][:])): obtime = begin + nc.variables['time'][t] # now fetch all the desired variables and save them! wspd = nc.variables['wspd'][t] wdir = nc.variables['wdir'][t] wvert = nc.variables['wvert'][t] height = nc.variables['heights'][t] snrw = nc.variables['snrw'][t] u = nc.variables['u_classicC'][t] # constant, vs linear v = nc.variables['v_classicC'][t] # ditto w = nc.variables['w_classicC'][t] # ditto snrw = nc.variables['snrw'][t] sw = nc.variables['specWid'][t] edr = nc.variables['edr'][t] # eddy dissipation rate print "Appending",obtime doc.append(obtime,persist=True,wspd=wspd,wdir=wdir,height=height,snrw=snrw,u=u,v=v,w=w,sw=sw,edr=edr) nc.close() doc.close() return True
def rwp (files,variable='wspd',nanvalue=nan,save=True): """ ingest RWP Data from the NCAR NetCDFs """ if save: # then create the new file unless save is a file handle, in which case just save to that doc = h5(save) # establish the hdf5 object. #REMOVE :s doc.create(wspd:38,wdir:38,height:38)# create the h5 object #FIXME - need more variables! # Height can be an index, but it does not have to be... files = sorted(files) # a last resort effort to sort these turkies # initialize output lists X = zeros(len(files),dtype=int) Y = array.array('f') T = zeros((len(files),38)) # set a numpy array # FIXME - that 20 may not be stable!!! print "Finding RASS Files"; n = 0 # a counter for file_dir in files: # EACH NETCDF FILE IS AN OBSERVATION!!! fname = file_dir.split("/")[-1] print file_dir # ok, begin/end check ###if obtime < self.data.begin or obtime > self.data.end: continue try: nc = ncf(file_dir) obtime = calendar.timegm(time.strptime(fname.split(".")[1]+fname.split(".")[2]+"UTC",'%Y%m%d%H%M%S%Z')) except: # something there did not work, either in the name, or in the netcdf reading in general continue if variable not in nc.variables.keys(): print variable,"Is not a valid RASS variable..." # be ince and return the valid variables print "Here are the valid variables: ",nc.variables.keys() exit() try: T[n] = nc.variables[variable][:] Y = nc.variables['height'][0] # numpy array! # heights X[n]=obtime#nc.variables['time'][0] except: continue nc.close() n+=1 T = T[:n] X = X[:n] T[T==9999.] = nanvalue # set T to be nan wherever it equals the null value return X,Y,T
def read (files,save): """ ingest RWP NIMA processed Data from the NCAR NetCDFs each file here is a day, with times as an element! This will use for loops, and it will go slowly... """ # then create the new file unless save is a file handle, in which case just save to that doc = h5(save) # establish the hdf5 object. doc.create(tvu=20,tvc=20,height=20,snrtv=20) print "Finding RASS Files"; for f in sorted(files): fname = f.split("/")[-1] if 'mom' in fname or 'winds' in fname: continue #wind profiler and moment riffraf. print fname try: nc = ncf(f) except: # something there did not work, either in the name, or in the netcdf reading in general continue # check to make sure this is the right kind of data, full 20 obs. l = nc.dimensions['height'] if l > 20: print 'Data wrong size' nc.close() continue begin = s2t(getattr(nc,'Data_start_time'),'%a %b %d %H:%M:%S %Y %Z') #should work for PCAPS data for t in range(len(nc.variables['time'][:])): obtime = begin + nc.variables['time'][t] # now fetch all the desired variables and save them! tvu = nc.variables['tv'][t] # uncorrected virtual temp tvc = nc.variables['tvc'][t] # vertical motion corrected snrtv = nc.variables['snrtv'][t] # well, boo, this data is not so good height = nc.variables['heights'][t] print "Appending",obtime doc.append(obtime,persist=True,height=height,tvu=tvu,tvc=tvc,snrtv=snrtv) nc.close() doc.close() return True
def read (files,save): """ ingest RWP NIMA processed Data from the NCAR NetCDFs each file here is a day, with times as an element! This will use for loops, and it will go slowly... """ # then create the new file unless save is a file handle, in which case just save to that doc = h5(save) # establish the hdf5 object. size = 38 # this is how long the profiles are (FOR PCAPS - they were 45 during the run-up to PCAPS) # NOTE this code is disregarding many of the potentially interesting datasets within this data... doc.create(height=size,beamnum=1,elevation=1,az=1,vel=size,snr=size,sw=size,noise=size,mom1Conf=size,mom2Conf=size,power=size,poptemp=size, qc=size,interpv=size,iverr=size,clutter=size,othersig=size) print "Finding RWP Files"; for file_dir in sorted(files): fname = file_dir.split("/")[-1] if 'mom' not in fname or 'rass' in fname: continue #rass and rwp riffraf. print file_dir try: nc = ncf(file_dir) except: # something there did not work, either in the name, or in the netcdf reading in general continue # check to make sure this is the right kind of data, a full 38 obs l = nc.dimensions['height'] if l > size: print "Wrong length:",l nc.close() continue begin = s2t(getattr(nc,'Data_start_time'),'%a %b %d %H:%M:%S %Y %Z') #should work for PCAPS data for t in range(len(nc.variables['time'][:])): obtime = begin + nc.variables['time'][t] # yay, this still works! # now fetch all the desired variables and save them! beamnum = nc.variables['beamNum'][t] elevation = nc.variables['elevation'][t] az = nc.variables['azimuth'][t] height = nc.variables['heights'][t] # THIS ACTUALLY CHANGES HERE... snr = nc.variables['sigNoiseRatio'][t] vel = nc.variables['vel'][t] # constant, vs linear sw = nc.variables['specWid'][t] # ditto noise = nc.variables['noise'][t] # ditto m1c = nc.variables['mom1Conf'][t] # velocity m2c = nc.variables['mom2Conf'][t] # spectrum width power = nc.variables['power'][t] poptemp = nc.variables['popTemp'][t] qc = nc.variables['qualityControl'][t] interpv = nc.variables['interpVel'][t] iverr = nc.variables['errorVel'][t] clutter = nc.variables['clutter'][t] os = nc.variables['othersig'][t] #non-atmospheric signals # for all variables the value -9999 signals nan data!!! #print "Appending",obtime doc.append(obtime,persist=True,height=height,beamnum=[beamnum],elevation=[elevation],az=[az],vel=vel,sw=sw,snr=snr,noise=noise,mom1Conf=m1c, mom2Conf=m2c,power=power,poptemp=poptemp,qc=qc,interpv=interpv,iverr=iverr,clutter=clutter,othersig=os) nc.close() doc.close() return True
import matplotlib.pyplot as plt from matplotlib.colors import LinearSegmentedColormap, ListedColormap from mpl_toolkits.basemap import Basemap from scipy.io.netcdf import netcdf_file as ncf points = np.array([ [335.36-360, 42.24], [17.60, 42.24], [60.28, 42.24], [335.36-360, -1.32], [17.60, -1.32], [60.28, -1.32], [335.36-360, -45.76], [17.60, -45.76], [60.28, -45.76] ]) ff = ncf(sys.argv[1],'r') try: lat_0 = float(ff.latitude_of_projection_origin) lon_0 = float(ff.longitude_of_projection_origin) grdis = float(ff.grid_size_in_meters) nx = int(ff.dimensions['jx']) ny = int(ff.dimensions['iy']) ht = ff.variables['topo'][12:-12,12:-12] xlat = ff.variables['xlat'][12:-12,12:-12] xlon = ff.variables['xlon'][12:-12,12:-12] lsmask = ff.variables['mask'][12:-12,12:-12] m = Basemap(resolution='l', projection='merc',llcrnrlat=ff.variables['xlat'][0,0],llcrnrlon=ff.variables['xlon'][0,0],