From 84b6e301ecfeca2ec389a5b51cdf0908257e6af6 Mon Sep 17 00:00:00 2001 From: Robert Ford <50349951+r-ford@users.noreply.github.com> Date: Tue, 21 May 2024 18:20:23 -0400 Subject: [PATCH 1/2] Remove line causing error --- notebooks/example-workflows/enso-esgf.ipynb | 22 +-------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/notebooks/example-workflows/enso-esgf.ipynb b/notebooks/example-workflows/enso-esgf.ipynb index 88956b6..822a9d7 100644 --- a/notebooks/example-workflows/enso-esgf.ipynb +++ b/notebooks/example-workflows/enso-esgf.ipynb @@ -134,18 +134,6 @@ "tos_tree" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "3694d7de-3b75-4e25-8001-1fa5c7877f53", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "tos_tree[]" - ] - }, { "cell_type": "markdown", "id": "5395c611-afda-405e-9b1c-35b7566c557f", @@ -467,14 +455,6 @@ "## Resources and references\n", "- [Intake-ESGF Documentation](https://github.com/nocollier/intake-esgf)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f5b2864f-6661-4aa4-8d65-8dc10c961b36", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -493,7 +473,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.10.14" } }, "nbformat": 4, From dfcde9c1a466025cca823705b6a73acb0b786eb8 Mon Sep 17 00:00:00 2001 From: Robert Ford <50349951+r-ford@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:34:01 -0400 Subject: [PATCH 2/2] Fix ECS notebook --- notebooks/example-workflows/ecs-cmip6.ipynb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/notebooks/example-workflows/ecs-cmip6.ipynb b/notebooks/example-workflows/ecs-cmip6.ipynb index b575cb5..9d5988a 100644 --- a/notebooks/example-workflows/ecs-cmip6.ipynb +++ b/notebooks/example-workflows/ecs-cmip6.ipynb @@ -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", @@ -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", @@ -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()" ] }, @@ -776,7 +774,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.10.15" }, "nbdime-conflicts": { "local_diff": [