%%HTML
<video controls autoplay width="100%" height="100%" stype="float">
<source src="./video/sst_pos.mp4" type="video/mp4">
</video>
import s3fs
import xarray as xr
endpoint_url = 'https://ncsa.osn.xsede.org'
fs_osn = s3fs.S3FileSystem(anon=True, client_kwargs={'endpoint_url': endpoint_url},)
path = "Pangeo/pangeo-forge/noaa_oisst/v2.1-avhrr.zarr"
ds = xr.open_zarr(fs_osn.get_mapper(path), consolidated=True).resample(time='MS').mean()
from dask_gateway import Gateway
from dask.distributed import Client
gateway = Gateway()
cluster = gateway.new_cluster() # new Dask cluster
cluster.adapt(minimum=1, maximum=30) # cluster will automatically resize itself based on the workload
cluster
client = Client(cluster) # creates a client so computations using Dask will be executed on the cluster.
client
Client
|
Cluster
|
import numpy as np
if ds.anom.chunks:
ds['anom'] = ds.anom.chunk({'time': -1})
anom_threshold = ds.anom.quantile(.90, dim=('time'))
anom_mhw = ds.anom.where(ds.anom>=anom_threshold, other=np.nan).isel(zlev=0)
mhw_binary = anom_mhw.where(anom_mhw>0, other=0)
mhw_binary = mhw_binary.where(mhw_binary==0, other=1)
# Set model parameters
da = mhw_binary[:100,:,:].load() # taking a slice of the dataset
radius = 8 # radius for structuring element
min_size_quartile = 0.75 # threshold for object areas
xdim = 'lon'
ydim = 'lat'
import ocetrac.model as oce
Tracker = oce.Tracker(da, mask, radius, min_size_quartile, xdim, ydim)
blobs = Tracker.track()
minimum area: 1901.0 inital objects identified 1901 final objects tracked 194
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
import cartopy.crs as ccrs
import cartopy.feature as cfeature
maxl = int(np.nanmax(blobs.values))
cm = ListedColormap(np.random.random(size=(maxl, 3)).tolist())
plt.rc('font', size=20); plt.figure(figsize=(15,6));
ax = plt.axes(projection=ccrs.PlateCarree())
blobs.isel(time=0).plot(transform=ccrs.PlateCarree(), cmap=cm, add_colorbar=False)
ax.coastlines(resolution='110m', color='black', linewidth=1)
ax.add_feature(cfeature.LAND, facecolor='w');
id = 35
event = blobs.where(blobs==id, drop=True)
plt.rc('font', size=12); plt.figure(figsize=(15,6));
for i in enumerate(range(1,len(event.time))):
ax = plt.subplot(2,3,i[1],projection=ccrs.PlateCarree())
event.isel(time=i[0]).plot(transform=ccrs.PlateCarree(),
cmap=cm, add_colorbar=False, add_labels=False)
plt.title(event.isel(time=i[0]).time.values.astype('datetime64[D]'))
ax.coastlines(resolution='110m', color='black', linewidth=1)
ax.add_feature(cfeature.LAND, facecolor='w');
# Create intensity image for the Indian Ocean marine heatwave
event_intensity = ds.anom.isel(zlev=0).where((ds.time==event.time) &
(ds.lat==event.lat) &
(ds.lon==event.lon),
drop=True).load();
event_intensity = event_intensity.expand_dims(dim='intensity', axis=3)
events_contour = event.fillna(0)
plt.rc('font', size=12); plt.figure(figsize=(15,6));
for i in enumerate(range(1,len(event.time))):
ax = plt.subplot(2,3,i[1],projection=ccrs.PlateCarree())
event_intensity.isel(time=i[0], intensity=0).plot(transform=ccrs.PlateCarree(), vmin=-2, vmax=2,
cmap='RdBu_r', extend='both', add_colorbar=True, add_labels=False)
plt.title(event.isel(time=i[0]).time.values.astype('datetime64[D]'))
ax.coastlines(resolution='110m', color='black', linewidth=1)
ax.add_feature(cfeature.LAND, facecolor='w');
events_contour.isel(time=i[0]).plot.contour(levels=[34,35], transform=ccrs.PlateCarree(), colors='b', linewidths=4, add_colorbar=False, add_labels=False)
from skimage.measure import regionprops_table
# Use regionprops to calculate it's area and intensity
props = regionprops_table(np.asarray(event.astype('int')),
intensity_image=np.asarray(event_intensity.astype('int')),
properties=('label', 'area', 'mean_intensity', 'max_intensity'))
props
{'label': array([35]), 'area': array([31087]), 'mean_intensity-0': array([0.42535465]), 'max_intensity-0': array([2])}
%%HTML
<video controls autoplay width="100%" height="100%" stype="float">
<source src="./video/GoM_movie.mp4" type="video/mp4">
</video>
%%HTML
<video controls autoplay width="100%" height="100%" stype="float">
<source src="./video/blob_movie.mp4" type="video/mp4">
</video>
conda install -c conda-forge ocetrac