Skip to content

Commit 3235846

Browse files
committed
Add subseasonal calibration pipeline
1 parent 52ee523 commit 3235846

File tree

16 files changed

+824
-263
lines changed

16 files changed

+824
-263
lines changed

.buildkite/longruns/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ steps:
183183
- label: "Perfect model calibration test"
184184
key: "amip_pm_calibration"
185185
command:
186-
- "julia --color=yes --project=experiments/ClimaEarth experiments/calibration/run_calibration.jl"
186+
- "julia --color=yes --project=experiments/ClimaEarth experiments/calibration/coarse_amip/run_calibration.jl"
187187
artifact_paths: "experiments/calibration/output/*"
188188
env:
189189
CLIMACOMMS_DEVICE: "CUDA"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ docs/src/generated/
3030
# Experiments
3131
!experiments/ClimaEarth/**/Manifest.toml
3232
!experiments/ClimaCore/**/Manifest.toml
33+
experiments/calibration/coarse_amip/output*/
3334

3435
# Output
3536
output/

config/atmos_configs/climaatmos_wx_progedmf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ moist: equil
5151

5252
cloud_model: "quadrature_sgs"
5353
use_itime: true
54-
deep_atmosphere: false
54+
deep_atmosphere: false
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
FLOAT_TYPE: "Float32"
22
albedo_model: "CouplerAlbedo"
33
atmos_config_file: "config/atmos_configs/climaatmos_wx_diagedmf.yml"
4-
coupler_toml: ["toml/amip.toml"]
5-
mode_name: "subseasonal"
6-
era5_initial_condition_dir: "/net/sampo/data1/wxquest_data/initial_conditions"
4+
coupler_toml: ["toml/amip.toml", "toml/wxquest_diagedmf.toml"]
75
initial_condition: "WeatherModel"
8-
checkpoint_dt: "7days"
6+
checkpoint_dt: "93days"
97
co2_model: "fixed"
10-
dt: "30secs"
11-
dt_cpl: "30secs"
8+
coupler_output_dir: "output_quick"
9+
dt: "90secs"
10+
dt_cpl: "90secs"
1211
energy_check: false
1312
h_elem: 16
14-
15-
### integrated land ###
16-
# land_model: "integrated"
17-
18-
### bucket land ###
13+
mode_name: "subseasonal"
14+
era5_initial_condition_dir: /net/sampo/data1/wxquest_data/initial_conditions
1915
land_model: "bucket"
2016
bucket_albedo_type: "map_temporal"
21-
bucket_initial_condition: "/net/sampo/data1/wxquest_data/initial_conditions/era5_bucket_processed_20250907_0000.nc"
22-
2317
land_spun_up_ic: false
2418
land_temperature_anomaly: "nothing"
25-
use_land_diagnostics: true
2619
radiation_reset_rng_seed: true
27-
start_date: "20250907"
20+
start_date: "20180901"
2821
surface_setup: "PrescribedSurface"
2922
topo_smoothing: true
3023
topography: "Earth"
31-
t_end: "7days"
24+
t_end: "700days"
3225
netcdf_output_at_levels: true
26+
output_default_diagnostics: false
27+
use_coupler_diagnostics: false
28+
use_land_diagnostics: true
29+
strict_params: false
3330
extra_atmos_diagnostics:
34-
- short_name: [tas, mslp, pr, ua, va, rhoa, pfull, hur, hus, clw, cli, clivi, clwvi, cl, arup, tke]
35-
period: 1hours
36-
reduction_time: average
31+
- short_name: [hfls, hfss, mslp, tas, pr, ta, pfull, hur, rsut, rsds, rsus, rsuscs, rsutcs, rlutcs, rlut, rlds, rlus, rlucs, ts, evspsbl, hfes]
32+
period: 1months
33+
reduction_time: average

experiments/calibration/README.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
# ClimaCoupler Calibration Experiments
22

3-
This folder contains a trivial perfect-model calibration of the atmosphere coupled with the bucket model.
4-
The calibration uses 30-day and lat/lon averages of top-of-atmosphere shortwave
5-
radiation to calibrate the `total_solar_irradiance` parameter in a perfect model setting.
6-
The current run script uses the `ClimaCalibrate.SlurmManager` to add Slurm workers
7-
which run each ensemble member in parallel.
8-
9-
To run this calibration on a Slurm cluster, ensure that `run_calibration.sh` is
10-
configured for your cluster and run `sbatch run_calibration.sh`. The output will
11-
be generated in `experiments/calibration/output`.
3+
This folder contains coupled calibration experiment scripts.
4+
The `coarse_amip` calibration uses the October monthly surface fluxes to calibrate the inverse entrainment timescale.
125

136
Components:
14-
- run_calibration.sh: SBATCH script used to instantiate the project and run the calibration on a Slurm cluster.
15-
- run_calibration.jl: Julia script for the overall calibration and postprocessing. Contains the expriment configuration, such as ensemble size and number of iterations.
7+
- generate_observations.jl: Script to generate observations for the calibration pipeline
8+
- run_calibration.jl: Script for the overall calibration and postprocessing. Contains the expriment configuration, such as ensemble size and number of iterations.
169
- model_interface.jl: Contains `forward_model`, the function that gets run during calibration. This basically just uses the `setup_run` function.
17-
- model_config.yml: Contains the configuration for the coupler
18-
-
10+
- observation_map.jl: Contains the loss function and generalized plotting utilities.

