arlmet.index#
- arlmet.index(directory, *, recursive=False, cache_dir=None)[source]#
Index 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
DirectoryIndex.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. 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.) and backup copies (names ending in~) 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 index of a large archive keeps what it read.
- 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-index.csv(.arlmet-index-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/indexin$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
DirectoryIndex.coveringThe files for a time window.
File.checkDamage that opening a file does not catch.
Examples
>>> idx = arlmet.index("hrrr") >>> idx.covering("2021-01-14 06:00", "2021-01-15 06:00") [PosixPath('hrrr/20210114_06-11_hrrr'), ..., PosixPath('hrrr/20210115_06-11_hrrr')]