Low-level utilities (util
)¶
Submodules:
Command-line utilities. |
|
Load model and project code from |
|
Logging utilities. |
Commonly used:
|
Convert data to a |
|
Load a |
|
Load a private data file from |
|
Construct a path to a file under |
|
Construct a path to a file under |
-
message_ix_models.util.
PACKAGE_DATA
: Dict[str, Any] = {}¶ Package data already loaded with
load_package_data()
.
-
message_ix_models.util.
PRIVATE_DATA
: Dict[str, Any] = {}¶ Data already loaded with
load_private_data()
.
-
message_ix_models.util.
as_codes
(data) → List[sdmx.model.Code][source]¶ Convert data to a
list
ofCode
objects.Various inputs are accepted:
-
message_ix_models.util.
load_package_data
(*parts: str, suffix: Optional[str] = '.yaml') → Mapping[source]¶ Load a
message_ix_models
package data file and return its contents.Data is re-used if already loaded.
Example
The single call:
>>> info = load_package_data("node", "R11")
loads the metadata file
data/node/R11.yaml
, parsing its contents,stores those values at
PACKAGE_DATA["node R11"]
for use by other code, andreturns the loaded values.
-
message_ix_models.util.
load_private_data
(*parts: str) → Mapping[source]¶ Load a private data file from
message_data
and return its contents.Analogous to
load_package_data
, but for non-public data.- Parameters
parts (iterable of str) – Used to construct a path under
data/
in themessage_data
repository.- Returns
Configuration values that were loaded.
- Return type
- Raises
RuntimeError – if
message_data
is not installed.
-
message_ix_models.util.
package_data_path
(*parts) → pathlib.Path[source]¶ Construct a path to a file under
message_ix_models/data/
.
-
message_ix_models.util.
private_data_path
(*parts) → pathlib.Path[source]¶ Construct a path to a file under
data/
inmessage_data
.
util.click
¶
Command-line utilities.
These are used for building CLIs using click
.
-
message_ix_models.util.click.
PARAMS
= {'dest': <Option dest>, 'dry_run': <Option dry_run>, 'force': <Option force>, 'output_model': <Option output_model>, 'platform_dest': <Option platform_dest>, 'policy_path': <Option policy_path>, 'quiet': <Option quiet>, 'regions': <Option regions>, 'rep_out_path': <Option rep_out_path>, 'rep_template': <Option rep_template>, 'run_reporting_only': <Option run_reporting_only>, 'ssp': <Argument ssp>, 'verbose': <Option verbose>}¶ Common command-line parameters (arguments and options). See
common_params()
.
-
message_ix_models.util.click.
common_params
(param_names: str)[source]¶ Decorate a click.command with common parameters param_names.
param_names must be a space-separated string of names appearing in
PARAMS
, e.g."ssp force output_model"
. The decorated function receives keyword arguments with these names:@click.command() @common_params("ssp force output_model") def mycmd(ssp, force, output_model) # ...
-
message_ix_models.util.click.
default_path_cb
(*default_parts)[source]¶ Return a callback function for click.Option handling.
If no option value is given, the callback uses
Context.get_local_path()
and default_parts to provide a path that is relative to local data directory, e.g. the current working directory (see Data, metadata, and configuration).
util.context
¶
util.importlib
¶
Load model and project code from message_data
.
util.logging
¶
Logging utilities.
-
class
message_ix_models.util.logging.
Formatter
(colorama)[source]¶ Formatter for log records.
- Parameters
colorama (module) – If provided,
colorama
is used to colour log messages printed to stdout.
-
message_ix_models.util.logging.
make_formatter
()[source]¶ Return a
Formatter
instance for themessage_ix_models
logger.See also