diff --git a/examples/coupled_model/config.yml b/examples/coupled_model/config.yml index b8e13800..c88ed433 100644 --- a/examples/coupled_model/config.yml +++ b/examples/coupled_model/config.yml @@ -151,13 +151,13 @@ compute_notebooks: parameter_groups: none: cases: - - g.e23_a16g.GJRAv4.TL319_t232_hycom1_N75.2024.005 - - g.e23_a16g.GJRAv4.TL319_t232_zstar_N65.2024.004 - begyr1: 245 - endyr1: 305 - begyr2: 245 - endyr2: 305 - nyears: 25 + - b.e23_alpha17f.BLTHIST.ne30_t232.092 + - b.e30_beta02.BLTHIST.ne30_t232.104 + begyr1: 1850 + endyr1: 2013 + begyr2: 1850 + endyr2: 2013 + nyears: 35 ########### JUPYTER BOOK CONFIG ########### diff --git a/examples/key_metrics/config.yml b/examples/key_metrics/config.yml index 8fd88e21..802ba49c 100644 --- a/examples/key_metrics/config.yml +++ b/examples/key_metrics/config.yml @@ -46,6 +46,8 @@ global_params: CESM_output_dir: /glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing start_date: '0001-01-01' end_date: '0101-01-01' + base_start_date: '0001-01-01' + base_end_date: '0101-01-01' lc_kwargs: threads_per_worker: 1 @@ -80,9 +82,9 @@ timeseries: level: 'lev' ice: - vars: [] + vars: ['aice','hi','hs'] derive_vars: [] - hist_str: 'h' + hist_str: 'cice.h' start_years: [1,1] end_years: [100,100] level: 'lev' @@ -162,18 +164,11 @@ compute_notebooks: # rof_end_date: '0101-01-01' # figureSave: False -# ice: -# seaice: -# parameter_groups: -# none: -# cases: -# - g.e23_a16g.GJRAv4.TL319_t232_hycom1_N75.2024.005 -# - g.e23_a16g.GJRAv4.TL319_t232_zstar_N65.2024.004 -# begyr1: 245 -# endyr1: 305 -# begyr2: 245 -# endyr2: 305 -# nyears: 25 + ice: + Hemis_seaice_visual_compare_obs_lens: + parameter_groups: + none: + climo_nyears: 35 lnd: Global_TerrestrialCouplingIndex_VisualCompareObs: @@ -232,9 +227,9 @@ book_toc: chapters: - file: lnd/Global_TerrestrialCouplingIndex_VisualCompareObs - # - caption: Sea Ice - # chapters: - # - file: ice/seaice + - caption: Sea Ice + chapters: + - file: ice/Hemis_seaice_visual_compare_obs_lens - caption: Land Ice chapters: diff --git a/nblibrary/ice/seaice.ipynb b/nblibrary/ice/Hemis_seaice_visual_compare_full.ipynb similarity index 63% rename from nblibrary/ice/seaice.ipynb rename to nblibrary/ice/Hemis_seaice_visual_compare_full.ipynb index 077cfd56..dc7f7588 100644 --- a/nblibrary/ice/seaice.ipynb +++ b/nblibrary/ice/Hemis_seaice_visual_compare_full.ipynb @@ -3,7 +3,15 @@ { "cell_type": "markdown", "id": "351f2902-54b0-463c-9d61-23574844481f", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "source": [ "## Sea Ice Diagnostics for two CESM3 runs" ] @@ -17,7 +25,9 @@ "slideshow": { "slide_type": "" }, - "tags": [] + "tags": [ + "hide-input" + ] }, "outputs": [], "source": [ @@ -25,8 +35,7 @@ "import numpy as np\n", "import yaml\n", "import pandas as pd\n", - "import matplotlib.pyplot as plt\n", - "from dask.distributed import Client, LocalCluster" + "import matplotlib.pyplot as plt" ] }, { @@ -39,7 +48,8 @@ "slide_type": "" }, "tags": [ - "parameters" + "parameters", + "hide-input" ] }, "outputs": [], @@ -47,28 +57,66 @@ "CESM_output_dir = \"/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing\"\n", "serial = False # use dask LocalCluster\n", "cases = [\n", - " \"g.e23_a16g.GJRAv4.TL319_t232_zstar_N65.2024.004\",\n", - " \"g.e23_a16g.GJRAv4.TL319_t232_hycom1_N75.2024.005\",\n", + " \"b.e23_alpha17f.BLTHIST.ne30_t232.092\",\n", + " \"b.e30_beta02.BLTHIST.ne30_t232.104\",\n", "]\n", "\n", "lc_kwargs = {}\n", "\n", - "begyr1 = 245\n", - "endyr1 = 305\n", - "begyr2 = 245\n", - "endyr2 = 305\n", - "nyears = 25" + "begyr1 = 1850\n", + "endyr1 = 2013\n", + "begyr2 = 1850\n", + "endyr2 = 2013\n", + "nyears = 35" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dfbdb3ea-b818-44be-aafa-1dd9be54715d", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "# from dask.distributed import Client\n", + "# from dask_jobqueue import PBSCluster\n", + "\n", + "# cluster = PBSCluster(cores=16,processes=16,memory='100GB',project='P93300665',queue='casper',walltime='02:00:00')\n", + "\n", + "# client = Client(cluster)\n", + "\n", + "# cluster.scale(1)\n", + "\n", + "# print(cluster)\n", + "# print(client)" ] }, { "cell_type": "code", "execution_count": null, "id": "03782fa0-3224-4c2d-8355-b89d1b5f57c1", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ + "from dask.distributed import Client, LocalCluster\n", + "\n", "# Spin up cluster (if running in parallel)\n", - "client = None\n", + "# client = None\n", "if not serial:\n", " cluster = LocalCluster(**lc_kwargs)\n", " client = Client(cluster)\n", @@ -80,7 +128,15 @@ "cell_type": "code", "execution_count": null, "id": "d3f591cc-dd67-4a3f-abe7-bfc740743db1", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "# Read in two cases. The ADF timeseries are needed here.\n", @@ -97,14 +153,14 @@ " CESM_output_dir\n", " + \"/\"\n", " + case1\n", - " + \"/ts/\"\n", + " + \"/ice/proc/tseries/month_1/\"\n", " + case1\n", " + \".cice.h.\"\n", " + \"*.\"\n", " + cbegyr1\n", " + \"01-\"\n", " + cendyr1\n", - " + \"12.nc\",\n", + " + \"02.nc\",\n", " data_vars=\"minimal\",\n", " compat=\"override\",\n", " coords=\"minimal\",\n", @@ -113,7 +169,7 @@ " CESM_output_dir\n", " + \"/\"\n", " + case2\n", - " + \"/ts/\"\n", + " + \"/ice/proc/tseries/month_1/\"\n", " + case2\n", " + \".cice.h.\"\n", " + \"*.\"\n", @@ -126,9 +182,11 @@ " coords=\"minimal\",\n", ")\n", "\n", - "TLAT = ds1[\"TLAT\"]\n", - "TLON = ds1[\"TLON\"]\n", - "tarea = ds1[\"tarea\"]\n", + "ds_grid = xr.open_dataset(\"/glade/campaign/cesm/community/omwg/grids/tx2_3v2_grid.nc\")\n", + "TLAT = ds_grid[\"TLAT\"]\n", + "TLON = ds_grid[\"TLONG\"]\n", + "tarea = ds_grid[\"TAREA\"] * 1.0e-4\n", + "angle = ds_grid[\"ANGLE\"]\n", "\n", "# Make a DataArray with the number of days in each month, size = len(time)\n", "month_length = ds1.time.dt.days_in_month\n", @@ -165,7 +223,15 @@ "cell_type": "code", "execution_count": null, "id": "da24abe2-7b48-4c3d-b8a5-95847029bd74", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "from plot_diff import plot_diff\n", @@ -176,7 +242,15 @@ "cell_type": "code", "execution_count": null, "id": "28a0da20-6bad-45d7-a61a-43d55ea2acd2", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "for var in cice_vars:\n", @@ -193,7 +267,15 @@ "cell_type": "code", "execution_count": null, "id": "17591ebc-5360-479f-93bc-6ba8847df5c1", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "for var in cice_vars:\n", @@ -210,7 +292,15 @@ "cell_type": "code", "execution_count": null, "id": "ab1c8910-677e-4345-8f06-ec3f7a4a9f07", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "ds1_area = (tarea * ds1.aice).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", @@ -256,7 +346,15 @@ "cell_type": "code", "execution_count": null, "id": "cbf46c87-c3be-4a9e-90e8-e2a6633109e3", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "ds1_area_ann = (tarea * ds1_ann[\"aice\"]).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", @@ -301,7 +399,15 @@ { "cell_type": "markdown", "id": "dad0ad61-9566-4e49-8262-1516174fe322", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "source": [ "ds1_area.sel(time=ds1_area.time.dt.month.isin([10])).plot()\n", "ds2_area.sel(time=ds2_area.time.dt.month.isin([10])).plot()\n", @@ -316,7 +422,15 @@ "cell_type": "code", "execution_count": null, "id": "45366ccd-555b-49aa-93a2-51b83e802d16", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "ds1_area = (tarea * ds1.aice).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", @@ -335,7 +449,15 @@ "cell_type": "code", "execution_count": null, "id": "68400aca-aa0c-47f1-b7de-2c34dca5ac70", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "ds1_area_ann = (tarea * ds1_ann.aice).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", @@ -355,7 +477,13 @@ "execution_count": null, "id": "de2232e9-2705-4894-b98a-a93082ae7f79", "metadata": { - "tags": [] + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] }, "outputs": [], "source": [ @@ -421,16 +549,106 @@ "plt.plot(nsidc_clim)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "23ab7224-a908-4efd-9a79-45e50e2841b1", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "### Read in the SH NSIDC data from files\n", + "\n", + "path_nsidc = \"/glade/campaign/cesm/development/pcwg/ice/data/NSIDC_SeaIce_extent/\"\n", + "\n", + "jan_nsidc_sh = pd.read_csv(path_nsidc + \"S_01_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "feb_nsidc_sh = pd.read_csv(path_nsidc + \"S_02_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "mar_nsidc_sh = pd.read_csv(path_nsidc + \"S_03_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "apr_nsidc_sh = pd.read_csv(path_nsidc + \"S_04_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "may_nsidc_sh = pd.read_csv(path_nsidc + \"S_05_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "jun_nsidc_sh = pd.read_csv(path_nsidc + \"S_06_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "jul_nsidc_sh = pd.read_csv(path_nsidc + \"S_07_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "aug_nsidc_sh = pd.read_csv(path_nsidc + \"S_08_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "sep_nsidc_sh = pd.read_csv(path_nsidc + \"S_09_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "oct_nsidc_sh = pd.read_csv(path_nsidc + \"S_10_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "nov_nsidc_sh = pd.read_csv(path_nsidc + \"S_11_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "dec_nsidc_sh = pd.read_csv(path_nsidc + \"S_12_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "\n", + "jan_area_sh = jan_nsidc_sh.iloc[:, 5].values\n", + "feb_area_sh = feb_nsidc_sh.iloc[:, 5].values\n", + "mar_area_sh = mar_nsidc_sh.iloc[:, 5].values\n", + "apr_area_sh = apr_nsidc_sh.iloc[:, 5].values\n", + "may_area_sh = may_nsidc_sh.iloc[:, 5].values\n", + "jun_area_sh = jun_nsidc_sh.iloc[:, 5].values\n", + "jul_area_sh = jul_nsidc_sh.iloc[:, 5].values\n", + "aug_area_sh = aug_nsidc_sh.iloc[:, 5].values\n", + "sep_area_sh = sep_nsidc_sh.iloc[:, 5].values\n", + "oct_area_sh = oct_nsidc_sh.iloc[:, 5].values\n", + "nov_area_sh = nov_nsidc_sh.iloc[:, 5].values\n", + "dec_area_sh = dec_nsidc_sh.iloc[:, 5].values\n", + "\n", + "jan_ext_sh = jan_nsidc_sh.iloc[:, 4].values\n", + "feb_ext_sh = feb_nsidc_sh.iloc[:, 4].values\n", + "mar_ext_sh = mar_nsidc_sh.iloc[:, 4].values\n", + "apr_ext_sh = apr_nsidc_sh.iloc[:, 4].values\n", + "may_ext_sh = may_nsidc_sh.iloc[:, 4].values\n", + "jun_ext_sh = jun_nsidc_sh.iloc[:, 4].values\n", + "jul_ext_sh = jul_nsidc_sh.iloc[:, 4].values\n", + "aug_ext_sh = aug_nsidc_sh.iloc[:, 4].values\n", + "sep_ext_sh = sep_nsidc_sh.iloc[:, 4].values\n", + "oct_ext_sh = oct_nsidc_sh.iloc[:, 4].values\n", + "nov_ext_sh = nov_nsidc_sh.iloc[:, 4].values\n", + "dec_ext_sh = dec_nsidc_sh.iloc[:, 4].values\n", + "\n", + "print(dec_ext_sh)\n", + "nsidc_clim_sh = [\n", + " np.nanmean(jan_ext_sh[0:35]),\n", + " np.nanmean(feb_ext_sh[0:35]),\n", + " np.nanmean(mar_ext_sh[0:35]),\n", + " np.nanmean(apr_ext_sh[0:35]),\n", + " np.nanmean(may_ext_sh[0:35]),\n", + " np.nanmean(jun_ext_sh[0:35]),\n", + " np.nanmean(jul_ext_sh[0:35]),\n", + " np.nanmean(aug_ext_sh[0:35]),\n", + " np.nanmean(sep_ext_sh[0:35]),\n", + " np.nanmean(oct_ext_sh[0:35]),\n", + " np.nanmean(nov_ext_sh[0:35]),\n", + " np.nanmean(dec_ext_sh[0:35]),\n", + "]\n", + "\n", + "plt.plot(nsidc_clim_sh)" + ] + }, { "cell_type": "code", "execution_count": null, "id": "dcfc33a9-1dce-4dc7-95e3-dbdccee3575a", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ - "aice1_month = ds1[\"aice\"].groupby(\"time.month\").mean(dim=\"time\", skipna=True)\n", - "aice2_month = ds2[\"aice\"].groupby(\"time.month\").mean(dim=\"time\", skipna=True)\n", + "print(ds1[\"aice\"])\n", "\n", + "aice1_month = (\n", + " ds1[\"aice\"][1535:1955, :, :].groupby(\"time.month\").mean(dim=\"time\", skipna=True)\n", + ")\n", + "aice2_month = (\n", + " ds2[\"aice\"][923:1343, :, :].groupby(\"time.month\").mean(dim=\"time\", skipna=True)\n", + ")\n", "mask_tmp1 = np.where(np.logical_and(aice1_month > 0.15, ds1[\"TLAT\"] > 0), 1.0, 0.0)\n", "mask_tmp2 = np.where(np.logical_and(aice2_month > 0.15, ds1[\"TLAT\"] > 0), 1.0, 0.0)\n", "\n", @@ -451,11 +669,54 @@ "plt.legend([case1, case2, \"NSIDC\"])" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "bdcfc214-ab3c-4444-86ff-6cb9bea19236", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "mask_tmp1_sh = np.where(np.logical_and(aice1_month > 0.15, ds1[\"TLAT\"] < 0), 1.0, 0.0)\n", + "mask_tmp2_sh = np.where(np.logical_and(aice2_month > 0.15, ds1[\"TLAT\"] < 0), 1.0, 0.0)\n", + "\n", + "mask_ext1_sh = xr.DataArray(data=mask_tmp1_sh, dims=[\"month\", \"nj\", \"ni\"])\n", + "mask_ext2_sh = xr.DataArray(data=mask_tmp2_sh, dims=[\"month\", \"nj\", \"ni\"])\n", + "\n", + "\n", + "ext1_sh = (mask_ext1_sh * tarea).sum([\"ni\", \"nj\"]) * 1.0e-12\n", + "ext2_sh = (mask_ext2_sh * tarea).sum([\"ni\", \"nj\"]) * 1.0e-12\n", + "\n", + "plt.plot(ext1_sh)\n", + "plt.plot(ext2_sh)\n", + "plt.plot(nsidc_clim_sh)\n", + "\n", + "plt.ylim((0, 25))\n", + "plt.xlabel(\"Month\")\n", + "plt.ylabel(\"Climatological Seasonal Cycle Ice Extent $m x 10^{12}$\")\n", + "plt.legend([case1, case2, \"NSIDC\"])" + ] + }, { "cell_type": "code", "execution_count": null, "id": "00fc5097-af7d-4cf2-94ab-bb4e0a63960c", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "ds1_area = (tarea * ds1.aice).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", @@ -464,9 +725,51 @@ "ds1_sep = ds1_area.sel(time=(ds1_area.time.dt.month == 9))\n", "ds2_sep = ds2_area.sel(time=(ds2_area.time.dt.month == 9))\n", "\n", - "plt.plot(ds1_sep)\n", - "plt.plot(ds2_sep)\n", - "plt.plot(sep_area)\n", + "x1 = np.linspace(1850, 2012, 163)\n", + "x2 = np.linspace(1850, 2013, 164)\n", + "x3 = np.linspace(1979, 2014, 36)\n", + "\n", + "plt.plot(x1, ds1_sep)\n", + "plt.plot(x2, ds2_sep)\n", + "plt.plot(x3, sep_area[0:36])\n", + "\n", + "plt.ylim((0, 25))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"Sea Ice Area $mx10^{12}$\")\n", + "plt.legend([case1, case2, \"NSIDC\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f26a3f2-6a7c-4878-a352-f289a7efbd81", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "ds1_area_sh = (tarea * ds1.aice).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "ds2_area_sh = (tarea * ds2.aice).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "\n", + "ds1_feb_sh = ds1_area_sh.sel(time=(ds1_area_sh.time.dt.month == 2))\n", + "ds2_feb_sh = ds2_area_sh.sel(time=(ds2_area_sh.time.dt.month == 2))\n", + "\n", + "ds1_sep_sh = ds1_area_sh.sel(time=(ds1_area_sh.time.dt.month == 9))\n", + "ds2_sep_sh = ds2_area_sh.sel(time=(ds2_area_sh.time.dt.month == 9))\n", + "\n", + "x1 = np.linspace(1850, 2013, 163)\n", + "x2 = np.linspace(1850, 2014, 164)\n", + "x3 = np.linspace(1979, 2014, 36)\n", + "\n", + "plt.plot(x1, ds1_sep_sh)\n", + "plt.plot(x2, ds2_sep_sh)\n", + "plt.plot(x3, sep_area_sh[0:36])\n", "\n", "plt.ylim((0, 25))\n", "plt.xlabel(\"Year\")\n", @@ -478,14 +781,21 @@ "cell_type": "code", "execution_count": null, "id": "b9a9ad99-e580-4188-a328-950c84eb1b62", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "latm = cice_masks[\"Lab_lat\"]\n", "lonm = cice_masks[\"Lab_lon\"]\n", "\n", "lon = np.where(TLON < 0, TLON + 360.0, TLON)\n", - "\n", "mask1 = np.where(np.logical_and(TLAT > latm[0], TLAT < latm[1]), 1.0, 0.0)\n", "mask2 = np.where(np.logical_or(lon > lonm[0], lon < lonm[1]), 1.0, 0.0)\n", "mask = mask1 * mask2\n", @@ -506,17 +816,21 @@ "cell_type": "code", "execution_count": null, "id": "cfc18c63-fc78-45c3-a402-cfa57a6827cd", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "uvel1 = ds1_ann[\"uvel\"].isel(time=slice(-nyears, None)).mean(\"time\").squeeze()\n", "vvel1 = ds1_ann[\"vvel\"].isel(time=slice(-nyears, None)).mean(\"time\").squeeze()\n", "uvel2 = ds2_ann[\"uvel\"].isel(time=slice(-nyears, None)).mean(\"time\").squeeze()\n", "vvel2 = ds2_ann[\"vvel\"].isel(time=slice(-nyears, None)).mean(\"time\").squeeze()\n", - "ds_angle = xr.open_dataset(\n", - " \"/glade/campaign/cesm/development/cross-wg/diagnostic_framework/angle_tx2_3v2.nc\"\n", - ")\n", - "angle = ds_angle[\"ANGLE\"]\n", "\n", "vect_diff(uvel1, vvel1, uvel2, vvel2, angle, \"N\", case1, case2, TLAT, TLON)" ] @@ -525,7 +839,15 @@ "cell_type": "code", "execution_count": null, "id": "8116dbe6-6052-4d4e-8cf1-8a9feaf7d48e", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "vect_diff(uvel1, vvel1, uvel2, vvel2, angle, \"S\", case1, case2, TLAT, TLON)" @@ -542,9 +864,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python [conda env:cupid-analysis]", + "display_name": "NPL 2024a", "language": "python", - "name": "conda-env-cupid-analysis-py" + "name": "npl-2024a" }, "language_info": { "codemirror_mode": { @@ -556,7 +878,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.11.6" } }, "nbformat": 4, diff --git a/nblibrary/ice/Hemis_seaice_visual_compare_obs_lens.ipynb b/nblibrary/ice/Hemis_seaice_visual_compare_obs_lens.ipynb new file mode 100644 index 00000000..56cbefd4 --- /dev/null +++ b/nblibrary/ice/Hemis_seaice_visual_compare_obs_lens.ipynb @@ -0,0 +1,729 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "351f2902-54b0-463c-9d61-23574844481f", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "source": [ + "# Sea Ice Diagnostics for two CESM3 runs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7e7f10ae-61c8-45f1-9d5c-9be60632b556", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "import xarray as xr\n", + "import numpy as np\n", + "import yaml\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "270b0ff5-779c-4293-8d06-bd91eb8eee2b", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "parameters", + "hide-input" + ] + }, + "outputs": [], + "source": [ + "CESM_output_dir = \"/glade/campaign/cesm/development/cross-wg/diagnostic_framework/CESM_output_for_testing\"\n", + "serial = False # use dask LocalCluster\n", + "\n", + "case_name = \"b.e30_beta02.BLT1850.ne30_t232.104\"\n", + "base_case_name = \"b.e23_alpha17f.BLT1850.ne30_t232.092\"\n", + "\n", + "start_date = \"0001-01-01\"\n", + "end_date = \"0101-01-01\"\n", + "base_start_date = \"0001-01-01\"\n", + "base_end_date = \"0101-01-01\"\n", + "\n", + "climo_nyears = 35\n", + "\n", + "lc_kwargs = {}\n", + "\n", + "hist = 0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dfbdb3ea-b818-44be-aafa-1dd9be54715d", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "cupid_run = 1\n", + "\n", + "if cupid_run == 1:\n", + "\n", + " from dask.distributed import Client, LocalCluster\n", + "\n", + " # Spin up cluster (if running in parallel)\n", + " # client = None\n", + " if not serial:\n", + " cluster = LocalCluster(**lc_kwargs)\n", + " client = Client(cluster)\n", + "\n", + " client\n", + "\n", + "else:\n", + "\n", + " from dask.distributed import Client\n", + " from dask_jobqueue import PBSCluster\n", + "\n", + " cluster = PBSCluster(\n", + " cores=16,\n", + " processes=16,\n", + " memory=\"100GB\",\n", + " account=\"P93300065\",\n", + " queue=\"casper\",\n", + " walltime=\"02:00:00\",\n", + " )\n", + "\n", + " client = Client(cluster)\n", + "\n", + " cluster.scale(1)\n", + "\n", + " print(cluster)\n", + " print(client)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d3f591cc-dd67-4a3f-abe7-bfc740743db1", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "# Read in two cases. The ADF timeseries are needed here.\n", + "\n", + "ds1 = xr.open_mfdataset(\n", + " CESM_output_dir\n", + " + \"/\"\n", + " + case_name\n", + " + \"/ice/proc/tseries/month_1/\"\n", + " + case_name\n", + " + \".cice.h.\"\n", + " + \"*.nc\",\n", + " data_vars=\"minimal\",\n", + " compat=\"override\",\n", + " coords=\"minimal\",\n", + ").sel(time=slice(start_date, end_date))\n", + "ds2 = xr.open_mfdataset(\n", + " CESM_output_dir\n", + " + \"/\"\n", + " + base_case_name\n", + " + \"/ice/proc/tseries/month_1/\"\n", + " + base_case_name\n", + " + \".cice.h.\"\n", + " + \"*.nc\",\n", + " data_vars=\"minimal\",\n", + " compat=\"override\",\n", + " coords=\"minimal\",\n", + ").sel(time=slice(base_start_date, base_end_date))\n", + "\n", + "ds_grid = xr.open_dataset(\"/glade/campaign/cesm/community/omwg/grids/tx2_3v2_grid.nc\")\n", + "TLAT = ds_grid[\"TLAT\"]\n", + "TLON = ds_grid[\"TLONG\"]\n", + "tarea = ds_grid[\"TAREA\"] * 1.0e-4\n", + "angle = ds_grid[\"ANGLE\"]\n", + "\n", + "ds1_ann = ds1.resample(time=\"YS\").mean(dim=\"time\")\n", + "ds2_ann = ds2.resample(time=\"YS\").mean(dim=\"time\")\n", + "\n", + "with open(\"cice_masks.yml\", \"r\") as file:\n", + " cice_masks = yaml.safe_load(file)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "173299ea-d64e-48ad-aa9a-40663dd5c7e9", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "### Read in the CESM1 and CESM2 LE sea ice area\n", + "\n", + "# cesm1_path = \"/glade/campaign/cesm/collections/cesmLE/CESM-CAM5-BGC-LE/ice/proc/tseries/monthly/aice/\"\n", + "\n", + "# ds_cesm1_nh = xr.open_dataset(cesm1_path + \"b.e11.B1850C5CN.f09_g16.005.cice.h.aice_nh.210001-220012.nc\")\n", + "# ds_cesm1_sh = xr.open_dataset(cesm1_path + \"b.e11.B1850C5CN.f09_g16.005.cice.h.aice_sh.210001-220012.nc\")\n", + "\n", + "# cesm2_path = \"/glade/campaign/collections/cmip/CMIP6/timeseries-cmip6/b.e21.B1850.f09_g17.CMIP6-piControl.001/ice/proc/tseries/month_1/\"\n", + "# cesm2_ds = xr.open_dataset(cesm2_path + \"b.e21.B1850.f09_g17.CMIP6-piControl.001.cice.h.aice.190001-200012.nc\")\n", + "\n", + "# nj_nh = ds_cesm1_nh['nj']\n", + "# nj_sh = ds_cesm2_sh['nh']\n", + "\n", + "# aice_cesm1 = cesm2_ds['aice']\n", + "\n", + "# aice_cesm1 = 0.0\n", + "# aice_cesm1[:,0:nj_sh-1,:] = ds_cesm1_sh['aice']\n", + "# aice_cesm1[:,383-nj_nh:383,:] = ds_cesm1_nh['aice']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cbf46c87-c3be-4a9e-90e8-e2a6633109e3", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "ds1_area_ann = (tarea * ds1_ann[\"aice\"]).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "ds2_area_ann = (tarea * ds2_ann[\"aice\"]).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "\n", + "ds1_vhi_ann = (tarea * ds1_ann[\"hi\"]).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-13\n", + "ds2_vhi_ann = (tarea * ds2_ann[\"hi\"]).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-13\n", + "\n", + "ds1_vhs_ann = (tarea * ds1_ann[\"hs\"]).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-13\n", + "ds2_vhs_ann = (tarea * ds2_ann[\"hs\"]).where(TLAT > 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-13\n", + "\n", + "fig = plt.figure(figsize=(10, 10), tight_layout=True)\n", + "\n", + "ax = fig.add_subplot(3, 1, 1)\n", + "ds1_vhi_ann.plot()\n", + "ds2_vhi_ann.plot()\n", + "\n", + "plt.title(\"NH Annual Mean Integrated Timeseries\")\n", + "plt.ylim((0, 5))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"NH Annual Mean Sea Ice Volume $m x 10^{13}$\")\n", + "plt.legend([case_name, base_case_name])\n", + "\n", + "ax = fig.add_subplot(3, 1, 2)\n", + "ds1_vhs_ann.plot()\n", + "ds2_vhs_ann.plot()\n", + "\n", + "plt.ylim((0, 0.5))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"NH Annual Mean Snow Volume $m x 10^{13}$\")\n", + "plt.legend([case_name, base_case_name])\n", + "\n", + "ax = fig.add_subplot(3, 1, 3)\n", + "ds1_area_ann.plot()\n", + "ds2_area_ann.plot()\n", + "\n", + "plt.ylim((0, 25))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"NH Annual Mean Sea Ice Area $m x 10^{12}$\")\n", + "plt.legend([case_name, base_case_name])" + ] + }, + { + "cell_type": "markdown", + "id": "dad0ad61-9566-4e49-8262-1516174fe322", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "source": [ + "ds1_area.sel(time=ds1_area.time.dt.month.isin([10])).plot()\n", + "ds2_area.sel(time=ds2_area.time.dt.month.isin([10])).plot()\n", + "\n", + "plt.ylim((0,25))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"NH September Sea Ice Area $m x 10^{12}$\")\n", + "plt.legend([case_name,base_case_name])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "45366ccd-555b-49aa-93a2-51b83e802d16", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "ds1_area_ann = (tarea * ds1_ann[\"aice\"]).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "ds2_area_ann = (tarea * ds2_ann[\"aice\"]).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "\n", + "ds1_vhi_ann = (tarea * ds1_ann[\"hi\"]).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-13\n", + "ds2_vhi_ann = (tarea * ds2_ann[\"hi\"]).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-13\n", + "\n", + "ds1_vhs_ann = (tarea * ds1_ann[\"hs\"]).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-13\n", + "ds2_vhs_ann = (tarea * ds2_ann[\"hs\"]).where(TLAT < 0).sum(dim=[\"nj\", \"ni\"]) * 1.0e-13\n", + "\n", + "fig = plt.figure(figsize=(10, 10), tight_layout=True)\n", + "\n", + "ax = fig.add_subplot(3, 1, 1)\n", + "ds1_vhi_ann.plot()\n", + "ds2_vhi_ann.plot()\n", + "\n", + "plt.title(\"SH Annual Mean Integrated Timeseries\")\n", + "plt.ylim((0, 5))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"SH Annual Mean Sea Ice Volume $m x 10^{13}$\")\n", + "plt.legend([case_name, base_case_name])\n", + "\n", + "ax = fig.add_subplot(3, 1, 2)\n", + "ds1_vhs_ann.plot()\n", + "ds2_vhs_ann.plot()\n", + "\n", + "plt.ylim((0, 0.5))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"SH Annual Mean Snow Volume $m x 10^{13}$\")\n", + "plt.legend([case_name, base_case_name])\n", + "\n", + "ax = fig.add_subplot(3, 1, 3)\n", + "ds1_area_ann.plot()\n", + "ds2_area_ann.plot()\n", + "\n", + "plt.ylim((0, 25))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"SH Annual Mean Sea Ice Area $m x 10^{12}$\")\n", + "plt.legend([case_name, base_case_name])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "de2232e9-2705-4894-b98a-a93082ae7f79", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "### Read in the NSIDC data from files\n", + "\n", + "path_nsidc = \"/glade/campaign/cesm/development/pcwg/ice/data/NSIDC_SeaIce_extent/\"\n", + "\n", + "jan_nsidc = pd.read_csv(path_nsidc + \"N_01_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "feb_nsidc = pd.read_csv(path_nsidc + \"N_02_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "mar_nsidc = pd.read_csv(path_nsidc + \"N_03_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "apr_nsidc = pd.read_csv(path_nsidc + \"N_04_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "may_nsidc = pd.read_csv(path_nsidc + \"N_05_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "jun_nsidc = pd.read_csv(path_nsidc + \"N_06_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "jul_nsidc = pd.read_csv(path_nsidc + \"N_07_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "aug_nsidc = pd.read_csv(path_nsidc + \"N_08_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "sep_nsidc = pd.read_csv(path_nsidc + \"N_09_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "oct_nsidc = pd.read_csv(path_nsidc + \"N_10_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "nov_nsidc = pd.read_csv(path_nsidc + \"N_11_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "dec_nsidc = pd.read_csv(path_nsidc + \"N_12_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "\n", + "jan_area = jan_nsidc.iloc[:, 5].values\n", + "feb_area = feb_nsidc.iloc[:, 5].values\n", + "mar_area = mar_nsidc.iloc[:, 5].values\n", + "apr_area = apr_nsidc.iloc[:, 5].values\n", + "may_area = may_nsidc.iloc[:, 5].values\n", + "jun_area = jun_nsidc.iloc[:, 5].values\n", + "jul_area = jul_nsidc.iloc[:, 5].values\n", + "aug_area = aug_nsidc.iloc[:, 5].values\n", + "sep_area = sep_nsidc.iloc[:, 5].values\n", + "oct_area = oct_nsidc.iloc[:, 5].values\n", + "nov_area = nov_nsidc.iloc[:, 5].values\n", + "dec_area = dec_nsidc.iloc[:, 5].values\n", + "\n", + "jan_ext = jan_nsidc.iloc[:, 4].values\n", + "feb_ext = feb_nsidc.iloc[:, 4].values\n", + "mar_ext = mar_nsidc.iloc[:, 4].values\n", + "apr_ext = apr_nsidc.iloc[:, 4].values\n", + "may_ext = may_nsidc.iloc[:, 4].values\n", + "jun_ext = jun_nsidc.iloc[:, 4].values\n", + "jul_ext = jul_nsidc.iloc[:, 4].values\n", + "aug_ext = aug_nsidc.iloc[:, 4].values\n", + "sep_ext = sep_nsidc.iloc[:, 4].values\n", + "oct_ext = oct_nsidc.iloc[:, 4].values\n", + "nov_ext = nov_nsidc.iloc[:, 4].values\n", + "dec_ext = dec_nsidc.iloc[:, 4].values\n", + "\n", + "nsidc_clim = [\n", + " np.nanmean(jan_ext[0:35]),\n", + " np.nanmean(feb_ext[0:35]),\n", + " np.nanmean(mar_ext[0:35]),\n", + " np.nanmean(apr_ext[0:35]),\n", + " np.nanmean(may_ext[0:35]),\n", + " np.nanmean(jun_ext[0:35]),\n", + " np.nanmean(jul_ext[0:35]),\n", + " np.nanmean(aug_ext[0:35]),\n", + " np.nanmean(sep_ext[0:35]),\n", + " np.nanmean(oct_ext[0:35]),\n", + " np.nanmean(nov_ext[0:35]),\n", + " np.nanmean(dec_ext[0:35]),\n", + "]\n", + "\n", + "# plt.plot(nsidc_clim)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23ab7224-a908-4efd-9a79-45e50e2841b1", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "### Read in the SH NSIDC data from files\n", + "\n", + "path_nsidc = \"/glade/campaign/cesm/development/pcwg/ice/data/NSIDC_SeaIce_extent/\"\n", + "\n", + "jan_nsidc_sh = pd.read_csv(path_nsidc + \"S_01_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "feb_nsidc_sh = pd.read_csv(path_nsidc + \"S_02_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "mar_nsidc_sh = pd.read_csv(path_nsidc + \"S_03_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "apr_nsidc_sh = pd.read_csv(path_nsidc + \"S_04_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "may_nsidc_sh = pd.read_csv(path_nsidc + \"S_05_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "jun_nsidc_sh = pd.read_csv(path_nsidc + \"S_06_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "jul_nsidc_sh = pd.read_csv(path_nsidc + \"S_07_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "aug_nsidc_sh = pd.read_csv(path_nsidc + \"S_08_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "sep_nsidc_sh = pd.read_csv(path_nsidc + \"S_09_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "oct_nsidc_sh = pd.read_csv(path_nsidc + \"S_10_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "nov_nsidc_sh = pd.read_csv(path_nsidc + \"S_11_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "dec_nsidc_sh = pd.read_csv(path_nsidc + \"S_12_extent_v3.0.csv\", na_values=[\"-99.9\"])\n", + "\n", + "jan_area_sh = jan_nsidc_sh.iloc[:, 5].values\n", + "feb_area_sh = feb_nsidc_sh.iloc[:, 5].values\n", + "mar_area_sh = mar_nsidc_sh.iloc[:, 5].values\n", + "apr_area_sh = apr_nsidc_sh.iloc[:, 5].values\n", + "may_area_sh = may_nsidc_sh.iloc[:, 5].values\n", + "jun_area_sh = jun_nsidc_sh.iloc[:, 5].values\n", + "jul_area_sh = jul_nsidc_sh.iloc[:, 5].values\n", + "aug_area_sh = aug_nsidc_sh.iloc[:, 5].values\n", + "sep_area_sh = sep_nsidc_sh.iloc[:, 5].values\n", + "oct_area_sh = oct_nsidc_sh.iloc[:, 5].values\n", + "nov_area_sh = nov_nsidc_sh.iloc[:, 5].values\n", + "dec_area_sh = dec_nsidc_sh.iloc[:, 5].values\n", + "\n", + "jan_ext_sh = jan_nsidc_sh.iloc[:, 4].values\n", + "feb_ext_sh = feb_nsidc_sh.iloc[:, 4].values\n", + "mar_ext_sh = mar_nsidc_sh.iloc[:, 4].values\n", + "apr_ext_sh = apr_nsidc_sh.iloc[:, 4].values\n", + "may_ext_sh = may_nsidc_sh.iloc[:, 4].values\n", + "jun_ext_sh = jun_nsidc_sh.iloc[:, 4].values\n", + "jul_ext_sh = jul_nsidc_sh.iloc[:, 4].values\n", + "aug_ext_sh = aug_nsidc_sh.iloc[:, 4].values\n", + "sep_ext_sh = sep_nsidc_sh.iloc[:, 4].values\n", + "oct_ext_sh = oct_nsidc_sh.iloc[:, 4].values\n", + "nov_ext_sh = nov_nsidc_sh.iloc[:, 4].values\n", + "dec_ext_sh = dec_nsidc_sh.iloc[:, 4].values\n", + "\n", + "nsidc_clim_sh = [\n", + " np.nanmean(jan_ext_sh[0:35]),\n", + " np.nanmean(feb_ext_sh[0:35]),\n", + " np.nanmean(mar_ext_sh[0:35]),\n", + " np.nanmean(apr_ext_sh[0:35]),\n", + " np.nanmean(may_ext_sh[0:35]),\n", + " np.nanmean(jun_ext_sh[0:35]),\n", + " np.nanmean(jul_ext_sh[0:35]),\n", + " np.nanmean(aug_ext_sh[0:35]),\n", + " np.nanmean(sep_ext_sh[0:35]),\n", + " np.nanmean(oct_ext_sh[0:35]),\n", + " np.nanmean(nov_ext_sh[0:35]),\n", + " np.nanmean(dec_ext_sh[0:35]),\n", + "]\n", + "\n", + "# plt.plot(nsidc_clim_sh)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dcfc33a9-1dce-4dc7-95e3-dbdccee3575a", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "aice1_month = (\n", + " ds1[\"aice\"]\n", + " .isel(time=slice(-climo_nyears, None))\n", + " .groupby(\"time.month\")\n", + " .mean(dim=\"time\", skipna=True)\n", + ")\n", + "aice2_month = (\n", + " ds2[\"aice\"]\n", + " .isel(time=slice(-climo_nyears, None))\n", + " .groupby(\"time.month\")\n", + " .mean(dim=\"time\", skipna=True)\n", + ")\n", + "mask_tmp1 = np.where(np.logical_and(aice1_month > 0.15, ds1[\"TLAT\"] > 0), 1.0, 0.0)\n", + "mask_tmp2 = np.where(np.logical_and(aice2_month > 0.15, ds1[\"TLAT\"] > 0), 1.0, 0.0)\n", + "\n", + "mask_ext1 = xr.DataArray(data=mask_tmp1, dims=[\"month\", \"nj\", \"ni\"])\n", + "mask_ext2 = xr.DataArray(data=mask_tmp2, dims=[\"month\", \"nj\", \"ni\"])\n", + "\n", + "\n", + "ext1 = (mask_ext1 * tarea).sum([\"ni\", \"nj\"]) * 1.0e-12\n", + "ext2 = (mask_ext2 * tarea).sum([\"ni\", \"nj\"]) * 1.0e-12\n", + "\n", + "plt.plot(ext1)\n", + "plt.plot(ext2)\n", + "plt.plot(nsidc_clim)\n", + "\n", + "plt.title(\"NH Climatological Seasonal Cycle\")\n", + "plt.ylim((0, 25))\n", + "plt.xlabel(\"Month\")\n", + "plt.ylabel(\"Climatological Seasonal Cycle Ice Extent $m x 10^{12}$\")\n", + "plt.legend([case_name, base_case_name, \"NSIDC\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bdcfc214-ab3c-4444-86ff-6cb9bea19236", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "mask_tmp1_sh = np.where(np.logical_and(aice1_month > 0.15, ds1[\"TLAT\"] < 0), 1.0, 0.0)\n", + "mask_tmp2_sh = np.where(np.logical_and(aice2_month > 0.15, ds1[\"TLAT\"] < 0), 1.0, 0.0)\n", + "\n", + "mask_ext1_sh = xr.DataArray(data=mask_tmp1_sh, dims=[\"month\", \"nj\", \"ni\"])\n", + "mask_ext2_sh = xr.DataArray(data=mask_tmp2_sh, dims=[\"month\", \"nj\", \"ni\"])\n", + "\n", + "\n", + "ext1_sh = (mask_ext1_sh * tarea).sum([\"ni\", \"nj\"]) * 1.0e-12\n", + "ext2_sh = (mask_ext2_sh * tarea).sum([\"ni\", \"nj\"]) * 1.0e-12\n", + "\n", + "plt.plot(ext1_sh)\n", + "plt.plot(ext2_sh)\n", + "plt.plot(nsidc_clim_sh)\n", + "\n", + "plt.title(\"NH Climatological Seasonal Cycle\")\n", + "plt.ylim((0, 25))\n", + "plt.xlabel(\"Month\")\n", + "plt.ylabel(\"Climatological Seasonal Cycle Ice Extent $m x 10^{12}$\")\n", + "plt.legend([case_name, base_case_name, \"NSIDC\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00fc5097-af7d-4cf2-94ab-bb4e0a63960c", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "ds1_area = (tarea * ds1.aice).isel(time=slice(-climo_nyears * 12, None)).where(\n", + " TLAT > 0\n", + ").sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "ds2_area = (tarea * ds2.aice).isel(time=slice(-climo_nyears * 12, None)).where(\n", + " TLAT > 0\n", + ").sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "\n", + "ds1_sep = ds1_area.sel(time=(ds1_area.time.dt.month == 9))\n", + "ds2_sep = ds2_area.sel(time=(ds2_area.time.dt.month == 9))\n", + "\n", + "if hist == 0:\n", + " x1 = np.linspace(1, climo_nyears, climo_nyears)\n", + " x2 = np.linspace(1, climo_nyears, climo_nyears)\n", + " x3 = np.linspace(1, 36, 36)\n", + "else:\n", + " x1 = np.linspace(1, climo_nyears, climo_nyears)\n", + " x2 = np.linspace(1, climo_nyears, climo_nyears)\n", + " x3 = np.linspace(1, 36, 36)\n", + "plt.plot(x1, ds1_sep)\n", + "plt.plot(x2, ds2_sep)\n", + "plt.plot(x3, sep_area[0:36])\n", + "\n", + "plt.title(\"NH Annual Mean Sea Ice Area\")\n", + "plt.ylim((0, 25))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"Sea Ice Area $mx10^{12}$\")\n", + "plt.legend([case_name, base_case_name, \"NSIDC\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f26a3f2-6a7c-4878-a352-f289a7efbd81", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "ds1_area_sh = (tarea * ds1.aice).isel(time=slice(-climo_nyears * 12, None)).where(\n", + " TLAT < 0\n", + ").sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "ds2_area_sh = (tarea * ds2.aice).isel(time=slice(-climo_nyears * 12, None)).where(\n", + " TLAT < 0\n", + ").sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "\n", + "ds1_feb_sh = ds1_area_sh.sel(time=(ds1_area_sh.time.dt.month == 2))\n", + "ds2_feb_sh = ds2_area_sh.sel(time=(ds2_area_sh.time.dt.month == 2))\n", + "\n", + "ds1_sep_sh = ds1_area_sh.sel(time=(ds1_area_sh.time.dt.month == 9))\n", + "ds2_sep_sh = ds2_area_sh.sel(time=(ds2_area_sh.time.dt.month == 9))\n", + "\n", + "x1 = np.linspace(1, climo_nyears, climo_nyears)\n", + "x2 = np.linspace(1, climo_nyears, climo_nyears)\n", + "x3 = np.linspace(1, 36, 36)\n", + "\n", + "plt.plot(x1, ds1_sep_sh)\n", + "plt.plot(x2, ds2_sep_sh)\n", + "plt.plot(x3, sep_area_sh[0:36])\n", + "\n", + "plt.title(\"SH Annual Mean Sea Ice Area\")\n", + "plt.ylim((0, 25))\n", + "plt.xlabel(\"Year\")\n", + "plt.ylabel(\"Sea Ice Area $mx10^{12}$\")\n", + "plt.legend([case_name, base_case_name, \"NSIDC\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b9a9ad99-e580-4188-a328-950c84eb1b62", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "hide-input" + ] + }, + "outputs": [], + "source": [ + "latm = cice_masks[\"Lab_lat\"]\n", + "lonm = cice_masks[\"Lab_lon\"]\n", + "\n", + "lon = np.where(TLON < 0, TLON + 360.0, TLON)\n", + "mask1 = np.where(np.logical_and(TLAT > latm[0], TLAT < latm[1]), 1.0, 0.0)\n", + "mask2 = np.where(np.logical_or(lon > lonm[0], lon < lonm[1]), 1.0, 0.0)\n", + "mask = mask1 * mask2\n", + "\n", + "ds1_lab = (mask * tarea * ds1.aice).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "ds2_lab = (mask * tarea * ds2.aice).sum(dim=[\"nj\", \"ni\"]) * 1.0e-12\n", + "\n", + "ds1_lab.plot()\n", + "ds2_lab.plot()\n", + "\n", + "plt.title(\"Labrador Sea Montly Mean Sea Ice Area\")\n", + "plt.ylim((0, 10))\n", + "plt.xlabel(\"Month\")\n", + "plt.ylabel(\"Labrador Sea Ice Area $m x 10^{12}$\")\n", + "plt.legend([case_name, base_case_name])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:cupid-analysis]", + "language": "python", + "name": "conda-env-cupid-analysis-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/nblibrary/ice/cice_vars.yml b/nblibrary/ice/cice_vars.yml index 5c5de2da..5af3b8ee 100644 --- a/nblibrary/ice/cice_vars.yml +++ b/nblibrary/ice/cice_vars.yml @@ -9,45 +9,3 @@ hi: hs: - levels: [0.01,0.03,0.05,0.07,0.10,0.13,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50] - title: "Snow Depth (m)" -Tsfc: - - levels: [-40.,-37.,-34.,-31.,-28.,-25.,-22.,-19.,-16.,-13.,-10.,-5.,-3.,-1.] - - title: "Surface Temperature (C)" -albsni: - - levels: [5,10,15,20,30,40,50, 60, 65, 70, 75, 80,85, 90] - - title: "Snow Ice Albedo" -flat: - - levels: [-18.,-16.,-14.,-12.,-10.,-8.,-6.,-5.,-4.,-3.,-2.,-1.,0.,2.] - - title: "Latent Heat Flux (W/m^2}" -fsens: - - levels: [-30.,-25.,-20.,-15.,-10.,-5.,-2.5,0,2.5,5,10,15,20,25] - - title: "Sensible Heat Flux (W/m^2)" -congel: - - levels: [0, 0.5, 1 ,1.5 ,2 ,2.5,3,4,5,6,7,8,9,10] - - title: "Congelation growth (cm/day)" -frazil: - - levels: [0.0,0.02,0.04,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20,0.22,0.24,0.26] - - title: "Frazil growth (cm/day)" -snoice: - - levels: [0.0,0.01,0.02,0.03,0.04,0.05,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20] - - title: "Snow-ice growth (cm/day)" -meltb: - - levels: [0.05,0.1,0.25,0.5,0.75,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0] - - title: "Bottom Melt (cm/day)" -meltt: - - levels: [0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3] - - title: "Top Melt (cm/day)" -meltl: - - levels: [0.01,0.04,0.08,0.12,0.16,0.2,0.24,0.28,0.32,0.36,0.4,0.44,0.48,0.52] - - title: "Lateral Melt (cm/day)" -dvidtt: - - levels: [-3.6,-3.0,-2.4,-1.8,-1.2,-0.6,0.0,0.6,1.2,1.8,2.4,3.0,3.6,4.0] - - title: "Volume tendency due to thermodynamics (cm/day)" -dvidtd: - - levels: [-3.6,-3.0,-2.4,-1.8,-1.2,-0.6,0.0,0.6,1.2,1.8,2.4,3.0,3.6,4.0] - - title: "Volume tendency due to dynamics (cm/day)" -daidtt: - - levels: [-3.6,-3.0,-2.4,-1.8,-1.2,-0.6,0.0,0.6,1.2,1.8,2.4,3.0,3.6,4.0] - - title: "Area tendency due to thermodynamics (%/day)" -daidtd: - - levels: [-3.6,-3.0,-2.4,-1.8,-1.2,-0.6,0.0,0.6,1.2,1.8,2.4,3.0,3.6,4.0] - - title: "Area tendency due to dynamics (%/day)" diff --git a/nblibrary/ice/cice_vars_full.yml b/nblibrary/ice/cice_vars_full.yml new file mode 100644 index 00000000..5c5de2da --- /dev/null +++ b/nblibrary/ice/cice_vars_full.yml @@ -0,0 +1,53 @@ +--- + +aice: + - levels: [0.05,0.10,0.15,0.20,0.30,0.40,0.50,0.60,0.70,0.80,0.85,0.90,0.95,0.99] + - title: "Sea Ice Concentration" +hi: + - levels: [0.05,0.1,0.25,0.5,0.75,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0] + - title: "Sea Ice Thickness (m)" +hs: + - levels: [0.01,0.03,0.05,0.07,0.10,0.13,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50] + - title: "Snow Depth (m)" +Tsfc: + - levels: [-40.,-37.,-34.,-31.,-28.,-25.,-22.,-19.,-16.,-13.,-10.,-5.,-3.,-1.] + - title: "Surface Temperature (C)" +albsni: + - levels: [5,10,15,20,30,40,50, 60, 65, 70, 75, 80,85, 90] + - title: "Snow Ice Albedo" +flat: + - levels: [-18.,-16.,-14.,-12.,-10.,-8.,-6.,-5.,-4.,-3.,-2.,-1.,0.,2.] + - title: "Latent Heat Flux (W/m^2}" +fsens: + - levels: [-30.,-25.,-20.,-15.,-10.,-5.,-2.5,0,2.5,5,10,15,20,25] + - title: "Sensible Heat Flux (W/m^2)" +congel: + - levels: [0, 0.5, 1 ,1.5 ,2 ,2.5,3,4,5,6,7,8,9,10] + - title: "Congelation growth (cm/day)" +frazil: + - levels: [0.0,0.02,0.04,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20,0.22,0.24,0.26] + - title: "Frazil growth (cm/day)" +snoice: + - levels: [0.0,0.01,0.02,0.03,0.04,0.05,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20] + - title: "Snow-ice growth (cm/day)" +meltb: + - levels: [0.05,0.1,0.25,0.5,0.75,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0] + - title: "Bottom Melt (cm/day)" +meltt: + - levels: [0.05,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3] + - title: "Top Melt (cm/day)" +meltl: + - levels: [0.01,0.04,0.08,0.12,0.16,0.2,0.24,0.28,0.32,0.36,0.4,0.44,0.48,0.52] + - title: "Lateral Melt (cm/day)" +dvidtt: + - levels: [-3.6,-3.0,-2.4,-1.8,-1.2,-0.6,0.0,0.6,1.2,1.8,2.4,3.0,3.6,4.0] + - title: "Volume tendency due to thermodynamics (cm/day)" +dvidtd: + - levels: [-3.6,-3.0,-2.4,-1.8,-1.2,-0.6,0.0,0.6,1.2,1.8,2.4,3.0,3.6,4.0] + - title: "Volume tendency due to dynamics (cm/day)" +daidtt: + - levels: [-3.6,-3.0,-2.4,-1.8,-1.2,-0.6,0.0,0.6,1.2,1.8,2.4,3.0,3.6,4.0] + - title: "Area tendency due to thermodynamics (%/day)" +daidtd: + - levels: [-3.6,-3.0,-2.4,-1.8,-1.2,-0.6,0.0,0.6,1.2,1.8,2.4,3.0,3.6,4.0] + - title: "Area tendency due to dynamics (%/day)" diff --git a/nblibrary/ice/plot_diff.py b/nblibrary/ice/plot_diff.py index d6395dec..fa5dd87e 100644 --- a/nblibrary/ice/plot_diff.py +++ b/nblibrary/ice/plot_diff.py @@ -17,7 +17,7 @@ def plot_diff(field1, field2, levels, case1, case2, title, proj, TLAT, TLON): circle = mpath.Path(verts * radius + center) if np.size(levels) > 2: - cmap = mpl.colormaps["tab20"] + cmap = mpl.colormaps["ocean"] norm = mpl.colors.BoundaryNorm(levels, ncolors=cmap.N) # set up the figure with a North Polar Stereographic projection @@ -44,7 +44,7 @@ def plot_diff(field1, field2, levels, case1, case2, title, proj, TLAT, TLON): TLAT, field1, norm=norm, - cmap="tab20", + cmap="ocean", transform=ccrs.PlateCarree(), ) plt.colorbar(this, orientation="vertical", fraction=0.04, pad=0.01) @@ -67,7 +67,7 @@ def plot_diff(field1, field2, levels, case1, case2, title, proj, TLAT, TLON): TLAT, field2, norm=norm, - cmap="tab20", + cmap="ocean", transform=ccrs.PlateCarree(), ) plt.colorbar(this, orientation="vertical", fraction=0.04, pad=0.01) diff --git a/nblibrary/ice/vect_diff.py b/nblibrary/ice/vect_diff.py index 80ca09e3..a47016dc 100644 --- a/nblibrary/ice/vect_diff.py +++ b/nblibrary/ice/vect_diff.py @@ -49,7 +49,7 @@ def vect_diff(uvel1, vvel1, uvel2, vvel2, angle, proj, case1, case2, TLAT, TLON) speed1, vmin=0.0, vmax=0.5, - cmap="tab20", + cmap="ocean", transform=ccrs.PlateCarree(), ) plt.colorbar(this, orientation="vertical", fraction=0.04, pad=0.01) @@ -97,7 +97,7 @@ def vect_diff(uvel1, vvel1, uvel2, vvel2, angle, proj, case1, case2, TLAT, TLON) speed2, vmin=0.0, vmax=0.5, - cmap="tab20", + cmap="ocean", transform=ccrs.PlateCarree(), ) plt.colorbar(this, orientation="vertical", fraction=0.04, pad=0.01)