select_validtime_obs module
- select_validtime_obs(valid_time, outdir, source, in_template, out_template, window=900, debug=False)
Identifies the observation file closest to the valid time of the forecast. For observation types with irregular observation times (MRMS, GOES), obs files do not always exactly match the valid time. This script is used to identify and rename these files to match the valid time of the forecast.
The “template” variables represent special templates for the expected filename of the observation containing a date/time string (in_template) and the output filename. The date/time template should be contained in brackets [] and using expected python date codes. For example, MRMS echo top files are named like
EchoTop_18_00.50_20240111-000034.grib2.gz
where the date and time of the observation file is 2024-01-11, 00:00:34. The “in_template” for this observation type should therefore be:
EchoTop_18_00.50_[%Y%m%d-%H%M%S].grib2.gz
Globbables are allowed for “in_template” but not “out_template”. For example, GOES AOD files have names like
OR_ABI-L2-AODF-M6_G16_s20240180620209_e20240180629517_c20240180630532.nc
where the filenames contain multiple date strings and other information that may change for different data sources. For this specific filename, a valid “in_template” would be
OR_ABI-L2-AODF_[%Y%j%H%M%S]*.nc
Be sure that any “in_template” value can be unambiguously globbed, otherwise unexpected results may occur.
- Returns:
string – The staged filename
- Raises:
FileNotFoundError – If no valid file was found within “window” seconds of the valid time of the forecast