arlmet.catalog#
- arlmet.catalog(directory, *, recursive=False, cache_dir=None)[source]#
Catalog the ARL files in a directory by their headers.
Each file in directory is opened once, and what its index records say is kept: its source, grid, first and last valid time, and time step. The table is cached, so a later call reads again only the files that are new or changed (by size or modification time) and drops the files that are gone. Use
Catalog.covering()to find the files for a time window.Links to files are followed, and each real file is one row, shown by its real path (
pathlib.Path.resolve()) however many links reach it; of hard links to one file, the first by name is the row. A link that cannot be followed (its target is gone, or links loop) is a row with the reason inerror. Links to folders are not followed. Hidden files and folders (names starting with.), backup copies (names ending in~), lock files (names ending in.lockor holding.lock.) and copies set aside (names ending in.partialor.bad) are skipped. A file that is not ARL, or is damaged, is kept with the reason inerrorand is not used to cover a window.Files are opened 16 at a time: on a network filesystem each one waits on a few small reads. The cache is saved every 500 files, so an interrupted first catalog of a large archive keeps what it read. Processes that start on the same folder at once, such as the tasks of a Slurm job array, open its files one process at a time: the first holds a lock folder beside the cache (its name ending in
.lock) and the others wait, then read the table it saved. A lock with no progress for 5 minutes is taken over.When the cache is not beside the files (directory is read-only, or cache_dir is given) and the folder holds the table its maintainer saved there by running
catalogon it, that table is the starting point, read-only: a file whose size and modification time match its row is not opened, and the rest are read. Rows already in your own cache win. A stale published table therefore costs a few reads, never a wrong answer.- Parameters:
recursive (
bool) – Also read every folder below directory, as a copy of NOAA’sYYYY/MM/layout needs. By default only the files directly in directory are read.cache_dir (
str|PathLike[str] |None) – Folder for the cache file. By default the cache is.arlmet-catalog.csv(.arlmet-catalog-recursive.csvwith recursive) in directory when directory is writable, and otherwise a file named after the directory in$ARLMET_CACHE_DIR, or in the platform’s user cache folder (arlmet/catalogin$XDG_CACHE_HOMEon Linux) when that variable is not set.
- Return type:
- Raises:
FileNotFoundError – If directory does not exist.
OSError – If the cache cannot be written, or a folder cannot be listed.
- Warns:
ARLFormatWarning – Whatever opening a file warns, such as a time step repeated byte for byte.
See also
Catalog.coveringThe files for a time window.
File.checkDamage that opening a file does not catch.
Examples
>>> cat = arlmet.catalog("hrrr") >>> cat.covering("2021-01-14 06:00", "2021-01-15 06:00") [PosixPath('hrrr/20210114_06-11_hrrr'), ..., PosixPath('hrrr/20210115_06-11_hrrr')]