forked from WCRP-CMIP/WCRP-universe
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate-experiments.py
More file actions
1098 lines (968 loc) · 37.8 KB
/
generate-experiments.py
File metadata and controls
1098 lines (968 loc) · 37.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Generate experiment entries
Not actually all experiments,
rather just those listed in
[Dunne et al., 2025](https://doi.org/10.5194/gmd-18-6671-2025)
for the CMIP7 fast-track.
"""
import json
from datetime import datetime
from pathlib import Path
from typing import Any
from pydantic import BaseModel, ConfigDict
class ExperimentUniverse(BaseModel):
model_config = ConfigDict(
validate_assignment=True,
validate_default=True,
extra="forbid",
strict=True,
)
drs_name: str
description: str
activity: str
additional_allowed_model_components: list[str]
branch_information: str | None = "dont_write"
end_timestamp: datetime | None | str
min_ensemble_size: int
min_number_yrs_per_sim: float | None | str = "dont_write"
parent_activity: str | None = "dont_write"
parent_experiment: str | None = "dont_write"
parent_mip_era: str | None = "dont_write"
required_model_components: list[str]
start_timestamp: datetime | None | str
tier: int | str = "dont_write"
def write_file(self, universe_root: Path) -> None:
id = self.drs_name.lower()
content = {
"@context": "000_context.jsonld",
"id": id,
"type": "experiment",
"drs_name": self.drs_name,
"description": self.description,
"activity": self.activity,
"additional_allowed_model_components": self.additional_allowed_model_components,
"min_ensemble_size": self.min_ensemble_size,
"required_model_components": self.required_model_components,
}
for attr in (
"branch_information",
"min_number_yrs_per_sim",
"parent_activity",
"parent_experiment",
"parent_mip_era",
"tier",
"start_timestamp",
"end_timestamp",
):
val = getattr(self, attr)
if val != "dont_write":
content[attr] = val
out_file = str(universe_root / "experiment" / f"{id}.json")
write_file(out_file, content)
class ExperimentProject(BaseModel):
model_config = ConfigDict(
validate_assignment=True,
validate_default=True,
extra="forbid",
strict=True,
)
id: str
activity: str
description: str = "dont_write"
branch_information: str | None = "dont_write"
start_timestamp: datetime | None | str = "dont_write"
end_timestamp: datetime | None | str = "dont_write"
min_number_yrs_per_sim: float | None | str = "dont_write"
min_ensemble_size: int | str = "dont_write"
parent_activity: str | None = "dont_write"
parent_experiment: str | None = "dont_write"
parent_mip_era: str | None = "dont_write"
tier: int
def write_file(self, project_root: Path) -> None:
content = {
"@context": "000_context.jsonld",
"id": self.id,
"type": "experiment",
"tier": self.tier,
}
for attr in (
"branch_information",
"description",
"start_timestamp",
"end_timestamp",
"min_number_yrs_per_sim",
"min_ensemble_size",
"parent_activity",
"parent_experiment",
"parent_mip_era",
):
val = getattr(self, attr)
if val != "dont_write":
content[attr] = val
out_file = str(project_root / "experiment" / f"{self.id}.json")
write_file(out_file, content)
class ActivityProject(BaseModel):
model_config = ConfigDict(
validate_assignment=True,
validate_default=True,
extra="forbid",
strict=True,
)
id: str
experiments: list[str]
urls: list[str]
def write_file(self, project_root: Path) -> None:
content = {
"@context": "000_context.jsonld",
"id": self.id,
"type": "activity",
"experiments": sorted(self.experiments),
"urls": sorted(self.urls),
}
out_file = str(project_root / "activity" / f"{self.id}.json")
write_file(out_file, content)
class Holder(BaseModel):
"""
God class :)
"""
model_config = ConfigDict(
validate_assignment=True,
validate_default=True,
extra="forbid",
strict=True,
)
experiments_project: list[ExperimentProject]
experiments_universe: list[ExperimentUniverse]
activities: list[ActivityProject]
def initialise_activities(self) -> "Holder":
self.activities = [
ActivityProject(
id="c4mip",
experiments=[],
urls=[
"https://doi.org/10.5194/gmd-17-8141-2024",
"https://doi.org/10.5194/egusphere-2024-3356",
"https://doi.org/10.5194/gmd-9-2853-2016",
],
),
ActivityProject(
id="cfmip",
experiments=[],
urls=["https://doi.org/10.5194/gmd-10-359-2017"],
),
ActivityProject(
id="cmip",
experiments=[],
urls=["https://doi.org/10.5194/gmd-18-6671-2025"],
),
ActivityProject(
id="damip",
experiments=[],
urls=["https://doi.org/10.5194/gmd-18-4399-2025"],
),
ActivityProject(
id="geomip",
experiments=[],
urls=["https://doi.org/10.5194/gmd-17-2583-2024"],
),
ActivityProject(
id="pmip",
experiments=[],
urls=[
"https://doi.org/10.5194/gmd-10-3979-2017",
"https://doi.org/10.5194/cp-19-883-2023",
],
),
ActivityProject(
id="scenariomip",
experiments=[],
urls=["https://doi.org/10.5194/egusphere-2024-3765"],
),
]
def add_experiment_to_activity(self, experiment: ExperimentProject) -> "Holder":
for activity_idx, activity in enumerate(self.activities):
if activity.id == experiment.activity:
break
else:
msg = f"No activity {experiment.activity} found. {self.activities=}"
raise AssertionError(msg)
if experiment.id not in self.activities[activity_idx]:
self.activities[activity_idx].experiments.append(experiment.id)
return self
def add_1pctco2_entries(self) -> "Holder":
for (
drs_name,
description_start,
activity,
required_model_components,
additional_allowed_model_components,
) in (
(
"1pctCO2",
"",
"cmip",
["aogcm"],
["aer", "chem", "bgc"],
),
(
"1pctCO2-bgc",
(
"Biogeochemically coupled simulation "
"(i.e. the carbon cycle only 'sees' the increase in atmospheric carbon dioxide, "
"not any change in temperature) of a "
),
"c4mip",
["aogcm", "bgc"],
["aer", "chem"],
),
(
"1pctCO2-rad",
(
"Radiatively coupled simulation "
"(i.e. the carbon cycle only 'sees' the increase in temperature, "
"not any change in atmospheric carbon dioxide) of a "
),
"c4mip",
["aogcm", "bgc"],
["aer", "chem"],
),
):
univ = ExperimentUniverse(
drs_name=drs_name,
description=(
f"{description_start}"
"1% per year increase in atmospheric carbon dioxide levels. "
"All other conditions are kept the same as piControl."
),
activity=activity,
additional_allowed_model_components=additional_allowed_model_components,
branch_information="Branch from `piControl` at a time of your choosing",
end_timestamp=None,
min_ensemble_size=1,
# Defined in project
min_number_yrs_per_sim="dont_write",
parent_activity="cmip",
parent_experiment="picontrol",
# Defined in project
parent_mip_era="dont_write",
required_model_components=required_model_components,
start_timestamp=None,
tier=1,
)
self.experiments_universe.append(univ)
proj = ExperimentProject(
id=univ.drs_name.lower(),
activity=univ.activity,
min_number_yrs_per_sim=150,
parent_mip_era="cmip7",
tier=1,
)
self.experiments_project.append(proj)
self.add_experiment_to_activity(proj)
return self
def add_abruptco2_entries(self) -> "Holder":
for drs_name, description_start, activity in (
(
"abrupt-4xCO2",
"Abrupt quadrupling of atmospheric carbon dioxide levels.",
"cmip",
),
(
"abrupt-2xCO2",
"Abrupt doubling of atmospheric carbon dioxide levels.",
"cfmip",
),
(
"abrupt-0p5xCO2",
"Abrupt halving of atmospheric carbon dioxide levels.",
"cfmip",
),
):
univ = ExperimentUniverse(
drs_name=drs_name,
description=(
f"{description_start} All other conditions are kept the same as piControl."
),
activity=activity,
additional_allowed_model_components=["aer", "chem", "bgc"],
branch_information="Branch from `piControl` at a time of your choosing",
end_timestamp=None,
min_ensemble_size=1,
# Defined in project
min_number_yrs_per_sim="dont_write",
parent_activity="cmip",
parent_experiment="picontrol",
# Defined in project
parent_mip_era="dont_write",
required_model_components=["aogcm"],
start_timestamp=None,
tier=1,
)
self.experiments_universe.append(univ)
proj = ExperimentProject(
id=univ.drs_name.lower(),
activity=univ.activity,
min_number_yrs_per_sim=300,
parent_mip_era="cmip7",
tier=1,
)
self.experiments_project.append(proj)
self.add_experiment_to_activity(proj)
return self
def add_amip_entries(self) -> "Holder":
for (
drs_name,
description,
activity,
start_timestamp,
end_timestamp,
min_number_yrs_per_sim,
) in (
(
"amip",
"Simulation of the climate of the recent past with prescribed sea surface temperatures and sea ice concentrations.",
"cmip",
"1979-01-01",
"2021-12-31",
43,
),
(
"amip-p4k",
"Same as `amip` simulation, except sea surface temperatures are increased by 4K in ice-free regions.",
"cfmip",
"1979-01-01",
"2021-12-31",
43,
),
(
"amip-piForcing",
(
"Same as `amip` simulation, except it starts in 1870 "
"and all forcings are set to pre-industrial levels "
"rather than time-varying forcings."
),
"cfmip",
"1870-01-01",
"2021-12-31",
152,
),
):
univ = ExperimentUniverse(
drs_name=drs_name,
description=description,
activity=activity,
additional_allowed_model_components=["aer", "chem", "bgc"],
branch_information=None,
end_timestamp=None,
min_ensemble_size=1,
# Defined in project
min_number_yrs_per_sim="dont_write",
parent_activity=None,
parent_experiment=None,
parent_mip_era=None,
required_model_components=["agcm"],
start_timestamp=None,
tier=1,
)
self.experiments_universe.append(univ)
proj = ExperimentProject(
id=univ.drs_name.lower(),
activity=univ.activity,
start_timestamp=start_timestamp,
end_timestamp=end_timestamp,
min_number_yrs_per_sim=min_number_yrs_per_sim,
parent_mip_era="cmip7",
tier=1,
)
self.experiments_project.append(proj)
self.add_experiment_to_activity(proj)
return self
def add_picontrol_entries(self) -> "Holder":
for (
drs_name,
description,
min_number_yrs_per_sim,
tier,
parent_experiment,
branch_information,
) in (
(
"piControl",
(
"Pre-industrial control simulation "
"with prescribed carbon dioxide concentrations "
"(for prescribed carbon dioxide emissions, see `esm-piControl`). "
"Used to characterise natural variability and unforced behaviour."
),
400,
1,
"picontrol-spinup",
"Branch from `piControl-spinup` at a time of your choosing",
),
(
"piControl-spinup",
(
"Spin-up simulation. "
"Used to get the model into a state of approximate radiative equilibrium "
"before starting the `piControl` simulation."
),
None,
3,
None,
None,
),
(
"esm-piControl",
(
"Pre-industrial control simulation "
"with prescribed carbon dioxide emissions "
"(for prescribed carbon dioxide concentrations, see `piControl`). "
"Used to characterise natural variability and unforced behaviour."
),
400,
1,
"esm-picontrol-spinup",
"Branch from `esm-piControl-spinup` at a time of your choosing",
),
(
"esm-piControl-spinup",
(
"Spin-up simulation. "
"Used to get the model into a state of approximate radiative equilibrium "
"before starting the `esm-piControl` simulation."
),
None,
3,
None,
None,
),
):
if drs_name.startswith("esm-"):
additional_allowed_model_components = ["aer", "chem"]
required_model_components = ["aogcm", "bgc"]
else:
additional_allowed_model_components = ["aer", "chem", "bgc"]
required_model_components = ["aogcm"]
univ = ExperimentUniverse(
drs_name=drs_name,
description=description,
activity="cmip",
additional_allowed_model_components=additional_allowed_model_components,
branch_information=branch_information,
end_timestamp=None,
min_ensemble_size=1,
# Defined in project
min_number_yrs_per_sim="dont_write",
parent_activity=None if parent_experiment is None else "cmip",
parent_experiment=parent_experiment,
# Defined in project
parent_mip_era=None if parent_experiment is None else "dont_write",
required_model_components=required_model_components,
start_timestamp=None,
tier=1,
)
self.experiments_universe.append(univ)
proj = ExperimentProject(
id=univ.drs_name.lower(),
activity=univ.activity,
min_number_yrs_per_sim=min_number_yrs_per_sim,
parent_mip_era="cmip7" if parent_experiment is not None else None,
tier=tier,
)
self.experiments_project.append(proj)
self.add_experiment_to_activity(proj)
return self
def add_historical_entries(self) -> "Holder":
for (
drs_name,
description,
parent_experiment,
branch_information,
) in (
(
"historical",
(
"Simulation of the climate of the recent past "
"(typically meaning 1850 to present-day) "
"with prescribed carbon dioxide concentrations "
"(for prescribed carbon dioxide emissions, see `esm-hist`)."
),
"picontrol",
"Branch from `piControl` at a time of your choosing",
),
(
"esm-hist",
(
"Simulation of the climate of the recent past "
"(typically meaning 1850 to present-day) "
"with prescribed carbon dioxide emissions "
"(for prescribed carbon dioxide concentrations, see `historical`)."
),
"esm-picontrol",
"Branch from esm-piControl at a time of your choosing",
),
):
if drs_name.startswith("esm-"):
additional_allowed_model_components = ["aer", "chem"]
required_model_components = ["aogcm", "bgc"]
else:
additional_allowed_model_components = ["aer", "chem", "bgc"]
required_model_components = ["aogcm"]
univ = ExperimentUniverse(
drs_name=drs_name,
description=description,
activity="cmip",
additional_allowed_model_components=additional_allowed_model_components,
branch_information=branch_information,
# Defined in project
end_timestamp="dont_write",
min_ensemble_size=1,
# Defined in project
min_number_yrs_per_sim="dont_write",
parent_activity="cmip",
parent_experiment=parent_experiment,
# Defined in project
parent_mip_era="dont_write",
required_model_components=required_model_components,
start_timestamp="1850-01-01",
tier=1,
)
self.experiments_universe.append(univ)
proj = ExperimentProject(
id=univ.drs_name.lower(),
activity=univ.activity,
start_timestamp="1850-01-01",
end_timestamp="2021-12-31",
min_number_yrs_per_sim=172,
parent_mip_era="cmip7",
tier=1,
)
self.experiments_project.append(proj)
self.add_experiment_to_activity(proj)
return self
def add_flat10_entries(self) -> "Holder":
univ_flat10 = ExperimentUniverse(
drs_name="esm-flat10",
description="10 PgC / yr constant carbon dioxide emissions.",
activity="c4mip",
additional_allowed_model_components=["aer", "chem"],
branch_information="Branch from `esm-piControl` at a time of your choosing",
end_timestamp=None,
min_ensemble_size=1,
min_number_yrs_per_sim=100.0,
parent_activity="cmip",
parent_experiment="esm-picontrol",
# Defined in project
parent_mip_era="dont_write",
required_model_components=["aogcm", "bgc"],
start_timestamp=None,
tier=1,
)
self.experiments_universe.append(univ_flat10)
proj_flat10 = ExperimentProject(
id=univ_flat10.drs_name.lower(),
activity=univ_flat10.activity,
parent_mip_era="cmip7",
tier=1,
)
self.experiments_project.append(proj_flat10)
self.add_experiment_to_activity(proj_flat10)
for (
drs_name,
description,
branch_information,
min_number_yrs_per_sim,
) in (
(
"esm-flat10-cdr",
(
"Extension of `esm-flat10` where emissions decline linearly to -10 PgC / yr "
"then stay constant until cumulative emissions "
"(including the emissions in `esm-flat10`) reach zero. "
"An extra 20 years is included at the end to allow for calculating averages over different time windows."
),
"Branch from `esm-flat10` at the end of year 100.",
220.0,
),
(
"esm-flat10-zec",
"Extension of `esm-flat10` with zero emissions.",
"Branch from `esm-flat10` at the end of year 100.",
100.0,
),
):
univ = ExperimentUniverse(
drs_name=drs_name,
description=description,
activity=univ_flat10.activity,
additional_allowed_model_components=univ_flat10.additional_allowed_model_components,
branch_information=branch_information,
end_timestamp=None,
min_ensemble_size=1,
min_number_yrs_per_sim=min_number_yrs_per_sim,
parent_activity=univ_flat10.activity,
parent_experiment=proj_flat10.id,
# Defined in project
parent_mip_era="dont_write",
required_model_components=univ_flat10.required_model_components,
start_timestamp=None,
tier=1,
)
self.experiments_universe.append(univ)
proj = ExperimentProject(
id=univ.drs_name.lower(),
activity=univ.activity,
parent_mip_era="cmip7",
tier=1,
)
self.experiments_project.append(proj)
self.add_experiment_to_activity(proj)
return self
def add_damip_entries(self) -> "Holder":
for drs_name, forcing in (
("hist-aer", "aerosol"),
("hist-GHG", "aerosol"),
("hist-nat", "aerosol"),
):
univ = ExperimentUniverse(
drs_name=drs_name,
description=(
f"Response to historical {forcing} forcing "
"(often with extension using forcings from a scenario simulation specific to the CMIP phase). "
"All other conditions are kept the same as piControl."
),
activity="damip",
additional_allowed_model_components=["aer", "chem", "bgc"],
branch_information="Branch from `piControl` at a time of your choosing",
# Defined in project
end_timestamp="dont_write",
min_ensemble_size=1,
# Defined in project
min_number_yrs_per_sim="dont_write",
parent_activity="cmip",
parent_experiment="picontrol",
# Defined in project
parent_mip_era="dont_write",
required_model_components=["aogcm"],
# Defined in project
start_timestamp="1850-01-01",
tier=1,
)
self.experiments_universe.append(univ)
proj = ExperimentProject(
id=univ.drs_name.lower(),
description=(
f"Response to historical {forcing} forcing "
"(with extension using forcings from the `m` scenario simulation). "
"All other conditions are kept the same as piControl."
),
activity=univ.activity,
start_timestamp="1850-01-01",
end_timestamp="2035-12-31",
min_number_yrs_per_sim=186,
min_ensemble_size=3,
parent_mip_era="cmip7",
tier=1,
)
self.experiments_project.append(proj)
self.add_experiment_to_activity(proj)
return self
def add_pmip_entries(self) -> "Holder":
drs_name = "abrupt-127k"
description = (
"Simulation to examine the response to orbital and greenhouse gas concentration changes "
"associated with the last interglacial (127 000 years before present)."
)
univ = ExperimentUniverse(
drs_name=drs_name,
description=description,
activity="pmip",
additional_allowed_model_components=["aer", "chem", "bgc"],
branch_information="Branch from `piControl` at a time of your choosing",
end_timestamp=None,
min_ensemble_size=1,
min_number_yrs_per_sim=100.0,
parent_activity="cmip",
parent_experiment="picontrol",
parent_mip_era="dont_write",
required_model_components=["aogcm"],
start_timestamp=None,
tier=1,
)
self.experiments_universe.append(univ)
proj = ExperimentProject(
id=univ.drs_name.lower(),
activity=univ.activity,
min_number_yrs_per_sim=100.0,
parent_mip_era="cmip7",
tier=1,
)
self.experiments_project.append(proj)
self.add_experiment_to_activity(proj)
return self
@staticmethod
def get_scenario_tier(drs_name: str) -> int:
# TODO: update
return 1
@staticmethod
def get_scenario_project(
scenario_universe: ExperimentUniverse,
) -> ExperimentProject:
res = ExperimentProject(
id=scenario_universe.drs_name.lower(),
activity=scenario_universe.activity,
start_timestamp=scenario_universe.start_timestamp,
end_timestamp=scenario_universe.end_timestamp,
min_number_yrs_per_sim=scenario_universe.min_number_yrs_per_sim,
parent_mip_era="cmip7",
tier=scenario_universe.tier,
)
return res
def get_scenario_extension(
self,
scenario: ExperimentUniverse,
) -> ExperimentUniverse:
res = scenario.model_copy()
scenario_end_timestamp_dt = datetime.strptime(
scenario.end_timestamp, "%Y-%m-%d"
)
extension_start_timestamp = f"{scenario_end_timestamp_dt.year + 1}-01-01"
# TODO: check
extension_end_timestamp = "2500-12-31"
res.description = f"Extension of `{scenario.drs_name}` beyond {scenario_end_timestamp_dt.year}."
# Unclear to me how this is meant to work.
# scenario ends at 2100-12-31, extensions starts at 2101-01-01.
# Is it an implied join rather than a true overlap
# (like we have for piControl to historical)?
res.branch_information = f"Branch from `{scenario.drs_name}` at {scenario_end_timestamp_dt.strftime('%Y-%m-%d')}"
res.start_timestamp = extension_start_timestamp
res.end_timestamp = extension_end_timestamp
res.min_number_yrs_per_sim = 50.0
res.parent_activity = scenario.activity
res.parent_experiment = scenario.drs_name.lower()
res.drs_name = f"{scenario.drs_name}-ext"
res.tier = self.get_scenario_tier(res.drs_name)
return res
@staticmethod
def get_scenario_drs_name(scenario_acronym: str) -> str:
return f"scen7-{scenario_acronym}"
@staticmethod
def get_scenario_esm_drs_name(scenario_drs_name: str) -> str:
return f"esm-{scenario_drs_name}"
def get_scenario_esm(
self,
scenario: ExperimentUniverse,
) -> ExperimentUniverse:
res = scenario.model_copy()
res.drs_name = self.get_scenario_esm_drs_name(scenario.drs_name)
res.description = (
scenario.description.replace(
"carbon dioxide concentrations", "carbon dioxide emissions"
)
.replace("carbon dioxide emissions,", "carbon dioxide concentrations,")
.replace(res.drs_name, scenario.drs_name)
)
res.required_model_components = ["aogcm", "bgc"]
res.additional_allowed_model_components = ["aer", "chem"]
if scenario.parent_experiment != "historical":
raise AssertionError
res.parent_experiment = "esm-hist"
res.branch_information = scenario.branch_information.replace(
scenario.parent_experiment, res.parent_experiment
)
res.tier = self.get_scenario_tier(res.drs_name)
return res
def add_scenario_entries(self) -> "Holder":
acronym_descriptions = [
("vl", "PLACEHOLDER TBC. CMIP7 ScenarioMIP very low emissions future."),
(
"ln",
"PLACEHOLDER TBC. CMIP7 ScenarioMIP low followed by negative (steep reductions begin in 2040, negative from TBD) emissions future.",
),
("l", "PLACEHOLDER TBC. CMIP7 ScenarioMIP low emissions future."),
(
"ml",
"PLACEHOLDER TBC. CMIP7 ScenarioMIP medium followed by low (from 2040) emissions future.",
),
("m", "PLACEHOLDER TBC. CMIP7 ScenarioMIP medium emissions future."),
(
"hl",
"PLACEHOLDER TBC. CMIP7 ScenarioMIP High followed by low (from 2060) emissions future.",
),
("h", "PLACEHOLDER TBC. CMIP7 ScenarioMIP high emissions future."),
]
for acronym, description_base in acronym_descriptions:
drs_name = self.get_scenario_drs_name(acronym)
drs_name_esm_scenario = self.get_scenario_esm_drs_name(drs_name)
if "CMIP7 ScenarioMIP" not in description_base:
raise AssertionError(description_base)
description = (
f"{description_base} Run with prescribed carbon dioxide concentrations "
f"(for prescribed carbon dioxide emissions, see `{drs_name_esm_scenario}`)."
)
univ_base = ExperimentUniverse(
drs_name=drs_name,
description=description,
activity="scenariomip",
additional_allowed_model_components=["aer", "chem", "bgc"],
branch_information="Branch from `historical` at 2022-01-01.",
# TODO: check if 2100-21-31 or 2100-01-01
end_timestamp="2100-12-31",
min_ensemble_size=1,
min_number_yrs_per_sim=79.0,
parent_activity="cmip",
parent_experiment="historical",
parent_mip_era="cmip7",
required_model_components=["aogcm"],
start_timestamp="2022-01-01",
tier=self.get_scenario_tier(drs_name),
)
proj_base = self.get_scenario_project(univ_base)
self.experiments_universe.append(univ_base)
self.experiments_project.append(proj_base)
self.add_experiment_to_activity(proj_base)
univ_ext = self.get_scenario_extension(univ_base)
proj_ext = self.get_scenario_project(univ_ext)
self.experiments_universe.append(univ_ext)
self.experiments_project.append(proj_ext)
self.add_experiment_to_activity(proj_ext)
univ_esm = self.get_scenario_esm(univ_base)
proj_esm = self.get_scenario_project(univ_esm)
self.experiments_universe.append(univ_esm)
self.experiments_project.append(proj_esm)
self.add_experiment_to_activity(proj_esm)
univ_esm_ext = self.get_scenario_extension(univ_esm)
proj_esm_ext = self.get_scenario_project(univ_esm_ext)
self.experiments_universe.append(univ_esm_ext)
self.experiments_project.append(proj_esm_ext)
self.add_experiment_to_activity(proj_esm_ext)
return self
def add_geomip_entries(self) -> "Holder":
for (
drs_name,
description_univ,
description_proj_to_format,
base_scenario,
start_year,
) in (
(
# TODO: check if this is the desired drs_name
"G7-1p5K-SAI",
(
"Stablisation of global-mean temperature at 1.5C "
"by holding stratospheric sulfur forcing constant "
# TODO: check - constant forcing may not lead to stable temperatures?!
"(at whatever level is required to achieve stable temperatures). "
"The simulation generally branches from a scenario simulation at some point in the future."
),
(
"After following the `{scenario}` scenario until 2035, "
"stablisation of global-mean temperature at 1.5C "
"by holding stratospheric sulfur forcing constant "
# TODO: check - constant forcing may not lead to stable temperatures?!
"(at whatever level is required to achieve stable temperatures)."
),
"scen7-m",
2035,
),
):
description_proj = description_proj_to_format.format(scenario=base_scenario)
start_timestamp = f"{start_year}-01-01"
for exp_proj in self.experiments_project:
if exp_proj.id == base_scenario:
parent = exp_proj
break
else:
raise AssertionError(base_scenario)
univ = ExperimentUniverse(
drs_name=drs_name,
description=description_univ,
activity="geomip",
additional_allowed_model_components=["aer", "chem", "bgc"],
# Defined in project
branch_information="dont_write",
end_timestamp="dont_write",
min_ensemble_size=1,
# Defined in project
min_number_yrs_per_sim="dont_write",
parent_activity="dont_write",
parent_experiment="dont_write",
parent_mip_era="dont_write",
required_model_components=["aogcm"],
# Defined in project
start_timestamp="dont_write",