experiments/calibration/api.jl

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import Dates
2+
3+
"""
4+
struct CalibrateConfig{SPINUP <: Dates.Period, EXTEND <: Dates.Period}
5+
short_names::Vector{String}
6+
minibatch_size::Int64
7+
n_iterations::Int64
8+
sample_date_ranges::Vector{NTuple{2, DATE}}
9+
extend::EXTEND
10+
spinup::SPINUP
11+
nelements::Tuple{Int64, Int64}
12+
output_dir::String
13+
rng_seed::Int64
14+
end
15+
16+
A configuration struct for keeping track of multiple fields that are of interest
17+
to a user running calibration, or that are needed in multiple places (e.g., for
18+
ensemble members and generating observations).
19+
"""
20+
struct CalibrateConfig{SPINUP <: Dates.Period, EXTEND <: Dates.Period}
21+
"Configuration file to use for ClimaCoupler simulation"
22+
config_file::String
23+
24+
"The short names of the observations used for calibration. The short names
25+
should match the same names used for the diagnostics."
26+
short_names::Vector{String}
27+
28+
"The size of the minibatch for each iteration"
29+
minibatch_size::Int64
30+
31+
"The number of iterations to run the calibration for"
32+
n_iterations::Int64
33+
34+
"The date ranges of the samples for calibration and used to determine the
35+
start and end dates of a simulation for each iteration of calibration"
36+
sample_date_ranges::Vector{NTuple{2, Dates.DateTime}}
37+
38+
"The amount of time to run a simulation after the last date of the
39+
minibatch"
40+
extend::EXTEND
41+
42+
"The amount of time to run a simulation before the first date of the
43+
minibatch"
44+
spinup::SPINUP
45+
46+
"The directory to store the iterations and members of the calibration."
47+
output_dir::String
48+
49+
"An integer value for ensuring calibrations are the same between multiple
50+
calibrations with the same settings"
51+
rng_seed::Int64
52+
end
53+
54+
"""
55+
CalibrateConfig(;
56+
config_file,
57+
short_names,
58+
sample_date_ranges,
59+
extend,
60+
spinup = Dates.Month(3),
61+
minibatch_size,
62+
n_iterations,
63+
output_dir = "calibration/weatherquest",,
64+
rng_seed = 42,
65+
)
66+
67+
Initializes a CalibrateConfig, which is of interest to a user running
68+
calibration or contains values needed in multiple places during calibration.
69+
70+
Keyword arguments
71+
=====================
72+
73+
- `config_file`: Configuration file to use for ClimaCoupler simulation.
74+
75+
- `short_names`: Short names of the observations. The currently supported short
76+
names are `pr`, `tas`, and `mslp`.
77+
78+
- `minibatch_size`: The size of the minibatch for each iteration.
79+
80+
- `n_iterations`: The number of iterations to run the calibration for.
81+
82+
- `sample_date_ranges`: The date ranges for each sample. The dates should be the
83+
same as found in the time series data of the observations.
84+
85+
- `extend`: The amount of time to run the simulation after the end date
86+
determined by `sample_date_ranges`. For seasonal averages, `extend` should be
87+
`Dates.Month(3)` and for monthly averages, `extend` should be
88+
`Dates.Month(1)`.
89+
90+
- `spinup`: The amount of time to run the simulation before the start date
91+
determined by `sample_date_ranges`.
92+
93+
- `nelements`: The resolution of the model. This is also used to determine the
94+
mask of the observations.
95+
96+
- `output_dir`: The location to save the calibration at.
97+
98+
- `rng_seed`: An integer to ensure that calibration runs with the same settings
99+
are the same.
100+
"""
101+
function CalibrateConfig(;
102+
config_file,
103+
short_names,
104+
minibatch_size,
105+
n_iterations,
106+
sample_date_ranges,
107+
extend,
108+
spinup = Dates.Month(3),
109+
output_dir = "calibration/weatherquest",
110+
rng_seed = 42,
111+
)
112+
isempty(short_names) && error("Cannot run calibration with no short names")
113+
isempty(sample_date_ranges) &&
114+
error("Cannot run calibration with no date ranges for the samples")
115+
116+
sample_date_ranges = [
117+
(Dates.DateTime(date_pair[1]), Dates.DateTime(date_pair[2])) for
118+
date_pair in sample_date_ranges
119+
]
120+
121+
for (start_date, stop_date) in sample_date_ranges
122+
start_date <= stop_date || error(
123+
"The start date ($start_date) should be before the stop date ($stop_date)",
124+
)
125+
end
126+
issorted(sample_date_ranges) ||
127+
error("The samples in $sample_date_ranges should be sorted")
128+
129+
minibatch_size > 0 || error("The minibatch size ($minibatch_size) should be positive")
130+
n_iterations > 0 || error("The number of iterations ($n_iterations) should be positive")
131+
132+
num_samples = length(sample_date_ranges)
133+
minibatch_size > num_samples && error(
134+
"The minibatch size is $minibatch_size, but the number of samples is $num_samples",
135+
)
136+
137+
remaining = num_samples % minibatch_size
138+
remaining == 0 || @warn(
139+
"Number of samples is not divisible by the minibatch size; the last $remaining samples may be missing when running the calibration"
140+
)
141+
142+
return CalibrateConfig(
143+
config_file,
144+
short_names,
145+
minibatch_size,
146+
n_iterations,
147+
sample_date_ranges,
148+
extend,
149+
spinup,
150+
output_dir,
151+
rng_seed,
152+
)
153+
154+
end

0 commit comments

Comments
 (0)