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

CTD Transect (OTF KBNERR): Repeated from Anchor Point

CTD Transect Across Anchor Point, for GEM Project 030670.

This project used a vessel of opportunity to collect physical oceanographic and fisheries data at six stations along a transect across lower Cook Inlet from Anchor Point (AP) to the Red River delta each day during July. Logistical support for the field sampling was provided in part by the Alaska Department of Fish and Game which has chartered a drift gillnet vessel annually to fish along this transect providing inseason projections of the size of sockeye salmon runs entering Cook Inlet. This project funded collection of physical oceanographic data on board the chartered vessel to help identify intrusions of the Alaska Coastal Current (ACC) into Cook Inlet and test six hypotheses regarding effects of changing oceanographic conditions on migratory behavior and catchability of sockeye salmon entering Cook Inlet. In 2003-2007, a conductivity-temperature-depth profiler was deployed at each station. In 2003-2005, current velocities were estimated along the transect using a towed acoustic Doppler current profiler, and salmon relative abundance and vertical distribution was estimated using towed fisheries acoustic equipment.

Willette, T.M., W.S. Pegau, and R.D. DeCino. 2010. Monitoring dynamics of the Alaska coastal current and development of applications for management of Cook Inlet salmon - a pilot study. Exxon Valdez Oil Spill Gulf Ecosystem Monitoring and Research Project Final Report (GEM Project 030670), Alaska Department of Fish and Game, Commercial Fisheries Division, Soldotna, Alaska.

Report: https://evostc.state.ak.us/media/2176/2004-040670-final.pdf Project description: https://evostc.state.ak.us/restoration-projects/project-search/monitoring-dynamics-of-the-alaska-coastal-current-and-development-of-applications-for-management-of-cook-inlet-salmon-040670/

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

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
['2003-07-01',
 '2003-07-02',
 '2003-07-04',
 '2003-07-05',
 '2003-07-06',
 '2003-07-07',
 '2003-07-08',
 '2003-07-09',
 '2003-07-10',
 '2003-07-11',
 '2003-07-12',
 '2003-07-13',
 '2003-07-14',
 '2003-07-15',
 '2003-07-16',
 '2003-07-17',
 '2003-07-18',
 '2003-07-19',
 '2003-07-21',
 '2003-07-22',
 '2003-07-23',
 '2003-07-24',
 '2003-07-25',
 '2003-07-26',
 '2003-07-28',
 '2003-07-29',
 '2003-07-30',
 '2004-07-01',
 '2004-07-02',
 '2004-07-03',
 '2004-07-04',
 '2004-07-05',
 '2004-07-06',
 '2004-07-07',
 '2004-07-08',
 '2004-07-09',
 '2004-07-10',
 '2004-07-11',
 '2004-07-12',
 '2004-07-13',
 '2004-07-14',
 '2004-07-15',
 '2004-07-16',
 '2004-07-17',
 '2004-07-18',
 '2004-07-19',
 '2004-07-20',
 '2004-07-21',
 '2004-07-22',
 '2004-07-23',
 '2004-07-24',
 '2004-07-25',
 '2004-07-27',
 '2004-07-28',
 '2004-07-29',
 '2004-07-30',
 '2005-07-01',
 '2005-07-02',
 '2005-07-03',
 '2005-07-04',
 '2005-07-05',
 '2005-07-06',
 '2005-07-07',
 '2005-07-08',
 '2005-07-09',
 '2005-07-10',
 '2005-07-11',
 '2005-07-12',
 '2005-07-13',
 '2005-07-14',
 '2005-07-15',
 '2005-07-16',
 '2005-07-17',
 '2005-07-18',
 '2005-07-19',
 '2005-07-20',
 '2005-07-21',
 '2005-07-22',
 '2005-07-23',
 '2005-07-24',
 '2005-07-25',
 '2005-07-26',
 '2005-07-27',
 '2005-07-28',
 '2005-07-29',
 '2005-07-30',
 '2006-07-01',
 '2006-07-02',
 '2006-07-03',
 '2006-07-04',
 '2006-07-05',
 '2006-07-06',
 '2006-07-07',
 '2006-07-09',
 '2006-07-10',
 '2006-07-11',
 '2006-07-12',
 '2006-07-13',
 '2006-07-15',
 '2006-07-16',
 '2006-07-17',
 '2006-07-18',
 '2006-07-19',
 '2006-07-21',
 '2006-07-23',
 '2006-07-25',
 '2006-07-26',
 '2006-07-27',
 '2006-07-28']

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
2003-07-04
---------------------------------------------------------------------------
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)