heiplanet_data.utils module⚓︎
heiplanet_data.utils
⚓︎
Functions:
-
generate_unique_tag–Generate a unique tag based on the current timestamp and hostname.
-
is_non_empty_file–Check if a file exists and is not empty.
-
is_valid_settings–Check if the settings are valid.
-
load_settings–Get the settings for preprocessing steps.
-
save_settings_to_file–Save the settings to a file.
Attributes:
DEFAULT_SETTINGS_FILE
module-attribute
⚓︎
DEFAULT_SETTINGS_FILE = {'era5': Path(pkg / 'era5_settings.json'), 'isimip': Path(pkg / 'isimip_settings.json')}
generate_unique_tag
⚓︎
Generate a unique tag based on the current timestamp and hostname.
Returns:
-
str(str) –A unique tag in the format "YYYYMMDD-HHMMSS_hostname".
is_non_empty_file
⚓︎
Check if a file exists and is not empty.
Parameters:
-
file_path(Path) –The path to the file.
Returns:
-
bool(bool) –True if the file exists and is not empty, False otherwise.
is_valid_settings
⚓︎
Check if the settings are valid. Args: settings (dict): The settings.
Returns:
-
bool(bool) –True if the settings are valid, False otherwise.
load_settings
⚓︎
Get the settings for preprocessing steps. If the setting path is "default", return the default settings of the source. If the setting path is not default, read the settings from the file. If the new settings are provided, overwrite the default/loaded settings.
Parameters:
-
source(str, default:'era5') –Source of the data to get corresponding settings.
-
setting_path(Path | str, default:'default') –Path to the settings file. Defaults to "default".
-
new_settings(dict | None, default:None) –New settings to overwrite the existing settings. Defaults to {}.
Returns:
-
Tuple[Dict[str, Any], str]–Tuple[Dict[str, Any], str]: A tuple containing the settings dictionary and the name of the settings file.
save_settings_to_file
⚓︎
Save the settings to a file. If dir_path is None, save to the current directory.
Parameters:
-
settings(dict) –The settings.
-
dir_path(str, default:None) –The path to save the settings file. Defaults to None.
-
file_name(str, default:'updated_settings.json') –The name for the settings file. Defaults to "updated_settings.json".