本文整理汇总了Python中WhfLog类的典型用法代码示例。如果您正苦于以下问题:Python WhfLog类的具体用法?Python WhfLog怎么用?Python WhfLog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WhfLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _forecastExists
def _forecastExists(self, dir):
""" Check if forecast indicated by local state exists
Parameters
----------
dir : str
Full path to the issue time directories
Returns
-------
bool
True if the forecast does exist on disk
"""
path = dir + "/"
path += self._issue.strftime("%Y%m%d%H")
if (os.path.isdir(path)):
fname = self._valid.strftime("%Y%m%d%H%M") + ".LDASIN_DOMAIN1.nc"
names = df.getFileNames(path)
for n in names:
if (n == fname):
WhfLog.debug("Found %s in %s", fname, path)
return True
return False
else:
return False
示例2: layerIfReady
def layerIfReady(self, parms, configFile):
""" Perform layering if state is such that it should be done
Parameters
----------
parms : Parms
Parameters
configFile : string
name of file with settings
Returns
-------
bool
True if layering was done, or had previously been done
"""
if (self._layered):
return True
if ((not self._hrrr) and (not self._rap)):
return False
if (self._hrrr and self._rap):
self._layer(parms, configFile)
self._layered = True
return True
if (self._rap and not self._hrrr):
ntime = datetime.datetime.utcnow()
diff = ntime - self._clockTime
idiff = diff.total_seconds()
if (idiff > parms._maxWaitSeconds):
WhfLog.debug("timeout..Should layer, dt=%d", idiff)
self._passthroughRap(parms)
self._layered = True
return True
return False
示例3: parmRead
def parmRead(fname, fileType, realtime):
"""Read in the main config file, return needed parameters
Parameters
----------
fname: str
name of parameter file to read in
fileType: str
'RAP', 'HRRR', 'MRMS', 'GFS'
realtime: boolean
True if realtime, False for archive mode
Returns
-------
Parms
values as pulled from the file
"""
parser = SafeConfigParser()
parser.read(fname)
label = 'Regrid' + fileType
if (realtime):
WhfLog.init(parser, label, False)
else:
WhfLog.set(label)
dataDir = parser.get('data_dir', fileType + '_data')
maxFcstHour = int(parser.get('fcsthr_max', fileType + '_fcsthr_max'))
hoursBack = int(parser.get('triggering', fileType + '_hours_back'))
stateFile = parser.get('triggering', fileType + '_regrid_state_file')
parms = Parms(dataDir, maxFcstHour, hoursBack, stateFile)
return parms
示例4: withinNHours
def withinNHours(self, ftime, N):
""" Check if input time is within some number of issue hours of self
Parameters
----------
ftime: ForecastTime
N:int
Number of hours to check
Returns
-------
True if input time - local time <= N hours
"""
# same day, issue hour match
# same day, issue hour input - issue hour <= N
if (self._fcstTime == ftime._fcstTime):
if (self._issueHour == ftime._issueHour):
return True
elif (ftime._issueHour-self._issueHour <= N):
return True
else:
return False
else:
# create a full time from local and input states
timeIn = ftime.ymdh()
timeLoc = self.ymdh()
diff = (timeIn - timeLoc).total_seconds()
maxSeconds = N*3600
if (diff < 0):
WhfLog.error("Unexpected data newer than newest")
return False
else:
return (diff <= maxSeconds)
示例5: regridIfZeroHr
def regridIfZeroHr(configFile, fileType, fname):
"""If it is a 0 hour forecast (RAP or HRRR) regrid in a special way
Parameters
----------
configFile : str
configuration file with all settings
fileType: str
HRRR, RAP, ... string
fname: str
name of file to regrid and downscale, with yyyymmdd parent dir
Returns
-------
None
"""
# check for 0 hour by creating a DataFile and checking forecast hour
try:
f = df.DataFile(fname[0:8], fname[9:], fileType)
except FilenameMatchError as fe:
WhfLog.debug("Cannot check for 0 hour data due to %s", fe)
raise
except InvalidArgumentError as ie:
WhfLog.debug("Cannot check for 0 hour data due to %s", ie)
raise
if (f._time._forecastHour == 0):
WhfLog.setConfigType('AA')
WhfLog.debug("SPECIAL 0 hour case %s", fname[9:0])
aaf.forcing(configFile, 'regrid', fileType, fname[9:])
WhfLog.setConfigType('Short')
示例6: lookForNew
def lookForNew(self, data, hoursBack, fileType):
""" See if new data has arrived compared to state.
If a new issue time, purge older stuff from state.
Parameters
----------
data: DataFiles
The newest data
hoursBack: int
Maximum number of hours back to keep data in state
fileType : str
'HRRR', 'RAP', ...
Returns
-------
list[str]
The data file names that are are to be added to state
"""
ret = []
fnames = data.getFnames()
if (not fnames):
return ret
if (self.isEmpty()):
WhfLog.debug("Adding to empty list")
else:
sname = self.newest()
if (not sname):
WhfLog.error("Expected file, got none")
return ret
self._analyzeNewest(fnames[-1], sname, hoursBack, fileType)
for f in fnames:
if (self._isNew(f)):
ret.append(f)
return ret
示例7: filterWithinNHours
def filterWithinNHours(files, type, ftime, N):
"""Filter a list of file names with assumed format to those in a time range
Parameters
----------
files: list[str]
file names, each with parent directory: 'yyyymmdd/<file>
type: str
file type string, 'RAP', 'HRRR', 'MRMS', GFS'
ftime: ForecastTime
time to compare against, assumed most recent time
N: int
Number of hours back from ftime to keep
Returns
-------
list[str]
subset of input files with issue time is in the range [ftime-N,ftime]
"""
ret = []
for f in files:
df = DataFile(f[0:8], f[9:], type)
if (df._ok):
ithFtime = df._time
if (ithFtime.withinNHours(ftime, N)):
ret.append(f)
else:
WhfLog.debug("Did not append file, too old compared to %s file=%s", ftime.debugString(), f)
WhfLog.debug("filtering within %d hours, input length %d output %d",
N, len(files), len(ret))
return ret
示例8: parmRead
def parmRead(fname):
"""Read in the main config file, return needed parameters
Parameters
----------
fname: str
name of parameter file to read in
Returns
-------
Parms
values as pulled from the file
"""
parser = SafeConfigParser()
parser.read(fname)
forcing_config_label = "LongRangeRegridDriver"
WhfLog.init(parser, forcing_config_label, 'Long', 'Regrid', 'CFS')
cfsDir = parser.get('data_dir', 'CFS_data')
cfsNumEnsemble = int(parser.get('data_dir', 'CFS_num_ensemble'))
maxFcstHourCfs = int(parser.get('fcsthr_max', 'CFS_fcsthr_max'))
hoursBackCfs = int(parser.get('triggering', 'CFS_hours_back'))
stateFile = parser.get('triggering', 'long_range_regrid_state_file')
parms = Parms(cfsDir, cfsNumEnsemble, maxFcstHourCfs, hoursBackCfs,
stateFile)
return parms
示例9: obsExists
def obsExists(dir, issueTime):
""" Check if obs exists
Parameters
----------
dir : str
Full path to the MRMS directories
issueTime : datetime
The issue time (y,m,d,h)
Returns
-------
bool
True if the data does exist on disk
"""
path = dir + "/"
path += issueTime.strftime("%Y%m%d%H")
if (os.path.isdir(path)):
fname = issueTime.strftime("%Y%m%d%H%M") + ".LDASIN_DOMAIN1.nc"
names = df.getFileNames(path)
for n in names:
if (n == fname):
WhfLog.debug("Found %s in %s", fname, path)
return True
return False
示例10: forecastExists
def forecastExists(dir, issueTime, fcstHour):
""" Check if forecast exists
Parameters
----------
dir : str
Full path to the issue time directories
issueTime : datetime
The issue time (y,m,d,h)
fcstHour: int
should be 0 or 3
Returns
-------
bool
True if the forecast does exist on disk
"""
path = dir + "/"
path += issueTime.strftime("%Y%m%d%H")
if (os.path.isdir(path)):
validTime = issueTime + datetime.timedelta(hours=fcstHour)
fname = validTime.strftime("%Y%m%d%H%M") + ".LDASIN_DOMAIN1.nc"
names = df.getFileNames(path)
for n in names:
if (n == fname):
WhfLog.debug("Found %s in %s", fname, path)
return True
return False
示例11: _allDataFiles
def _allDataFiles(self):
"""Return all data files on disk, in order
Parameters
----------
none
Returns
-------
list[DataFile]
The DataFile specs, in order oldest to newest
"""
# get the yyyymmdd subdirs
dirs = getYyyymmddSubdirectories(self._topDir)
# sort them into ascending order
dirs = sorted(dirs)
if not dirs:
# nothing there
WhfLog.debug("_allDataFiles: No data in %s", self._topDir)
return []
else:
# make one big array
ret = []
for d in dirs:
ret.extend(self._allDataFilesInDir(d))
return ret
示例12: createStateFile
def createStateFile(parms, fileType, realtime):
""" Called if there is no state file, look at data dirs and create state
in realtime, in non-realtime create an empty state. Write to file.
Parameters
----------
parms: Parms
Parameter settings
fileType: str
'HRRR', ...
realtime: boolean
True if realtime, False for archive mode
Returns
-------
none
Writes out the state file after creating it
"""
WhfLog.info("Initializing")
state = State("")
if (realtime):
# query each directory and get newest model run file for each, then
# get all for that and previous issue time, this becomes state that
# is not re-processed, we only look for new stuff
data = df.DataFiles(parms._dataDir, parms._maxFcstHour, fileType)
data.setNewestFiles(parms._hoursBack)
for f in data._content:
f.debugPrint("Newest files: " + fileType)
state.initialize(data)
# write out file (at least try to)
state.write(parms._stateFile, fileType)
示例13: debugPrint
def debugPrint(self):
""" WhfLog debug of content
"""
WhfLog.debug("Model: empty=%d", df.boolToInt(self._empty))
if (self._empty):
return
WhfLog.debug("Model: Issue=%s clockTime=%s",
self._issue.strftime("%Y%m%d%H"),
self._clockTime.strftime("%Y-%m-%d_%H:%M:%S"))
示例14: debugPrint
def debugPrint(self):
""" logging debug of content
"""
WhfLog.debug("FcstStep: empty=%d", self._empty)
if (self._empty):
return
WhfLog.debug("FcstStep[%d] hrrr0:%d hrrr3:%d rap0:%d rap3:%d mrms:%d lay:%d",
self._step, self._hrrr0, self._hrrr3, self._rap0,
self._rap3, self._mrms, self._layered)
示例15: debugPrint
def debugPrint(self):
""" Debug logging of content
"""
WhfLog.debug("%s data = %s", self._dataType, self._dataDir)
WhfLog.debug("%s source = %s", self._dataType, self._sourceDataDir)
WhfLog.debug("%s statefile = %s", self._dataType, self._stateFile)
WhfLog.debug("%s format = %s", self._dataType, self._format)