-
Notifications
You must be signed in to change notification settings - Fork 7
WeatherQuest Calibration pipeline with weekly/monthly support + CERES, ERA5 Pressure Levels #1747
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
Open
costachris
wants to merge
25
commits into
main
Choose a base branch
from
cc/wxquest_v4_final
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,914
−83
Open
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0c70491
Update weatherquest configs. Clip bucket fields.
costachris 5778e99
restore subseasonal dir to match main
costachris c090c81
add subseasonal weekly folder
costachris a090e74
remove NH mask
costachris 7011dfb
consolidate weekly and monthly
costachris 5ce743c
remove unused files.
costachris fbfddca
consolidate model interface.
costachris f353f7f
Add back variable normalization. Setup for derecho.
costachris 6b522e6
clean up comments
costachris 96a7399
add CERES dataloader.
costachris 9a68101
Add CERES data support to pipeline. Use extend + spinup to compare 3 …
costachris fec3460
average daily output files in obs map to get aggregated values for loss.
costachris c56a274
address some pr comments
costachris 351bd80
Use 1 week spinup + full 1 month of calibration. Clean up time_averag…
costachris baf62e2
start adding pressure levels.
costachris d2936e3
remove CERES dataload.
costachris c5635f0
Add other data loaders
ph-kev b11cd7d
update CERES dataloader, use time = [target_date]) for .select
costachris 164343c
Add pressure level support.
costachris 54cd2ae
hack to remove time dim
costachris 0ad35f8
remove add time dim logic.
costachris 8820be9
add dataloaders
nefrathenrici db3114b
Add bias plots
nefrathenrici def6919
Use dataloaders, automatically determine backend
nefrathenrici adc7a90
Use SVDplusD covariance matrix
ph-kev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
config/subseasonal_configs/wxquest_diagedmf_weekly_calibration.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| FLOAT_TYPE: "Float32" | ||
| albedo_model: "CouplerAlbedo" | ||
| atmos_config_file: "config/atmos_configs/climaatmos_wx_diagedmf.yml" | ||
| coupler_toml: ["toml/wxquest_diagedmf.toml"] | ||
| strict_params: false | ||
| mode_name: "subseasonal" | ||
| era5_initial_condition_dir: "/glade/campaign/univ/ucit0011/cchristo/wxquest_data/initial_conditions/initial_conditions_v1_dev" | ||
| initial_condition: "WeatherModel" | ||
| checkpoint_dt: "100days" | ||
| dt: "150secs" | ||
| dt_cpl: "150secs" | ||
| dt_cloud_fraction: "1hours" | ||
| dt_rad: "1hours" | ||
| dt_seaice: "150secs" | ||
| ode_algo: "ARS232" | ||
| energy_check: false | ||
| h_elem: 12 | ||
| z_elem: 63 | ||
| z_max: 60000.0 | ||
| land_fraction_source: "era5" | ||
| binary_area_fraction: false | ||
|
|
||
| ### integrated land ### | ||
| land_model: "integrated" | ||
| lai_source: "modis_monthly_climatology" | ||
|
|
||
| ### gravity waves | ||
| # orographic_gravity_wave: "raw_topo" | ||
| non_orographic_gravity_wave: true | ||
|
|
||
|
|
||
|
|
||
| ### bucket land ### | ||
| # land_model: "bucket" | ||
| # bucket_albedo_type: "map_temporal" | ||
| # bucket_albedo_type: "era5" | ||
| # bucket_initial_condition: "/net/sampo/data1/cchristo/WeatherQuest_data/archive_dev4/era5_bucket_processed_20250831_0000.nc" | ||
|
|
||
| land_spun_up_ic: false | ||
| land_temperature_anomaly: "nothing" | ||
| radiation_reset_rng_seed: true | ||
| start_date: "20230115" | ||
| surface_setup: "PrescribedSurface" | ||
| topo_smoothing: true | ||
| topography: "Earth" | ||
| # t_end: "8days" | ||
| t_end: "1days" | ||
| netcdf_output_at_levels: true | ||
| output_default_diagnostics: false | ||
| use_coupler_diagnostics: false | ||
| use_land_diagnostics: false | ||
| extra_atmos_diagnostics: | ||
| - short_name: [tas, pr, mslp, rsut, rlut] | ||
| period: 1days | ||
| reduction_time: average |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,17 +3,33 @@ using Statistics | |
| import Dates | ||
| using ClimaAnalysis | ||
|
|
||
| include(joinpath(pkgdir(ClimaCoupler), "experiments/ClimaEarth/setup_run.jl")) | ||
| # Shared variable units (used by both subseasonal and subseasonal_weekly) | ||
|
|
||
| var_units = Dict( | ||
| # Surface temperature/pressure | ||
| "pr" => "kg m^-2 s^-1", | ||
| "mslp" => "Pa", | ||
| "tas" => "K", | ||
| "tas - ta" => "K", | ||
| "ts" => "K", | ||
| "sp" => "Pa", | ||
| # Surface fluxes | ||
| "hfls" => "W m^-2", | ||
| "hfss" => "W m^-2", | ||
| "rsus" => "W m^-2", | ||
| "rlus" => "W m^-2", | ||
| # Radiation (TOA) | ||
| "rsdt" => "W m^-2", # incoming solar | ||
| "rsut" => "W m^-2", # TOA outgoing SW | ||
| "rlut" => "W m^-2", # TOA outgoing LW | ||
| "rsutcs" => "W m^-2", # TOA outgoing SW clear-sky | ||
| "rlutcs" => "W m^-2", # TOA outgoing LW clear-sky | ||
| # Radiation (surface) | ||
| "rsds" => "W m^-2", # surface downwelling SW | ||
| "rsus" => "W m^-2", # surface upwelling SW | ||
| "rlds" => "W m^-2", # surface downwelling LW | ||
| "rlus" => "W m^-2", # surface upwelling LW | ||
| "rsdscs" => "W m^-2", # surface downwelling SW clear-sky | ||
| "rsuscs" => "W m^-2", # surface upwelling SW clear-sky | ||
| "rldscs" => "W m^-2", # surface downwelling LW clear-sky | ||
| ) | ||
|
|
||
| """ | ||
|
|
@@ -26,3 +42,40 @@ function remove_global_mean(var) | |
| mean_data = mean_var.data | ||
| return ClimaAnalysis.replace(val -> val - mean_data[1], var) | ||
| end | ||
|
|
||
| """ | ||
| get_var(short_name, simdir) | ||
|
|
||
| Get an `OutputVar` from `simdir` for the given `short_name`. | ||
| Handles composite variables like "tas - ta" (surface-minus-boundary-layer temperature). | ||
| """ | ||
| function get_var(short_name, simdir) | ||
| if short_name == "tas - ta" | ||
| tas = get(simdir; short_name = "tas") | ||
| ta = get(simdir; short_name = "ta") | ||
| ta_900hpa = slice(ta; z = 1000) | ||
| var = tas - ta_900hpa | ||
| else | ||
| var = get(simdir; short_name) | ||
| end | ||
|
|
||
| var.attributes["short_name"] = short_name | ||
| return var | ||
| end | ||
|
|
||
| """ | ||
| preprocess_var(var::ClimaAnalysis.OutputVar, sample_date_range) | ||
|
|
||
| Preprocess simulation output `var` before flattening for the G ensemble matrix. | ||
|
|
||
| Shifts the time axis by the largest period in the date range, sets units, and | ||
| windows to the date range. Calls `largest_period` (defined per-pipeline) to | ||
| determine the shift. | ||
|
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. There shouldn't be a need for shifting the times. |
||
| """ | ||
| function preprocess_var(var, sample_date_range) | ||
| period = largest_period(sample_date_range) | ||
| var = ClimaAnalysis.Var._shift_by(var, date -> date - period) | ||
| var = set_units(var, var_units[short_name(var)]) | ||
| var = window(var, "time"; left = sample_date_range[1], right = sample_date_range[2]) | ||
| return var | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Subseasonal Calibration | ||
|
|
||
| Calibrate ClimaCoupler parameters using EnsembleKalmanProcesses against ERA5 observations. | ||
|
|
||
| ## Quick Start | ||
|
|
||
|
|
||
| ### Option A: TransformUnscented (recommended, simpler) | ||
|
|
||
| ```bash | ||
| cd /glade/u/home/cchristo/clima/copies2/ClimaCoupler.jl | ||
|
|
||
| # 1. Generate observations (only needed once, or when changing obs settings) | ||
| julia --project=experiments/ClimaEarth experiments/calibration/subseasonal_weekly/generate_observations.jl | ||
|
|
||
| # 2. Run calibration (from tmux on login node) | ||
| julia --project=experiments/ClimaEarth experiments/calibration/subseasonal_weekly/run_calibration.jl | ||
| ``` | ||
|
|
||
| ### Option B: TransformInversion (more robust, needs precompute) | ||
|
|
||
| ```bash | ||
| cd /glade/u/home/cchristo/clima/copies2/ClimaCoupler.jl | ||
|
|
||
| # 1. Generate observations (only needed once) | ||
| julia --project=experiments/ClimaEarth experiments/calibration/subseasonal_weekly/generate_observations.jl | ||
|
|
||
| # 2. Run full calibration (from tmux - handles precompute automatically) | ||
| ./experiments/calibration/subseasonal_weekly/run_full_calibration.sh | ||
| ``` | ||
|
|
||
| ## Switching Between Process Types | ||
|
|
||
| Edit `run_calibration.jl` and comment/uncomment the appropriate OPTION block (~line 116-156). | ||
|
|
||
| ## Changing Parameters | ||
|
|
||
| Edit `calibration_setup.jl` - this is the single source of truth for: | ||
| - `CALIBRATION_PRIORS` - list of parameters to calibrate | ||
| - `CALIBRATION_ENSEMBLE_SIZE` - ensemble size (for TransformInversion only) | ||
| - `NORMALIZE_VARIABLES` - if true, normalize variables to zero mean and unit variance | ||
| - `CALIBRATION_NOISE_SCALAR` - noise variance for observation covariance | ||
|
|
||
| ### Variable Normalization | ||
|
|
||
| When `NORMALIZE_VARIABLES = true` (default), each variable is normalized to zero mean and unit variance: | ||
| 1. `generate_observations.jl` computes latitude-weighted mean and std from ERA5 data | ||
| 2. Stats are saved to `norm_stats.jld2` | ||
| 3. Observations are normalized before creating the observation vector | ||
| 4. `observation_map.jl` loads the same stats and applies them to model output | ||
|
|
||
| This ensures variables with different magnitudes (e.g., temperature in K vs radiation in W/m²) contribute equally to the calibration objective. | ||
|
|
||
| ## Data Source | ||
|
|
||
| Uses weekly-averaged ERA5 data from: | ||
| `/glade/campaign/univ/ucit0011/cchristo/wxquest_data/daily_weekly_stats/weekly` | ||
|
|
||
| # Analyzing Calibration | ||
| `julia --project=experiments/ClimaEarth experiments/calibration/subseasonal_weekly/analyze_calibration.jl` | ||
|
|
||
| ## Key Files | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `calibration_setup.jl` | defines parameters and settings to calibrate | | ||
| | `run_calibration.jl` | Main calibration script | | ||
| | `generate_observations.jl` | Loads weekly ERA5 data, creates observation vector | | ||
| | `observation_map.jl` | Maps model output to observation space | | ||
| | `run_full_calibration.sh` | Orchestrator for TransformInversion | | ||
|
|
||
| ## Output | ||
|
|
||
| Results go to the `output_dir` specified in `run_calibration.jl` (currently `/glade/derecho/scratch/cchristo/calibration/expXX`). | ||
| Logs are saved to `calibration_YYYYMMDD_HHMMSS.log` in the output directory. | ||
|
|
||
| Plot results: | ||
| ```bash | ||
| julia --project=experiments/ClimaEarth experiments/calibration/subseasonal_weekly/quick_plot_cal.jl | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
| **Bus error**: JLD2 mmap issue on Derecho Lustre - use JLD2 IOStream mode. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be simplified once we put all of this in a data loader.