Work with paths to files and data
This HOWTO contains some code examples that may help with following the requirements on data.
Connect static data to local data
Use the -rs options to the cp command:
git clone [email protected]:iiasa/message-static-data.git
cd /path/to/message-local-data
cp -rsv /path/to/message-static-data ./
This recursively creates subdirectories in the local data directory that mirror those existing in message-static-data, and creates a symlink to every file in every directory. Code that looks within the local data directory will then be able to locate these files.
If needed, delete the directories in message-local-data and repeat the cp call to recreate.
Identify the cache path used on the current system
from message_ix_models.util.config import Config
cfg = Config()
print(cfg.cache_path)
Identify the cache path without a Context
Internal code that cannot access a Config
or Context
instance
should instead use platformdirs.user_cache_path()
directly:
from platformdirs import user_cache_path
# Always use "message-ix-models" as the `appname` parameter
ucp = user_cache_path("message-ix-models")
# Construct the sub-directory for the current module
dir_ = ucp.joinpath("my-project", "subdir")
dir_.mkdir(parents=True, exist_ok=True)
# Construct a file path within this directory
p = dir_.joinpath("data-file-name.csv")