Transport across sections

mom6_tools.section_transports collection of functions for computing and plotting time-series of transports across pre-defined vertical sections.

The goal of this notebook is the following:

  1. server as an example on how to post-process the CESM/MOM6 vertical sections defined in diag_table. The location of the current vertical sections computed online can be found at the end of this notebook;

  2. evaluate model experiments by comparing transports against observed estimates;

[1]:
%load_ext autoreload
%autoreload 2
[2]:
%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
from mom6_tools.section_transports import Transport, options
import matplotlib.pyplot as plt
from mom6_tools.m6toolbox import cime_xmlquery
import xarray as xr
import yaml, os, numpy
[3]:
# Read in the yaml file
diag_config_yml_path = "diag_config.yml"
diag_config_yml = yaml.load(open(diag_config_yml_path,'r'), Loader=yaml.Loader)
[4]:
# create an empty class object
class args:
    pass
[5]:
caseroot = diag_config_yml['Case']['CASEROOT']
args.casename = cime_xmlquery(caseroot, 'CASE')
DOUT_S = cime_xmlquery(caseroot, 'DOUT_S')
if DOUT_S:
  OUTDIR = cime_xmlquery(caseroot, 'DOUT_S_ROOT')+'/ocn/hist/'
else:
  OUTDIR = cime_xmlquery(caseroot, 'RUNDIR')

print('Output directory is:', OUTDIR)
print('Casename is:', args.casename)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[5], line 2
      1 caseroot = diag_config_yml['Case']['CASEROOT']
----> 2 args.casename = cime_xmlquery(caseroot, 'CASE')
      3 DOUT_S = cime_xmlquery(caseroot, 'DOUT_S')
      4 if DOUT_S:

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/m6toolbox.py:47, in cime_xmlquery(caseroot, varname)
     45 """run CIME's xmlquery for varname in the directory caseroot, return the value"""
     46 try:
---> 47   value = subprocess.check_output(
     48       ["./xmlquery", "-N", "--value", varname],
     49       stderr=subprocess.STDOUT,
     50       cwd=caseroot,
     51   )
     52 except subprocess.CalledProcessError:
     53   value = subprocess.check_output(
     54       ["./xmlquery", "--value", varname], stderr=subprocess.STDOUT, cwd=caseroot
     55   )

File ~/.asdf/installs/python/3.10.20/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
    418         empty = b''
    419     kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    422            **kwargs).stdout

File ~/.asdf/installs/python/3.10.20/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    500     kwargs['stdout'] = PIPE
    501     kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
    504     try:
    505         stdout, stderr = process.communicate(input, timeout=timeout)

File ~/.asdf/installs/python/3.10.20/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
    967         if self.text_mode:
    968             self.stderr = io.TextIOWrapper(self.stderr,
    969                     encoding=encoding, errors=errors)
--> 971     self._execute_child(args, executable, preexec_fn, close_fds,
    972                         pass_fds, cwd, env,
    973                         startupinfo, creationflags, shell,
    974                         p2cread, p2cwrite,
    975                         c2pread, c2pwrite,
    976                         errread, errwrite,
    977                         restore_signals,
    978                         gid, gids, uid, umask,
    979                         start_new_session)
    980 except:
    981     # Cleanup if the child failed starting.
    982     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File ~/.asdf/installs/python/3.10.20/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
   1861     if errno_num != 0:
   1862         err_msg = os.strerror(errno_num)
-> 1863     raise child_exception_type(errno_num, err_msg, err_filename)
   1864 raise child_exception_type(err_msg)

FileNotFoundError: [Errno 2] No such file or directory: '/glade/work/gmarques/cesm.cases/G/g.e30_a07c_cesm.GJRAv4.TL319_t232_wgx3_hycom1_N75.2025.130/'
[6]:
# load sections where transports are computed online
sections = diag_config_yml['Transports']['sections']

Define the arguments expected by class “Transport”. These have been hard-coded here fow now…

[7]:
args.infile = OUTDIR
# set avg dates
avg = diag_config_yml['Avg']
args.start_date = '0001-01-01' # override start date
args.end_date = avg['end_date']
args.label = ''
args.parallel = False
args.debug = False
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 args.infile = OUTDIR
      2 # set avg dates
      3 avg = diag_config_yml['Avg']

NameError: name 'OUTDIR' is not defined

Observed flows, more options can be added here

  • Griffies et al., 2016: OMIP contribution to CMIP6: experimental and diagnostic protocol for the physical component of the Ocean Model Intercomparison Project. Geosci. Model. Dev., 9, 3231-3296. doi:10.5194/gmd-9-3231-2016

Below we define a function for plotting transport time series. Note the following:

