|
| 1 | +# Configuration |
| 2 | + |
| 3 | +This tutorial assumes that you have already installed Climate-REF and are using a Linux or MacOS operating system. |
| 4 | +The `ref` CLI tool should be available in your terminal after installation |
| 5 | +(or via `uv run ref` if you are installing from source). |
| 6 | +For installation instructions, see [Installation](../installation.md). |
| 7 | + |
| 8 | +Climate-REF uses a TOML configuration file to specify data paths, output directories, and other settings. In this step, we'll generate and customize your configuration file. |
| 9 | + |
| 10 | +Additional information about the configuration file can be found in the [Configuration documentation](../configuration.md). |
| 11 | + |
| 12 | + |
| 13 | +## 1. Select a location for storing your configuration |
| 14 | + |
| 15 | +The most important part of the REF configuration is the location where the REF will store its data and results. |
| 16 | +This is determined using the `$REF_CONFIGURATION` environment variable. |
| 17 | +This can use up a large amount of disk space, so it is important to choose a location with sufficient storage. |
| 18 | + |
| 19 | +If no value is provided a default location will be used, but this will not be suitable for most users |
| 20 | +who use shared computing facilities. |
| 21 | + |
| 22 | +This environment variable can be set in your shell configuration file (e.g., `.bashrc`, `.zshrc`, etc.) |
| 23 | +or exported directly in your terminal session. |
| 24 | + |
| 25 | +```bash |
| 26 | +export REF_CONFIGURATION="/path/to/your/ref/configuration" |
| 27 | +``` |
| 28 | + |
| 29 | + |
| 30 | +## 2. Generate |
| 31 | + |
| 32 | +Climate-REF provides a script to write out the default configuration. |
| 33 | + |
| 34 | +```bash |
| 35 | +mkdir $REF_CONFIGURATION |
| 36 | +ref config list > $REF_CONFIGURATION/ref.toml |
| 37 | +``` |
| 38 | + |
| 39 | +This command will create the `$REF_CONFIGURATION` directory and create a `ref.toml` inside it with the default configuration settings. |
| 40 | + |
| 41 | +/// admonition | Note |
| 42 | + |
| 43 | +The location that the REF looks for the configuration file can be viewed by running a CLI command using the `-v` flag: |
| 44 | + |
| 45 | +``` |
| 46 | +$ ref -v config list |
| 47 | +2025-05-28 10:45:29.244 +10:00 | DEBUG | climate_ref.cli - Configuration loaded from: /path/to/your/climate-ref/.ref/ref.toml |
| 48 | +... |
| 49 | +``` |
| 50 | + |
| 51 | +/// |
| 52 | + |
| 53 | +## 3. Edit your configuration |
| 54 | + |
| 55 | +Open `$REF_CONFIGURATION/ref.toml` in your editor of choice. |
| 56 | +You will see a template configuration file with sections for logging, paths, database settings, and diagnostic providers. |
| 57 | +These should be customized to suit your environment and preferences. |
| 58 | + |
| 59 | +Additional information about the configuration file can be found in the [Configuration documentation](../configuration.md). |
| 60 | + |
| 61 | +An example configuration file might look like this with some placeholders: |
| 62 | + |
| 63 | +```toml |
| 64 | +log_level = "INFO" |
| 65 | +log_format = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan> - <level>{message}</level>" |
| 66 | + |
| 67 | +[paths] |
| 68 | +log = "$REF_CONFIGURATION/log" |
| 69 | +scratch = "$REF_CONFIGURATION/scratch" |
| 70 | +software = "$REF_CONFIGURATION/software" |
| 71 | +results = "$REF_CONFIGURATION/results" |
| 72 | +dimensions_cv = "$REF_INSTALL_DIR/climate-ref-core/src/climate_ref_core/pycmec/cv_cmip7_aft.yaml" |
| 73 | + |
| 74 | +[db] |
| 75 | +database_url = "sqlite:///$REF_CONFIGURATION/db/climate_ref.db" |
| 76 | +run_migrations = true |
| 77 | +max_backups = 5 |
| 78 | + |
| 79 | +[executor] |
| 80 | +executor = "climate_ref.executor.LocalExecutor" |
| 81 | + |
| 82 | +[executor.config] |
| 83 | + |
| 84 | +[[diagnostic_providers]] |
| 85 | +provider = "climate_ref_esmvaltool.provider" |
| 86 | + |
| 87 | +[diagnostic_providers.config] |
| 88 | + |
| 89 | +[[diagnostic_providers]] |
| 90 | +provider = "climate_ref_ilamb.provider" |
| 91 | + |
| 92 | +[diagnostic_providers.config] |
| 93 | + |
| 94 | +[[diagnostic_providers]] |
| 95 | +provider = "climate_ref_pmp.provider" |
| 96 | + |
| 97 | +[diagnostic_providers.config] |
| 98 | +``` |
| 99 | + |
| 100 | + |
| 101 | +The particularly important sections to customize are: |
| 102 | + |
| 103 | +- **paths**: Set the paths for logs, scratch space, software, and results. These should point to directories where you have write access. |
| 104 | +- **db**: Configure the database URL. By default, it uses SQLite, but you can change it to a PostgreSQL or other database if needed. |
| 105 | +- **executor**: Set the executor type. The default is `LocalExecutor`, but you can change it to `CeleryExecutor` or `HPCExecutor` for distributed execution (see the [Executor documentation](../how-to-guides/executors.md) for more details). |
| 106 | +- **diagnostic_providers**: List the diagnostic providers you want to use. The default includes ESMValTool, ILAMB, and PMP. You can add or remove providers as needed. |
| 107 | + |
| 108 | +## 4. Environment variables |
| 109 | + |
| 110 | +Optionally, you can export environment variables instead of hardcoding paths. See the [Environment Variables documentation](../configuration.md#additional-environment-variables) for more details. |
| 111 | + |
| 112 | +One important environment variable is `REF_DATASET_CACHE_DIR`, |
| 113 | +which specifies where the REF will cache downloaded datasets. |
| 114 | +This can be GBs of data, so it is recommended to set this to a scratch filesystem or a location with sufficient disk space. |
| 115 | + |
| 116 | +This can be set as follows: |
| 117 | + |
| 118 | +```bash |
| 119 | +export REF_DATASET_CACHE_DIR="/path/to/your/dataset/cache" |
| 120 | +``` |
| 121 | + |
| 122 | +If set, Climate-REF will use these environment variables in preference to the configuration file. |
| 123 | + |
| 124 | + |
| 125 | +## 5. Validate your configuration |
| 126 | + |
| 127 | +To ensure your configuration is valid and correctly read by the REF, you can run the following command: |
| 128 | + |
| 129 | +```bash |
| 130 | +ref config list |
| 131 | +``` |
| 132 | + |
| 133 | +Your configuration should be displayed without errors and should include any changes you made in the `ref.toml` file. |
| 134 | + |
| 135 | + |
| 136 | +## 6. Create Proivider-specific conda environments |
| 137 | + |
| 138 | +Some diagnostic providers require specific conda environments to be created before they can be used. |
| 139 | +This should happen before you run any diagnostics to avoid multiple installations of the same environment. |
| 140 | +By default, these conda environments will be installed the `$REF_CONFIGURATION/software` directory, |
| 141 | +but the location can be changed in the configuration file using the [paths.software](../configuration.md#paths_software). |
| 142 | + |
| 143 | +You can create these environments using the following command: |
| 144 | + |
| 145 | +```bash |
| 146 | +ref providers create-env |
| 147 | +``` |
| 148 | + |
| 149 | +## Next steps |
| 150 | + |
| 151 | +After configuring, proceed to the [Download Datasets](02-download-datasets.md) tutorial to load your data into Climate-REF. |
0 commit comments