oceans.datasets

oceans.datasets.etopo_subset(min_lon, max_lon, min_lat, max_lat, tfile=None, smoo=False)[source]

Get a etopo subset. Should work on any netCDF with x, y, data

Examples

>>> from oceans.datasets import etopo_subset
>>> import matplotlib.pyplot as plt
>>> bbox = [-43, -30, -22, -17]
>>> lon, lat, bathy = etopo_subset(*bbox, smoo=True)
>>> fig, ax = plt.subplots()
>>> cs = ax.pcolormesh(lon, lat, bathy)

Based on trondkristiansen contourICEMaps.py

oceans.datasets.get_depth(lon, lat, tfile=None)[source]

Find the depths for each station on the etopo2 database.

Examples

>>> from oceans.datasets import get_depth
>>> station_lon = [-40, -32]
>>> station_lat = [-20, -20]
>>> get_depth(station_lon, station_lat)
array([  -32.988163, -4275.634   ], dtype=float32)
oceans.datasets.get_isobath(bbox, iso=-200, tfile=None, smoo=False)[source]

Finds an isobath on the etopo2 database and returns its lon, lat segments for plotting.

Examples

>>> from oceans.datasets import etopo_subset, get_isobath
>>> import matplotlib.pyplot as plt
>>> bbox = [-43, -30, -22, -17]
>>> segments = get_isobath(bbox=bbox, iso=-200, smoo=True)
>>> lon, lat, bathy = etopo_subset(*bbox, smoo=True)
>>> fig, ax = plt.subplots()
>>> cs = ax.pcolormesh(lon, lat, bathy)
>>> for segment in segments:
...     lines = ax.plot(segment[:, 0], segment[:, -1], "k", linewidth=2)
...
oceans.datasets.woa_profile(lon, lat, variable='temperature', time_period='annual', resolution='1')[source]

Return a xarray DAtaset instance from a World Ocean Atlas variable at a given lon, lat point.

Parameters:
  • lon (float) – point positions to extract the interpolated profile.

  • lat (float) – point positions to extract the interpolated profile.

  • from (Choose resolution) – ‘temperature’, ‘salinity’, ‘silicate’, ‘phosphate’, ‘nitrate’, ‘oxygen_saturation’, ‘dissolved_oxygen’, or ‘apparent_oxygen_utilization’.

  • from – 01-12: January to December 13-16: seasonal (North Hemisphere Winter, Spring, Summer, and Autumn respectively) 00: Annual

  • from – ‘5’, ‘1’, or ‘1/4’ degrees (str)

Return type:

xr.Dataset instance with the climatology.

Examples

>>> import matplotlib.pyplot as plt
>>> from oceans.datasets import woa_profile
>>> woa = woa_profile(
...     -143, 10, variable="temperature", time_period="annual", resolution="5"
... )
>>> fig, ax = plt.subplots(figsize=(2.25, 5))
>>> l = woa.plot(ax=ax, y="depth")
>>> ax.grid(True)
>>> ax.invert_yaxis()
oceans.datasets.woa_subset(min_lon, max_lon, min_lat, max_lat, variable='temperature', time_period='annual', resolution='5', full=False)[source]

Return an xarray Dataset instance from a World Ocean Atlas variable at a given lon, lat bounding box.

Parameters:
  • min_lon (positions to extract.)

  • max_lon (positions to extract.)

  • min_lat (positions to extract.)

  • max_lat (positions to extract.)

  • options. (See woa_profile for the other)

Return type:

xr.Dataset instance with the climatology.

Examples

>>> # Extract a 2D surface -- Annual temperature climatology:
>>> import matplotlib.pyplot as plt
>>> from cmcrameri import cm
>>> from oceans.datasets import woa_subset
>>> bbox = [-177.5, 177.5, -87.5, 87.5]
>>> woa = woa_subset(
...     *bbox, variable="temperature", time_period="annual", resolution="5"
... )
>>> cs = woa["t_mn"].sel(depth=0).plot(cmap=cm.lajolla)
>>> # Extract a square around the Mariana Trench averaging into a profile.
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from oceans.colormaps import get_color
>>> colors = get_color(12)
>>> months = "Jan Feb Apr Mar May Jun Jul Aug Sep Oct Nov Dec".split()
>>> def area_weights_avg(woa):
...     woa = woa["t_mn"].squeeze()
...     weights = np.cos(np.deg2rad(woa["lat"])).where(~woa.isnull())
...     weights /= weights.mean()
...     return (woa * weights).mean(dim=["lon", "lat"])
...
>>> bbox = [-143, -141, 10, 12]
>>> fig, ax = plt.subplots(figsize=(5, 5))
>>> for month in months:
...     woa = woa_subset(
...         *bbox, time_period=month, variable="temperature", resolution="1"
...     )
...     profile = area_weights_avg(woa)
...     l = profile.plot(ax=ax, y="depth", label=month, color=next(colors))
...
>>> ax.grid(True)
>>> ax.invert_yaxis()
>>> leg = ax.legend(loc="lower left")
>>> _ = ax.set_ylim(200, 0)