green = mean transport is within observed values

red = mean transport is not within observed values

gray = either there isn’t observed values to compare with or just a mean value is available (not a range)

[8]:
def plotPanel(section,observedFlows=None,colorCode=True):
    plt.figure(figsize=(7,3))
    ax = plt.subplot(1,1,1,)
    color = '#c3c3c3'; obsLabel = None
    if section.label in observedFlows.keys():
      if isinstance(observedFlows[section.label][1:],list) and isinstance(observedFlows[section.label][1:][0],float):
        if colorCode == True:
          if min(observedFlows[section.label][1:]) <= section.data.mean() <= max(observedFlows[section.label][1:]):
            color = '#90ee90'
          else: color = '#f26161';
        obsLabel = str(min(observedFlows[section.label][1:])) + ' to ' + str(max(observedFlows[section.label][1:]))
      else: obsLabel = str(observedFlows[section.label][1:]);
    plt.plot(section.time,section.data,color=color)
    plt.title(section.label,fontsize=14)
    plt.text(0.04,0.11,'Mean = '+'{0:.2f}'.format(section.data.mean()),transform=ax.transAxes,fontsize=14)
    if obsLabel is not None: plt.text(0.04,0.04,'Obs. = '+obsLabel,transform=ax.transAxes,fontsize=14)
    if section.ylim is not None: plt.ylim(section.ylim)
    plt.ylabel('Transport (Sv)',fontsize=14); plt.xlabel('Time since beginning of run (yr)',fontsize=14)
    plt.grid()
    return

Plot section transports in alphabetical order

Agulhas Section

