Skip to content

heiplanet_data.utils module⚓︎

heiplanet_data.utils ⚓︎

Functions:

Attributes:

DEFAULT_SCRIPT_CONFIG_FILE module-attribute ⚓︎

DEFAULT_SCRIPT_CONFIG_FILE = Path(pkg / 'script_config.json')

DEFAULT_SETTINGS_FILE module-attribute ⚓︎

DEFAULT_SETTINGS_FILE = {'era5': Path(pkg / 'era5_settings.json'), 'isimip': Path(pkg / 'isimip_settings.json')}

pkg module-attribute ⚓︎

pkg = resources.files('heiplanet_data')

generate_unique_tag ⚓︎

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 ⚓︎

is_non_empty_file(file_path)

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 ⚓︎

is_valid_settings(settings)

Check if the settings are valid. Args: settings (dict): The settings.

Returns:

  • bool ( bool ) –

    True if the settings are valid, False otherwise.

load_script_config ⚓︎

load_script_config(config_path='default')

Load user-configurable variables for the example scripts (e.g. script.py), such as the download request and data folders. If config_path is "default", load the packaged script_config.json. Otherwise, read the config from the given file path.

Parameters:

  • config_path (Path | str, default: 'default' ) –

    Path to the config file, or "default" to use the packaged default config. Defaults to "default".

Returns:

  • dict[str, Any] –

    Dict[str, Any]: The script config.

load_settings ⚓︎

load_settings(source='era5', setting_path='default', new_settings=None)

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_settings_to_file(settings, dir_path=None, file_name='updated_settings.json')

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".