import intake
import hvplot.pandas
import hvplot.xarray
import cook_inlet_catalogs as cic
import holoviews as hv

CTD Transects (UAF): Repeated in central Cook Inlet

Observations of hydrography and currents in central Cook Inlet, Alaska during diurnal and semidiurnal tidal cycles

Surface-to-bottom measurements of temperature, salinity, and transmissivity, as well as measurements of surface currents (vessel drift speeds) were acquired along an east-west section in central Cook Inlet, Alaska during a 26-hour period on 9-10 August 2003. These measurements are used to describe the evolution of frontal features (tide rips) and physical properties along this section during semidiurnal and diurnal tidal cycles. The observation that the amplitude of surface currents is a function of water depth is used to show that strong frontal features occur in association with steep bathymetry. The positions and strengths of these fronts vary with the semidiurnal tide. The presence of freshwater gradients alters the phase and duration of tidal currents across the section. Where mean density-driven flow is northward (along the eastern shore and near Kalgin Island), the onset of northward tidal flow (flood tide) occurs earlier and has longer duration than the onset and duration of northward tidal flow where mean density-driven flow is southward (in the shipping channel). Conversely, where mean density-driven flow is southward (in the shipping channel), the onset of southward tidal flow (ebb tide) occurs earlier and has longer duration than the onset and duration of southward tidal flow along the eastern shore and near Kalgin Island.

Observations of hydrography and currents in central Cook Inlet, Alaska during diurnal and semidiurnal tidal cycles Stephen R. Okkonen Institute of Marine Science University of Alaska Fairbanks Report: https://www.circac.org/wp-content/uploads/Okkonen_2005_hydrography-and-currents-in-Cook-Inlet.pdf

cat = intake.open_catalog(cic.utils.cat_path("ctd_transects_uaf"))

Plot all datasets in catalog

dd, ddlabels = cic.utils.combine_datasets_for_map(cat)
dd.hvplot(**cat.metadata["map"]) * ddlabels.hvplot(**cat.metadata["maplabels"])

List available datasets in the catalog

dataset_ids = list(cat)
dataset_ids
['Transect_01',
 'Transect_02',
 'Transect_03',
 'Transect_04',
 'Transect_05',
 'Transect_06',
 'Transect_07',
 'Transect_08',
 'Transect_09']

Select one dataset to investigate

try:
    dataset_id = dataset_ids[2]
except:
    dataset_id = dataset_ids[0]
print(dataset_id)

dd = cat[dataset_id].read()
dd
Transect_03
---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
Cell In[5], line 7
      4     dataset_id = dataset_ids[0]
      5 print(dataset_id)
----> 7 dd = cat[dataset_id].read()
      8 dd

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/intake/readers/readers.py:121, in BaseReader.read(self, *args, **kwargs)
    119 kw.update(kwargs)
    120 args = kw.pop("args", ()) or args
--> 121 return self._read(*args, **kw)

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/intake/readers/convert.py:631, in Pipeline._read(self, discover, **kwargs)
    629         data = self._read_stage_n(i, data=data, **kw)
    630     else:
--> 631         data = self._read_stage_n(i, discover=discover, **kw)
    632 return data

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/intake/readers/convert.py:620, in Pipeline._read_stage_n(self, stage, discover, **kwargs)
    618         return func.discover(*arg, **kw2)
    619     else:
--> 620         return func.read(*arg, **kw2)
    621 else:
    622     return func(*arg, **kw2)

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/intake/readers/readers.py:121, in BaseReader.read(self, *args, **kwargs)
    119 kw.update(kwargs)
    120 args = kw.pop("args", ()) or args
--> 121 return self._read(*args, **kw)

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/intake/readers/readers.py:176, in FileReader._read(self, data, **kw)
    174 if self.storage_options and data.storage_options:
    175     kw["storage_options"] = data.storage_options
--> 176 return self._func(**kw)

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/pandas/io/parsers/readers.py:1026, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)
   1013 kwds_defaults = _refine_defaults_read(
   1014     dialect,
   1015     delimiter,
   (...)   1022     dtype_backend=dtype_backend,
   1023 )
   1024 kwds.update(kwds_defaults)
-> 1026 return _read(filepath_or_buffer, kwds)

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/pandas/io/parsers/readers.py:620, in _read(filepath_or_buffer, kwds)
    617 _validate_names(kwds.get("names", None))
    619 # Create the parser.
--> 620 parser = TextFileReader(filepath_or_buffer, **kwds)
    622 if chunksize or iterator:
    623     return parser

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/pandas/io/parsers/readers.py:1620, in TextFileReader.__init__(self, f, engine, **kwds)
   1617     self.options["has_index_names"] = kwds["has_index_names"]
   1619 self.handles: IOHandles | None = None
-> 1620 self._engine = self._make_engine(f, self.engine)

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/pandas/io/parsers/readers.py:1880, in TextFileReader._make_engine(self, f, engine)
   1878     if "b" not in mode:
   1879         mode += "b"
-> 1880 self.handles = get_handle(
   1881     f,
   1882     mode,
   1883     encoding=self.options.get("encoding", None),
   1884     compression=self.options.get("compression", None),
   1885     memory_map=self.options.get("memory_map", False),
   1886     is_text=is_text,
   1887     errors=self.options.get("encoding_errors", "strict"),
   1888     storage_options=self.options.get("storage_options", None),
   1889 )
   1890 assert self.handles is not None
   1891 f = self.handles.handle

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/pandas/io/common.py:728, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    725     codecs.lookup_error(errors)
    727 # open URLs
