Skip to content
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

Adding key metrics: Isla's NMSE metric #121

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions examples/key_metrics/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ timeseries:
case_name: 'b.e23_alpha17f.BLT1850.ne30_t232.092'

atm:
vars: ['ACTNI', 'ACTNL', 'ACTREI', 'ACTREL', 'AODDUST']
derive_vars: [] # {'PRECT':['PRECL', 'PRECC'], 'RESTOM':['FLNT', 'FSNT']}
hist_str: 'h0'
vars: ['PSL']
derive_vars: []
hist_str: 'h0a'
start_years: [1]
end_years: [100]
level: 'lev'
Expand Down Expand Up @@ -99,21 +99,22 @@ compute_notebooks:
# parameters are specified. Several examples of different
# types of notebooks are provided.

# The first key (here simple_no_params_nb) is the name of the
# The first key (here infrastructure) is the name of the
# notebook from nb_path_root, minus the .ipynb

infrastructure:
index:
parameter_groups:
none: {}

# atm:
# adf_quick_run:
# parameter_groups:
# none:
# adf_path: ../../../externals/ADF
# config_path: .
# config_fil_str: "config_f.cam6_3_119.FLTHIST_ne30.r328_gamma0.33_soae.001.yaml"
atm:
nmse_PSL:
parameter_groups:
none:
regridded_output: True
validation_path: '/glade/campaign/cesm/development/cross-wg/diagnostic_framework/nmse_validation/fv0.9x1.25'
start_date: '0001-01-01'
end_date: '0101-01-01'

glc:
LIWG_SMB_diagnostic:
Expand Down Expand Up @@ -181,13 +182,12 @@ book_toc:

# Parts group notebooks into different sections in the Jupyter book
# table of contents, so you can organize different parts of your project.
# Each chapter is the name of one of the notebooks that you executed
# in compute_notebooks above, also without .ipynb

# - caption: Atmosphere

# # Each chapter is the name of one of the notebooks that you executed
# # in compute_notebooks above, also without .ipynb
# chapters:
# - file: atm/adf_quick_run
- caption: Atmosphere
chapters:
- file: atm/nmse_PSL

# - caption: Ocean
# chapters:
Expand Down
54 changes: 54 additions & 0 deletions examples/nblibrary/atm/averaging_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import annotations

import xarray as xr

dpseas = {"DJF": 90, "MAM": 92, "JJA": 92, "SON": 91}


def seasonal_climatology_weighted(dat):
TeaganKing marked this conversation as resolved.
Show resolved Hide resolved
"""Calculate seasonal and annual average climatologies"""
days_in_month = dat.time.dt.days_in_month
mons = dat.time.dt.month
wgts = mons.copy(deep=True)
wgts = xr.where(
(mons == 1) | (mons == 2) | (mons == 12),
days_in_month / dpseas["DJF"],
wgts,
)
wgts = xr.where(
(mons == 3) | (mons == 4) | (mons == 5),
days_in_month / dpseas["MAM"],
wgts,
)
wgts = xr.where(
(mons == 6) | (mons == 7) | (mons == 8),
days_in_month / dpseas["JJA"],
wgts,
)
wgts = xr.where(
(mons == 9) | (mons == 10) | (mons == 11),
days_in_month / dpseas["SON"],
wgts,
)
datw = dat * wgts

wgts_am = days_in_month / 365.0
datw_am = dat * wgts_am

ds_season = (
datw.rolling(min_periods=3, center=True, time=3).sum().dropna("time", how="all")
)
dat_djf = ds_season.where(ds_season.time.dt.month == 1, drop=True).mean("time")
dat_mam = ds_season.where(ds_season.time.dt.month == 4, drop=True).mean("time")
dat_jja = ds_season.where(ds_season.time.dt.month == 7, drop=True).mean("time")
dat_son = ds_season.where(ds_season.time.dt.month == 10, drop=True).mean("time")
dat_am = datw_am.groupby("time.year").sum("time")
dat_am = dat_am.mean("year")

dat_djf = dat_djf.rename("DJF")
dat_mam = dat_mam.rename("MAM")
dat_jja = dat_jja.rename("JJA")
dat_son = dat_son.rename("SON")
dat_am = dat_am.rename("AM")

return xr.merge([dat_djf, dat_mam, dat_jja, dat_son, dat_am])
Loading
Loading