arlmet.concat_by_time#
- arlmet.concat_by_time(directory, dest_dir, *, freq='1D', pattern='*', start=None, end=None, template='{time:%Y%m%d}_arl', overwrite=True)[source]#
Group every ARL file in a directory by valid time and concatenate each group.
Each input is assigned to a time bin from its valid times — read from the file’s index records, not parsed from its name — floored to
freq. All files in a bin are concatenated into one output file. This is the batch form ofconcat(): e.g. turning a directory of 6-hourly HRRR files into one file per day. Files are never split, so every input must fall entirely within one bin.- Parameters:
directory (
str|PathLike[str]) – Directory to scan for input ARL files (non-recursive).dest_dir (
str|PathLike[str]) – Directory to write the concatenated files into. Created if missing. Should differ fromdirectory.freq (
str) – Fixed-frequency pandas offset alias giving the size of each output chunk:"1D"= one file per day,"6h"= one per six hours, etc. Each input must fit entirely within one bin: a file whose first and last valid times floor to different bins raisesValueError.pattern (
str) – Glob (relative todirectory) selecting input files. Scope it to ARL files; every match must be a readable ARL file. Hidden files (names starting with., such as the.partialfile an interrupted run leaves) are skipped unless the pattern itself starts a name with a dot, like".*.arl".start (
str|Timestamp|None) – Inclusive bounds on each file’s first valid time; files outside them are skipped. Either may be omitted to leave that side open.end (
str|Timestamp|None) – Inclusive bounds on each file’s first valid time; files outside them are skipped. Either may be omitted to leave that side open.template (
str) –str.formattemplate for output filenames, given the bin start time astime(apandas.Timestamp), e.g."{time:%Y%m%d}_hrrr". It must encode enough resolution to keep bins distinct atfreq; two bins that format to the same filename raiseValueError.overwrite (
bool) – Replace existing output files. With False a bin whose output file exists is left as it is (and still listed), so rerunning after a failure writes only the missing bins; nothing checks that an existing file holds the bin’s current inputs.
- Returns:
The output paths, one per non-empty time bin, in time order.
- Return type:
- Raises:
ValueError – If
patternmatches no files, a matched file cannot be read as ARL, a file’s valid times straddle afreqbin boundary, ortemplateformats two bins to the same filename.concat()’s grid/axis and duplicate-time checks also apply within each group. All checks run before any output is written.
Examples
Turn the files of a directory (here
met_00.arlandmet_06.arl, both on 2024-07-18) into one file per day:>>> import arlmet >>> days = arlmet.concat_by_time( ... ".", ... "daily/", ... freq="1D", ... pattern="met_*.arl", ... template="{time:%Y%m%d}_arl", ... ) >>> [path.name for path in days] ['20240718_arl']