Assignment 0: dense flow over an obstacle#

For this assignment you will run and plot some data from a Veros simulation. Once you have the model running, please answer the questions below, and hand your Notebook in using Brightspace as a PDF.

Run the model#

The model setup file to use is ./hydraulic.py. If you have set up veros on your machine and you have activated the environment (mamba activate eos431) then you should be able to do:

veros run --force-overwrite hydraulic.py

or, if you managed to get mpi to install and your computer has at least 4 cores:

mpirun -np 4 veros run --force-overwrite hydraulic.py -n 4 1

You should see output scroll by like:

 Current iteration: 2     (0.00/2.50d |  0.0% | 6.14d/(model year) | 1.0h left)
 Current iteration: 3     (0.00/2.50d |  0.0% | 4.49d/(model year) | 44.9m left)
 Current iteration: 4     (0.00/2.50d |  0.0% | 3.67d/(model year) | 36.7m left)
 Current iteration: 5     (0.00/2.50d |  0.0% | 3.13d/(model year) | 31.3m left)

interspersed with snapshots being written to the netcdf file:

 Current iteration: 358   (0.08/2.50d |  3.3% | 1.00d/(model year) | 9.7m left)
 Current iteration: 359   (0.08/2.50d |  3.3% | 1.00d/(model year) | 9.7m left)
 Writing snapshot at 2.00 hours
 Current iteration: 360   (0.08/2.50d |  3.3% | 1.01d/(model year) | 9.7m left)
 Current iteration: 361   (0.08/2.50d |  3.3% | 1.01d/(model year) | 9.7m left)

A file hydraulic.snapshot.nc should be increasing in size while you run this.

Note that depending on the speed of your computer this could take a little while to run - after the first 20 iterations, the “time left” indication should be relatively accurate.

Note

Help! my model doesn’t run, or is so painfully slow I can’t wait for it to complete! Please contact the instructor, preferably on Brightspace.

Q1.1#

Make a plot of the evolution of the flow (u) over time, for at least 2 days (no need to show every time step). Ideally, contour temperature as well as color velocity (I usually use pcolormesh). Please take some care to center your colormaps, and label the axes properly (though if the axes limits are repeated, you need not label all the axes). Also use some discretion in choosing the xlimits of your plot.

import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
# use the matplotlib widget
%matplotlib widget
with xr.open_dataset('hydraulic.snapshot.nc') as ds0:
    print(ds0)
    print(ds0.xt.mean())

    ds0 = ds0.isel(Time=0, yt=1, yu=1)
    fig, ax = plt.subplots()
    ax.pcolormesh(ds0.xu, ds0.zt, ds0.u)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/file_manager.py:209, in CachingFileManager._acquire_with_cache_info(self, needs_lock)
    208 try:
--> 209     file = self._cache[self._key]
    210 except KeyError:

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/lru_cache.py:55, in LRUCache.__getitem__(self, key)
     54 with self._lock:
---> 55     value = self._cache[key]
     56     self._cache.move_to_end(key)

KeyError: [<class 'netCDF4._netCDF4.Dataset'>, ('/Users/jklymak/Dropbox/Teaching/Eos431Phy441/release/Assign0/hydraulic.snapshot.nc',), 'r', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False)), 'f5209ca0-551e-4794-b240-f6774fcfcf9c']

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 1
----> 1 with xr.open_dataset('hydraulic.snapshot.nc') as ds0:
      2     print(ds0)
      3     print(ds0.xt.mean())

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/api.py:541, in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, inline_array, backend_kwargs, **kwargs)
    529 decoders = _resolve_decoders_kwargs(
    530     decode_cf,
    531     open_backend_dataset_parameters=backend.open_dataset_parameters,
   (...)
    537     decode_coords=decode_coords,
    538 )
    540 overwrite_encoded_chunks = kwargs.pop("overwrite_encoded_chunks", None)
--> 541 backend_ds = backend.open_dataset(
    542     filename_or_obj,
    543     drop_variables=drop_variables,
    544     **decoders,
    545     **kwargs,
    546 )
    547 ds = _dataset_from_backend_dataset(
    548     backend_ds,
    549     filename_or_obj,
   (...)
    557     **kwargs,
    558 )
    559 return ds

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/netCDF4_.py:578, in NetCDF4BackendEntrypoint.open_dataset(self, filename_or_obj, mask_and_scale, decode_times, concat_characters, decode_coords, drop_variables, use_cftime, decode_timedelta, group, mode, format, clobber, diskless, persist, lock, autoclose)
    557 def open_dataset(
    558     self,
    559     filename_or_obj,
   (...)
    574     autoclose=False,
    575 ):
    577     filename_or_obj = _normalize_path(filename_or_obj)
