isofit.data
Submodules
Attributes
Classes
Functions
|
Prints the path to a specific product |
|
Extra commands for developers |
|
|
|
|
|
Generates the Click shell completion script for a user's shell, if it is supported. |
Package Contents
- class Ini[source]
-
- _path_bak = None
- __getattr__(key: str) str | None[source]
Retrieves a value from CONFIG[SECTION] if the key doesn’t exist on the module already.
- items(kind: str = None) Iterable[Tuple[str, str]][source]
Passthrough to the items() function on the working section of the config.
- Parameters:
kind ("dirs" | "keys" | None) – Returns an iterable for the specific items: - “dirs” only keys in Ini._dirs - “dirs” only keys in Ini._keys - None returns combined both
- changeBase(base: str) None[source]
Changes the base path for each directory.
- Parameters:
base (str) – Path to base directory to set
- changeKey(key: str, value: str = '') None[source]
Change the value associated with the specified key in the CONFIG[SECTION].
- changeSection(section: str) None[source]
Changes the working section of the config.
- Parameters:
section (str) – The section of the config to reference for lookups.
- changePath(key: str, value: str) None[source]
Change the path associated with the specified key in the CONFIG[SECTION].
- load(ini: str | None = None, section: str | None = None) None[source]
Load environment variables from an ini file.
- Parameters:
- save(ini: str | None = None, diff_only: bool = True) None[source]
Save CONFIG variables to the INI (ini) file.
- Parameters:
ini (str or Path, optional) – The path to save the config variables to. If None, the default INI file path is used. If provided, sets the global INI for the remainder of the session.
diff_only (bool, default=True) – Only save if there is a difference between the currently existing ini file and the config in memory. If False, will save regardless, possibly overwriting an existing file
- path(dir: str, *path: List[str], key: str = None, template: bool = False) pathlib.Path[source]
Retrieves a path under one of the env directories and validates the path exists.
- Parameters:
dir (str) – One of the env directories, eg. “data”, “examples”
*path (List[str]) – Path to a file under the dir
key (str, default=None) – Optional key value to append to the resolved path. Assumes the path is a directory and the key will be a file name
template (bool, default=False) – Returns the path as a template string. The path will still be validated, but the return will be “{env.[dir]}/*path”, to be used with Ini.replace
- Returns:
Validated full path
- Return type:
Examples
>>> from isofit.data import env >>> env.load() >>> env.path("data") ~/.isofit/data >>> env.path("examples", "20171108_Pasadena", "configs", "ang20171108t184227_surface.json") ~/.isofit/examples/20171108_Pasadena/configs/ang20171108t184227_surface.json >>> env.path("srtmnet", key="srtmnet.file") ~/.isofit/srtmnet/sRTMnet_v120.h5 >>> env.path("srtmnet", key="srtmnet.aux") ~/.isofit/srtmnet/sRTMnet_v120_aux.npz
- toTemplate(data: str | dict, replace='dirs', save: bool = True, report: bool = True, **kwargs) dict[source]
Recursively converts string values in a dict to be template values which can be converted back using Ini.fromTemplate(). Template values are in the form of “{env.[value]}”.
:param data: The dictionary to walk over and update values. If string, checks if this
exists as a file and loads that in as the data dict
- Parameters:
replace ("dirs" | "keys" | None, default="dirs") – Defines what kind of values from the ini to replace in strings: - “dirs” only replace directory paths - “keys” only replace key strings - None replaces both Recommended to only use “dirs” to remain consistent. “keys” can have unintended consequences and may replace more than it should
save (bool, default=True) – If the data was a file and this is enabled, saves the converted data dict to another file. The new file will simply append “.tmpl” to its name
report (bool, default=True) – Reports if no value in the input data was changed
**kwargs (dict) – Additional strings to replace. The values are replaced in a string with the key of the kwarg. For example: >>> kwargs = {“xyz”: “abc”} >>> data[“some_key”] = “replace abc here” will be replaced as: >>> data[“some_key”] = “replace {xyz} here” This is to be used with Ini.fromTemplate to replace values that are not found in the ini object
- Returns:
data – In-place replaced string values with template values If saved as a new file, returns the path instead
- Return type:
- fromTemplate(data: str | dict, save: bool = True, prepend: str = None, **kwargs) dict[source]
Recursively replaces the template values in found in string values with the real value from the ini. Template values are in the form of “{env.[value]}”. This is an in-place operation.
:param data: The dictionary to walk over and update values. If string, checks if this
exists as a file and loads that in as the data dict
- Parameters:
save (bool, default=True) – If the data was a file and this is enabled, saves the converted data dict to another file. If the input file ends with “.tmpl” then it will simply be cut. If it doesn’t or already exists, then the output filename will be the input filename prepended with prepend value.
prepend (str, default=None) – Prepend a string to the output filename. If not set and the input filename doesn’t end with “.tmpl”, then this is auto-set to “replaced”
**kwargs (dict) – Additional strings to replace. The values are replaced in a string with the key of the kwarg. For example: >>> kwargs = {“xyz”: “abc”} >>> data[“some_key”] = “replace {xyz} here” will be replaced as: >>> data[“some_key”] = “replace abc here” This is to be used with Ini.toTemplate to replace values that are not found in the ini object
- Returns:
data – In-place replaced template values with actual from a loaded ini If saved as a new file, returns the path instead
- Return type: