scm4opt 4.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. scm4opt/__init__.py +8 -0
  2. scm4opt/__main__.py +8 -0
  3. scm4opt/cli.py +45 -0
  4. scm4opt/core/__init__.py +2 -0
  5. scm4opt/core/config.py +297 -0
  6. scm4opt/core/constants.py +25 -0
  7. scm4opt/core/errors.py +19 -0
  8. scm4opt/core/registry.py +217 -0
  9. scm4opt/core/sets.py +46 -0
  10. scm4opt/core/tables.py +20 -0
  11. scm4opt/core/units.py +167 -0
  12. scm4opt/core/version.py +21 -0
  13. scm4opt/data/AGAGE/c2f6.csv +127 -0
  14. scm4opt/data/AGAGE/c3f8.csv +127 -0
  15. scm4opt/data/AGAGE/cc4f8.csv +94 -0
  16. scm4opt/data/AGAGE/ccl4.csv +279 -0
  17. scm4opt/data/AGAGE/cf4.csv +127 -0
  18. scm4opt/data/AGAGE/cfc11.csv +279 -0
  19. scm4opt/data/AGAGE/cfc113.csv +214 -0
  20. scm4opt/data/AGAGE/cfc114.csv +85 -0
  21. scm4opt/data/AGAGE/cfc115.csv +127 -0
  22. scm4opt/data/AGAGE/cfc12.csv +279 -0
  23. scm4opt/data/AGAGE/cfc13.csv +127 -0
  24. scm4opt/data/AGAGE/ch2cl2.csv +178 -0
  25. scm4opt/data/AGAGE/ch3br.csv +162 -0
  26. scm4opt/data/AGAGE/ch3ccl3.csv +279 -0
  27. scm4opt/data/AGAGE/ch3cl.csv +162 -0
  28. scm4opt/data/AGAGE/chcl3.csv +187 -0
  29. scm4opt/data/AGAGE/halon1211.csv +179 -0
  30. scm4opt/data/AGAGE/halon1301.csv +162 -0
  31. scm4opt/data/AGAGE/halon2402.csv +127 -0
  32. scm4opt/data/AGAGE/hcfc124.csv +162 -0
  33. scm4opt/data/AGAGE/hcfc132b.csv +72 -0
  34. scm4opt/data/AGAGE/hcfc133a.csv +72 -0
  35. scm4opt/data/AGAGE/hcfc141b.csv +175 -0
  36. scm4opt/data/AGAGE/hcfc142b.csv +182 -0
  37. scm4opt/data/AGAGE/hcfc22.csv +161 -0
  38. scm4opt/data/AGAGE/hfc125.csv +162 -0
  39. scm4opt/data/AGAGE/hfc134a.csv +182 -0
  40. scm4opt/data/AGAGE/hfc143a.csv +127 -0
  41. scm4opt/data/AGAGE/hfc152a.csv +182 -0
  42. scm4opt/data/AGAGE/hfc227ea.csv +122 -0
  43. scm4opt/data/AGAGE/hfc23.csv +105 -0
  44. scm4opt/data/AGAGE/hfc236fa.csv +110 -0
  45. scm4opt/data/AGAGE/hfc245fa.csv +123 -0
  46. scm4opt/data/AGAGE/hfc32.csv +127 -0
  47. scm4opt/data/AGAGE/hfc365mfc.csv +133 -0
  48. scm4opt/data/AGAGE/hfc4310mee.csv +88 -0
  49. scm4opt/data/AGAGE/nf3.csv +70 -0
  50. scm4opt/data/AGAGE/sf6.csv +141 -0
  51. scm4opt/data/AGAGE/so2f2.csv +121 -0
  52. scm4opt/data/AR6/AR6_foricng_contrails.csv +1616 -0
  53. scm4opt/data/CMIP6/doe_gcm_est_etminan.csv +27 -0
  54. scm4opt/data/CMIP6/doe_gcm_est_myhre.csv +27 -0
  55. scm4opt/data/CMIP6/doe_gcm_est_ssp534.csv +8 -0
  56. scm4opt/data/CMIP6/land_gcm_est.csv +27 -0
  57. scm4opt/data/CMIP6/ocean_gcm_est.csv +27 -0
  58. scm4opt/data/CMIP6/ocean_gcm_osc_est.csv +27 -0
  59. scm4opt/data/CMonitor/CMonitor_bimon.csv +38 -0
  60. scm4opt/data/MAGICC6/NOTICE.txt +20 -0
  61. scm4opt/data/MAGICC6/land_c4mip_bern.csv +19 -0
  62. scm4opt/data/NOAA/noaa_ch4_mm_gl.gdx.csv +256 -0
  63. scm4opt/data/NOAA/noaa_co2_mm_mlo.gdx.csv +408 -0
  64. scm4opt/data/NOAA/noaa_n2o_mm_gl.gdx.csv +151 -0
  65. scm4opt/data/NOAA/noaa_sf6_mm_gl.gdx.csv +172 -0
  66. scm4opt/data/RCMIP/1pctCO2-cdr_tas_CNRM-ESM2-1.csv +2090 -0
  67. scm4opt/data/RCMIP3/esm-allGHG-hist.csv +1041 -0
  68. scm4opt/data/RCMIP3/esm-allGHG-hist_1750.csv +1641 -0
  69. scm4opt/data/RCMIP3/esm-hist.csv +1041 -0
  70. scm4opt/data/RCMIP3/esm-hist_1750.csv +1641 -0
  71. scm4opt/data/RCMIP3/esm-hist_conc.csv +1035 -0
  72. scm4opt/data/RCMIP3/esm-hist_conc_1750.csv +1635 -0
  73. scm4opt/data/RCMIP3/historical.csv +1041 -0
  74. scm4opt/data/RCMIP3/historical_1750.csv +1641 -0
  75. scm4opt/data/RCMIP3/historical_conc.csv +1035 -0
  76. scm4opt/data/RCMIP3/historical_conc_1750.csv +1635 -0
  77. scm4opt/data/RCMIP3/ssp126.csv +3903 -0
  78. scm4opt/data/RCMIP3/ssp585.csv +3903 -0
  79. scm4opt/data/RCMIP3/ssp585_conc.csv +3903 -0
  80. scm4opt/data/RCMIP3_src/conc_mapping_1750.csv +44 -0
  81. scm4opt/data/RCMIP3_src/output_mapping.csv +273 -0
  82. scm4opt/data/RCMIP3_src/rcmip3-data-submission-template-v1-1-0_columns.csv +1 -0
  83. scm4opt/data/contrib/COMB_IAMC/total/SSP1_19_WORLD.csv +1503 -0
  84. scm4opt/data/contrib/LC_LUH_IAMC/AFR/lc_SSP1_19.csv +1502 -0
  85. scm4opt/data/contrib/LC_LUH_IAMC/AFR/lc_SSP2_45.csv +1502 -0
  86. scm4opt/data/contrib/LC_LUH_IAMC/CHN/lc_SSP1_19.csv +1502 -0
  87. scm4opt/data/contrib/LC_LUH_IAMC/CHN/lc_SSP2_45.csv +1502 -0
  88. scm4opt/data/contrib/LC_LUH_IAMC/EUR/lc_SSP1_19.csv +1502 -0
  89. scm4opt/data/contrib/LC_LUH_IAMC/EUR/lc_SSP2_45.csv +1502 -0
  90. scm4opt/data/contrib/LC_LUH_IAMC/IND/lc_SSP1_19.csv +1502 -0
  91. scm4opt/data/contrib/LC_LUH_IAMC/IND/lc_SSP2_45.csv +1502 -0
  92. scm4opt/data/contrib/LC_LUH_IAMC/JPN/lc_SSP1_19.csv +1502 -0
  93. scm4opt/data/contrib/LC_LUH_IAMC/JPN/lc_SSP2_45.csv +1502 -0
  94. scm4opt/data/contrib/LC_LUH_IAMC/LAM/lc_SSP1_19.csv +1502 -0
  95. scm4opt/data/contrib/LC_LUH_IAMC/LAM/lc_SSP2_45.csv +1502 -0
  96. scm4opt/data/contrib/LC_LUH_IAMC/MEA/lc_SSP1_19.csv +1502 -0
  97. scm4opt/data/contrib/LC_LUH_IAMC/MEA/lc_SSP2_45.csv +1502 -0
  98. scm4opt/data/contrib/LC_LUH_IAMC/OAS/lc_SSP1_19.csv +1502 -0
  99. scm4opt/data/contrib/LC_LUH_IAMC/OAS/lc_SSP2_45.csv +1502 -0
  100. scm4opt/data/contrib/LC_LUH_IAMC/ROW/lc_SSP1_19.csv +1502 -0
  101. scm4opt/data/contrib/LC_LUH_IAMC/ROW/lc_SSP2_45.csv +1502 -0
  102. scm4opt/data/contrib/LC_LUH_IAMC/RUS/lc_SSP1_19.csv +1502 -0
  103. scm4opt/data/contrib/LC_LUH_IAMC/RUS/lc_SSP2_45.csv +1502 -0
  104. scm4opt/data/contrib/LC_LUH_IAMC/USA/lc_SSP1_19.csv +1502 -0
  105. scm4opt/data/contrib/LC_LUH_IAMC/USA/lc_SSP2_45.csv +1502 -0
  106. scm4opt/data/contrib/LUC_BLUE_IAMC/WORLD/CO2_EMISS_LUC_SSP1_19.csv +1502 -0
  107. scm4opt/data/ensemble/contrib_unc_h.txt +2000 -0
  108. scm4opt/data/ensemble/rcmip_unc.txt +500 -0
  109. scm4opt/data/hector/ocean26.csv +3212 -0
  110. scm4opt/data/inputs_manifest.csv +81 -0
  111. scm4opt/data/nat/Solar_foricng_bimon.csv +2701 -0
  112. scm4opt/data/nat/Solar_foricng_rcmip3_hist_bimon.csv +3903 -0
  113. scm4opt/data/nat/Solar_foricng_rcmip3_hist_bimon_1750.csv +4503 -0
  114. scm4opt/data/nat/Solar_foricng_rcmip3_scen7_bimon.csv +3903 -0
  115. scm4opt/data/nat/Solar_foricng_rcmip3_scen7_bimon_1750.csv +4503 -0
  116. scm4opt/data/nat/Solar_foricng_rcmip3_ssp_bimon.csv +3903 -0
  117. scm4opt/data/nat/Solar_foricng_rcmip3_ssp_bimon_1750.csv +4503 -0
  118. scm4opt/data/nat/Solar_foricng_rcmip3_zero_bimon.csv +3903 -0
  119. scm4opt/data/nat/Solar_foricng_rcmip3_zero_bimon_1750.csv +4503 -0
  120. scm4opt/data/nat/Volcanic_foricng_bimon.csv +1051 -0
  121. scm4opt/data/nat/Volcanic_foricng_rcmip3_hist_bimon.csv +3903 -0
  122. scm4opt/data/nat/Volcanic_foricng_rcmip3_hist_bimon_1750.csv +4503 -0
  123. scm4opt/data/nat/Volcanic_foricng_rcmip3_scen7_bimon.csv +3903 -0
  124. scm4opt/data/nat/Volcanic_foricng_rcmip3_scen7_bimon_1750.csv +4503 -0
  125. scm4opt/data/nat/Volcanic_foricng_rcmip3_ssp_bimon.csv +3903 -0
  126. scm4opt/data/nat/Volcanic_foricng_rcmip3_ssp_bimon_1750.csv +4503 -0
  127. scm4opt/data/nat/Volcanic_foricng_rcmip3_zero_bimon.csv +3903 -0
  128. scm4opt/data/nat/Volcanic_foricng_rcmip3_zero_bimon_1750.csv +4503 -0
  129. scm4opt/data/registry/registry.csv +802 -0
  130. scm4opt/data/tables/halo_fracrel.csv +21 -0
  131. scm4opt/data/tables/halo_parameters.csv +49 -0
  132. scm4opt/data/tables/halo_radeff.csv +49 -0
  133. scm4opt/data/tables/lcc_albedo_global.csv +13 -0
  134. scm4opt/data/tables/lcc_albedo_regional.csv +133 -0
  135. scm4opt/ensemble.py +213 -0
  136. scm4opt/io/__init__.py +2 -0
  137. scm4opt/io/datasets.py +227 -0
  138. scm4opt/io/inputs.py +512 -0
  139. scm4opt/io/rcmip_export.py +271 -0
  140. scm4opt/io/report.py +339 -0
  141. scm4opt/physics/__init__.py +2 -0
  142. scm4opt/physics/atmosphere.py +109 -0
  143. scm4opt/physics/chemistry.py +735 -0
  144. scm4opt/physics/doeclim.py +399 -0
  145. scm4opt/physics/forcing.py +580 -0
  146. scm4opt/physics/forcing_data.py +48 -0
  147. scm4opt/physics/halo_data.py +44 -0
  148. scm4opt/physics/land.py +487 -0
  149. scm4opt/physics/ocean_hector.py +460 -0
  150. scm4opt/physics/ocean_models.py +45 -0
  151. scm4opt/physics/ocean_oscar.py +377 -0
  152. scm4opt/scenarios/__init__.py +2 -0
  153. scm4opt/scenarios/forward.py +303 -0
  154. scm4opt/scenarios/rcmip3_data.py +538 -0
  155. scm4opt-4.1.0.dist-info/METADATA +157 -0
  156. scm4opt-4.1.0.dist-info/RECORD +162 -0
  157. scm4opt-4.1.0.dist-info/WHEEL +5 -0
  158. scm4opt-4.1.0.dist-info/entry_points.txt +2 -0
  159. scm4opt-4.1.0.dist-info/licenses/LICENSE +674 -0
  160. scm4opt-4.1.0.dist-info/licenses/NOTICE +64 -0
  161. scm4opt-4.1.0.dist-info/licenses/scm4opt/data/MAGICC6/NOTICE.txt +20 -0
  162. scm4opt-4.1.0.dist-info/top_level.txt +1 -0