[9]:
ds = []
agulhas = Transport(args,sections,'h.Agulhas_Section',debug=False); ds.append(agulhas)
plotPanel(agulhas, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[9], line 2
      1 ds = []
----> 2 agulhas = Transport(args,sections,'h.Agulhas_Section',debug=False); ds.append(agulhas)
      3 plotPanel(agulhas, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Bering Strait

[10]:
bering = Transport(args, sections, 'h.Bering_Strait'); ds.append(bering)
plotPanel(bering, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[10], line 1
----> 1 bering = Transport(args, sections, 'h.Bering_Strait'); ds.append(bering)
      2 plotPanel(bering, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Barents opening

[11]:
barents = Transport(args, sections, 'h.Barents_Opening'); ds.append(barents)
plotPanel(barents, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[11], line 1
----> 1 barents = Transport(args, sections, 'h.Barents_Opening'); ds.append(barents)
      2 plotPanel(barents, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Davis Strait

[12]:
davis = Transport(args, sections,'h.Davis_Strait'); ds.append(davis)
plotPanel(davis, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[12], line 1
----> 1 davis = Transport(args, sections,'h.Davis_Strait'); ds.append(davis)
      2 plotPanel(davis, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Denmark Strait

[13]:
denmark = Transport(args, sections,'h.Denmark_Strait'); ds.append(denmark)
plotPanel(denmark, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[13], line 1
----> 1 denmark = Transport(args, sections,'h.Denmark_Strait'); ds.append(denmark)
      2 plotPanel(denmark, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Drake Passage

[14]:
drake = Transport(args, sections,'h.Drake_Passage'); ds.append(drake)
plotPanel(drake, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[14], line 1
----> 1 drake = Transport(args, sections,'h.Drake_Passage'); ds.append(drake)
      2 plotPanel(drake, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

English Channel

[15]:
english = Transport(args, sections, 'h.English_Channel'); ds.append(english)
plotPanel(english, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[15], line 1
----> 1 english = Transport(args, sections, 'h.English_Channel'); ds.append(english)
      2 plotPanel(english, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Fram Strait

[16]:
fram = Transport(args, sections, 'h.Fram_Strait'); ds.append(fram)
plotPanel(fram, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[16], line 1
----> 1 fram = Transport(args, sections, 'h.Fram_Strait'); ds.append(fram)
      2 plotPanel(fram, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Florida Bahamas

[17]:
#florida1 = Transport(args, sections, 'h.Florida_Bahamas', debug=True); ds.append(florida1)
#plotPanel(florida1, observedFlows=sections)

Florida Bahamas extended

[18]:
florida2 = Transport(args, sections, 'h.Florida_Bahamas_extended'); ds.append(florida2)
plotPanel(florida2, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[18], line 1
----> 1 florida2 = Transport(args, sections, 'h.Florida_Bahamas_extended'); ds.append(florida2)
      2 plotPanel(florida2, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Florida Cuba

[19]:
florida3 = Transport(args, sections, 'h.Florida_Cuba'); ds.append(florida3)
plotPanel(florida3, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[19], line 1
----> 1 florida3 = Transport(args, sections, 'h.Florida_Cuba'); ds.append(florida3)
      2 plotPanel(florida3, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Gibraltar Strait

[20]:
gibraltar = Transport(args, sections, 'h.Gibraltar_Strait'); ds.append(gibraltar)
plotPanel(gibraltar, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[20], line 1
----> 1 gibraltar = Transport(args, sections, 'h.Gibraltar_Strait'); ds.append(gibraltar)
      2 plotPanel(gibraltar, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Iceland Norway

[21]:
#iceland = Transport(args, sections, 'h.Iceland_Norway', debug=True); ds.append(iceland)
#plotPanel(iceland, observedFlows=sections)

Indonesian Throughflow

[22]:
indo = Transport(args, sections, 'h.Indonesian_Throughflow'); ds.append(indo)
plotPanel(indo, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[22], line 1
----> 1 indo = Transport(args, sections, 'h.Indonesian_Throughflow'); ds.append(indo)
      2 plotPanel(indo, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Mozambique Channel

[23]:
mozambique = Transport(args, sections, 'h.Mozambique_Channel'); ds.append(mozambique)
plotPanel(mozambique, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[23], line 1
----> 1 mozambique = Transport(args, sections, 'h.Mozambique_Channel'); ds.append(mozambique)
      2 plotPanel(mozambique, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Pacific undercurrent

[24]:
euc = Transport(args, sections, 'h.Pacific_undercurrent'); ds.append(euc)
plotPanel(euc, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[24], line 1
----> 1 euc = Transport(args, sections, 'h.Pacific_undercurrent'); ds.append(euc)
      2 plotPanel(euc, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Taiwan Luzon

[25]:
taiwan = Transport(args, sections, 'h.Taiwan_Luzon'); ds.append(taiwan)
plotPanel(taiwan, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[25], line 1
----> 1 taiwan = Transport(args, sections, 'h.Taiwan_Luzon'); ds.append(taiwan)
      2 plotPanel(taiwan, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Windward Passage

[26]:
windward = Transport(args, sections, 'h.Windward_Passage'); ds.append(windward)
plotPanel(windward, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[26], line 1
----> 1 windward = Transport(args, sections, 'h.Windward_Passage'); ds.append(windward)
      2 plotPanel(windward, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Robeson_Channel

[27]:
roberson = Transport(args, sections, 'h.Robeson_Channel'); ds.append(roberson)
plotPanel(roberson, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[27], line 1
----> 1 roberson = Transport(args, sections, 'h.Robeson_Channel'); ds.append(roberson)
      2 plotPanel(roberson, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Yucatan_Channel

[28]:
yucatan = Transport(args, sections, 'h.Yucatan_Channel'); ds.append(yucatan)
plotPanel(yucatan, observedFlows=sections)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[28], line 1
----> 1 yucatan = Transport(args, sections, 'h.Yucatan_Channel'); ds.append(yucatan)
      2 plotPanel(yucatan, observedFlows=sections)

File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/section_transports.py:39, in Transport.__init__(self, args, sections_dict, section, ylim, zlim, mks2Sv, debug)
     37 obs = sections_dict[section][1]
     38 label = section
---> 39 debug = debug or args.debug
     40 if debug: print('\n')
     41 if debug: print('##################################')

AttributeError: type object 'args' has no attribute 'debug'

Bosporus_Strait

[29]:
#bosporus = Transport(args, sections, 'h.Bosporus_Strait', debug=True); ds.append(bosporus)
#plotPanel(bosporus, observedFlows=sections)

Save netcdf

[30]:
print('Saving netCDF file with transports...\n')
os.makedirs('ncfiles', exist_ok=True)

# create a dataaray
labels = [];
for n in range(len(ds)): labels.append(ds[n].label)
var = numpy.zeros((len(ds),len(ds[0].time)))
ds_out = xr.Dataset(data_vars={ 'transport' : (('sections', 'time'), var)},
                       coords={'sections': labels,
                               'time': ds[0].time})
for n in range(len(ds)):
  ds_out.transport.values[n,:] = ds[n].data

ds_out.to_netcdf('ncfiles/'+args.casename+'_section_transports.nc')
Saving netCDF file with transports...

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[30], line 7
      5 labels = [];
      6 for n in range(len(ds)): labels.append(ds[n].label)
----> 7 var = numpy.zeros((len(ds),len(ds[0].time)))
      8 ds_out = xr.Dataset(data_vars={ 'transport' : (('sections', 'time'), var)},
      9                        coords={'sections': labels,
     10                                'time': ds[0].time})
     11 for n in range(len(ds)):

IndexError: list index out of range