--> 578     store = NetCDF4DataStore.open(
    579         filename_or_obj,
    580         mode=mode,
    581         format=format,
    582         group=group,
    583         clobber=clobber,
    584         diskless=diskless,
    585         persist=persist,
    586         lock=lock,
    587         autoclose=autoclose,
    588     )
    590     store_entrypoint = StoreBackendEntrypoint()
    591     with close_on_error(store):

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/netCDF4_.py:382, in NetCDF4DataStore.open(cls, filename, mode, format, group, clobber, diskless, persist, lock, lock_maker, autoclose)
    376 kwargs = dict(
    377     clobber=clobber, diskless=diskless, persist=persist, format=format
    378 )
    379 manager = CachingFileManager(
    380     netCDF4.Dataset, filename, mode=mode, kwargs=kwargs
    381 )
--> 382 return cls(manager, group=group, mode=mode, lock=lock, autoclose=autoclose)

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/netCDF4_.py:329, in NetCDF4DataStore.__init__(self, manager, group, mode, lock, autoclose)
    327 self._group = group
    328 self._mode = mode
--> 329 self.format = self.ds.data_model
    330 self._filename = self.ds.filepath()
    331 self.is_remote = is_remote_uri(self._filename)

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/netCDF4_.py:391, in NetCDF4DataStore.ds(self)
    389 @property
    390 def ds(self):
--> 391     return self._acquire()

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/netCDF4_.py:385, in NetCDF4DataStore._acquire(self, needs_lock)
    384 def _acquire(self, needs_lock=True):
--> 385     with self._manager.acquire_context(needs_lock) as root:
    386         ds = _nc4_require_group(root, self._group, self._mode)
    387     return ds

File ~/mambaforge/envs/veros/lib/python3.8/contextlib.py:113, in _GeneratorContextManager.__enter__(self)
    111 del self.args, self.kwds, self.func
    112 try:
--> 113     return next(self.gen)
    114 except StopIteration:
    115     raise RuntimeError("generator didn't yield") from None

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/file_manager.py:197, in CachingFileManager.acquire_context(self, needs_lock)
    194 @contextlib.contextmanager
    195 def acquire_context(self, needs_lock=True):
    196     """Context manager for acquiring a file."""
--> 197     file, cached = self._acquire_with_cache_info(needs_lock)
    198     try:
    199         yield file

File ~/mambaforge/envs/veros/lib/python3.8/site-packages/xarray/backends/file_manager.py:215, in CachingFileManager._acquire_with_cache_info(self, needs_lock)
    213     kwargs = kwargs.copy()
    214     kwargs["mode"] = self._mode
--> 215 file = self._opener(*self._args, **kwargs)
    216 if self._mode == "w":
    217     # ensure file doesn't get overridden when opened again
    218     self._mode = "a"

File src/netCDF4/_netCDF4.pyx:2464, in netCDF4._netCDF4.Dataset.__init__()

File src/netCDF4/_netCDF4.pyx:2027, in netCDF4._netCDF4._ensure_nc_success()

FileNotFoundError: [Errno 2] No such file or directory: '/Users/jklymak/Dropbox/Teaching/Eos431Phy441/release/Assign0/hydraulic.snapshot.nc'
# YOUR CODE HERE
raise NotImplementedError()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[3], line 2
      1 # YOUR CODE HERE
----> 2 raise NotImplementedError()

NotImplementedError: 

Q1.2 Describe:#

Describe the flow that is shown in your plot.

  • the water is moving. Why?

  • why do you think the shallow layer of water is moving in the negative x direction?

  • we often discuss flows being in “steady state”. Does this flow acheive steady state? If so, where?

  • the water flowing in the bottom layer clearly accelerates. Do you think it transports more water?

YOUR ANSWER HERE

Q1.3 Hovmoller diagram:#

If you did the above properly, you selected a given Time for each frame. For ths problem, choose a certain depth, and plot the velocity as function of xu on the x axis and Time on the y axis. This is called a Hovmoller diagram and is a very useful way to see signals propagating. Do a couple of interesting depths.

Note

Time in Veros is stored as np.timedelta64 which is time since the model run started in nanoseconds. Nanoseconds are pretty useless time unit, so convert to something more convenient (I used hours): ds0['Time'] = ds0.Time / np.timedelta64(1, 'h')

# YOUR CODE HERE
raise NotImplementedError()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[4], line 2
      1 # YOUR CODE HERE
----> 2 raise NotImplementedError()

NotImplementedError: 

Q1.4 Describe#

Describe the signals seen in the Hovmoller diagram - refer to the time slice plots to help orient yourself.

YOUR ANSWER HERE