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')
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')
def do_regrid(config_file, dir_base, prod, data_files, is_yellowstone): """Do the regridding and downscaling of the product""" for file in data_files: # Use only the filename of the file, the # regrid_data() is only expecting a file name. if prod == 'MRMS': match = re.match(r'.*(GaugeCorr.*00.00_[0-9]{8}_[0-9]{6}.*)',file) file_only = match.group(1) else: match = re.match(r'(.*)/([0-9]{8}_i[0-9]{2}_f[0-9]{2,3}.*)',file) file_only = match.group(2) aaf.forcing(config_file,"regrid",prod,file_only)
def regrid(fname, fileType, configFile): """Invoke regridding/downscaling Parameters ---------- fname: str name of file to regrid and downscale, with yyyymmdd parent dir fileType: str HRRR, RAP, ... string configFile : str configuration file with all settings Returns ------- None """ WhfLog.info("REGRIDDING %s DATA, file=%s", fileType, fname) try: if (fileType == 'HRRR'): srf.forcing(configFile, 'regrid', 'HRRR', fname[9:]) # special case, if it is a 0 hour forecast, do double regrid regridIfZeroHr(configFile, fileType, fname) elif (fileType == 'RAP'): srf.forcing(configFile, 'regrid', 'RAP', fname[9:]) # special case, if it is a 0 hour forecast, do double regrid regridIfZeroHr(configFile, fileType, fname) elif (fileType == 'GFS'): mrf.forcing(configFile, 'regrid', 'GFS', fname[9:]) elif (fileType == 'MRMS'): aaf.forcing(configFile, 'regrid', 'MRMS', fname[9:]) else: WhfLog.info("ERROR REGRIDDING %s DATA, file=%s", fileType, fname) raise InvalidArgumentError("Unknown file type " + fileType) except ZeroHourReplacementError as z: WhfLog.info("ERROR REGRIDDING: %s", z) WhfLog.info("Remove this forecast from state and continue") return except: WhfLog.info("ERROR REGRIDDING %s DATA, file=%s", fileType, fname) raise WhfLog.info("DONE REGRIDDING %s DATA, file=%s", fileType, fname)