def do_savexL(self): check = 'True' self.do_progress(text='Exporting Diurnal NetCDF -> Xcel ...') # put up the progress message #if metutils.cfkeycheck(self.cf,'Output','noDefaultXl'): # self.cf = metio.loadcontrolfile('../controlfiles') # if len(self.cf)==0: # self.do_progress(text='Waiting for input ...') # return try: self.cf if len(self.cf)==0: self.cf = metio.loadcontrolfile('../controlfiles') if len(self.cf)==0: self.do_progress(text='Waiting for input ...'); return check = 'False' except: self.cf = metio.loadcontrolfile('../controlfiles') if len(self.cf)==0: self.do_progress(text='Waiting for input ...'); return check = 'False' if (metutils.cfkeycheck(self.cf,Base='Output',ThisOne='DefaultXl') and self.cf['Output']['DefaultXl'] == 'False') and check == 'True': self.cf = metio.loadcontrolfile('../controlfiles') if len(self.cf)==0: self.do_progress(text='Waiting for input ...'); return if metutils.cfkeycheck(self.cf,Base='General',ThisOne='OutputLevel'): OutLevel = self.cf['General']['OutputLevel'] else: OutLevel = 'Envelope' metio.autonc2xl(self.cf,OutLevel) self.do_progress(text='Finished Data Export') # tell the user we are done log.info(' Finished saving data')
def do_xl2ncCall(self): self.do_progress(text='Load xl2nc Control File ...') self.cf = metio.loadcontrolfile('../controlfiles') if len(self.cf)==0: self.do_progress(text='Waiting for input ...') return self.do_progress(text='Importing Xcel file -> NetCDF v4 ...') if metutils.cfkeycheck(self.cf,'General','InLevel') and metutils.cfkeycheck(self.cf,'General','OutLevel'): InLevel = self.cf['General']['InLevel'] OutLevel = self.cf['General']['OutLevel'] else: InLevel = 'L3' OutLevel = 'L3' metio.autoxl2nc(self.cf,InLevel,OutLevel) self.do_progress(text='Finished Data Ingest') log.info(' Finished Data Ingest')
def do_qcEs(self): self.cf = metio.loadcontrolfile('../controlfiles') if len(self.cf)==0: self.do_progress(text='Waiting for input ...') return if metutils.cfkeycheck(self.cf,Base='General',ThisOne='InputLevel'): InLevel = self.cf['General']['InputLevel'] else: InLevel = 'L3' self.ds2 = metio.nc_read_series(self.cf,InLevel) self.do_progress(text='Doing met envelope prep...') self.ds3 = metls.l3envelope(self.cf,self.ds2,Params='Es') self.do_progress(text='Finished met envelope prep') self.do_progress(text='Saving met envelope NetCDF data ...') # put up the progress message if metutils.cfkeycheck(self.cf,Base='General',ThisOne='OutputLevel'): OutLevel = self.cf['General']['OutputLevel'] else: OutLevel = 'MetEnvelope' metio.nc_write_series(self.cf,self.ds3,OutLevel) # save the L3 data self.do_progress(text='Finished Blocking') # tell the user we are done log.info(' Finished saving NetCDF data')
def nc_write_series(cf, ds, level): ncFullName = cf['Files'][level]['ncFilePath'] + cf['Files'][level][ 'ncFileName'] log.info(' Writing netCDF file ' + ncFullName) if metutils.cfkeycheck( cf, Base='General', ThisOne='netCDFv3') and cf['General']['netCDFv3'] == 'False': ncFile = netCDF4.Dataset(ncFullName, 'w') else: ncFile = netCDF4.Dataset(ncFullName, 'w', format='NETCDF3_CLASSIC') for ThisOne in ds.globalattributes.keys(): setattr(ncFile, ThisOne, ds.globalattributes[ThisOne]) t = time.localtime() RunDateTime = str(datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5])) setattr(ncFile, 'RunDateTime', RunDateTime) nRecs = len(ds.series['xlDateTime']['Data']) setattr(ncFile, 'NumRecs', str(nRecs)) setattr(ncFile, 'Level', level) ncFile.createDimension('Time', nRecs) SeriesList = ds.series.keys() for ThisOne in [ 'xlDateTime', 'Year', 'Month', 'Day', 'Hour', 'Minute', 'Second', 'Hdh' ]: if ThisOne in SeriesList: dt = get_ncdtype(ds.series[ThisOne]['Data']) ncVar = ncFile.createVariable(ThisOne, dt, ('Time', )) ncVar[:] = ds.series[ThisOne]['Data'].tolist() setattr(ncVar, 'Description', ThisOne) setattr(ncVar, 'units', 'none') SeriesList.remove(ThisOne) if 'DateTime' in SeriesList: SeriesList.remove('DateTime') for ThisOne in SeriesList: if 'Data' in ds.series[ThisOne].keys(): dt = get_ncdtype(ds.series[ThisOne]['Data']) ncVar = ncFile.createVariable(ThisOne, dt, ('Time', )) ncVar[:] = ds.series[ThisOne]['Data'].tolist() if 'Attr' in ds.series[ThisOne].keys(): for attr in ds.series[ThisOne]['Attr']: setattr(ncVar, attr, ds.series[ThisOne]['Attr'][attr]) if 'Flag' in ds.series[ThisOne].keys(): dt = get_ncdtype(ds.series[ThisOne]['Flag']) ncVar = ncFile.createVariable(ThisOne + '_QCFlag', dt, ('Time', )) ncVar[:] = ds.series[ThisOne]['Flag'].tolist() setattr(ncVar, 'Description', 'QC flag') setattr(ncVar, 'units', 'none') ncFile.close()
def nc_write_series(cf,ds,level): ncFullName = cf['Files'][level]['ncFilePath']+cf['Files'][level]['ncFileName'] log.info(' Writing netCDF file '+ncFullName) if metutils.cfkeycheck(cf,Base='General',ThisOne='netCDFv3') and cf['General']['netCDFv3'] == 'False': ncFile = netCDF4.Dataset(ncFullName,'w') else: ncFile = netCDF4.Dataset(ncFullName,'w',format='NETCDF3_CLASSIC') for ThisOne in ds.globalattributes.keys(): setattr(ncFile,ThisOne,ds.globalattributes[ThisOne]) t = time.localtime() RunDateTime = str(datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5])) setattr(ncFile,'RunDateTime',RunDateTime) nRecs = len(ds.series['xlDateTime']['Data']) setattr(ncFile,'NumRecs',str(nRecs)) setattr(ncFile,'Level',level) ncFile.createDimension('Time',nRecs) SeriesList = ds.series.keys() for ThisOne in ['xlDateTime','Year','Month','Day','Hour','Minute','Second','Hdh']: if ThisOne in SeriesList: dt = get_ncdtype(ds.series[ThisOne]['Data']) ncVar = ncFile.createVariable(ThisOne,dt,('Time',)) ncVar[:] = ds.series[ThisOne]['Data'].tolist() setattr(ncVar,'Description',ThisOne) setattr(ncVar,'units','none') SeriesList.remove(ThisOne) if 'DateTime' in SeriesList: SeriesList.remove('DateTime') for ThisOne in SeriesList: if 'Data' in ds.series[ThisOne].keys(): dt = get_ncdtype(ds.series[ThisOne]['Data']) ncVar = ncFile.createVariable(ThisOne,dt,('Time',)) ncVar[:] = ds.series[ThisOne]['Data'].tolist() if 'Attr' in ds.series[ThisOne].keys(): for attr in ds.series[ThisOne]['Attr']: setattr(ncVar,attr,ds.series[ThisOne]['Attr'][attr]) if 'Flag' in ds.series[ThisOne].keys(): dt = get_ncdtype(ds.series[ThisOne]['Flag']) ncVar = ncFile.createVariable(ThisOne+'_QCFlag',dt,('Time',)) ncVar[:] = ds.series[ThisOne]['Flag'].tolist() setattr(ncVar,'Description','QC flag') setattr(ncVar,'units','none') ncFile.close()