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

Fix error in ECS notebook #87

Merged
merged 3 commits into from
Oct 17, 2024
Merged
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
14 changes: 6 additions & 8 deletions notebooks/example-workflows/ecs-cmip6.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
" which can lead to issues when merging.\"\"\"\n",
" drop_vars = [vname for vname in ds.coords\n",
" if (('_bounds') in vname ) or ('_bnds') in vname]\n",
" return ds.drop(drop_vars)\n",
" return ds.drop_vars(drop_vars)\n",
"\n",
"def open_dsets(df):\n",
" \"\"\"Open datasets from cloud storage and return xarray dataset.\"\"\"\n",
Expand Down Expand Up @@ -471,7 +471,7 @@
" # https://github.com/pydata/xarray/issues/2237#issuecomment-620961663\n",
" dsets_ann_mean = [v[expt].pipe(global_mean)\n",
" .swap_dims({'time': 'year'})\n",
" .drop('time')\n",
" .drop_vars('time')\n",
" .coarsen(year=12).mean()\n",
" for expt in expts]\n",
"\n",
Expand Down Expand Up @@ -645,14 +645,12 @@
"source": [
"ds_abrupt = ds_anom.sel(year=first_150_years, experiment_id=co2_option).reset_coords(drop=True)\n",
"\n",
"def calc_ecs(ds):\n",
" # Some sources don't have all 150 years, drop those missing values.\n",
" a, b = np.polyfit(ds.tas.dropna(\"year\"),\n",
" ds.imbalance.dropna(\"year\"), 1)\n",
"def calc_ecs(tas, imb):\n",
" a, b = np.polyfit(tas, imb, 1)\n",
" ecs = -1.0 * (b/a) # Change -1.0 to -0.5 if using 4xCO2\n",
" return xr.DataArray(ecs)\n",
"\n",
"ds_abrupt['ecs'] = ds_abrupt.groupby('source_id').apply(calc_ecs)\n",
"ds_abrupt['ecs'] = xr.apply_ufunc(calc_ecs, ds_abrupt.tas, ds_abrupt.imbalance, vectorize=True, input_core_dims=[['year'], ['year']])\n",
"ds_abrupt.compute()"
]
},
Expand Down Expand Up @@ -776,7 +774,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.15"
},
"nbdime-conflicts": {
"local_diff": [
Expand Down