eradiate.data.FileResolver¶
- class eradiate.data.FileResolver(paths=NOTHING)[source]¶
Bases:
objectThis class resolves paths relative to a list of locations on disk. Locations are looked up in order upon calling the
resolve()method. If a lookup is successful, the resolved absolute path is returned; otherwise, the input path is returned unchanged.- Parameters:
paths (
listofpath-likes, optional) – A list of search directories. Each entry must exist.
Notes
By default, the unique file resolver instance
eradiate.fresolveris initialized with the installation path of the asset manager (seeAssetManager) and, when in dev mode (seeSOURCE_DIR), the path to the location of test files.The current working directory is not appended to the file resolver by default. It can however optionally be added temporarily when calling
resolve()(and wrappers such asload_dataset()). This is useful when using thestrictmode, which raises if the requested path cannot be resolved to an existing file.
Examples
A single instance of the file resolver is available as
eradiate.fresolver:>>> from eradiate import fresolverTo add a path to the file resolver, use the
append()orprepend()methods, e.g.:>>> fresolver.append("some/path/on/the/drive")To resolve a relative path, use the
resolve()method:>>> fresolver.resolve("srf/sentinel_2a-msi-3.nc")If the path is expected to point to an existing dataset file, the
load_dataset()method can be used to load it immediately:>>> fresolver.load_dataset("srf/sentinel_2a-msi-3.nc")- append(path, avoid_duplicates=True)[source]¶
Append an entry to the end of the list of search paths.
- Parameters:
See also
- load_dataset(path, strict=False, cwd=False)[source]¶
Chain
resolve()andxarray.load_dataset().
- prepend(path, avoid_duplicates=True)[source]¶
Prepend an entry at the beginning of the list of search paths.
- Parameters:
See also
- resolve(path, strict=False, cwd=False)[source]¶
Resolve a path: search all registered locations in order. If no file is found in any of the registered location,
pathis returned unchanged.- Parameters:
- Returns:
Path– Resolved path- Raises:
FileNotFoundError – If
strictisTrueandpathwas not found in one of the registered directories.