scm4opt/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ """SCM4OPT: Simple Climate Model for OPTimization (Python version).
3
+
4
+ A reduced-complexity coupled climate model (carbon cycle, atmospheric chemistry,
5
+ radiative forcing, DOECLIM energy balance), version 4.1. See README.md.
6
+ """
7
+
8
+ from .core.version import RCMIP_CLIMATE_MODEL, __version__ # noqa: F401
scm4opt/__main__.py ADDED
@@ -0,0 +1,8 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ """python3 -m scm4opt ...: the command line (cli.py)."""
3
+
4
+ import sys
5
+
6
+ from .cli import main
7
+
8
+ sys.exit(main())
scm4opt/cli.py ADDED
@@ -0,0 +1,45 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ """Command line.
3
+
4
+ scm4opt [run] [--flag=value ...] coupled forward run
5
+ (--name=value flags, e.g. --scen=rcmip3 --rname=ssp585)
6
+ scm4opt ensemble [options] [-- flags] ensemble via GNU parallel (ensemble.py)
7
+ scm4opt export [options] combine ensemble members into RCMIP3 files
8
+ (io/rcmip_export.py; scm4opt export --help)
9
+ scm4opt data verify|pack|fetch|manifest scenario input data: checksums, archives for
10
+ hosting, download (io/datasets.py; scm4opt data --help)
11
+ scm4opt --version package version and RCMIP3 model name
12
+ """
13
+
14
+ import sys
15
+
16
+
17
+ def main(argv=None):
18
+ argv = list(sys.argv[1:] if argv is None else argv)
19
+ if argv[:1] in (["-V"], ["--version"], ["version"]):
20
+ from .core.version import version_line
21
+ print(version_line())
22
+ return 0
23
+ if argv[:1] in (["-h"], ["--help"], ["help"]):
24
+ print(__doc__)
25
+ return 0
26
+ cmd = argv[0] if argv and not argv[0].startswith("-") else "run"
27
+ if argv and argv[0] == cmd:
28
+ argv = argv[1:]
29
+ if cmd == "run":
30
+ from .scenarios.forward import main as run_main
31
+ run_main(argv)
32
+ return 0
33
+ if cmd == "ensemble":
34
+ from .ensemble import main as ensemble_main
35
+ return ensemble_main(argv)
36
+ if cmd == "export":
37
+ from .io.rcmip_export import main as export_main
38
+ return export_main(argv)
39
+ if cmd == "data":
40
+ from .io.datasets import main as data_main
41
+ return data_main(argv)
42
+ if cmd in ("-h", "--help", "help"):
43
+ print(__doc__)
44
+ return 0
45
+ sys.exit(f"unknown command {cmd!r}; use run, ensemble, export or data (scm4opt help)")
@@ -0,0 +1,2 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ """Configuration, constants and index sets."""
scm4opt/core/config.py ADDED
@@ -0,0 +1,297 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ """Run configuration: the model's --name=value options.
3
+
4
+ Defaults are the standard configuration for --scen=contrib.
5
+ """
6
+
7
+ import dataclasses
8
+ import os
9
+ import sys
10
+ from dataclasses import dataclass, field
11
+ from importlib.resources import files
12
+ from pathlib import Path
13
+
14
+ # Data locations
15
+ # PACKAGE_DATA_DIR <package>/data/: in the exported repository the one data folder
16
+ # (parameter tables shipped with the package + scenario inputs);
17
+ # absent in the development tree
18
+ # DAT_DIR where inputs are read: the SCM4OPT_DATA environment variable, else
19
+ # dat/ next to the package if it exists (development tree),
20
+ # else PACKAGE_DATA_DIR (exported repository)
21
+ PACKAGE_ROOT = Path(str(files(__package__.split(".")[0])))
22
+ PACKAGE_DATA_DIR = PACKAGE_ROOT / "data"
23
+ REPO_DIR = PACKAGE_ROOT.parent
24
+ DAT_DIR = Path(os.environ.get("SCM4OPT_DATA")
25
+ or (REPO_DIR / "dat" if (REPO_DIR / "dat").is_dir() else PACKAGE_DATA_DIR))
26
+ TRUNK_DIR = REPO_DIR # former name, kept for old scripts
27
+
28
+
29
+ def n_steps(cfg):
30
+ """Number of model steps (1/6 yr) of a configuration, first_year..last_year inclusive
31
+ (after the scenario's own horizon is applied, see resolve)."""
32
+ cfg = resolve(cfg)
33
+ return (cfg.last_year - cfg.first_year) * 6 + 1
34
+
35
+
36
+ def data_path(dat_dir, *parts):
37
+ """dat_dir/<parts> if it exists, else the copy shipped in PACKAGE_DATA_DIR, else
38
+ dat_dir/<parts> (so a missing file is reported under the user's data directory)."""
39
+ p = Path(dat_dir).joinpath(*parts)
40
+ if p.exists():
41
+ return p
42
+ q = PACKAGE_DATA_DIR.joinpath(*parts)
43
+ return q if q.exists() else p
44
+
45
+
46
+ @dataclass(frozen=True)
47
+ class ChemOptions:
48
+ """Chemistry model choices (the --<process>_mdl options).
49
+
50
+ Field names are the option names (e.g. --OHSNKfct_mdl=lin); defaults are the
51
+ standard configuration.
52
+ """
53
+ OHSNK_mdl: str = "CMAM" # CH4 OH lifetime (tau_CH4_OH0)
54
+ OHSNKfct_mdl: str = "log" # OH dependence on NOx/CO/VOC: log | lin
55
+ OHSNKtrans_mdl: str = "Oslo-CTM3" # OH sensitivities
56
+ HVSNK_mdl: str = "G2d" # N2O photolysis lifetime
57
+ HVSNKtrans_mdl: str = "G2d" # photolysis sensitivities
58
+ HVSNKcirc_mdl: str = "CAM-35" # age-of-air sensitivity
59
+ O3Temis_mdl: str = "mean-OxComp" # tropospheric O3 vs emissions
60
+ O3Tclim_mdl: str = "CESM-CAM-superfast" # tropospheric O3 vs climate
61
+ O3Strans_mdl: str = "LMDZrepro" # stratospheric O3
62
+ O3Snitrous_mdl: str = "Daniel2010-lin" # stratospheric O3 vs N2O
63
+ O3Sfracrel_mdl: str = "Engel2017" # fractional release for EESC
64
+ POAconv_mdl: str = "default" # OC -> POM conversion
65
+ POAload_mdl: str = "CSIRO-Mk360"
66
+ SO4load_mdl: str = "MIROC-CHEM"
67
+ BCload_mdl: str = "MIROC-CHEM"
68
+ NO3load_mdl: str = "Hauglustaine2014"
69
+ SOAload_mdl: str = "GFDL-AM3"
70
+ DUSTload_mdl: str = "CSIRO-Mk360"
71
+ SALTload_mdl: str = "GFDL-AM3"
72
+ solub_mdl: str = "Lamarque2011" # aerosol solubility (cloud forcing)
73
+
74
+
75
+ @dataclass(frozen=True)
76
+ class OceanOptions:
77
+ """Ocean model choices (OSCAR ocean; option names).
78
+
79
+ Defaults are the standard configuration: BD-model surface box model, CO2SysPower
80
+ carbonate chemistry, MPI-ESM-LR mixed-layer response and pco2 weights 0/0/1.
81
+ v_osn_model, mod_OSNKchem, mod_OSNKtrans and the three pco2_w_* weights can all be
82
+ set from the command line.
83
+ """
84
+ v_osn_model: str = "BD-model" # surface box model: HILDA | BD-model | 2D-model | 3D-model
85
+ mod_OSNKchem: str = "CO2SysPower" # carbonate chemistry: CO2SysPower | CO2SysPade | (else) Poly
86
+ mod_OSNKtrans: str = "MPI-ESM-LR" # mixed-layer response when --cm6mdl is unset
87
+ pco2_form: str | None = None # --pco2_form=Poly|Pade|Power, overrides mod_OSNKchem
88
+ pco2_w_poly: float | None = 0.0 # weights override both (None = not set); normalised
89
+ pco2_w_pade: float | None = 0.0
90
+ pco2_w_power: float | None = 1.0
91
+ ocn_nsub: int = 4 # Euler sub-steps per model step
92
+ ocean_model: str = "osc" # --ocean_model=osc (OSCAR ocean, default) |
93
+ # hector (Hector v1.0 ocean, ocean_hector.py)
94
+ same_alk: bool = False # --same_alk (hector): one alkalinity for all boxes
95
+ hector_tcre_rates: bool = False # hector, --scen=tcre|tcre2: recompute the k-rates
96
+ # from the tcre transports (default: keep them)
97
+
98
+
99
+ @dataclass(frozen=True)
100
+ class ForcingOptions:
101
+ """Forcing model choices (the --<process>_mdl options; standard defaults)."""
102
+ O3Tradeff_mdl: str = "IPCC-AR5" # tropospheric O3 radiative efficiency
103
+ O3Sradeff_mdl: str = "IPCC-AR4" # stratospheric O3 radiative efficiency
104
+ POAradeff_mdl: str = "mean-AeroCom2"
105
+ SO4radeff_mdl: str = "mean-AeroCom2"
106
+ BCradeff_mdl: str = "mean-AeroCom2"
107
+ BCadjust_mdl: str = "CSIRO" # BC semi-direct adjustment
108
+ NO3radeff_mdl: str = "mean-AeroCom2"
109
+ SOAradeff_mdl: str = "mean-AeroCom2"
110
+ CLOUDerf_mdl: str = "mean-ACCMIP" # aerosol-cloud interaction
111
+ CLOUDpreind_mdl: str = "median" # preindustrial hydrophilic aerosol: low | median | high
112
+ ALBBCrf_mdl: str = "mean-ACCMIP" # BC on snow
113
+ ALBBCwarm_mdl: str = "median" # BC-on-snow efficacy: low | median | high
114
+ ALBLCwarm_mdl: str = "Jones2013" # land-cover albedo efficacy
115
+ PRECradfact_mdl: str = "Kvalevag2013" # atmospheric absorption fractions (rfc_atm)
116
+ ALBLCflux_mdl: str = "CERES" # land-cover albedo: flux | albedo | cover datasets
117
+ ALBLCalb_mdl: str = "GlobAlbedo"
118
+ ALBLCcover_mdl: str = "ESA-CCI"
119
+
120
+
121
+ @dataclass(frozen=True)
122
+ class RunConfig:
123
+ scen: str = "contrib" # scenario driver: contrib | rcmip3 | contrib_rfc | tcre | tcre2
124
+ psce: str = "SSP1_19" # scenario name in the input file names
125
+ psrc: str = "IAMC" # scenario source
126
+ hsrc: str = "COMB" # historical source of the emission totals
127
+ land: str | None = "LUC_BLUE" # land-use CO2 source; None = keep co2l from the totals
128
+ lcov: str = "LUH" # land-cover source for the albedo forcing
129
+ rgn: str = "WORLD"
130
+ csec: str = "EMISS_IND" # emission sector tag (used in the contrib_rfc file names)
131
+ ems: str = "CO2" # --ems: emission species tag of the contribution reports; unused otherwise
132
+
133
+ cm6mdl: str | None = "NorESM2-MM" # None = no --cm6mdl: MAGICC6 defaults
134
+ rname: str | None = None # RCMIP scenario name (--rname); switches a few model branches
135
+ use_ncycle: bool = False # --use_ncycle: N-cycle limitation of land NPP
136
+ ch4rfc: str = "etminan"
137
+ nat_grp: str | None = None # natural-forcing group; None = from rname
138
+ # marginal-analysis period tmargin: at most one of these
139
+ tproj: bool = False # --tproj: 2023-2100
140
+ thist: bool = False # --thist: 1850-2022
141
+ tyear: int | None = None # --tyear=Y: the six steps of year Y
142
+ byear: int | None = None # --byear=Y: t.val < Y+1
143
+ dyear: int | None = None # --dyear=Y: Y+1 <= t.val < Y+11
144
+ rdc_rfc: str | None = None # --rdc_rfc=rfc_volc|rfc_solar|rfc_DUST: zero it over tmargin
145
+ rdc_lcc: str | None = None # --rdc_lcc=WORLD|<region>: hold 1850 land cover over tmargin
146
+ zero_nature: bool = False # --zero_nature: no volcanic, solar or dust forcing
147
+ clim_sensi: float | None = None # --clim_sensi: overrides DOECLIM's doe_t2co (ECS)
148
+ use_ssp534: bool = False # --use_ssp534: DOECLIM parameters from doe_gcm_est_ssp534.csv
149
+ co2_only: bool = False # --co2_only: DOECLIM driven by rfc_CO2 instead of erf_tot
150
+ load_conc: str | None = None # --load_conc=all|nco2: prescribed concentrations;
151
+ # "all" includes CO2, "nco2" keeps CO2 emission-driven
152
+ load_AGAGE: bool = False # --load_AGAGE: overwrite prescribed halogens with AGAGE data
153
+ load_NOAA: bool = False # --load_NOAA: overwrite prescribed CO2/CH4/N2O/SF6 with NOAA data
154
+ fix_conc: bool = False # --fix_conc (contrib): CO2 concentration prescribed from
155
+ # dat/contrib/<hsrc>_<psrc>/conc/<psce>_WORLD.csv
156
+ co2_conc_initial: float | None = None # --co2_conc_initial=<ppm> (former --co2_conc_1850):
157
+ # CO2 of the atmospheric pool at the first step (default 284, or
158
+ # 278.00745 with --first_year=1750); e.g. the prescribed first-year
159
+ # value, to rerun compatible emissions (scm_eind_co2_compat) exactly
160
+ lnd_fb_1850: str | None = None # --first_year=1750: fert (default) starts the CO2 fertilisation
161
+ # in 1850, relative to the simulated 1850 CO2; both also starts the
162
+ # land temperature feedbacks in 1850; none applies them from 1750
163
+ norgrwth_pre1850: str | None = None # --first_year=1750: non-regrowing fraction of the land-use
164
+ # emissions before 1850 (default 1: no regrowth legacy of the
165
+ # 1750-1849 land use, as in the 1850 start); none = the model's
166
+ # fraction for all years
167
+ fol: str | None = None # --fol: forcing-data folder for --scen=contrib_rfc
168
+ case: str | None = None # --case: ensemble member of the contrib_rfc forcing data
169
+ minus_rfc: str | None = None # --minus_rfc=rfc_X: scale component X by (1-fraction) over tmargin
170
+ fraction: float | None = None # --fraction: cnb_fraction (default 0.001)
171
+ minus_ems: bool = False # --minus_ems (contrib): reduce the --rdc_ems emissions over tmargin
172
+ rdc_ems: str | None = None # --rdc_ems=<column>: co2i, co2l, co2n (taken from co2i), ch4, bc,
173
+ # ..., or a halogen; a column absent from the inputs stays 0
174
+ rdc_mix: bool = False # --rdc_mix: reduce <rdc_ems>i by fraction * (<rdc_ems>i + <rdc_ems>l)
175
+ use_cm: bool = False # --use_cm (contrib): Carbon Monitor CO2 (co2i) 2019-2025, the other
176
+ # emissions after 2022.833 held at their 2018-2022.833 mean to 2025
177
+ reduce_after_cm: bool = False # --reduce_after_cm: --minus_ems reduces the emissions after
178
+ # --use_cm (reference: before, so the Carbon Monitor values replace
179
+ # the reduced co2i of 2019-2025 and the reduction enters the means);
180
+ # also set by --ref_compat=0
181
+ rout3: str | None = None # --rout3=<dir>: output folder of the report (report.py)
182
+ cout5: str | None = None # --cout5=<dir>: contribution report (report.py, write_cout5_csv)
183
+ ctag: str = "all" # --ctag: tag in the report file name <rname>_<case>_<ctag>
184
+ climate_model: str | None = None # --climate_model: climate_model of the RCMIP3 rows
185
+ # (default version.RCMIP_CLIMATE_MODEL)
186
+ ref_compat: bool = True # --ref_compat=0: corrected behaviour instead of the deliberate
187
+ # quirks kept for the SCM4OPT v4.1 reference results (README: Reference compatibility)
188
+ rcmip_csv: bool = True # with --rout3, also write the RCMIP3 template CSV
189
+ rcmip_compat_ems: bool = False # --rcmip_compat_ems=1: where CO2 is prescribed, the RCMIP3
190
+ # rows Emissions|CO2 and Emissions|CO2|Fossil and Industry hold
191
+ # the compatible emissions (scm_ems_co2_compat, scm_eind_co2_compat)
192
+ # instead of the scenario's input emissions
193
+ report_csv: bool = True # with --rout3, write the per-step report CSV (~27 MB per run)
194
+ first_year: int = 1850 # --first_year=1750 (--scen=rcmip3): extended run from 1750 with the
195
+ # "_1750" inputs (anomalies from 1750) and 1750 reference values
196
+ last_year: int = 2100 # end of the --scen=contrib horizon
197
+ chem: ChemOptions = field(default_factory=ChemOptions)
198
+ ocean: OceanOptions = field(default_factory=OceanOptions)
199
+ forcing: ForcingOptions = field(default_factory=ForcingOptions)
200
+ dat_dir: Path = DAT_DIR
201
+
202
+
203
+ def nat_grp_of(cfg):
204
+ """Natural-forcing group: explicit cfg.nat_grp, else from --rname."""
205
+ if cfg.nat_grp is not None:
206
+ return cfg.nat_grp
207
+ from ..scenarios.rcmip3_data import NAT_GRP_BY_RNAME
208
+ return NAT_GRP_BY_RNAME.get(cfg.rname, "default") if cfg.rname else "default"
209
+
210
+
211
+ # --scen=rcmip3 forces these options, whatever was passed
212
+ RCMIP3_FORCED = dict(psce="SSP2_45", lcov="LUH", hsrc="CEDS", psrc="IAMC", land="LUC_GCP")
213
+
214
+
215
+ def resolve(cfg):
216
+ """The effective configuration: the rcmip3 overrides and time horizons."""
217
+ import dataclasses
218
+ check_first_year(cfg)
219
+ y1750 = cfg.first_year == 1750 # defaults of the 1750-only land options
220
+ cfg = dataclasses.replace(
221
+ cfg, lnd_fb_1850=cfg.lnd_fb_1850 or ("fert" if y1750 else "none"),
222
+ norgrwth_pre1850=cfg.norgrwth_pre1850 or ("1" if y1750 else "none"))
223
+ if cfg.scen != "rcmip3":
224
+ return cfg
225
+ if not cfg.rname:
226
+ raise ValueError("--scen=rcmip3 needs --rname")
227
+ from ..scenarios.rcmip3_data import DEFAULT_LAST_YEAR, LAST_YEAR_BY_RNAME
228
+ return dataclasses.replace(cfg, **RCMIP3_FORCED,
229
+ last_year=LAST_YEAR_BY_RNAME.get(cfg.rname, DEFAULT_LAST_YEAR))
230
+
231
+
232
+ def check_first_year(cfg):
233
+ """--first_year: 1850, or 1750 with --scen=rcmip3; the 1750-only options need 1750."""
234
+ if cfg.first_year not in (1850, 1750):
235
+ raise ValueError(f"--first_year={cfg.first_year}: use 1850 or 1750")
236
+ if cfg.first_year == 1750 and cfg.scen != "rcmip3":
237
+ raise ValueError("--first_year=1750 is only available with --scen=rcmip3")
238
+ if cfg.first_year != 1750:
239
+ for name in ("lnd_fb_1850", "norgrwth_pre1850"):
240
+ if getattr(cfg, name) not in (None, "none"):
241
+ raise ValueError(f"--{name} is only available with --first_year=1750")
242
+ if cfg.lnd_fb_1850 not in (None, "none", "fert", "both"):
243
+ raise ValueError(f"--lnd_fb_1850={cfg.lnd_fb_1850!r}: use fert, both or none")
244
+
245
+
246
+ def rcmip_sfx(cfg):
247
+ """Suffix of the RCMIP3 input files: "" (1850 start) or "_1750" (--first_year=1750)."""
248
+ return "_1750" if cfg.first_year == 1750 else ""
249
+
250
+
251
+ def config_from_flags(flags):
252
+ """RunConfig from --name=value flags (RunConfig or ChemOptions fields)."""
253
+ run, chem, ocean, forcing = {}, {}, {}, {}
254
+ forcing_names = {f.name for f in dataclasses.fields(ForcingOptions)}
255
+ run_names = {f.name for f in dataclasses.fields(RunConfig)}
256
+ chem_names = {f.name for f in dataclasses.fields(ChemOptions)}
257
+ ocean_names = {f.name for f in dataclasses.fields(OceanOptions)}
258
+ for flag in flags:
259
+ if not flag.startswith("--") or "=" not in flag:
260
+ sys.exit(f"bad flag {flag!r}; use --name=value")
261
+ name, value = flag[2:].split("=", 1)
262
+ if name == "co2_conc_1850": # former name
263
+ name = "co2_conc_initial"
264
+ if name in chem_names:
265
+ chem[name] = value
266
+ elif name in forcing_names:
267
+ forcing[name] = value
268
+ elif name in ocean_names:
269
+ if name == "ocn_nsub":
270
+ value = int(value)
271
+ elif name in ("same_alk", "hector_tcre_rates"):
272
+ value = value not in ("0", "")
273
+ elif name.startswith("pco2_w_"):
274
+ value = None if value.lower() == "none" else float(value)
275
+ ocean[name] = value
276
+ elif name in run_names:
277
+ if name in ("first_year", "last_year", "tyear", "byear", "dyear"):
278
+ value = int(value)
279
+ elif name in ("clim_sensi", "fraction", "co2_conc_initial"):
280
+ value = float(value)
281
+ elif name == "dat_dir":
282
+ from pathlib import Path
283
+ value = Path(value)
284
+ elif name in ("use_ncycle", "tproj", "thist", "zero_nature", "use_ssp534", "co2_only",
285
+ "load_AGAGE", "load_NOAA", "fix_conc", "rcmip_csv", "report_csv",
286
+ "rcmip_compat_ems",
287
+ "minus_ems", "rdc_mix", "use_cm", "reduce_after_cm",
288
+ "ref_compat",
289
+ ):
290
+ value = value not in ("0", "")
291
+ elif name == "cm6mdl" and value.lower() == "none":
292
+ value = None
293
+ run[name] = value
294
+ else:
295
+ sys.exit(f"unknown flag --{name}")
296
+ return RunConfig(**run, chem=ChemOptions(**chem), ocean=OceanOptions(**ocean),
297
+ forcing=ForcingOptions(**forcing))
@@ -0,0 +1,25 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ """Physical constants shared by the SCM4OPT Python forward model.
3
+
4
+ Values are those of the SCM4OPT v4.1 parameter definitions; keep them in sync.
5
+ """
6
+
7
+ # Atmospheric CO2 conversion and pre-industrial level
8
+ PPM2GTC = 2.123 # GtC per ppm CO2
9
+ CO2_CONC_INITIAL = 284.0 # ppm, CO2 at the first step (1850 start)
10
+ # --first_year=1750: the 1750 values of the RCMIP3 v3.0.1 inputs
11
+ # (RCMIP3_src/conc_mapping_1750.csv), reference and initial concentrations
12
+ CO2_CONC_1750 = 278.00745 # ppm
13
+ CH4_CONC_1750 = 720.8548 # ppb
14
+ N2O_CONC_1750 = 266.57 # ppb
15
+
16
+ # Internal time step of the model (1/6 year)
17
+ DT = 1.0 / 6.0 # years per step
18
+
19
+ # Sigmoid CO2 fertilisation; NOT the CSV's CO2_GIFFORD_CONC_FOR_ZERONPP, which the
20
+ # land carbon cycle reads but never uses
21
+ CO2_NPP_ZERO_CONC = 31.0 # ppm
22
+
23
+ # Reference CO2 for anomalies in both CH4-forcing branches,
24
+ # scm_D_CO2 = scm_atmoCO2 - CO2_0
25
+ CO2_0 = 284.0 # ppm
scm4opt/core/errors.py ADDED
@@ -0,0 +1,19 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ """Model errors."""
3
+
4
+
5
+ class ModelBoundsError(FloatingPointError):
6
+ """A model variable left its admissible range.
7
+
8
+ variable : name of the variable (e.g. "scm_atmo_pool", "hct_dic(ob_LL)")
9
+ value : its value, if known
10
+ bound : the violated bound or range (e.g. "[1, 1e5]", ">= 1e-3")
11
+ Subclass of FloatingPointError, so `except FloatingPointError` still catches it.
12
+ """
13
+
14
+ def __init__(self, variable, value=None, bound=None, message=None):
15
+ self.variable, self.value, self.bound = variable, value, bound
16
+ if message is None:
17
+ message = f"{variable}" + (f" = {value:.6g}" if isinstance(value, (int, float)) else "") \
18
+ + (f" outside {bound}" if bound is not None else " outside its admissible range")
19
+ super().__init__(message)
@@ -0,0 +1,217 @@
1
+ # SPDX-License-Identifier: GPL-3.0-or-later
2
+ """The variable registry: one row per output, report symbol and parameter.
3
+
4
+ registry/registry.csv (in the package data: registry/registry.csv) has the columns
5
+
6
+ name, kind (output | report | parameter), module, dims, unit, time_basis
7
+ (state | per_step | per_year | none), description, reference,
8
+ report_order (position in the model report, empty if not reported),
9
+ report_group (variable | parameter: how the RCMIP export treats a reported symbol)
10
+
11
+ and is the single source of truth for:
12
+ report_symbols() the report symbols in report order (report.py)
13
+ report_parameters() the reported symbols that are parameters (zero rows dropped)
14
+ per_step_names() outputs/report symbols stored per model step (the RCMIP export
15
+ sums their steps into yearly values)
16
+ check_registry() unit checks: unit grammar (units.py), time basis against the unit,
17
+ names, report order, and every RCMIP3 export conversion
18
+ (output_mapping.csv scale x steps per year) against the units
19
+ check_outputs(out) every array of a run is registered, with matching dimensions
20
+ """
21
+
22
+ from functools import lru_cache
23
+ from pathlib import Path
24
+
25
+ import pandas as pd
26
+
27
+ from .units import STEPS_PER_YEAR, UnitError, factor, parse, time_denominator
28
+ from .config import DAT_DIR, PACKAGE_DATA_DIR, data_path
29
+
30
+ _DEV_CSV = Path(__file__).resolve().parent / "registry" / "registry.csv"
31
+ REGISTRY_CSV = _DEV_CSV if _DEV_CSV.exists() else PACKAGE_DATA_DIR / "registry" / "registry.csv"
32
+
33
+ KINDS = ("output", "report", "parameter")
34
+ TIME_BASES = ("state", "per_step", "per_year", "none")
35
+ REPORT_GROUPS = ("variable", "parameter")
36
+ RCMIP_TOLERANCE = 2e-3 # the export uses rounded molar-mass ratios (44/12, 44/28, 17/14, 2)
37
+
38
+ # Known RCMIP3 export unit problems, kept so the export stays identical to the SCM4OPT v4.1
39
+ # reference submission files (see the registry descriptions of these variables):
40
+ # doe_heatcontent 1e22 J exported as ZJ (x10 missing); its interior part is summed
41
+ # without dt (6x too large)
42
+ # doe_heatflux a rate in 1e22 J/yr, exported as ZJ/yr (x10 missing) and summed over
43
+ # the steps of a year like a per-step amount (x6); its mixed-layer part
44
+ # is a per-step energy
45
+ KNOWN_RCMIP_ISSUES = frozenset(("doe_heatcontent", "doe_heatflux"))
46
+
47
+
48
+ @lru_cache(maxsize=None)
49
+ def load_registry(path=None):
50
+ """The registry as a DataFrame of strings (empty cells as "")."""
51
+ return pd.read_csv(path or REGISTRY_CSV, dtype=str, keep_default_na=False)
52
+
53
+
54
+ def variables(reg=None):
55
+ """Rows of the outputs and report symbols, indexed by name (names are unique there)."""
56
+ reg = load_registry() if reg is None else reg
57
+ return reg[reg["kind"] != "parameter"].set_index("name")
58
+
59
+
60
+ def report_symbols(reg=None):
61
+ """Report symbols in report order."""
62
+ v = variables(reg)
63
+ v = v[v["report_order"] != ""]
64
+ return tuple(v.index[v["report_order"].astype(int).argsort(kind="stable")])
65
+
66
+
67
+ def report_parameters(reg=None):
68
+ v = variables(reg)
69
+ return frozenset(v.index[(v["report_order"] != "") & (v["report_group"] == "parameter")])
70
+
71
+
72
+ def per_step_names(reg=None):
73
+ v = variables(reg)
74
+ return frozenset(v.index[v["time_basis"] == "per_step"])
75
+
76
+
77
+ # ---------------------------------------------------------------- checks
78
+ def check_registry(reg=None, mapping=None, known=KNOWN_RCMIP_ISSUES):
79
+ """Problems found in the registry: a list of strings (empty if none).
80
+
81
+ mapping : the RCMIP3 output mapping (report.load_output_mapping()); its conversions
82
+ are checked when given (known: see check_rcmip_mapping).
83
+ """
84
+ reg = load_registry() if reg is None else reg
85
+ err = []
86
+ for i, r in reg.iterrows():
87
+ where = f"{r['module']}.{r['name']} ({r['kind']})"
88
+ if r["kind"] not in KINDS:
89
+ err.append(f"{where}: kind {r['kind']!r} not in {KINDS}")
90
+ if r["time_basis"] not in TIME_BASES:
91
+ err.append(f"{where}: time_basis {r['time_basis']!r} not in {TIME_BASES}")
92
+ if not r["unit"]:
93
+ err.append(f"{where}: no unit")
94
+ continue
95
+ try:
96
+ parse(r["unit"])
97
+ except UnitError as e:
98
+ err.append(f"{where}: {e}")
99
+ continue
100
+ den = time_denominator(r["unit"])
101
+ want = {"step": "per_step", "yr": "per_year"}.get(den)
102
+ if want and r["time_basis"] != want:
103
+ err.append(f"{where}: unit {r['unit']!r} needs time_basis {want}, not {r['time_basis']}")
104
+ if not want and r["time_basis"] in ("per_step", "per_year"):
105
+ err.append(f"{where}: time_basis {r['time_basis']} but unit {r['unit']!r} has no /step or /yr")
106
+ if r["kind"] != "parameter" and r["time_basis"] == "none":
107
+ err.append(f"{where}: an output needs time_basis state, per_step or per_year")
108
+ if not r["description"]:
109
+ err.append(f"{where}: no description")
110
+ v = reg[reg["kind"] != "parameter"]
111
+ for n in sorted(set(v["name"][v["name"].duplicated()])):
112
+ err.append(f"{n}: registered more than once as output/report")
113
+ p = reg[reg["kind"] == "parameter"]
114
+ for (m, n) in sorted(set(map(tuple, p[["module", "name"]][p[["module", "name"]].duplicated()].values))):
115
+ err.append(f"{m}.{n}: parameter registered more than once")
116
+ rep = v[v["report_order"] != ""]
117
+ order = rep["report_order"].astype(int)
118
+ if sorted(order) != list(range(1, len(order) + 1)):
119
+ err.append("report_order is not 1..n without gaps or repeats")
120
+ bad = rep[~rep["report_group"].isin(REPORT_GROUPS)]
121
+ err += [f"{n}: report_group {g!r} not in {REPORT_GROUPS}" for n, g in zip(bad["name"], bad["report_group"])]
122
+ if mapping is not None:
123
+ err += check_rcmip_mapping(mapping, reg, known=known)
124
+ return err
125
+
126
+
127
+ def rcmip_conversions(mapping, reg=None):
128
+ """One row per reported RCMIP3 variable: registry unit, RCMIP unit, the factor
129
+ implied by the units and the factor the export applies (scale x steps per year)."""
130
+ v = variables(reg)
131
+ rows = []
132
+ for _, mp in mapping.iterrows():
133
+ name = mp["rpt_var"]
134
+ unit_rcmip = str(mp["Unit"]).replace("MAGICC ", "")
135
+ if name not in v.index:
136
+ rows.append(dict(rpt_var=name, variable=mp["Variable"], unit=None, unit_rcmip=unit_rcmip,
137
+ factor_units=None, factor_export=None, problem="not in the registry"))
138
+ continue
139
+ r = v.loc[name]
140
+ # the time scaling the export applies (report.load_output_mapping), else the registry's
141
+ steps = (float(mp["time_scale"]) if "time_scale" in mp else
142
+ STEPS_PER_YEAR if r["time_basis"] == "per_step" else 1)
143
+ applied = float(mp["rpt_var_scale"]) * steps
144
+ try:
145
+ f = factor(r["unit"], unit_rcmip)
146
+ problem = "" if abs(applied / f - 1) <= RCMIP_TOLERANCE else "factor mismatch"
147
+ except UnitError as e:
148
+ f, problem = None, str(e)
149
+ rows.append(dict(rpt_var=name, variable=mp["Variable"], unit=r["unit"], unit_rcmip=unit_rcmip,
150
+ factor_units=f, factor_export=applied, problem=problem))
151
+ return pd.DataFrame(rows)
152
+
153
+
154
+ def check_rcmip_mapping(mapping, reg=None, produced=None, known=KNOWN_RCMIP_ISSUES):
155
+ """Problems of the RCMIP3 export conversions (see rcmip_conversions).
156
+
157
+ produced : names the report can produce; mapped variables outside it are skipped
158
+ by the export and reported here only if registered.
159
+ known : variables whose problems are known and not reported (KNOWN_RCMIP_ISSUES);
160
+ pass () to see them.
161
+ """
162
+ c = rcmip_conversions(mapping, reg)
163
+ out = []
164
+ for _, r in c[(c["problem"] != "") & ~c["rpt_var"].isin(known)].iterrows():
165
+ if r["problem"] == "not in the registry" and (produced is None or r["rpt_var"] not in produced):
166
+ continue # mapped, but the model does not report it
167
+ detail = (f" (units give {r['factor_units']:.6g}, export applies {r['factor_export']:.6g})"
168
+ if r["problem"] == "factor mismatch" else "")
169
+ out.append(f"RCMIP {r['variable']} <- {r['rpt_var']} [{r['unit']} -> {r['unit_rcmip']}]: "
170
+ f"{r['problem']}{detail}")
171
+ return out
172
+
173
+
174
+ def check_outputs(out, reg=None):
175
+ """Problems of a run's outputs against the registry: unregistered arrays and
176
+ dimension mismatches (number of dimensions; dims 't,...' in the registry)."""
177
+ v = variables(reg)
178
+ err = []
179
+ for name, a in out.items():
180
+ if not hasattr(a, "ndim"):
181
+ continue
182
+ if name not in v.index:
183
+ err.append(f"{name}: output not in the registry")
184
+ continue
185
+ dims = [d for d in v.loc[name, "dims"].split(",") if d]
186
+ if dims and len(dims) != a.ndim:
187
+ err.append(f"{name}: {a.ndim}-D array, registry dims {v.loc[name, 'dims']!r}")
188
+ return err
189
+
190
+
191
+ def default_mapping():
192
+ """The RCMIP3 output mapping with the reported rows, with the export's time scaling
193
+ (report.load_output_mapping)."""
194
+ from ..io.report import load_output_mapping
195
+ return load_output_mapping(data_path(DAT_DIR, "RCMIP3_src", "output_mapping.csv"))
196
+
197
+
198
+ def main(argv=None):
199
+ """python3 -m scm4opt.core.registry [--all]: run the registry checks and print a
200
+ summary (--all also shows the known RCMIP3 export issues). Exit code 1 on problems."""
201
+ import sys
202
+ argv = sys.argv[1:] if argv is None else argv
203
+ reg = load_registry()
204
+ known = () if "--all" in argv else KNOWN_RCMIP_ISSUES
205
+ err = check_registry(reg, default_mapping(), known=known)
206
+ filled = {c: int((reg[c] != "").sum()) for c in ("unit", "time_basis", "description")}
207
+ print(f"registry {REGISTRY_CSV}: {len(reg)} rows, filled {filled}, "
208
+ f"{len(report_symbols(reg))} report symbols, {len(per_step_names(reg))} per-step variables")
209
+ print(f"{len(err)} problems" + ("" if known == () else f" (known RCMIP3 issues not shown: "
210
+ f"{', '.join(sorted(KNOWN_RCMIP_ISSUES))}; --all)"))
211
+ for e in err:
212
+ print(" " + e)
213
+ return 1 if err else 0
214
+
215
+
216
+ if __name__ == "__main__":
217
+ raise SystemExit(main())