-
Notifications
You must be signed in to change notification settings - Fork 7
Add subseasonal calibration pipeline #1583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,13 @@ | ||
| # ClimaCoupler Calibration Experiments | ||
|
|
||
| This folder contains a trivial perfect-model calibration of the atmosphere coupled with the bucket model. | ||
| The calibration uses 30-day and lat/lon averages of top-of-atmosphere shortwave | ||
| radiation to calibrate the `total_solar_irradiance` parameter in a perfect model setting. | ||
| The current run script uses the `ClimaCalibrate.SlurmManager` to add Slurm workers | ||
| which run each ensemble member in parallel. | ||
|
|
||
| To run this calibration on a Slurm cluster, ensure that `run_calibration.sh` is | ||
| configured for your cluster and run `sbatch run_calibration.sh`. The output will | ||
| be generated in `experiments/calibration/output`. | ||
|
Comment on lines
-9
to
-11
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you keep this information? I think it's helpful to explain a little bit how to run the experiments |
||
| This folder contains pipelines to reproduce coupled calibration experiments. | ||
| Each pipeline has its own subfolder: | ||
|
|
||
| Components: | ||
| - run_calibration.sh: SBATCH script used to instantiate the project and run the calibration on a Slurm cluster. | ||
| - run_calibration.jl: Julia script for the overall calibration and postprocessing. Contains the expriment configuration, such as ensemble size and number of iterations. | ||
| - model_interface.jl: Contains `forward_model`, the function that gets run during calibration. This basically just uses the `setup_run` function. | ||
| - model_config.yml: Contains the configuration for the coupler | ||
| - | ||
| - perfect_model: A trivial perfect-model calibration of the atmosphere coupled | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might be more clear if we rename the |
||
| with the bucket model. The calibration uses 30-day and lat/lon averages of | ||
| top-of-atmosphere shortwave radiation to calibrate the `total_solar_irradiance` | ||
| parameter in a perfect model setting. The current run script uses the | ||
| `ClimaCalibrate.SlurmManager` to add Slurm workers which run each ensemble | ||
| member in parallel. | ||
| - subseasonal: Calibrates the inverse entrainment timescale to ERA5 October monthly surface fluxes and surface temperature from 2018 to 2024. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,154 @@ | ||||||
| import Dates | ||||||
|
|
||||||
| """ | ||||||
| struct CalibrateConfig{SPINUP <: Dates.Period, EXTEND <: Dates.Period} | ||||||
| short_names::Vector{String} | ||||||
| minibatch_size::Int64 | ||||||
| n_iterations::Int64 | ||||||
| sample_date_ranges::Vector{NTuple{2, DATE}} | ||||||
| extend::EXTEND | ||||||
| spinup::SPINUP | ||||||
| nelements::Tuple{Int64, Int64} | ||||||
| output_dir::String | ||||||
| rng_seed::Int64 | ||||||
| end | ||||||
| A configuration struct for keeping track of multiple fields that are of interest | ||||||
| to a user running calibration, or that are needed in multiple places (e.g., for | ||||||
| ensemble members and generating observations). | ||||||
| """ | ||||||
| struct CalibrateConfig{SPINUP <: Dates.Period, EXTEND <: Dates.Period} | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been trying to move more code out of experiments/ and into src/ and ext/. A lot of the calibration-related code is for experiments so it probably does belong here, but maybe something like this could go in ClimaCouplerClimaCalibrateExt (it wouldn't have to be in this PR). What do you think? |
||||||
| "Configuration file to use for ClimaCoupler simulation" | ||||||
| config_file::String | ||||||
|
|
||||||
| "The short names of the observations used for calibration. The short names | ||||||
| should match the same names used for the diagnostics." | ||||||
| short_names::Vector{String} | ||||||
|
|
||||||
| "The size of the minibatch for each iteration" | ||||||
| minibatch_size::Int64 | ||||||
|
|
||||||
| "The number of iterations to run the calibration for" | ||||||
| n_iterations::Int64 | ||||||
|
|
||||||
| "The date ranges of the samples for calibration and used to determine the | ||||||
| start and end dates of a simulation for each iteration of calibration" | ||||||
| sample_date_ranges::Vector{NTuple{2, Dates.DateTime}} | ||||||
|
|
||||||
| "The amount of time to run a simulation after the last date of the | ||||||
| minibatch" | ||||||
| extend::EXTEND | ||||||
|
|
||||||
| "The amount of time to run a simulation before the first date of the | ||||||
| minibatch" | ||||||
| spinup::SPINUP | ||||||
|
|
||||||
| "The directory to store the iterations and members of the calibration." | ||||||
| output_dir::String | ||||||
|
|
||||||
| "An integer value for ensuring calibrations are the same between multiple | ||||||
| calibrations with the same settings" | ||||||
| rng_seed::Int64 | ||||||
| end | ||||||
|
|
||||||
| """ | ||||||
| CalibrateConfig(; | ||||||
| config_file, | ||||||
| short_names, | ||||||
| sample_date_ranges, | ||||||
| extend, | ||||||
| spinup = Dates.Month(3), | ||||||
| minibatch_size, | ||||||
| n_iterations, | ||||||
| output_dir = "calibration/weatherquest",, | ||||||
| rng_seed = 42, | ||||||
| ) | ||||||
| Initializes a CalibrateConfig, which is of interest to a user running | ||||||
| calibration or contains values needed in multiple places during calibration. | ||||||
| Keyword arguments | ||||||
| ===================== | ||||||
| - `config_file`: Configuration file to use for ClimaCoupler simulation. | ||||||
| - `short_names`: Short names of the observations. The currently supported short | ||||||
| names are `pr`, `tas`, and `mslp`. | ||||||
| - `minibatch_size`: The size of the minibatch for each iteration. | ||||||
| - `n_iterations`: The number of iterations to run the calibration for. | ||||||
| - `sample_date_ranges`: The date ranges for each sample. The dates should be the | ||||||
| same as found in the time series data of the observations. | ||||||
| - `extend`: The amount of time to run the simulation after the end date | ||||||
| determined by `sample_date_ranges`. For seasonal averages, `extend` should be | ||||||
| `Dates.Month(3)` and for monthly averages, `extend` should be | ||||||
| `Dates.Month(1)`. | ||||||
| - `spinup`: The amount of time to run the simulation before the start date | ||||||
| determined by `sample_date_ranges`. | ||||||
| - `nelements`: The resolution of the model. This is also used to determine the | ||||||
| mask of the observations. | ||||||
| - `output_dir`: The location to save the calibration at. | ||||||
| - `rng_seed`: An integer to ensure that calibration runs with the same settings | ||||||
| are the same. | ||||||
| """ | ||||||
| function CalibrateConfig(; | ||||||
| config_file, | ||||||
| short_names, | ||||||
| minibatch_size, | ||||||
| n_iterations, | ||||||
| sample_date_ranges, | ||||||
| extend, | ||||||
| spinup = Dates.Month(3), | ||||||
| output_dir = "calibration/weatherquest", | ||||||
| rng_seed = 42, | ||||||
| ) | ||||||
| isempty(short_names) && error("Cannot run calibration with no short names") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| isempty(sample_date_ranges) && | ||||||
| error("Cannot run calibration with no date ranges for the samples") | ||||||
|
|
||||||
| sample_date_ranges = [ | ||||||
| (Dates.DateTime(date_pair[1]), Dates.DateTime(date_pair[2])) for | ||||||
| date_pair in sample_date_ranges | ||||||
| ] | ||||||
|
|
||||||
| for (start_date, stop_date) in sample_date_ranges | ||||||
| start_date <= stop_date || error( | ||||||
| "The start date ($start_date) should be before the stop date ($stop_date)", | ||||||
| ) | ||||||
| end | ||||||
| issorted(sample_date_ranges) || | ||||||
| error("The samples in $sample_date_ranges should be sorted") | ||||||
|
|
||||||
| minibatch_size > 0 || error("The minibatch size ($minibatch_size) should be positive") | ||||||
| n_iterations > 0 || error("The number of iterations ($n_iterations) should be positive") | ||||||
|
|
||||||
| num_samples = length(sample_date_ranges) | ||||||
| minibatch_size > num_samples && error( | ||||||
| "The minibatch size is $minibatch_size, but the number of samples is $num_samples", | ||||||
| ) | ||||||
|
|
||||||
| remaining = num_samples % minibatch_size | ||||||
| remaining == 0 || @warn( | ||||||
| "Number of samples is not divisible by the minibatch size; the last $remaining samples may be missing when running the calibration" | ||||||
| ) | ||||||
|
|
||||||
| return CalibrateConfig( | ||||||
| config_file, | ||||||
| short_names, | ||||||
| minibatch_size, | ||||||
| n_iterations, | ||||||
| sample_date_ranges, | ||||||
| extend, | ||||||
| spinup, | ||||||
| output_dir, | ||||||
| rng_seed, | ||||||
| ) | ||||||
|
|
||||||
| end | ||||||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe instead we can change this to:
so we don't have a path in the gitignore that depends on a run name?