|
| 1 | +CMIP7 QC Validation |
| 2 | +=================== |
| 3 | + |
| 4 | +This page describes how to run ACCESS-MOPPy output quality-control checks on |
| 5 | +CMORised files. |
| 6 | + |
| 7 | +Scope |
| 8 | +----- |
| 9 | + |
| 10 | +- QC is run on the *CMORised output file*, not the raw model input. |
| 11 | +- For ``source_id=ACCESS-ESM1-6``, QC covers all variables present in |
| 12 | + ``ACCESS-ESM1-6_mappings.json`` with generic checks (non-missing values, |
| 13 | + finite values, and units checks where defined). |
| 14 | +- Physical ranges for all 293 ACCESS-ESM1-6 mapped variables are defined |
| 15 | + explicitly in the QC configuration with defaults and experiment-specific |
| 16 | + overrides (historical, piControl, ssp*). |
| 17 | +- Each variable's physical range is derived from its definition (mapping units) |
| 18 | + and stored as a per-variable rule entry. |
| 19 | +- Rules are loaded from: ``access_moppy/resources/qc/cmip7_ranges.yml``. |
| 20 | + |
| 21 | +Running QC in Notebooks |
| 22 | +----------------------- |
| 23 | + |
| 24 | +Use the Python API to validate a CMORised file after ``cmoriser.write()``. |
| 25 | + |
| 26 | +.. code-block:: python |
| 27 | +
|
| 28 | + from access_moppy.qc import validate_cmip7_output |
| 29 | +
|
| 30 | + # Write CMORised output first |
| 31 | + cmoriser.run() |
| 32 | + cmoriser.write() |
| 33 | +
|
| 34 | + # Validate the written file |
| 35 | + output_file = "/path/to/CMIP7/output.nc" |
| 36 | + validate_cmip7_output(output_file) |
| 37 | +
|
| 38 | +If a check fails, ``validate_cmip7_output`` raises ``ValueError`` with details |
| 39 | +about the variable, experiment, observed range, and allowed range. |
| 40 | + |
| 41 | +Running QC from the CLI |
| 42 | +----------------------- |
| 43 | + |
| 44 | +ACCESS-MOPPy provides a CLI command: |
| 45 | + |
| 46 | +.. code-block:: bash |
| 47 | +
|
| 48 | + moppy-qc /path/to/file1.nc /path/to/file2.nc |
| 49 | +
|
| 50 | +Exit status: |
| 51 | + |
| 52 | +- ``0``: all files passed |
| 53 | +- ``1``: one or more files failed |
| 54 | + |
| 55 | +Example output: |
| 56 | + |
| 57 | +.. code-block:: text |
| 58 | +
|
| 59 | + PASS /path/to/file1.nc |
| 60 | + FAIL /path/to/file2.nc: CMIP7 QC failed for tas in experiment piControl using rule piControl: observed range 182.000..329.400 K is outside allowed range 180.000..325.000 K. |
| 61 | +
|
| 62 | +Automatic QC during CMORisation |
| 63 | +------------------------------- |
| 64 | + |
| 65 | +For CMIP7 runs, ACCESS-MOPPy automatically validates output in the write path |
| 66 | +after writing and repacking the file. In other words, when you call |
| 67 | +``cmoriser.write()`` for CMIP7 output, QC is already executed. |
| 68 | + |
| 69 | +Batch Report QC Summary |
| 70 | +----------------------- |
| 71 | + |
| 72 | +When running a batch CMORisation, the batch report (``moppy_batch_report.json``) |
| 73 | +automatically includes a QC section summarizing validation results for all |
| 74 | +CMORised output files: |
| 75 | + |
| 76 | +.. code-block:: json |
| 77 | +
|
| 78 | + { |
| 79 | + "qc": { |
| 80 | + "passed": 42, |
| 81 | + "failed": 2, |
| 82 | + "total": 44, |
| 83 | + "failures": [ |
| 84 | + { |
| 85 | + "file": "/output/path/tas.nc", |
| 86 | + "variable_id": "tas", |
| 87 | + "experiment_id": "piControl", |
| 88 | + "error": "Observed range 182.000..329.400 K is outside allowed 180.000..325.000 K.", |
| 89 | + "observed_range": [182.0, 329.4], |
| 90 | + "allowed_range": [180.0, 325.0], |
| 91 | + "units": "K" |
| 92 | + } |
| 93 | + ] |
| 94 | + } |
| 95 | + } |
| 96 | +
|
| 97 | +To disable QC collection during batch report generation, use one of: |
| 98 | + |
| 99 | +.. code-block:: bash |
| 100 | +
|
| 101 | + # Environment variable |
| 102 | + export MOPPY_SKIP_QC=1 |
| 103 | + moppy-batch-report --db cmor_tasks.db |
| 104 | +
|
| 105 | + # CLI flag |
| 106 | + moppy-batch-report --db cmor_tasks.db --skip-qc |
| 107 | +
|
| 108 | +Or programmatically: |
| 109 | + |
| 110 | +.. code-block:: python |
| 111 | +
|
| 112 | + from access_moppy.batch_report import write_batch_report |
| 113 | + write_batch_report(db_path, skip_qc=True) |
| 114 | +
|
| 115 | +Extending rules |
| 116 | + |
| 117 | +--------------- |
| 118 | + |
| 119 | +To add experiment-specific thresholds for a variable, or to override ranges |
| 120 | +for newly added variables, edit: |
| 121 | + |
| 122 | +.. code-block:: text |
| 123 | +
|
| 124 | + src/access_moppy/resources/qc/cmip7_ranges.yml |
| 125 | +
|
| 126 | +Under the ``variables`` section, each variable has a ``default`` entry and an |
| 127 | +optional ``experiments`` map for experiment-specific min/max values. For example: |
| 128 | + |
| 129 | +.. code-block:: yaml |
| 130 | +
|
| 131 | + variables: |
| 132 | + tas: |
| 133 | + units: K |
| 134 | + default: |
| 135 | + min: 180.0 |
| 136 | + max: 330.0 |
| 137 | + experiments: |
| 138 | + historical: |
| 139 | + min: 180.0 |
| 140 | + max: 330.0 |
| 141 | + piControl: |
| 142 | + min: 180.0 |
| 143 | + max: 325.0 |
| 144 | +
|
| 145 | +Rule structure example: |
| 146 | + |
| 147 | +.. code-block:: yaml |
| 148 | +
|
| 149 | + variables: |
| 150 | + tas: |
| 151 | + units: K |
| 152 | + default: |
| 153 | + min: 180.0 |
| 154 | + max: 330.0 |
| 155 | + experiments: |
| 156 | + historical: |
| 157 | + min: 180.0 |
| 158 | + max: 330.0 |
| 159 | + piControl: |
| 160 | + min: 180.0 |
| 161 | + max: 325.0 |
| 162 | + ssp*: |
| 163 | + min: 180.0 |
| 164 | + max: 335.0 |
0 commit comments