--> 728 ioargs = _get_filepath_or_buffer(
    729     path_or_buf,
    730     encoding=encoding,
    731     compression=compression,
    732     mode=mode,
    733     storage_options=storage_options,
    734 )
    736 handle = ioargs.filepath_or_buffer
    737 handles: list[BaseBuffer]

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/pandas/io/common.py:430, in _get_filepath_or_buffer(filepath_or_buffer, encoding, compression, mode, storage_options)
    427     pass
    429 try:
--> 430     file_obj = fsspec.open(
    431         filepath_or_buffer, mode=fsspec_mode, **(storage_options or {})
    432     ).open()
    433 # GH 34626 Reads from Public Buckets without Credentials needs anon=True
    434 except tuple(err_types_to_retry_with_anon):

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/fsspec/core.py:491, in open(urlpath, mode, compression, encoding, errors, protocol, newline, expand, **kwargs)
    433 """Given a path or paths, return one ``OpenFile`` object.
    434 
    435 Parameters
   (...)    488   https://filesystem-spec.readthedocs.io/en/latest/api.html#other-known-implementations
    489 """
    490 expand = DEFAULT_EXPAND if expand is None else expand
--> 491 out = open_files(
    492     urlpath=[urlpath],
    493     mode=mode,
    494     compression=compression,
    495     encoding=encoding,
    496     errors=errors,
    497     protocol=protocol,
    498     newline=newline,
    499     expand=expand,
    500     **kwargs,
    501 )
    502 if not out:
    503     raise FileNotFoundError(urlpath)

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/fsspec/core.py:295, in open_files(urlpath, mode, compression, encoding, errors, name_function, num, protocol, newline, auto_mkdir, expand, **kwargs)
    216 def open_files(
    217     urlpath,
    218     mode="rb",
   (...)    228     **kwargs,
    229 ):
    230     """Given a path or paths, return a list of ``OpenFile`` objects.
    231 
    232     For writing, a str path must contain the "*" character, which will be filled
   (...)    293       https://filesystem-spec.readthedocs.io/en/latest/api.html#other-known-implementations
    294     """
--> 295     fs, fs_token, paths = get_fs_token_paths(
    296         urlpath,
    297         mode,
    298         num=num,
    299         name_function=name_function,
    300         storage_options=kwargs,
    301         protocol=protocol,
    302         expand=expand,
    303     )
    304     if fs.protocol == "file":
    305         fs.auto_mkdir = auto_mkdir

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/fsspec/core.py:667, in get_fs_token_paths(urlpath, mode, num, name_function, storage_options, protocol, expand)
    665     inkwargs["fo"] = urls
    666 paths, protocol, _ = chain[0]
--> 667 fs = filesystem(protocol, **inkwargs)
    668 if isinstance(urlpath, (list, tuple, set)):
    669     pchains = [
    670         _un_chain(stringify_path(u), storage_options or {})[0] for u in urlpath
    671     ]

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/fsspec/registry.py:322, in filesystem(protocol, **storage_options)
    315     warnings.warn(
    316         "The 'arrow_hdfs' protocol has been deprecated and will be "
    317         "removed in the future. Specify it as 'hdfs'.",
    318         DeprecationWarning,
    319     )
    321 cls = get_filesystem_class(protocol)
--> 322 return cls(**storage_options)

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/fsspec/spec.py:81, in _Cached.__call__(cls, *args, **kwargs)
     79     return cls._cache[token]
     80 else:
---> 81     obj = super().__call__(*args, **kwargs)
     82     # Setting _fs_token here causes some static linters to complain.
     83     obj._fs_token_ = token

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/fsspec/implementations/cached.py:762, in SimpleCacheFileSystem.__init__(self, **kwargs)
    760 for key in ["cache_check", "expiry_time", "check_files"]:
    761     kw[key] = False
--> 762 super().__init__(**kw)
    763 for storage in self.storage:
    764     if not os.path.exists(storage):

File ~/checkouts/readthedocs.org/user_builds/cook-inlet-catalogs/conda/stable/lib/python3.11/site-packages/fsspec/implementations/cached.py:137, in CachingFileSystem.__init__(self, target_protocol, cache_storage, cache_check, check_files, expiry_time, target_options, fs, same_names, compression, cache_mapper, **kwargs)
    135     else:
    136         storage = cache_storage
--> 137 os.makedirs(storage[-1], exist_ok=True)
    138 self.storage = storage
    139 self.kwargs = target_options or {}

File <frozen os>:215, in makedirs(name, mode, exist_ok)

File <frozen os>:215, in makedirs(name, mode, exist_ok)

File <frozen os>:225, in makedirs(name, mode, exist_ok)

PermissionError: [Errno 13] Permission denied: '/home/kristen'

Plot one dataset

keys = list(cat[dataset_id].metadata["plots"].keys())
print(keys)

plots = []
for key in keys:
    plot_kwargs = cat[dataset_id].metadata["plots"][key]
    if "clim" in plot_kwargs and isinstance(plot_kwargs["clim"], list):
        plot_kwargs["clim"] = tuple(plot_kwargs["clim"])
    if "dynamic" in plot_kwargs:
        plot_kwargs["dynamic"] = False
    plots.append(cat[dataset_id].ToHvPlot(**plot_kwargs).read())
hv.Layout(plots).cols(1)