# Parameters
variable = "ficeberg"
long_name = "Water Flux into Seawater from Icebergs"

ficeberg#

from IPython.display import display, Markdown
# Dynamically generate markdown content
markdown_text = f" This notebook compares area-weighted mean and, in some cases, integral time series for {variable} in different basins."

# Display the updated markdown content
display(Markdown(markdown_text))

This notebook compares area-weighted mean and, in some cases, integral time series for ficeberg in different basins.

%load_ext autoreload
%autoreload 2
%%capture 
# comment above line to see details about the run(s) displayed
import sys, os
sys.path.append(os.path.abspath(".."))
from misc import *
import glob
print("Last update:", date.today())
%matplotlib inline
# figure size
fs = (10,4)
# load data
ds = []
for c, p in zip(casename, ocn_path):
  file = glob.glob(p+'{}.native.{}.??????-??????.nc'.format(c, variable))[0]
  ds.append(xr.open_dataset(file))
The history saving thread hit an unexpected error (OperationalError('attempt to write a readonly database')).History will not be written to the database.
def ts_plot(variable, ds, fs, label, reg='Global'):
    """
    Plot time series of regional means and integrals for a given variable from a list of datasets.

    Parameters
    ----------
    variable : str
        Name of the variable to plot (prefix for "_mean" and "_int" variables in dataset).
    ds : list of xarray.Dataset
        List of datasets, each containing time series data for the specified variable with
        variables named as `<variable>_mean` and optionally `<variable>_int`, and with
        attributes 'long_name', 'units_mean', and optionally 'units_int'.
    fs : tuple
        Figure size (width, height) in inches for the plots.
    label : list of str
        List of labels corresponding to each dataset, used for the legend.
    reg : str, optional
        Name of the region to select for plotting (default is 'Global').

    Returns
    -------
    None
        Displays the plots but does not return any value.

    Notes
    -----
    - This function creates one or two plots:
        1. A time series of the variable's regional mean (`<variable>_mean`).
        2. If available, a time series of the variable's regional integral (`<variable>_int`).
    - The function expects each dataset to have attributes 'long_name', 'units_mean', and optionally 'units_int'.
    - The same region name is applied across all datasets.
    """
    
    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=fs)
    for l, i in zip(label, range(len(label))):
        ds[i][variable+"_mean"].sel(region=reg).plot(ax=ax, label=l, lw=3, linestyle=linestyle[i], color=color[i])
    
    long_name = ds[0].attrs['long_name']
    ax.set_title("{}, {}".format(reg, long_name))
    ax.set_ylabel(variable+"_mean, " + ds[i].attrs['units_mean'])
    ax.set_xlabel('Year')
    ax.grid()
    ax.legend(ncol=3, loc=1)
    
    if variable+"_int" in ds[0]:
        fig, ax = plt.subplots(nrows=1, ncols=1, figsize=fs)
        for l, i in zip(label, range(len(label))):
            ds[i][variable+"_int"].sel(region=reg).plot(ax=ax, label=l, lw=3, linestyle=linestyle[i], color=color[i])

        ax.set_title("{}, {}".format(reg, long_name))
        ax.set_ylabel(variable+"_int, " + ds[i].attrs['units_int'])
        ax.set_xlabel('Year')
        ax.grid()
        ax.legend(ncol=3, loc=1)

    return

Global#

reg = 'Global'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6f538c52062b4322cd2e6579c7c75b3508ff6bae7e224eb842cec2c9105313d0.png ../_images/1a7958161e056a35852f8f6990146d606322c30f9d0965095b99eb77bc77b743.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/940fded933d0c9782f59dba42194945d435f3ec7897649ce515b4adc0ad1c25d.png ../_images/9e7383ae197b494d4be77c2c3bad18ca8e03922d9d7542800f321e34ff24963d.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/455256e06b760c0484add46cbfdfba40ba78fce24d1a05d5238fcbc28f0f3ae1.png ../_images/8de99437d8f696425a6907ecbf4946dfac1f1e5e720414854845373b4fa1f935.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/01530a6aad0b9e6f6c04dd4a4d47e7714109939be7e1310567c85671dc192f28.png ../_images/998d23861f2867123f52f047a2121509fa56196550aa3408d12670ff6993a10c.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c2f216a1e75df020ed9eb1a910e4c02d2517ca982787e03b582e1e4419a24f17.png ../_images/a0daf600ce6e4801ba843d7234067c64082cbdb0e53eda68eb66969595b60460.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2c15088c8132670ad509a40869cc63fb8ce69466fc2c6e806ddd8132b20081ac.png ../_images/38d6235782fcc362d528fbc02926cf439bf2209ae52edd76496a505f4269679f.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/21aa2c0b7dd9b7939069b473ea8a6b56b26dc678f6c32e7ae4fa930990e6c5a2.png ../_images/683e18b2286133bdf0f7aa2f426819c0475d5bbb911e29594c830e9000969aae.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d4a343121b84e1f17139c6d948b9f23eafbf1dee8b6ca7962bf9b281f2d2ec56.png ../_images/110acaa3c0b4136bff03f02aca8a74ee7af55d55264b3ed39f65fe232c7f786b.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8472f4a94566aa445b042bdd331f121653a92525789dd9e45b35d4e1e7088d38.png ../_images/fb97365775e88e7ee323f1cc3b3962e6716f2dd88c2426bcb77f25d9fdc02ccd.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1f9ce58e2b5e3ed2b97e6fee5ea7280a494a976a7fafea3f43b564c139692ad4.png ../_images/5b070b1d4d65751ab44bdccb36f2d7762af54d9f25ad4f11e46e68561d36812c.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/781f0ce3814ad0d34ef29488170d482f1fccb4992d2560edfbe3dcaecddd215b.png ../_images/5c180636571effbf458c2030349804c9f25ed34ad29d0bff0ca6089d20364ba5.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9eaee00d56abaaba63a7855360a752f8e52441a15dbe6e49f9d27a31a52d0dc3.png ../_images/72f788aacecc82626f70837b781cf1c0865b1bd5dd919e59df44af3880cd15bd.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/981748d345ddcc33948daa88dade579877cd94b39369b5b2cfdcf8ba54467646.png ../_images/4cb131e4854139caebe8c3f2e5a0fed7f530154fce50ae9fee53227fb4a3e62e.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b923f3a1333f36438635877dc7ee65fb7dd32e8e9e21ae02e13823f502e74e1c.png ../_images/6f3c1ac83824c5641a0b41dd495ae8b1eb18f3fbf191af383b810ad6e68bb5b8.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3b4094b3ff0a8886130ca79bac072312ef440c96a04e9d45f961746a3591f68b.png ../_images/09ac5eb6e82da4431530e27fe073bfb9687367f20d0ecec25ae873f223c6c0d1.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0392de0b372103832262734670de1783249cc7df877dff71cfb3552407f8dbd9.png ../_images/2e0b68f80d72ab16b3d5ab91a6f9fb929d7dbb6e9f223bc7f8b031032b0c4609.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/058c3552fcf92a077eb2f06250af63f78dbf94b15e1c265b3a63d8976c08c1b0.png ../_images/730ecf105463596c037e101997e6f3049054a39da8553d4fb3858d0c2053c745.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/11f13d9488f3bd7e726610665b5548feb34d74fe02bad89f313737fc8d04414d.png ../_images/ff1292f8320902e4d2b09d7dc7f18a37ca8d5b54d78cbb831fdce51a84fe7e9e.png