Skip to content

Commit

Permalink
working version of nmse metric
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaganKing committed Aug 7, 2024
1 parent 2f01853 commit 98fd753
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions examples/nblibrary/atm/nmse_PSL.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"outputs": [],
"source": [
"dat = xr.open_mfdataset(\n",
" CESM_output_dir + \"/\" + case_name + \"/atm/proc/tseries/*.PSL*.nc\"\n",
" CESM_output_dir + \"/\" + case_name + \"/atm/proc/tseries/regrid/*PSL*.nc\"\n",
")"
]
},
Expand Down Expand Up @@ -114,24 +114,22 @@
"outputs": [],
"source": [
"# This will need to be changed if we have a common repo\n",
"validpath = \"/glade/campaign/cgd/cas/islas/python_savs/CUPID/PSL_validation/\"\n",
"validpath_old = (\n",
"validation_path = (\n",
" \"/glade/campaign/cgd/cas/islas/python_savs/CUPID/NMSE/validation_data_example/\"\n",
")\n",
"\n",
"# ---ERA5\n",
"era5 = xr.open_dataset(validpath_old + \"PSL_ERA5.nc\")\n",
"# era5 = xr.open_dataset(\"/glade/campaign/cgd/cas/islas/python_savs/CUPID/NMSE/validation_data_example/PSL_ERA5.nc\")\n",
"era5 = xr.open_dataset(validation_path + \"PSL_ERA5.nc\")\n",
"era5 = era5 / 100.0 # convert to hPa\n",
"\n",
"# ---CESM2\n",
"lens2 = xr.open_dataset(validpath_old + \"PSL_LENS2.nc\")\n",
"lens2 = xr.open_dataset(validation_path + \"PSL_LENS2.nc\")\n",
"lens2 = lens2 / 100.0 # convert to hPa\n",
"lens2[\"lon\"] = era5.lon\n",
"lens2[\"lat\"] = era5.lat\n",
"\n",
"# ---CMIP6\n",
"modelfiles = sorted(glob.glob(validpath_old + \"CMIP6/*.nc\"))\n",
"modelfiles = sorted(glob.glob(validation_path + \"CMIP6/*.nc\"))\n",
"datcmip6 = [xr.open_dataset(ifile).mean(\"M\") for ifile in modelfiles]\n",
"datcmip6 = xr.concat(datcmip6, dim=\"model\")\n",
"datcmip6 = datcmip6 / 100.0\n",
Expand Down Expand Up @@ -177,9 +175,19 @@
"outputs": [],
"source": [
"dat = dat.sel(time=slice(start_date, end_date))\n",
"\n",
"dat = dat.PSL / 100.0\n",
"dat = dat.expand_dims(lon=era5.lon, lat=era5.lat)"
"dat = dat.PSL / 100.0"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b11ed849-c8b2-4079-bde0-598f60ab4463",
"metadata": {},
"outputs": [],
"source": [
"# this requires the same grid\n",
"dat[\"lon\"] = era5.lon\n",
"dat[\"lat\"] = era5.lat"
]
},
{
Expand Down Expand Up @@ -220,7 +228,6 @@
},
"outputs": [],
"source": [
"print(\"moving on to compute the nmse\")\n",
"nmse_dat = []\n",
"nmse_cesm2 = []\n",
"nmse_cmip6 = []\n",
Expand Down

0 comments on commit 98fd753

Please sign in to comment.