本文整理汇总了Python中WhfLog.error方法的典型用法代码示例。如果您正苦于以下问题:Python WhfLog.error方法的具体用法?Python WhfLog.error怎么用?Python WhfLog.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WhfLog
的用法示例。
在下文中一共展示了WhfLog.error方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: withinNHours
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
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)
示例2: run
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def run(fileType, configFile, realtime):
""" Run the script, process any new data
Parameters
----------
fileType: str
'HRRR', ...
configFile : str
Name of the file with settings
realtime : boolean
True if this is realtime
Returns
-------
1 for error, 0 for success
"""
good = False
regriddable = ['HRRR', 'RAP', 'MRMS', 'GFS']
if (fileType not in regriddable):
print 'ERROR unknown file type command arg ', fileType
return 1
# User must pass the config file into the main driver.
if not os.path.exists(configFile):
print 'ERROR forcing engine config file not found:', configFile
return 1
# read in fixed main params
parms = parmRead(configFile, fileType, realtime)
#if there is not a state file, create one now using newest
if (not os.path.exists(parms._stateFile)):
parms.debugPrint()
createStateFile(parms, fileType, realtime)
# read in state
state = State(parms._stateFile, fileType)
# query each directory and get newest model run file for each, then
# get all for that and previous issue time
data = df.DataFiles(parms._dataDir, parms._maxFcstHour, fileType)
data.setNewestFiles(parms._hoursBack)
# Update the state to reflect changes, returning those files to regrid
# Regrid 'em
toProcess = state.lookForNew(data, parms._hoursBack, fileType)
for f in toProcess:
try:
regrid(f, fileType, configFile);
except:
WhfLog.error("Could not regrid/downscale %s", f)
else:
WhfLog.debug("Adding new file %s, and writing state file", f)
if (not state.addFileIfNew(f)):
WhfLog.error("File %s was not new", f)
else:
state.write(parms._stateFile, fileType);
# write out state (in case it has not been written yet) and exit
#state.debugPrint()
state.write(parms._stateFile, fileType)
return 0
示例3: lookForNew
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
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
示例4: updateWithNew
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def updateWithNew(self, data, hoursBack):
""" Update internal state with new data
The dataType is used to determine which part of state to update
Parameters
----------
data: DataFiles
The newest data
hoursBack: int
Maximum number of hours back to keep data in state
Returns
-------
list[str]
The data file names that are are newly added to state
"""
ret = []
fnames = data.getFnames()
if (not fnames):
return ret
if (self.isEmpty()):
WhfLog.debug("Adding to empty %s list")
else:
sname = self.newest()
if (not sname):
WhfLog.error("Expected file, got none")
return ret
if (fnames[-1] > sname):
WhfLog.debug("Newer time encountered")
# see if issue time has increased and if so, purge old stuff
# create DataFile objects
try:
df0 = df.DataFile(sname[0:8], sname[9:], 'CFS')
df1 = df.DataFile(fnames[-1][0:8], fnames[-1][9:], 'CFS')
except FilenameMatchError as fe:
WhfLog.debug("Skipping file use due to %s", fe)
except InvalidArgumentError as ie:
WhfLog.debug("Skipping file use due to %s", ie)
if (df0._time.inputIsNewerIssueHour(df1._time)):
WhfLog.debug("Issue hour has increased, purge now")
self.update(df1._time, hoursBack)
for f in fnames:
if (self.addFileIfNew(f)):
ret.append(f)
self.sortFiles()
return ret
示例5: setCurrentModelAvailability
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def setCurrentModelAvailability(self, parms, config):
""" Change availability status when appropriate by looking at disk
Parameters
----------
parms : Parms
parameters
config : str
Config file name
Returns
-------
none
"""
if (self._layered):
# no need to do more, already layered
return
if (self._empty):
WhfLog.error("Empty when not expected")
return
# make note if going from nothing to something
nothing = True
for f in self._step:
if (f._layered):
nothing = False
#if (nothing):
#WhfLog.debug("Nothing, so trying to get stuff")
# first time only, try the -1 and -2 steps, force with what we have
if (self._first):
self._step[2].forceLayer(parms, config, self._issue)
self._step[1].forceLayer(parms, config, self._issue)
self._first = False
self._step[0].layerIfReady(parms, config, self._issue)
self._layered = self._step[0]._layered
if (not self._layered):
tnow = datetime.datetime.utcnow()
diff = tnow - self._clockTime
idiff = (diff.microseconds +
(diff.seconds + diff.days*24*3600)*10**6)/10**6
if (idiff > parms._veryLateSeconds):
WhfLog.warning("WARNING: Inputs for layering timeout Issue:%s",
self._issue.strftime("%Y%m%d%H"))
s = self._step[0].debugPrintString()
WhfLog.warning("WARNING: 0, state=%s", s)
self._step[0].forceLayer(parms, config, self._issue)
self._layered = True
示例6: setCurrentModelAvailability
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def setCurrentModelAvailability(self, parms):
""" Change availability status when appropriate by looking at disk
Parameters
----------
parms : Parms
Params
"""
for f in self._fState:
# find matching model
didSet = False
for m in self._model:
if (f.matches(m)):
didSet = True
# need to pass that model in to check for 'very late'
f.setCurrentModelAvailability(parms, m)
if (not didSet):
WhfLog.error("No matching model for forecast")
示例7: _passthroughRap
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def _passthroughRap(self, parms):
""" Perform pass through of RAP data as if it were layered
NOTE: Add some error status catching for return
Parameters
----------
parms : Parms
parameters
"""
# lots of hardwires here
ymdh = self._issue.strftime("%Y%m%d%H")
path = ymdh + "/"
fname = self._valid.strftime("%Y%m%d%H%M") + ".LDASIN_DOMAIN1.nc"
fnameOut = self._valid.strftime("%Y%m%d%H%M") + ".LDASIN_DOMAIN1"
path += fname
WhfLog.setData('RAP')
WhfLog.info("LAYERING (Passthrough) %s ", path)
# if not there, create the directory to put the file into
fullPath = parms._layerDir + "/"
fullPath += ymdh
if not os.path.exists(fullPath):
os.makedirs(fullPath)
if not os.path.isdir(fullPath):
WhfLog.error("%s is not a directory", fullPath)
else:
# create copy command and do it
cmd = "cp " + parms._rapDir
cmd += "/" + path
cmd += " " + fullPath
cmd += "/"
cmd += fnameOut
WhfLog.info(cmd)
os.system(cmd)
WhfLog.info("LAYERING (Passthrough) %s complete", path)
WhfLog.setData('RAP/HRRR')
示例8: makeDirIfNeeded
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def makeDirIfNeeded(path):
""" Input is a to be a directory, make it if it does not exist.
Parameters
----------
path : str
full path
Returns
-------
bool
True if directory exists, or was created, false if error
"""
try:
os.makedirs(path)
return True
except OSError as exception:
if exception.errno != errno.EEXIST:
WhfLog.error("ERROR creating %s", path)
return False
else:
return True
示例9: forcing
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def forcing(config, action, prod, file):
"""Peforms the action on the given data
product and corresponding input file.
Args:
config (string) : Config file name
action (string): Supported actions are:
'regrid' - regrid and downscale
prod (string): The first product [mandatory option]:
(MRMS, HRRR or RAP)
file (string): The file name (full path not necessary,
this is derived from the Python config/
param file and the YYYMMDD portion of
the file name.
Returns:
None Performs the indicated action on the
files based on the type of product and
any other relevant information provided
by the Python config/param file,
wrf_hydro_forcing.parm
"""
# Read the parameters from the config/param file.
parser = SafeConfigParser()
parser.read(config)
# Set up logging, environments, etc.
forcing_config_label = "Anal_Assim"
whf.initial_setup(parser, forcing_config_label)
# Convert the action to lower case
# and the product name to upper case
# for consistent checking
action_requested = action.lower()
product_data_name = prod.upper()
# For analysis and assimilation, only 0hr, 3hr forecast fields from HRRR/RAP
# are necessary. 3hr forecast files are already regridded and downscaled
# from the short-range configuration, so only 0hr forecast files are regridded/downscaled
# here. In addition, MRMS data will be regridded, when available.
if action == "regrid":
(date, modelrun, fcsthr) = whf.extract_file_info(file)
# Usually check for forecast range, but only 0, 3 hr forecast/analysis data used
# Check for HRRR, RAP, MRMS products.
WhfLog.info("Regridding and Downscaling for %s", product_data_name)
if fcsthr == 0 and prod == "HRRR":
downscale_dir = parser.get("downscaling", "HRRR_downscale_output_dir_0hr")
try:
regridded_file = whf.regrid_data(product_data_name, file, parser, False, zero_process=True)
except (FilenameMatchError, NCLError) as e:
WhfLog.error("Unexpected filename format encountered while regridding 0hr HRRR")
raise
except NCLError:
WhfLog.error("NCL error encountered while regridding 0hr HRRR")
raise
try:
whf.downscale_data(product_data_name, regridded_file, parser, False, False, zero_process=True)
except (FilenameMatchError, NCLError) as e:
WhfLog.error("Unexpected filename format encountered while downscaling 0hr HRRR")
raise
except NCLError:
WhfLog.error("NCL error encountered while downscaling 0hr HRRR")
raise
# Move downscaled file to staging area where triggering will monitor
match = re.match(r".*/([0-9]{10})/([0-9]{12}.LDASIN_DOMAIN1.nc)", regridded_file)
if match:
full_dir = downscale_dir + "/" + match.group(1)
full_finished_file = full_dir + "/" + match.group(2)
# File should have been created in downscale_data step.
try:
whf.file_exists(full_finished_file)
except UnrecognizedCommandError:
WhfLog.error("File move failed for regridded/downscaled 0hr HRRR , filename format unexpected")
raise
try:
whf.move_to_finished_area(parser, prod, full_finished_file, zero_move=True)
except:
WhfLog.error("Unsupported/unrecognized command encountered while moving file to finished area.")
raise
else:
WhfLog.error("File name format is unexpected")
raise FilenameMatchError("File name format is unexpected")
elif fcsthr == 0 and prod == "RAP":
downscale_dir = parser.get("downscaling", "RAP_downscale_output_dir_0hr")
try:
regridded_file = whf.regrid_data(product_data_name, file, parser, False, zero_process=True)
except NCLError:
WhfLog.error("NCL error while regridding 0hr RAP")
raise
except FilenameMatchError:
WhfLog.error("Unexpected filename format encountered, cannot regrid 0hr RAP")
raise
#.........这里部分代码省略.........
示例10: anal_assim_layer
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def anal_assim_layer(cycleYYYYMMDDHH, fhr, action, config):
""" Analysis and Assimilation layering
Performs layering/combination of RAP/HRRR/MRMS
data for a particular analysis and assimilation
model cycle and forecast hour.
Args:
cycleYYYYMMDDHH (string): Analysis and assimilation
model cycle date.
fhr (string): Forecast hour of analysis and assimilation
model cycle. Possible values are -2, -1, 0.
action (string): Specifying which layering to do, given
possible available model data. Possible
values are "RAP", "RAP_HRRR", and
"RAP_HRRR_MRMS".
config (string) : Config file name
Returns:
None: Performs specified layering to final input directory
used for WRF-Hydro.
"""
# Determine specific layering route to take
str_split = action.split("_")
process = len(str_split)
# Determine specific date/time information used for composing regridded
# file paths.
yearCycle = int(cycleYYYYMMDDHH[0:4])
monthCycle = int(cycleYYYYMMDDHH[4:6])
dayCycle = int(cycleYYYYMMDDHH[6:8])
hourCycle = int(cycleYYYYMMDDHH[8:10])
fhr = int(fhr)
dateCurrent = datetime.datetime.today()
cycleDate = datetime.datetime(year=yearCycle, month=monthCycle, day=dayCycle, hour=hourCycle)
validDate = cycleDate + datetime.timedelta(seconds=fhr * 3600)
fcstWindowDate = validDate + datetime.timedelta(seconds=-3 * 3600) # Used for 3-hr forecast
# HRRR/RAP files necessary for fluxes and precipitation data.
# Obtain analysis and assimiltation configuration parameters.
parser = SafeConfigParser()
parser.read(config)
out_dir = parser.get("layering", "analysis_assimilation_output")
tmp_dir = parser.get("layering", "analysis_assimilation_tmp")
qpe_parm_dir = parser.get("layering", "qpe_combine_parm_dir")
hrrr_ds_dir_3hr = parser.get("downscaling", "HRRR_finished_output_dir")
hrrr_ds_dir_0hr = parser.get("downscaling", "HRRR_finished_output_dir_0hr")
rap_ds_dir_3hr = parser.get("downscaling", "RAP_finished_output_dir")
rap_ds_dir_0hr = parser.get("downscaling", "RAP_finished_output_dir_0hr")
mrms_ds_dir = parser.get("regridding", "MRMS_finished_output_dir")
layer_exe = parser.get("exe", "Analysis_Assimilation_layering")
ncl_exec = parser.get("exe", "ncl_exe")
# in case it is first time, create the output dirs
df.makeDirIfNeeded(out_dir)
df.makeDirIfNeeded(tmp_dir)
# Sanity checking
try:
whf.dir_exists(out_dir)
whf.dir_exists(tmp_dir)
whf.dir_exists(qpe_parm_dir)
whf.dir_exists(hrrr_ds_dir_3hr)
whf.dir_exists(hrrr_ds_dir_0hr)
whf.dir_exists(rap_ds_dir_3hr)
whf.dir_exists(rap_ds_dir_0hr)
whf.dir_exists(mrms_ds_dir)
whf.file_exists(layer_exe)
except MissingDirectoryError:
WhfLog.error("Missing directory during preliminary checking of Analysis Assimilation layering")
raise
# Establish final output directories to hold 'LDASIN' files used for
# WRF-Hydro long-range forecasting. If the directory does not exist,
# create it.
out_path = out_dir + "/" + cycleDate.strftime("%Y%m%d%H")
whf.mkdir_p(out_path)
# Compose necessary file paths
hrrr0Path = (
hrrr_ds_dir_0hr
+ "/"
+ validDate.strftime("%Y%m%d%H")
+ "/"
+ validDate.strftime("%Y%m%d%H")
+ "00.LDASIN_DOMAIN1.nc"
)
hrrr3Path = (
hrrr_ds_dir_3hr
+ "/"
+ fcstWindowDate.strftime("%Y%m%d%H")
+ "/"
+ validDate.strftime("%Y%m%d%H")
+ "00.LDASIN_DOMAIN1.nc"
)
rap0Path = (
rap_ds_dir_0hr
+ "/"
+ validDate.strftime("%Y%m%d%H")
#.........这里部分代码省略.........
示例11: main
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def main(argv):
fileType = argv[0]
good = False
if (fileType == 'HRRR' or fileType == 'RAP' or fileType == 'MRMS' or
fileType == 'GFS'):
good = True
if (not good):
print 'ERROR unknown file type command arg ', fileType
return 1
# User must pass the config file into the main driver.
configFile = argv[1]
if not os.path.exists(configFile):
print 'ERROR forcing engine config file not found:', configFile
return 1
# read in fixed main params
parms = parmRead(configFile, fileType)
#parms.debugPrint()
#if there is not a state file, create one now using newest
if (not os.path.exists(parms._stateFile)):
parms.debugPrint()
createStateFile(parms, fileType)
# begin normal processing situation
#WhfLog.debug("....Check for new input data to regid")
# read in state
state = State(parms._stateFile, fileType)
if state.isEmpty():
# error return here
return 0
#state.debugPrint()
# query each directory and get newest model run file for each, then
# get all for that and previous issue time
data = df.DataFiles(parms._dataDir, parms._maxFcstHour, fileType)
data.setNewestFiles(parms._hoursBack)
# Update the state to reflect changes, returning those files to regrid
# Regrid 'em
toProcess = state.lookForNew(data, parms._hoursBack, fileType)
for f in toProcess:
try:
regrid(f, fileType, configFile);
except:
WhfLog.error("Could not regrid/downscale %s", f)
else:
WhfLog.debug("Adding new file %s, and writing state file", f)
if (not state.addFileIfNew(f)):
WhfLog.error("File %s was not new", f)
else:
state.write(parms._stateFile, fileType);
# write out state (in case it has not been written yet) and exit
#state.debugPrint()
state.write(parms._stateFile, fileType)
return 0
示例12: lookForNew
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
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
if (fnames[-1] > sname):
WhfLog.debug("Newer time encountered")
# see if issue time has increased and if so, purge old stuff
# create DataFile objects, which requires breaking the full
# file into yymmdd/filename
sind = sname.find('/')
if (sind < 0):
raise FileNameMatchError('Cannot parse directory from ' + sname)
nind = fnames[-1].find('/')
if (sind < 0):
raise FileNameMatchError('Cannot parse directory from ' + fnames[-1])
symd = sname[:sind]
sfile = sname[sind+1:]
nymd = fnames[-1][:nind]
nfile = fnames[-1][nind+1:]
WhfLog.debug("Checking %s / %s against %s / %s", symd, sfile, nymd, nfile)
try:
df0 = df.DataFile(symd, sfile, fileType)
df1 = df.DataFile(nymd, nfile, fileType)
except FilenameMatchError as fe:
WhfLog.debug("Cannot update due to %s", fe)
except InvalidArgumentError as ie:
WhfLog.debug("Cannot update due to %s", ie)
if (df0._time.inputIsNewerIssueHour(df1._time)):
WhfLog.debug("%s Issue hour has increased, purge now",
fileType)
self.update(df1._time, hoursBack, fileType)
for f in fnames:
if (self.isNew(f)):
ret.append(f)
return ret
示例13: forcing
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def forcing(configFile, action, prod, file, prod2=None, file2=None):
"""Peforms the action on the given data
product and corresponding input file.
Args:
configFile (string): name of file with settings
action (string): Supported actions are:
'regrid' - regrid and downscale
'bias' - bias correction
(requires two
products and two files)
'layer' - layer (requires two
products and two files)
prod (string): The first product [mandatory option]:
(GFS)
file (string): The file name (full path not necessary,
this is derived from the Python config/
param file and the YYYMMDD portion of
the file name.
prod2 (string): The second product (????), default
is None. Required for layering.
file2 (string): The second file name, required for
layering, default is None.
Returns:
None Performs the indicated action on the
files based on the type of product and
any other relevant information provided
by the Python config/param file,
wrf_hydro_forcing.parm
"""
# Read the parameters from the config/param file.
parser = SafeConfigParser()
try:
parser.read(configFile)
except (NoSectionErrorException, DuplicateSectionErrorException,\
DuplicateOptionErrorException,MissingSectionHeaderErrorException,\
ParsingErrorException) as e:
raise
# Set up logging, environments, etc.
forcing_config_label = 'Medium_Range'
whf.initial_setup(parser,forcing_config_label)
# Extract the date, model run time, and forecast hour from the file name
# Use the fcsthr to process only the files that have a fcst hour less than
# the max fcst hr defined in the param/config file.
# Convert the action to lower case
# and the product name to upper case
# for consistent checking
action_requested = action.lower()
product_data_name = prod.upper()
regridded_dir = parser.get('regridding','GFS_output_dir')
downscale_dir = parser.get('downscaling','GFS_downscale_output_dir')
finished_downscale_dir = parser.get('downscaling','GFS_finished_output_dir')
final_dir = parser.get('layering','medium_range_output')
if action == 'regrid':
(date,modelrun,fcsthr) = whf.extract_file_info(file)
# Determine whether this current file lies within the forecast range
# for the data product (e.g. if processing RAP, use only the 0hr-18hr forecasts).
# Skip if this file has a forecast hour greater than the max indicated in the
# parm/config file.
in_fcst_range = whf.is_in_fcst_range(prod, fcsthr, parser)
if in_fcst_range:
# Check for RAP or GFS data products. If this file is
# a 0 hr fcst and is RAP or GFS, substitute each 0hr forecast
# with the file from the previous model run and the same valid
# time. This is necessary because there are missing variables
# in the 0hr forecasts (e.g. precip rate for RAP and radiation
# in GFS).
WhfLog.info("Regridding and Downscaling for %s", product_data_name)
# Determine if this is a 0hr forecast for RAP data (GFS is also missing
# some variables for 0hr forecast, but GFS is not used for Medium Range
# forcing). We will need to substitute this file for the downscaled
# file from a previous model run with the same valid time.
# We only need to do this for downscaled files, as the Medium Range
# forcing files that are regridded always get downscaled and we don't want
# to do this for both the regridding and downscaling.
if fcsthr == 0 and prod == 'GFS':
WhfLog.info("Regridding (ignoring f0 GFS files) %s: ", file )
try:
regridded_file = whf.regrid_data(product_data_name, file, parser, True)
except (FilenameMatchError,NCLError,MissingFileError) as e:
WhfLog.error('Failure:regridding of GFS (ignore 0hr fcst) file: ' + file)
WhfLog.error(e)
raise
try:
whf.downscale_data(product_data_name,regridded_file, parser, True, True)
except (MissingFileError, SystemCommandError,\
NCLError) as e:
WhfLog.error('Downscaling GFS failed: ' + e)
#.........这里部分代码省略.........
示例14: forcing
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import error [as 别名]
def forcing(configFile, action, prod, file, prod2=None, file2=None):
"""Peforms the action on the given data
product and corresponding input file.
Args:
configFile (string): The config file with all the settings
action (string): Supported actions are:
'regrid' - regrid and downscale
'bias' - bias correction
(requires two
products and two files)
'layer' - layer (requires two
products and two files)
prod (string): The first product [mandatory option]:
(HRRR or RAP)
file (string): The file name (full path not necessary,
this is derived from the Python config/
param file and the YYYMMDD portion of
the file name.
prod2 (string): The second product (RAP or HRRR), default
is None. Required for layering.
file2 (string): The second file name, required for
layering, default is None.
Returns:
None Performs the indicated action on the
files based on the type of product and
any other relevant information provided
by the Python config/param file,
wrf_hydro_forcing.parm
"""
# Read the parameters from the config/param file.
parser = SafeConfigParser()
parser.read(configFile)
forcing_config_label = "Short Range"
try:
whf.initial_setup(parser,forcing_config_label)
except Exception as e:
raise
# Extract the date, model run time, and forecast hour from the file name
# Use the fcsthr to process only the files that have a fcst hour less than
# the max fcst hr defined in the param/config file.
# Convert the action to lower case
# and the product name to upper case
# for consistent checking
action_requested = action.lower()
product_data_name = prod.upper()
if action == 'regrid':
# Get the finished directory locations for the relevant product.
if prod == 'RAP':
regridded_dir = parser.get('regridding', 'RAP_output_dir')
downscale_dir = parser.get('downscaling', 'RAP_downscale_output_dir')
finished_downscale_dir = parser.get('downscaling', 'RAP_finished_output_dir')
downscale_input_dir = parser.get('downscaling', 'RAP_data_to_downscale')
elif prod == 'HRRR':
regridded_dir = parser.get('regridding', 'HRRR_output_dir')
downscale_dir = parser.get('downscaling', 'HRRR_downscale_output_dir')
finished_downscale_dir = parser.get('downscaling', 'HRRR_finished_output_dir')
downscale_input_dir = parser.get('downscaling', 'HRRR_data_to_downscale')
(date,modelrun,fcsthr) = whf.extract_file_info(file)
# Determine whether this current file lies within the forecast range
# for the data product (e.g. if processing RAP, use only the 0hr-18hr forecasts).
# Skip if this file has a forecast hour greater than the max indicated in the
# parm/config file.
in_fcst_range = whf.is_in_fcst_range(prod, fcsthr, parser)
if in_fcst_range:
# Check for RAP or GFS data products. If this file is
# a 0 hr fcst and is RAP or GFS, substitute each 0hr forecast
# with the file from the previous model run and the same valid
# time. This is necessary because there are missing variables
# in the 0hr forecasts (e.g. precip rate for RAP and radiation
# in GFS).
WhfLog.info("Regridding and Downscaling for: "+ product_data_name)
# Determine if this is a 0hr forecast for RAP data (GFS is also missing
# some variables for 0hr forecast, but GFS is not used for Short Range
# forcing). We will need to substitute this file for the downscaled
# file from a previous model run with the same valid time.
# We only need to do this for downscaled files, as the Short Range
# forcing files that are regridded always get downscaled and we don't want
# to do this for both the regridding and downscaling.
if fcsthr == 0 and prod == 'RAP':
WhfLog.info("Regridding, ignoring f0 RAP files " )
try:
regridded_file = whf.regrid_data(product_data_name, file, parser, True)
except FilenameMatchError:
WhfLog.error('file name format is unexpected')
raise
#.........这里部分代码省略.........