From 472ba81b0d17ffe83397c8019c5569701dbac705 Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Mon, 9 Nov 2026 17:50:50 -0500
Subject: [PATCH 01/10] warn that open_dataset is not for structured data
open_mfdataset, too. Also, further improves docstrings for those functions.
Also, removes `if grid.source_grid_spec == "Structured"` branch in `_map_dataset_to_ugrid`.
---
test/core/test_api.py | 40 +++++++++++++++++++++++
uxarray/core/api.py | 76 +++++++++++++++++++++++++++++++------------
uxarray/core/utils.py | 18 ++++++----
3 files changed, 107 insertions(+), 27 deletions(-)
diff --git a/test/core/test_api.py b/test/core/test_api.py
index 871ebe68c..14d8fe8c8 100644
--- a/test/core/test_api.py
+++ b/test/core/test_api.py
@@ -564,6 +564,46 @@ def test_open_dataset_with_fallback_chains_both_engine_errors(tmp_path):
)
+def test_open_dataset_warns_for_structured_inputs():
+ """open_dataset() must raise a FutureWarning when provided structured data.
+ (Update this test when structured data becomes fully deprecated here.)
+ """
+ ds = xr.Dataset(
+ {
+ "var": (("lat", "lon"), np.arange(4*8).reshape(4, 8)),
+ },
+ coords={
+ "lat": ("lat", np.linspace(-80, 80, 4), {"standard_name": "latitude"}),
+ "lon": ("lon", np.linspace(0, 350, 8), {"standard_name": "longitude"}),
+ },
+ )
+
+ with pytest.warns(FutureWarning, match=r"open_dataset\(\) is not intended for structured"):
+ uxds = ux.open_dataset(ds, ds) # grid, data
+
+
+def test_open_mfdataset_warns_for_structured_inputs(tmp_path):
+ """open_mfdataset() must raise a FutureWarning when provided structured data.
+ (Update this test when structured data becomes fully deprecated here.)
+ """
+ ds = xr.Dataset(
+ {
+ "var": (("lat", "lon"), np.arange(4*8).reshape(4, 8)),
+ },
+ coords={
+ "lat": ("lat", np.linspace(-80, 80, 4), {"standard_name": "latitude"}),
+ "lon": ("lon", np.linspace(0, 350, 8), {"standard_name": "longitude"}),
+ },
+ )
+
+ # Write the dataset to a temporary netCDF file
+ temp_file = tmp_path / "temp.nc"
+ ds.to_netcdf(temp_file)
+
+ with pytest.warns(FutureWarning, match=r"open_mfdataset\(\) is not intended for structured"):
+ uxds = ux.open_mfdataset(ds, [temp_file]) # grid, [paths to data files]
+
+
def test_list_grid_names_multigrid(gridpath):
"""List grids from an OASIS-style multi-grid file."""
grid_file = gridpath("scrip", "oasis", "grids.nc")
diff --git a/uxarray/core/api.py b/uxarray/core/api.py
index 9039aa5ae..dec93e6fb 100644
--- a/uxarray/core/api.py
+++ b/uxarray/core/api.py
@@ -14,6 +14,7 @@
from uxarray.core.utils import (
_map_dataset_to_ugrid,
_open_dataset_with_fallback,
+ _represents_structured_data,
match_chunks_to_ugrid,
)
from uxarray.errors import GridInvalidError, GridsMismatchError
@@ -380,22 +381,25 @@ def open_dataset(
Parameters
----------
grid_filename_or_obj : str | os.PathLike[Any] | dict | xr.Dataset | Grid
- Grid information for the ``UxDataset``. Strings and Path objects are interpreted as a path to a grid
- file. An ``xarray.Dataset`` containing grid information in a supported unstructured format is used to
- create a ``ux.Grid``. Similarly, a dictionary containing UGRID variables can be used to create a
- ``ux.Grid``. A path to a directory containing grid files (e.g. a FESOM2 ASCII grid) is also accepted,
- but only when ``filename_or_obj`` is provided; directory input is not supported in the single-argument
- form below. An existing ``ux.Grid`` can be used directly, allowing its
- topology and cached properties to be shared across datasets.
+ Specifies the unstructured grid data.
+
+ - Strings and Path objects are interpreted as a path to a data file.
+ A path to a directory containing grid files (e.g. a FESOM2 ASCII grid) is also accepted.
+ but only when ``filename_or_obj`` is also provided to separately specify the dataset data.
+ - A dict must specify UGRID variables ``node_lon``, ``node_lat``, and ``face_node_connectivity``,
+ as per :meth:`uxarray.Grid.from_topology`.
+ - An ``xarray.Dataset`` must contain grid information in any supported unstructured format.
+ - An existing ``ux.Grid`` is attached directly without reconstructing or modifying it,
+ allowing its cached properties to be shared across datasets.
+
+ Also specifies the dataset data if ``filename_or_obj`` is not provided. This single-argument
+ form requires ``grid_filename_or_obj`` to be a string, Path, or ``xarray.Dataset``, and causes
+ the resulting dataset to be populated with all variables it contains, including grid variables.
filename_or_obj : str | os.PathLike[Any] | xr.Dataset, optional
String or Path object as a path to a netCDF file or an OpenDAP URL that
stores the actual data set, or an already-open ``xarray.Dataset``. It
is the same ``filename_or_obj`` in ``xarray.open_dataset``. If omitted,
- ``grid_filename_or_obj`` is also used as the data source, allowing a
- combined grid-and-data file or ``xarray.Dataset`` to be opened with a
- single argument. In this single-argument form the file is used to build
- the grid and also treated as data; all variables it contains, including
- grid variables, will be included as data.
+ ``grid_filename_or_obj`` is also used as the data source instead.
chunks : int, dict, 'auto' or None, default: None
If provided, used to load file-based data into dask arrays. For an
``xarray.Dataset`` data input, this parameter is applied when
@@ -433,7 +437,6 @@ def open_dataset(
Returns
-------
-
uxds : uxarray.UxDataset
Dataset with linked `uxgrid` property of type `Grid`.
@@ -444,6 +447,10 @@ def open_dataset(
requiring information absent from the file will raise when used, but
unrelated functionality remains available.
+ Not intended for structured (lat/lon) grids or data.
+ The intended way to open structured datasets (or grids) in uxarray format is to use
+ :meth:`UxDataset.from_structured` (or :meth:`Grid.from_structured`) instead.
+
Examples
--------
Open a dataset with a grid file and data file
@@ -514,6 +521,15 @@ def open_dataset(
filename_or_obj, chunks=corrected_chunks, **kwargs
)
+ if _represents_structured_data(uxgrid):
+ warn(
+ "ux.open_dataset() is not intended for structured (lat/lon) grids or data. "
+ "Consider UxDataset.from_structured() or Grid.from_structured() instead. "
+ "Support for structured grids in open_dataset() was officially deprecated in "
+ "November 2026 and may be removed in a future release.",
+ category=FutureWarning,
+ )
+
# Map original dimensions to the UGRID conventions
ds = _map_dataset_to_ugrid(ds, uxgrid)
@@ -534,16 +550,21 @@ def open_mfdataset(
grid_kwargs: dict[str, Any] | None = None,
**kwargs: dict[str, Any],
) -> UxDataset:
- """Wraps ``xarray.open_dataset()`` to support reading in a grid and
+ """Wraps ``xarray.open_mfdataset()`` to support reading in a grid and
multiple data files together.
Parameters
----------
grid_filename_or_obj : str | os.PathLike[Any] | dict | xr.Dataset | Grid
- Strings and Path objects are interpreted as a path to a grid file. An ``xarray.Dataset`` containing
- grid information in a supported unstructured format is used to create a ``ux.Grid``. Similarly, a
- dictionary containing UGRID variables can be used to create a ``ux.Grid``. An existing
- ``ux.Grid`` is attached directly without reconstructing or modifying it.
+ Specifies the unstructured grid data.
+
+ - Strings and Path objects are interpreted as a path to a grid file.
+ - A dict must specify UGRID variables ``node_lon``, ``node_lat``, and ``face_node_connectivity``,
+ as per :meth:`uxarray.Grid.from_topology`.
+ - An ``xarray.Dataset`` must contain grid information in any supported unstructured format.
+ - An existing ``ux.Grid`` is attached directly without reconstructing or modifying it,
+ allowing its cached properties to be shared across datasets.
+
paths : string, required
Either a string glob in the form ``"path/to/my/files/*.nc"`` or an explicit
list of files to open. It is the same ``paths`` in ``xarray.open_mfdataset``.
@@ -580,13 +601,17 @@ def open_mfdataset(
Returns
-------
-
- object : uxarray.UxDataset
+ uxds : uxarray.UxDataset
Dataset with the unstructured grid.
+ Notes
+ -----
+ Not intended for structured (lat/lon) grids or data. The intended way to open structured
+ multi-file datasets in uxarray format is to use :func:`xarray.open_mfdataset` first
+ then :meth:`UxDataset.from_structured` to convert the result into a UxDataset.
+
Examples
--------
-
Open grid file along with multiple data files (two or more)
>>> import uxarray as ux
@@ -618,6 +643,15 @@ def open_mfdataset(
grid_kwargs,
)
+ if _represents_structured_data(uxgrid):
+ warn(
+ "ux.open_mfdataset() is not intended for structured (lat/lon) grids or data. "
+ "Consider UxDataset.from_structured(xarray.open_mf_dataset(...)) instead. "
+ "Support for structured grids in open_mfdataset() was officially deprecated in "
+ "November 2026 and may be removed in a future release.",
+ category=FutureWarning,
+ )
+
# Load the data as a Xarray Dataset
ds = xr.open_mfdataset(paths, chunks=corrected_chunks, **kwargs)
diff --git a/uxarray/core/utils.py b/uxarray/core/utils.py
index cb22baafc..c7f34a497 100644
--- a/uxarray/core/utils.py
+++ b/uxarray/core/utils.py
@@ -51,15 +51,21 @@ def _open_dataset_with_fallback(filename_or_obj, chunks=None, **kwargs):
raise fallback_error from default_engine_error
+def _represents_structured_data(grid):
+ """returns whether this Grid corresponds with structured data,
+ based on grid.source_grid_spec.
+ """
+ if grid.source_grid_spec == "Structured":
+ return True
+ elif grid.source_grid_spec == "GEOS-CS":
+ return True
+ else:
+ return False
+
+
def _map_dataset_to_ugrid(ds, grid):
"""Map member dimensions without modifying the Grid's source mapping."""
source_dims = grid._source_dims_dict.copy()
- if grid.source_grid_spec == "Structured":
- lon_dim, lat_dim = source_dims["n_face"]
- if lon_dim not in ds.dims and lat_dim not in ds.dims:
- # No source spatial axes remain to flatten, including members
- # located only on canonical nodes or edges.
- return ds
# Already-standardized dimensions must not be inferred by size: nodes and
# faces can have equal counts. Preserve any explicit source mapping.
for dim in ("n_face", "n_node", "n_edge"):
From 9ee2a8d2df62f5c01f5ea50d743ccd84fc64204e Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Mon, 9 Nov 2026 18:28:23 -0500
Subject: [PATCH 02/10] fix tiny typos spotted by copilot review
---
uxarray/core/api.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/uxarray/core/api.py b/uxarray/core/api.py
index dec93e6fb..494e2c1be 100644
--- a/uxarray/core/api.py
+++ b/uxarray/core/api.py
@@ -383,7 +383,7 @@ def open_dataset(
grid_filename_or_obj : str | os.PathLike[Any] | dict | xr.Dataset | Grid
Specifies the unstructured grid data.
- - Strings and Path objects are interpreted as a path to a data file.
+ - Strings and Path objects are interpreted as a path to a grid data file.
A path to a directory containing grid files (e.g. a FESOM2 ASCII grid) is also accepted.
but only when ``filename_or_obj`` is also provided to separately specify the dataset data.
- A dict must specify UGRID variables ``node_lon``, ``node_lat``, and ``face_node_connectivity``,
@@ -646,7 +646,7 @@ def open_mfdataset(
if _represents_structured_data(uxgrid):
warn(
"ux.open_mfdataset() is not intended for structured (lat/lon) grids or data. "
- "Consider UxDataset.from_structured(xarray.open_mf_dataset(...)) instead. "
+ "Consider UxDataset.from_structured(xarray.open_mfdataset(...)) instead. "
"Support for structured grids in open_mfdataset() was officially deprecated in "
"November 2026 and may be removed in a future release.",
category=FutureWarning,
From 43520ab676d028c6085ab80e9d73ff14b5fbdd71 Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Wed, 11 Nov 2026 11:49:01 -0500
Subject: [PATCH 03/10] crash (dont warn) if structured in open_dataset
and similar for open_mfdataset. See discussion in #1887 for details.
Also, some small rephrasing in docstrings
---
test/core/test_api.py | 14 +++++---------
uxarray/core/api.py | 40 ++++++++++++++--------------------------
2 files changed, 19 insertions(+), 35 deletions(-)
diff --git a/test/core/test_api.py b/test/core/test_api.py
index 14d8fe8c8..defe0da05 100644
--- a/test/core/test_api.py
+++ b/test/core/test_api.py
@@ -564,10 +564,8 @@ def test_open_dataset_with_fallback_chains_both_engine_errors(tmp_path):
)
-def test_open_dataset_warns_for_structured_inputs():
- """open_dataset() must raise a FutureWarning when provided structured data.
- (Update this test when structured data becomes fully deprecated here.)
- """
+def test_open_dataset_fails_for_structured_inputs():
+ """open_dataset() must crash with DimensionError when provided structured data."""
ds = xr.Dataset(
{
"var": (("lat", "lon"), np.arange(4*8).reshape(4, 8)),
@@ -578,14 +576,12 @@ def test_open_dataset_warns_for_structured_inputs():
},
)
- with pytest.warns(FutureWarning, match=r"open_dataset\(\) is not intended for structured"):
+ with pytest.raises(ux.errors.DimensionError, match=r"open_dataset\(\) is not intended for structured"):
uxds = ux.open_dataset(ds, ds) # grid, data
def test_open_mfdataset_warns_for_structured_inputs(tmp_path):
- """open_mfdataset() must raise a FutureWarning when provided structured data.
- (Update this test when structured data becomes fully deprecated here.)
- """
+ """open_mfdataset() must raise a DimensionError when provided structured data."""
ds = xr.Dataset(
{
"var": (("lat", "lon"), np.arange(4*8).reshape(4, 8)),
@@ -600,7 +596,7 @@ def test_open_mfdataset_warns_for_structured_inputs(tmp_path):
temp_file = tmp_path / "temp.nc"
ds.to_netcdf(temp_file)
- with pytest.warns(FutureWarning, match=r"open_mfdataset\(\) is not intended for structured"):
+ with pytest.raises(ux.errors.DimensionError, match=r"open_mfdataset\(\) is not intended for structured"):
uxds = ux.open_mfdataset(ds, [temp_file]) # grid, [paths to data files]
diff --git a/uxarray/core/api.py b/uxarray/core/api.py
index 494e2c1be..e5e7990a6 100644
--- a/uxarray/core/api.py
+++ b/uxarray/core/api.py
@@ -17,7 +17,7 @@
_represents_structured_data,
match_chunks_to_ugrid,
)
-from uxarray.errors import GridInvalidError, GridsMismatchError
+from uxarray.errors import DimensionError, GridInvalidError, GridsMismatchError
from uxarray.grid import Grid
from uxarray.io._scrip import (
_detect_multigrid,
@@ -381,9 +381,9 @@ def open_dataset(
Parameters
----------
grid_filename_or_obj : str | os.PathLike[Any] | dict | xr.Dataset | Grid
- Specifies the unstructured grid data.
+ Specifies the unstructured grid toplogy.
- - Strings and Path objects are interpreted as a path to a grid data file.
+ - Strings and Path objects are interpreted as a path to a grid file.
A path to a directory containing grid files (e.g. a FESOM2 ASCII grid) is also accepted.
but only when ``filename_or_obj`` is also provided to separately specify the dataset data.
- A dict must specify UGRID variables ``node_lon``, ``node_lat``, and ``face_node_connectivity``,
@@ -447,10 +447,6 @@ def open_dataset(
requiring information absent from the file will raise when used, but
unrelated functionality remains available.
- Not intended for structured (lat/lon) grids or data.
- The intended way to open structured datasets (or grids) in uxarray format is to use
- :meth:`UxDataset.from_structured` (or :meth:`Grid.from_structured`) instead.
-
Examples
--------
Open a dataset with a grid file and data file
@@ -522,12 +518,11 @@ def open_dataset(
)
if _represents_structured_data(uxgrid):
- warn(
- "ux.open_dataset() is not intended for structured (lat/lon) grids or data. "
- "Consider UxDataset.from_structured() or Grid.from_structured() instead. "
- "Support for structured grids in open_dataset() was officially deprecated in "
- "November 2026 and may be removed in a future release.",
- category=FutureWarning,
+ raise DimensionError(
+ "ux.open_dataset() is not intended for structured (lat/lon) grids or data, "
+ f"but received a grid with source_grid_spec={uxgrid.source_grid_spec!r} "
+ f"and dims {list(uxgrid._ds.dims)}. "
+ "Consider UxDataset.from_structured() or Grid.from_structured() instead."
)
# Map original dimensions to the UGRID conventions
@@ -556,7 +551,7 @@ def open_mfdataset(
Parameters
----------
grid_filename_or_obj : str | os.PathLike[Any] | dict | xr.Dataset | Grid
- Specifies the unstructured grid data.
+ Specifies the unstructured grid topology.
- Strings and Path objects are interpreted as a path to a grid file.
- A dict must specify UGRID variables ``node_lon``, ``node_lat``, and ``face_node_connectivity``,
@@ -604,12 +599,6 @@ def open_mfdataset(
uxds : uxarray.UxDataset
Dataset with the unstructured grid.
- Notes
- -----
- Not intended for structured (lat/lon) grids or data. The intended way to open structured
- multi-file datasets in uxarray format is to use :func:`xarray.open_mfdataset` first
- then :meth:`UxDataset.from_structured` to convert the result into a UxDataset.
-
Examples
--------
Open grid file along with multiple data files (two or more)
@@ -644,12 +633,11 @@ def open_mfdataset(
)
if _represents_structured_data(uxgrid):
- warn(
- "ux.open_mfdataset() is not intended for structured (lat/lon) grids or data. "
- "Consider UxDataset.from_structured(xarray.open_mfdataset(...)) instead. "
- "Support for structured grids in open_mfdataset() was officially deprecated in "
- "November 2026 and may be removed in a future release.",
- category=FutureWarning,
+ raise DimensionError(
+ "ux.open_mfdataset() is not intended for structured (lat/lon) grids or data, "
+ f"but received a grid with source_grid_spec={uxgrid.source_grid_spec!r} "
+ f"and dims {list(uxgrid._ds.dims)}. "
+ "Consider UxDataset.from_structured(xarray.open_mfdataset(...)) instead."
)
# Load the data as a Xarray Dataset
From 445e52e5db67b168b5d1e000a617d2f03a827865 Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Wed, 11 Nov 2026 12:29:46 -0500
Subject: [PATCH 04/10] crash if structured in from_xarray()
---
test/io/test_structured.py | 36 +++++++-----------------------------
uxarray/core/dataarray.py | 15 ++++++++++++---
uxarray/core/dataset.py | 9 +++++++++
3 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/test/io/test_structured.py b/test/io/test_structured.py
index 30941495c..2219158cb 100644
--- a/test/io/test_structured.py
+++ b/test/io/test_structured.py
@@ -39,42 +39,20 @@ def test_read_structured_uxds_from_ds(ds_name):
assert uxds.uxgrid.validate()
-
-@pytest.mark.parametrize("ds_name", ["air_temperature"])
-def test_from_xarray_with_grid_from_latlon(ds_name):
+def test_from_xarray_with_grid_from_latlon():
"""Regression test for GH #1410: a Grid built via ``from_structured(lon=, lat=)``
must record its source dimensions so ``UxDataset.from_xarray`` flattens the
structured (lon, lat) data variables onto ``n_face``."""
- ds = xr.tutorial.open_dataset(ds_name)
+ ds = xr.tutorial.open_dataset("air_temperature")
uxgrid = ux.Grid.from_structured(lon=ds.lon, lat=ds.lat)
- # The grid must carry the structured spec and the source-dim mapping.
- assert uxgrid.source_grid_spec == "Structured"
- assert uxgrid._source_dims_dict == {"n_face": (ds.lon.dims[0], ds.lat.dims[0])}
-
- uxds = ux.UxDataset.from_xarray(ds, uxgrid=uxgrid)
+ with pytest.raises(ux.errors.DimensionError, match=r"UxDataset.from_xarray\(\) is not intended for structured"):
+ ux.UxDataset.from_xarray(ds, uxgrid=uxgrid)
- # Data must now be mapped onto n_face, not left on lon/lat.
- assert "n_face" in uxds.dims
- assert "lon" not in uxds.dims
- assert "lat" not in uxds.dims
- assert uxds["air"].sizes["n_face"] == ds.sizes["lon"] * ds.sizes["lat"]
-
- # The flatten must preserve data order: each face value must equal the
- # original (lat, lon) cell value at that face. n_face is stacked as
- # (lat, lon) C-order, so face k corresponds to (k // n_lon, k % n_lon).
- n_lon = ds.sizes["lon"]
- original = ds["air"].isel(time=0).values # (lat, lon)
- flattened = uxds["air"].isel(time=0).values # (n_face,)
- for k in (0, n_lon + 1, flattened.size - 1): # first, an interior, last
- i, j = k // n_lon, k % n_lon
- assert flattened[k] == original[i, j]
-
- # End-to-end: the mapped data must be subsettable (the symptom in #1410).
- subset = uxds["air"].isel(time=0).subset.bounding_circle((-100.0, 40.0), 5)
- assert "n_face" in subset.dims
- assert subset.sizes["n_face"] > 0
+ arr = ds.air
+ with pytest.raises(ux.errors.DimensionError, match=r"UxDataArray.from_xarray\(\) is not intended for structured"):
+ ux.UxDataArray.from_xarray(arr, uxgrid=uxgrid)
def test_global_structured_grid_merges_poles_and_seam():
diff --git a/uxarray/core/dataarray.py b/uxarray/core/dataarray.py
index fb43a5220..2db25e56c 100644
--- a/uxarray/core/dataarray.py
+++ b/uxarray/core/dataarray.py
@@ -22,6 +22,7 @@
)
from uxarray.core.utils import (
_map_dims_to_ugrid,
+ _represents_structured_data,
_resolve_coordinate_labels_to_indices,
_validate_indexers,
)
@@ -2412,7 +2413,7 @@ def sel(
@classmethod
def from_xarray(cls, da: xr.DataArray, uxgrid: Grid, ugrid_dims: dict = None):
"""
- Converts a ``xarray.DataArray`` into a ``uxarray.UxDataset`` paired with a user-defined ``Grid``
+ Converts a ``xarray.DataArray`` into a ``uxarray.UxDataArray`` paired with a user-defined ``Grid``
Parameters
----------
@@ -2431,10 +2432,18 @@ def from_xarray(cls, da: xr.DataArray, uxgrid: Grid, ugrid_dims: dict = None):
if ugrid_dims is None:
ugrid_dims = uxgrid._source_dims_dict
+ if _represents_structured_data(uxgrid):
+ raise DimensionError(
+ "UxDataArray.from_xarray() is not intended for structured (lat/lon) grids or data, "
+ f"but received a grid with source_grid_spec={uxgrid.source_grid_spec!r} "
+ f"and dims {list(uxgrid._ds.dims)}. "
+ "Consider UxDataset.from_structured(arr.to_dataset()).to_dataarray() instead."
+ )
+
# map each dimension to its UGRID equivalent
- ds = _map_dims_to_ugrid(da, ugrid_dims, uxgrid)
+ da = _map_dims_to_ugrid(da, ugrid_dims, uxgrid)
- return cls(ds, uxgrid=uxgrid)
+ return cls(da, uxgrid=uxgrid)
@classmethod
def from_healpix(
diff --git a/uxarray/core/dataset.py b/uxarray/core/dataset.py
index b030aefbb..9836fc26f 100644
--- a/uxarray/core/dataset.py
+++ b/uxarray/core/dataset.py
@@ -17,6 +17,7 @@
from uxarray.core.utils import (
_map_dims_to_ugrid,
_open_dataset_with_fallback,
+ _represents_structured_data,
_resolve_coordinate_labels_to_indices,
_validate_indexers,
)
@@ -368,6 +369,14 @@ def from_xarray(cls, ds: xr.Dataset, uxgrid: Grid = None, ugrid_dims: dict = Non
uxgrid = Grid.from_dataset(ds)
ugrid_dims = uxgrid._source_dims_dict
+ if _represents_structured_data(uxgrid):
+ raise DimensionError(
+ "UxDataset.from_xarray() is not intended for structured (lat/lon) grids or data, "
+ f"but received a grid with source_grid_spec={uxgrid.source_grid_spec!r} "
+ f"and dims {list(uxgrid._ds.dims)}. "
+ "Consider UxDataset.from_structured() instead."
+ )
+
# map each dimension to its UGRID equivalent
ds = _map_dims_to_ugrid(ds, ugrid_dims, uxgrid)
From b394caa16b4e419377265eb5226b1aefd4fa7a3c Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Wed, 11 Nov 2026 13:33:44 -0500
Subject: [PATCH 05/10] fix: GEOS-CS does not represent structured data
---
uxarray/core/utils.py | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/uxarray/core/utils.py b/uxarray/core/utils.py
index c7f34a497..dd9cadbe7 100644
--- a/uxarray/core/utils.py
+++ b/uxarray/core/utils.py
@@ -55,12 +55,7 @@ def _represents_structured_data(grid):
"""returns whether this Grid corresponds with structured data,
based on grid.source_grid_spec.
"""
- if grid.source_grid_spec == "Structured":
- return True
- elif grid.source_grid_spec == "GEOS-CS":
- return True
- else:
- return False
+ return grid.source_grid_spec == "Structured"
def _map_dataset_to_ugrid(ds, grid):
From bb09218a897a01bd9ea3c7e810a028b2339cab54 Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Wed, 11 Nov 2026 13:42:35 -0500
Subject: [PATCH 06/10] small update to test docstring
---
test/io/test_structured.py | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/test/io/test_structured.py b/test/io/test_structured.py
index 2219158cb..9a1e9c800 100644
--- a/test/io/test_structured.py
+++ b/test/io/test_structured.py
@@ -40,9 +40,7 @@ def test_read_structured_uxds_from_ds(ds_name):
assert uxds.uxgrid.validate()
def test_from_xarray_with_grid_from_latlon():
- """Regression test for GH #1410: a Grid built via ``from_structured(lon=, lat=)``
- must record its source dimensions so ``UxDataset.from_xarray`` flattens the
- structured (lon, lat) data variables onto ``n_face``."""
+ """from_xarray must crash upon receiving structured data; see PR #1887."""
ds = xr.tutorial.open_dataset("air_temperature")
uxgrid = ux.Grid.from_structured(lon=ds.lon, lat=ds.lat)
From dd12353b649742b496e9c9da22e8ae3bd6c83fc6 Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Fri, 13 Nov 2026 11:18:09 -0500
Subject: [PATCH 07/10] remove from_xarray(structured) in userguide
also clears contents of cells; the version on the repo contains pre-rendered plots which is not desirable.
---
docs/user-guide/structured.ipynb | 7771 +-----------------------------
1 file changed, 25 insertions(+), 7746 deletions(-)
diff --git a/docs/user-guide/structured.ipynb b/docs/user-guide/structured.ipynb
index 00a4008eb..121b8dadd 100644
--- a/docs/user-guide/structured.ipynb
+++ b/docs/user-guide/structured.ipynb
@@ -12,7 +12,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": null,
"id": "149f175e67dc1a07",
"metadata": {
"execution": {
@@ -46,7 +46,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"id": "c63337e3083b6ca5",
"metadata": {
"execution": {
@@ -56,600 +56,7 @@
"shell.execute_reply": "2026-07-13T21:58:41.148588Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "
\n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<xarray.Dataset> Size: 31MB\n",
- "Dimensions: (time: 2920, lat: 25, lon: 53)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00\n",
- " * lat (lat) float32 100B 75.0 72.5 70.0 67.5 65.0 ... 22.5 20.0 17.5 15.0\n",
- " * lon (lon) float32 212B 200.0 202.5 205.0 207.5 ... 325.0 327.5 330.0\n",
- "Data variables:\n",
- " air (time, lat, lon) float64 31MB ...\n",
- "Attributes:\n",
- " Conventions: COARDS\n",
- " title: 4x daily NMC reanalysis (1948)\n",
- " description: Data is from NMC initialized reanalysis\\n(4x/day). These a...\n",
- " platform: Model\n",
- " references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly... Dimensions: Coordinates: (3)
time
(time)
datetime64[ns]
2013-01-01 ... 2014-12-31T18:00:00
standard_name : time long_name : Time array(['2013-01-01T00:00:00.000000000', '2013-01-01T06:00:00.000000000',\n",
- " '2013-01-01T12:00:00.000000000', ..., '2014-12-31T06:00:00.000000000',\n",
- " '2014-12-31T12:00:00.000000000', '2014-12-31T18:00:00.000000000'],\n",
- " shape=(2920,), dtype='datetime64[ns]') lat
(lat)
float32
75.0 72.5 70.0 ... 20.0 17.5 15.0
standard_name : latitude long_name : Latitude units : degrees_north axis : Y array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5,\n",
- " 45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5,\n",
- " 15. ], dtype=float32) lon
(lon)
float32
200.0 202.5 205.0 ... 327.5 330.0
standard_name : longitude long_name : Longitude units : degrees_east axis : X array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,\n",
- " 225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,\n",
- " 250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,\n",
- " 275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,\n",
- " 300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,\n",
- " 325. , 327.5, 330. ], dtype=float32) Data variables: (1)
Attributes: (5)
Conventions : COARDS title : 4x daily NMC reanalysis (1948) description : Data is from NMC initialized reanalysis\n",
- "(4x/day). These are the 0.9950 sigma level values. platform : Model references : http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html "
- ],
- "text/plain": [
- " Size: 31MB\n",
- "Dimensions: (time: 2920, lat: 25, lon: 53)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00\n",
- " * lat (lat) float32 100B 75.0 72.5 70.0 67.5 65.0 ... 22.5 20.0 17.5 15.0\n",
- " * lon (lon) float32 212B 200.0 202.5 205.0 207.5 ... 325.0 327.5 330.0\n",
- "Data variables:\n",
- " air (time, lat, lon) float64 31MB ...\n",
- "Attributes:\n",
- " Conventions: COARDS\n",
- " title: 4x daily NMC reanalysis (1948)\n",
- " description: Data is from NMC initialized reanalysis\\n(4x/day). These a...\n",
- " platform: Model\n",
- " references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly..."
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"ds_air_temp = xr.tutorial.open_dataset(\"air_temperature\")\n",
"ds_air_temp"
@@ -657,7 +64,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": null,
"id": "bc0fd470a7f64504",
"metadata": {
"execution": {
@@ -667,634 +74,7 @@
"shell.execute_reply": "2026-07-13T21:58:41.374313Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<xarray.Dataset> Size: 40MB\n",
- "Dimensions: (time: 624, nbnds: 2, lat: 89, lon: 180)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 5kB 1970-01-01 1970-02-01 ... 2021-12-01\n",
- " * lat (lat) float32 356B 88.0 86.0 84.0 82.0 ... -84.0 -86.0 -88.0\n",
- " * lon (lon) float32 720B 0.0 2.0 4.0 6.0 ... 352.0 354.0 356.0 358.0\n",
- "Dimensions without coordinates: nbnds\n",
- "Data variables:\n",
- " time_bnds (time, nbnds) float64 10kB ...\n",
- " sst (time, lat, lon) float32 40MB ...\n",
- "Attributes: (12/37)\n",
- " climatology: Climatology is based on 1971-2000 SST, Xue, Y....\n",
- " description: In situ data: ICOADS2.5 before 2007 and NCEP i...\n",
- " keywords_vocabulary: NASA Global Change Master Directory (GCMD) Sci...\n",
- " keywords: Earth Science > Oceans > Ocean Temperature > S...\n",
- " instrument: Conventional thermometers\n",
- " source_comment: SSTs were observed by conventional thermometer...\n",
- " ... ...\n",
- " creator_url_original: https://www.ncei.noaa.gov\n",
- " license: No constraints on data access or use\n",
- " comment: SSTs were observed by conventional thermometer...\n",
- " summary: ERSST.v5 is developed based on v4 after revisi...\n",
- " dataset_title: NOAA Extended Reconstructed SST V5\n",
- " data_modified: 2022-06-07 Dimensions: time : 624nbnds : 2lat : 89lon : 180Coordinates: (3)
time
(time)
datetime64[ns]
1970-01-01 ... 2021-12-01
long_name : Time delta_t : 0000-01-00 00:00:00 avg_period : 0000-01-00 00:00:00 prev_avg_period : 0000-00-07 00:00:00 standard_name : time axis : T actual_range : [19723. 81204.] array(['1970-01-01T00:00:00.000000000', '1970-02-01T00:00:00.000000000',\n",
- " '1970-03-01T00:00:00.000000000', ..., '2021-10-01T00:00:00.000000000',\n",
- " '2021-11-01T00:00:00.000000000', '2021-12-01T00:00:00.000000000'],\n",
- " shape=(624,), dtype='datetime64[ns]') lat
(lat)
float32
88.0 86.0 84.0 ... -86.0 -88.0
units : degrees_north long_name : Latitude actual_range : [ 88. -88.] standard_name : latitude axis : Y coordinate_defines : center array([ 88., 86., 84., 82., 80., 78., 76., 74., 72., 70., 68., 66.,\n",
- " 64., 62., 60., 58., 56., 54., 52., 50., 48., 46., 44., 42.,\n",
- " 40., 38., 36., 34., 32., 30., 28., 26., 24., 22., 20., 18.,\n",
- " 16., 14., 12., 10., 8., 6., 4., 2., 0., -2., -4., -6.,\n",
- " -8., -10., -12., -14., -16., -18., -20., -22., -24., -26., -28., -30.,\n",
- " -32., -34., -36., -38., -40., -42., -44., -46., -48., -50., -52., -54.,\n",
- " -56., -58., -60., -62., -64., -66., -68., -70., -72., -74., -76., -78.,\n",
- " -80., -82., -84., -86., -88.], dtype=float32) lon
(lon)
float32
0.0 2.0 4.0 ... 354.0 356.0 358.0
units : degrees_east long_name : Longitude actual_range : [ 0. 358.] standard_name : longitude axis : X coordinate_defines : center array([ 0., 2., 4., 6., 8., 10., 12., 14., 16., 18., 20., 22.,\n",
- " 24., 26., 28., 30., 32., 34., 36., 38., 40., 42., 44., 46.,\n",
- " 48., 50., 52., 54., 56., 58., 60., 62., 64., 66., 68., 70.,\n",
- " 72., 74., 76., 78., 80., 82., 84., 86., 88., 90., 92., 94.,\n",
- " 96., 98., 100., 102., 104., 106., 108., 110., 112., 114., 116., 118.,\n",
- " 120., 122., 124., 126., 128., 130., 132., 134., 136., 138., 140., 142.,\n",
- " 144., 146., 148., 150., 152., 154., 156., 158., 160., 162., 164., 166.,\n",
- " 168., 170., 172., 174., 176., 178., 180., 182., 184., 186., 188., 190.,\n",
- " 192., 194., 196., 198., 200., 202., 204., 206., 208., 210., 212., 214.,\n",
- " 216., 218., 220., 222., 224., 226., 228., 230., 232., 234., 236., 238.,\n",
- " 240., 242., 244., 246., 248., 250., 252., 254., 256., 258., 260., 262.,\n",
- " 264., 266., 268., 270., 272., 274., 276., 278., 280., 282., 284., 286.,\n",
- " 288., 290., 292., 294., 296., 298., 300., 302., 304., 306., 308., 310.,\n",
- " 312., 314., 316., 318., 320., 322., 324., 326., 328., 330., 332., 334.,\n",
- " 336., 338., 340., 342., 344., 346., 348., 350., 352., 354., 356., 358.],\n",
- " dtype=float32) Data variables: (2)
Attributes: (37)
climatology : Climatology is based on 1971-2000 SST, Xue, Y., T. M. Smith, and R. W. Reynolds, 2003: Interdecadal changes of 30-yr SST normals during 1871.2000. Journal of Climate, 16, 1601-1612. description : In situ data: ICOADS2.5 before 2007 and NCEP in situ data from 2008 to present. Ice data: HadISST ice before 2010 and NCEP ice after 2010. keywords_vocabulary : NASA Global Change Master Directory (GCMD) Science Keywords keywords : Earth Science > Oceans > Ocean Temperature > Sea Surface Temperature > instrument : Conventional thermometers source_comment : SSTs were observed by conventional thermometers in Buckets (insulated or un-insulated canvas and wooded buckets) or Engine Room Intaker geospatial_lon_min : -1.0 geospatial_lon_max : 359.0 geospatial_laty_max : 89.0 geospatial_laty_min : -89.0 geospatial_lat_max : 89.0 geospatial_lat_min : -89.0 geospatial_lat_units : degrees_north geospatial_lon_units : degrees_east cdm_data_type : Grid project : NOAA Extended Reconstructed Sea Surface Temperature (ERSST) original_publisher_url : http://www.ncdc.noaa.gov References : https://www.ncdc.noaa.gov/data-access/marineocean-data/extended-reconstructed-sea-surface-temperature-ersst-v5 at NCEI and http://www.esrl.noaa.gov/psd/data/gridded/data.noaa.ersst.v5.html source : In situ data: ICOADS R3.0 before 2015, NCEP in situ GTS from 2016 to present, and Argo SST from 1999 to present. Ice data: HadISST2 ice before 2015, and NCEP ice after 2015 title : NOAA ERSSTv5 (in situ only) history : created 07/2017 by PSD data using NCEI's ERSST V5 NetCDF values institution : This version written at NOAA/ESRL PSD: obtained from NOAA/NESDIS/National Centers for Environmental Information and time aggregated. Original Full Source: NOAA/NESDIS/NCEI/CCOG citation : Huang et al, 2017: Extended Reconstructed Sea Surface Temperatures Version 5 (ERSSTv5): Upgrades, Validations, and Intercomparisons. Journal of Climate, https://doi.org/10.1175/JCLI-D-16-0836.1 platform : Ship and Buoy SSTs from ICOADS R3.0 and NCEP GTS standard_name_vocabulary : CF Standard Name Table (v40, 25 January 2017) processing_level : NOAA Level 4 Conventions : CF-1.6, ACDD-1.3 metadata_link : :metadata_link = https://doi.org/10.7289/V5T72FNM (original format) creator_name : Boyin Huang (original) date_created : 2017-06-30T12:18:00Z (original) product_version : Version 5 creator_url_original : https://www.ncei.noaa.gov license : No constraints on data access or use comment : SSTs were observed by conventional thermometers in Buckets (insulated or un-insulated canvas and wooded buckets), Engine Room Intakers, or floats and drifters summary : ERSST.v5 is developed based on v4 after revisions of 8 parameters using updated data sets and advanced knowledge of ERSST analysis dataset_title : NOAA Extended Reconstructed SST V5 data_modified : 2022-06-07 "
- ],
- "text/plain": [
- " Size: 40MB\n",
- "Dimensions: (time: 624, nbnds: 2, lat: 89, lon: 180)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 5kB 1970-01-01 1970-02-01 ... 2021-12-01\n",
- " * lat (lat) float32 356B 88.0 86.0 84.0 82.0 ... -84.0 -86.0 -88.0\n",
- " * lon (lon) float32 720B 0.0 2.0 4.0 6.0 ... 352.0 354.0 356.0 358.0\n",
- "Dimensions without coordinates: nbnds\n",
- "Data variables:\n",
- " time_bnds (time, nbnds) float64 10kB ...\n",
- " sst (time, lat, lon) float32 40MB ...\n",
- "Attributes: (12/37)\n",
- " climatology: Climatology is based on 1971-2000 SST, Xue, Y....\n",
- " description: In situ data: ICOADS2.5 before 2007 and NCEP i...\n",
- " keywords_vocabulary: NASA Global Change Master Directory (GCMD) Sci...\n",
- " keywords: Earth Science > Oceans > Ocean Temperature > S...\n",
- " instrument: Conventional thermometers\n",
- " source_comment: SSTs were observed by conventional thermometer...\n",
- " ... ...\n",
- " creator_url_original: https://www.ncei.noaa.gov\n",
- " license: No constraints on data access or use\n",
- " comment: SSTs were observed by conventional thermometer...\n",
- " summary: ERSST.v5 is developed based on v4 after revisi...\n",
- " dataset_title: NOAA Extended Reconstructed SST V5\n",
- " data_modified: 2022-06-07"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"ds_ersstv5 = xr.tutorial.open_dataset(\"ersstv5\")\n",
"ds_ersstv5"
@@ -1312,7 +92,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": null,
"id": "d16555e6ec8dee74",
"metadata": {
"execution": {
@@ -1322,596 +102,7 @@
"shell.execute_reply": "2026-07-13T21:58:41.706500Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<uxarray.Grid>\n",
- "Original Grid Type: Structured\n",
- "Grid Dimensions:\n",
- " * n_node: 1404\n",
- " * n_face: 1325\n",
- " * n_max_face_nodes: 4\n",
- "Grid Coordinates (Spherical):\n",
- " * node_lon: (1404,)\n",
- " * node_lat: (1404,)\n",
- "Grid Coordinates (Cartesian):\n",
- "Grid Connectivity Variables:\n",
- " * face_node_connectivity: (1325, 4)\n",
- "Grid Descriptor Variables:\n",
- " "
- ],
- "text/plain": [
- "\n",
- "Original Grid Type: Structured\n",
- "Grid Dimensions:\n",
- " * n_node: 1404\n",
- " * n_face: 1325\n",
- " * n_max_face_nodes: 4\n",
- "Grid Coordinates (Spherical):\n",
- " * node_lon: (1404,)\n",
- " * node_lat: (1404,)\n",
- "Grid Coordinates (Cartesian):\n",
- "Grid Connectivity Variables:\n",
- " * face_node_connectivity: (1325, 4)\n",
- "Grid Descriptor Variables:"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"uxgrid = ux.Grid.from_structured(ds_air_temp)\n",
"uxgrid"
@@ -1927,7 +118,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
"id": "d121ef33c3aaed90",
"metadata": {
"execution": {
@@ -1937,596 +128,7 @@
"shell.execute_reply": "2026-07-13T21:58:41.714331Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<uxarray.Grid>\n",
- "Original Grid Type: Structured\n",
- "Grid Dimensions:\n",
- " * n_node: 1404\n",
- " * n_face: 1325\n",
- " * n_max_face_nodes: 4\n",
- "Grid Coordinates (Spherical):\n",
- " * node_lon: (1404,)\n",
- " * node_lat: (1404,)\n",
- "Grid Coordinates (Cartesian):\n",
- "Grid Connectivity Variables:\n",
- " * face_node_connectivity: (1325, 4)\n",
- "Grid Descriptor Variables:\n",
- " "
- ],
- "text/plain": [
- "\n",
- "Original Grid Type: Structured\n",
- "Grid Dimensions:\n",
- " * n_node: 1404\n",
- " * n_face: 1325\n",
- " * n_max_face_nodes: 4\n",
- "Grid Coordinates (Spherical):\n",
- " * node_lon: (1404,)\n",
- " * node_lat: (1404,)\n",
- "Grid Coordinates (Cartesian):\n",
- "Grid Connectivity Variables:\n",
- " * face_node_connectivity: (1325, 4)\n",
- "Grid Descriptor Variables:"
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"uxgrid = ux.Grid.from_structured(lon=ds_air_temp.lon, lat=ds_air_temp.lat)\n",
"uxgrid"
@@ -2534,7 +136,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": null,
"id": "ab3c5ca428b99bdc",
"metadata": {
"execution": {
@@ -2544,1746 +146,7 @@
"shell.execute_reply": "2026-07-13T21:58:50.511414Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- ""
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/javascript": [
- "(function(root) {\n",
- " function now() {\n",
- " return new Date();\n",
- " }\n",
- "\n",
- " const force = true;\n",
- " const version = '3.9.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n",
- " const reloading = false;\n",
- " const Bokeh = root.Bokeh;\n",
- " const BK_RE = /^https:\\/\\/cdn\\.bokeh\\.org\\/bokeh\\/(release|dev)\\/bokeh-/;\n",
- " const PN_RE = /^https:\\/\\/cdn\\.holoviz\\.org\\/panel\\/[^/]+\\/dist\\/panel/i;\n",
- "\n",
- " // Set a timeout for this load but only if we are not already initializing\n",
- " if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n",
- " root._bokeh_timeout = Date.now() + 5000;\n",
- " root._bokeh_failed_load = false;\n",
- " }\n",
- "\n",
- " function run_callbacks() {\n",
- " try {\n",
- " root._bokeh_onload_callbacks.forEach(function(callback) {\n",
- " if (callback != null)\n",
- " callback();\n",
- " });\n",
- " } finally {\n",
- " delete root._bokeh_onload_callbacks;\n",
- " }\n",
- " console.debug(\"Bokeh: all callbacks have finished\");\n",
- " }\n",
- "\n",
- " function load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, callback) {\n",
- " if (css_urls == null) css_urls = [];\n",
- " if (js_urls == null) js_urls = [];\n",
- " if (js_modules == null) js_modules = [];\n",
- " if (js_exports == null) js_exports = {};\n",
- "\n",
- " root._bokeh_onload_callbacks.push(callback);\n",
- "\n",
- " if (root._bokeh_is_loading > 0) {\n",
- " // Don't load bokeh if it is still initializing\n",
- " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
- " return null;\n",
- " } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n",
- " // There is nothing to load\n",
- " run_callbacks();\n",
- " return null;\n",
- " }\n",
- "\n",
- " function on_load() {\n",
- " root._bokeh_is_loading--;\n",
- " if (root._bokeh_is_loading === 0) {\n",
- " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
- " run_callbacks()\n",
- " }\n",
- " }\n",
- " window._bokeh_on_load = on_load\n",
- "\n",
- " function on_error(e) {\n",
- " const src_el = e.srcElement\n",
- " console.error(\"failed to load \" + (src_el.href || src_el.src));\n",
- " }\n",
- "\n",
- " const skip = [];\n",
- " if (window.requirejs) {\n",
- " window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n",
- " root._bokeh_is_loading = css_urls.length + 0;\n",
- " } else {\n",
- " root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n",
- " }\n",
- "\n",
- " const existing_stylesheets = []\n",
- " const links = document.getElementsByTagName('link')\n",
- " for (let i = 0; i < links.length; i++) {\n",
- " const link = links[i]\n",
- " if (link.href != null) {\n",
- " existing_stylesheets.push(link.href)\n",
- " }\n",
- " }\n",
- " for (let i = 0; i < css_urls.length; i++) {\n",
- " const url = css_urls[i];\n",
- " const escaped = encodeURI(url)\n",
- " if (existing_stylesheets.indexOf(escaped) !== -1) {\n",
- " on_load()\n",
- " continue;\n",
- " }\n",
- " const element = document.createElement(\"link\");\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.rel = \"stylesheet\";\n",
- " element.type = \"text/css\";\n",
- " element.href = url;\n",
- " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
- " document.body.appendChild(element);\n",
- " } var existing_scripts = []\n",
- " const scripts = document.getElementsByTagName('script')\n",
- " for (let i = 0; i < scripts.length; i++) {\n",
- " var script = scripts[i]\n",
- " if (script.src != null) {\n",
- " existing_scripts.push(script.src)\n",
- " }\n",
- " }\n",
- " for (let i = 0; i < js_urls.length; i++) {\n",
- " const url = js_urls[i];\n",
- " const escaped = encodeURI(url)\n",
- " const shouldSkip = skip.includes(escaped) || existing_scripts.includes(escaped)\n",
- " const isBokehOrPanel = BK_RE.test(escaped) || PN_RE.test(escaped)\n",
- " const missingOrBroken = Bokeh == null || Bokeh.Panel == null || (Bokeh.version != version && !Bokeh.versions?.has(version)) || Bokeh.versions?.get(version)?.Panel == null;\n",
- " if (shouldSkip && !(isBokehOrPanel && missingOrBroken)) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " const element = document.createElement('script');\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.src = url;\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " for (let i = 0; i < js_modules.length; i++) {\n",
- " const url = js_modules[i];\n",
- " const escaped = encodeURI(url)\n",
- " if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " var element = document.createElement('script');\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.src = url;\n",
- " element.type = \"module\";\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " for (const name in js_exports) {\n",
- " const url = js_exports[name];\n",
- " const escaped = encodeURI(url)\n",
- " if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " var element = document.createElement('script');\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.type = \"module\";\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " element.textContent = `\n",
- " import ${name} from \"${url}\"\n",
- " window.${name} = ${name}\n",
- " window._bokeh_on_load()\n",
- " `\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " if (!js_urls.length && !js_modules.length) {\n",
- " on_load()\n",
- " }\n",
- " };\n",
- "\n",
- " function inject_raw_css(css) {\n",
- " const element = document.createElement(\"style\");\n",
- " element.appendChild(document.createTextNode(css));\n",
- " document.body.appendChild(element);\n",
- " }\n",
- "\n",
- " const js_urls = [\"https://cdn.holoviz.org/panel/1.8.10/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-3.9.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.9.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.9.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.9.0.min.js\", \"https://cdn.holoviz.org/panel/1.8.10/dist/panel.min.js\"];\n",
- " const js_modules = [];\n",
- " const js_exports = {};\n",
- " const css_urls = [];\n",
- " const inline_js = [ function(Bokeh) {\n",
- " Bokeh.set_log_level(\"info\");\n",
- " },\n",
- "function(Bokeh) {} // ensure no trailing comma for IE\n",
- " ];\n",
- "\n",
- " function run_inline_js() {\n",
- " if ((root.Bokeh !== undefined) || (force === true)) {\n",
- " for (let i = 0; i < inline_js.length; i++) {\n",
- " try {\n",
- " inline_js[i].call(root, root.Bokeh);\n",
- " } catch(e) {\n",
- " if (!reloading) {\n",
- " throw e;\n",
- " }\n",
- " }\n",
- " }\n",
- " } else if (Date.now() < root._bokeh_timeout) {\n",
- " setTimeout(run_inline_js, 100);\n",
- " } else if (!root._bokeh_failed_load) {\n",
- " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
- " root._bokeh_failed_load = true;\n",
- " }\n",
- " root._bokeh_is_initializing = false;\n",
- " }\n",
- "\n",
- " function load_or_wait() {\n",
- " // Implement a backoff loop that tries to ensure we do not load multiple\n",
- " // versions of Bokeh and its dependencies at the same time.\n",
- " // In recent versions we use the root._bokeh_is_initializing flag\n",
- " // to determine whether there is an ongoing attempt to initialize\n",
- " // bokeh, however for backward compatibility we also try to ensure\n",
- " // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n",
- " // before older versions are fully initialized.\n",
- " if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n",
- " // If the timeout and bokeh was not successfully loaded we reset\n",
- " // everything and try loading again\n",
- " root._bokeh_timeout = Date.now() + 5000;\n",
- " root._bokeh_is_initializing = false;\n",
- " root._bokeh_onload_callbacks = undefined;\n",
- " root._bokeh_is_loading = 0;\n",
- " console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n",
- " load_or_wait();\n",
- " } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n",
- " setTimeout(load_or_wait, 100);\n",
- " } else {\n",
- " root._bokeh_is_initializing = true;\n",
- " root._bokeh_onload_callbacks = [];\n",
- " const bokeh_loaded = Bokeh != null && ((Bokeh.version === version && Bokeh.Panel) || (Bokeh.versions?.has(version) && Bokeh.versions.get(version)?.Panel));\n",
- " if (!reloading && !bokeh_loaded) {\n",
- " if (root.Bokeh) {\n",
- " root.Bokeh = undefined;\n",
- " }\n",
- " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
- " }\n",
- " load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, function() {\n",
- " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
- " run_inline_js();\n",
- " if (Bokeh != undefined && !reloading) {\n",
- " const NewBokeh = root.Bokeh;\n",
- " if (Bokeh.versions === undefined) {\n",
- " Bokeh.versions = new Map();\n",
- " }\n",
- " if (NewBokeh.version !== Bokeh.version) {\n",
- " Bokeh[NewBokeh.version] = NewBokeh;\n",
- " Bokeh.versions.set(NewBokeh.version, NewBokeh);\n",
- " }\n",
- " root.Bokeh = Bokeh;\n",
- " }\n",
- " });\n",
- " }\n",
- " }\n",
- " // Give older versions of the autoload script a head-start to ensure\n",
- " // they initialize before we start loading newer version.\n",
- " setTimeout(load_or_wait, 100)\n",
- "}(window));"
- ],
- "application/vnd.holoviews_load.v0+json": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n const version = '3.9.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = false;\n const Bokeh = root.Bokeh;\n const BK_RE = /^https:\\/\\/cdn\\.bokeh\\.org\\/bokeh\\/(release|dev)\\/bokeh-/;\n const PN_RE = /^https:\\/\\/cdn\\.holoviz\\.org\\/panel\\/[^/]+\\/dist\\/panel/i;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks;\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n root._bokeh_is_loading = css_urls.length + 0;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n const shouldSkip = skip.includes(escaped) || existing_scripts.includes(escaped)\n const isBokehOrPanel = BK_RE.test(escaped) || PN_RE.test(escaped)\n const missingOrBroken = Bokeh == null || Bokeh.Panel == null || (Bokeh.version != version && !Bokeh.versions?.has(version)) || Bokeh.versions?.get(version)?.Panel == null;\n if (shouldSkip && !(isBokehOrPanel && missingOrBroken)) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.holoviz.org/panel/1.8.10/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-3.9.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.9.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.9.0.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.9.0.min.js\", \"https://cdn.holoviz.org/panel/1.8.10/dist/panel.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\n ];\n\n function run_inline_js() {\n if ((root.Bokeh !== undefined) || (force === true)) {\n for (let i = 0; i < inline_js.length; i++) {\n try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n }\n root._bokeh_is_initializing = false;\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0;\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true;\n root._bokeh_onload_callbacks = [];\n const bokeh_loaded = Bokeh != null && ((Bokeh.version === version && Bokeh.Panel) || (Bokeh.versions?.has(version) && Bokeh.versions.get(version)?.Panel));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n if (Bokeh != undefined && !reloading) {\n const NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh[NewBokeh.version] = NewBokeh;\n Bokeh.versions.set(NewBokeh.version, NewBokeh);\n }\n root.Bokeh = Bokeh;\n }\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));"
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/javascript": [
- "\n",
- "if ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n",
- " window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n",
- "}\n",
- "\n",
- "\n",
- " function JupyterCommManager() {\n",
- " }\n",
- "\n",
- " JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n",
- " if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n",
- " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n",
- " comm_manager.register_target(comm_id, function(comm) {\n",
- " comm.on_msg(msg_handler);\n",
- " });\n",
- " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n",
- " window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n",
- " comm.onMsg = msg_handler;\n",
- " });\n",
- " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n",
- " google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n",
- " var messages = comm.messages[Symbol.asyncIterator]();\n",
- " function processIteratorResult(result) {\n",
- " var message = result.value;\n",
- " var content = {data: message.data, comm_id};\n",
- " var buffers = []\n",
- " for (var buffer of message.buffers || []) {\n",
- " buffers.push(new DataView(buffer))\n",
- " }\n",
- " var metadata = message.metadata || {};\n",
- " var msg = {content, buffers, metadata}\n",
- " msg_handler(msg);\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " return messages.next().then(processIteratorResult);\n",
- " })\n",
- " }\n",
- " }\n",
- "\n",
- " JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n",
- " if (comm_id in window.PyViz.comms) {\n",
- " return window.PyViz.comms[comm_id];\n",
- " } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n",
- " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n",
- " var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n",
- " if (msg_handler) {\n",
- " comm.on_msg(msg_handler);\n",
- " }\n",
- " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n",
- " var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n",
- " let retries = 0;\n",
- " const open = () => {\n",
- " if (comm.active) {\n",
- " comm.open();\n",
- " } else if (retries > 3) {\n",
- " console.warn('Comm target never activated')\n",
- " } else {\n",
- " retries += 1\n",
- " setTimeout(open, 500)\n",
- " }\n",
- " }\n",
- " if (comm.active) {\n",
- " comm.open();\n",
- " } else {\n",
- " setTimeout(open, 500)\n",
- " }\n",
- " if (msg_handler) {\n",
- " comm.onMsg = msg_handler;\n",
- " }\n",
- " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n",
- " var comm_promise = google.colab.kernel.comms.open(comm_id)\n",
- " comm_promise.then((comm) => {\n",
- " window.PyViz.comms[comm_id] = comm;\n",
- " if (msg_handler) {\n",
- " var messages = comm.messages[Symbol.asyncIterator]();\n",
- " function processIteratorResult(result) {\n",
- " var message = result.value;\n",
- " var content = {data: message.data};\n",
- " var metadata = message.metadata || {comm_id};\n",
- " var msg = {content, metadata}\n",
- " msg_handler(msg);\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " })\n",
- " var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n",
- " return comm_promise.then((comm) => {\n",
- " comm.send(data, metadata, buffers, disposeOnDone);\n",
- " });\n",
- " };\n",
- " var comm = {\n",
- " send: sendClosure\n",
- " };\n",
- " }\n",
- " window.PyViz.comms[comm_id] = comm;\n",
- " return comm;\n",
- " }\n",
- " window.PyViz.comm_manager = new JupyterCommManager();\n",
- " \n",
- "\n",
- "\n",
- "var JS_MIME_TYPE = 'application/javascript';\n",
- "var HTML_MIME_TYPE = 'text/html';\n",
- "var EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\n",
- "var CLASS_NAME = 'output';\n",
- "\n",
- "/**\n",
- " * Render data to the DOM node\n",
- " */\n",
- "function render(props, node) {\n",
- " var div = document.createElement(\"div\");\n",
- " var script = document.createElement(\"script\");\n",
- " node.appendChild(div);\n",
- " node.appendChild(script);\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle when a new output is added\n",
- " */\n",
- "function handle_add_output(event, handle) {\n",
- " var output_area = handle.output_area;\n",
- " var output = handle.output;\n",
- " if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
- " return\n",
- " }\n",
- " var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
- " var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
- " if (id !== undefined) {\n",
- " var nchildren = toinsert.length;\n",
- " var html_node = toinsert[nchildren-1].children[0];\n",
- " html_node.innerHTML = output.data[HTML_MIME_TYPE];\n",
- " var scripts = [];\n",
- " var nodelist = html_node.querySelectorAll(\"script\");\n",
- " for (var i in nodelist) {\n",
- " if (nodelist.hasOwnProperty(i)) {\n",
- " scripts.push(nodelist[i])\n",
- " }\n",
- " }\n",
- "\n",
- " scripts.forEach( function (oldScript) {\n",
- " var newScript = document.createElement(\"script\");\n",
- " var attrs = [];\n",
- " var nodemap = oldScript.attributes;\n",
- " for (var j in nodemap) {\n",
- " if (nodemap.hasOwnProperty(j)) {\n",
- " attrs.push(nodemap[j])\n",
- " }\n",
- " }\n",
- " attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n",
- " newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n",
- " oldScript.parentNode.replaceChild(newScript, oldScript);\n",
- " });\n",
- " if (JS_MIME_TYPE in output.data) {\n",
- " toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n",
- " }\n",
- " output_area._hv_plot_id = id;\n",
- " if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n",
- " window.PyViz.plot_index[id] = Bokeh.index[id];\n",
- " } else {\n",
- " window.PyViz.plot_index[id] = null;\n",
- " }\n",
- " } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
- " var bk_div = document.createElement(\"div\");\n",
- " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
- " var script_attrs = bk_div.children[0].attributes;\n",
- " for (var i = 0; i < script_attrs.length; i++) {\n",
- " toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
- " }\n",
- " // store reference to server id on output_area\n",
- " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
- " }\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle when an output is cleared or removed\n",
- " */\n",
- "function handle_clear_output(event, handle) {\n",
- " var id = handle.cell.output_area._hv_plot_id;\n",
- " var server_id = handle.cell.output_area._bokeh_server_id;\n",
- " if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n",
- " var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n",
- " if (server_id !== null) {\n",
- " comm.send({event_type: 'server_delete', 'id': server_id});\n",
- " return;\n",
- " } else if (comm !== null) {\n",
- " comm.send({event_type: 'delete', 'id': id});\n",
- " }\n",
- " delete PyViz.plot_index[id];\n",
- " if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n",
- " var doc = window.Bokeh.index[id].model.document\n",
- " doc.clear();\n",
- " const i = window.Bokeh.documents.indexOf(doc);\n",
- " if (i > -1) {\n",
- " window.Bokeh.documents.splice(i, 1);\n",
- " }\n",
- " }\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle kernel restart event\n",
- " */\n",
- "function handle_kernel_cleanup(event, handle) {\n",
- " delete PyViz.comms[\"hv-extension-comm\"];\n",
- " window.PyViz.plot_index = {}\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle update_display_data messages\n",
- " */\n",
- "function handle_update_output(event, handle) {\n",
- " handle_clear_output(event, {cell: {output_area: handle.output_area}})\n",
- " handle_add_output(event, handle)\n",
- "}\n",
- "\n",
- "function register_renderer(events, OutputArea) {\n",
- " function append_mime(data, metadata, element) {\n",
- " // create a DOM node to render to\n",
- " var toinsert = this.create_output_subarea(\n",
- " metadata,\n",
- " CLASS_NAME,\n",
- " EXEC_MIME_TYPE\n",
- " );\n",
- " this.keyboard_manager.register_events(toinsert);\n",
- " // Render to node\n",
- " var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
- " render(props, toinsert[0]);\n",
- " element.append(toinsert);\n",
- " return toinsert\n",
- " }\n",
- "\n",
- " events.on('output_added.OutputArea', handle_add_output);\n",
- " events.on('output_updated.OutputArea', handle_update_output);\n",
- " events.on('clear_output.CodeCell', handle_clear_output);\n",
- " events.on('delete.Cell', handle_clear_output);\n",
- " events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n",
- "\n",
- " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
- " safe: true,\n",
- " index: 0\n",
- " });\n",
- "}\n",
- "\n",
- "if (window.Jupyter !== undefined) {\n",
- " try {\n",
- " var events = require('base/js/events');\n",
- " var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
- " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
- " register_renderer(events, OutputArea);\n",
- " }\n",
- " } catch(err) {\n",
- " }\n",
- "}\n"
- ],
- "application/vnd.holoviews_load.v0+json": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n let retries = 0;\n const open = () => {\n if (comm.active) {\n comm.open();\n } else if (retries > 3) {\n console.warn('Comm target never activated')\n } else {\n retries += 1\n setTimeout(open, 500)\n }\n }\n if (comm.active) {\n comm.open();\n } else {\n setTimeout(open, 500)\n }\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n })\n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n}\n\n/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n"
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/vnd.holoviews_exec.v0+json": "",
- "text/html": [
- "\n",
- ""
- ]
- },
- "metadata": {
- "application/vnd.holoviews_exec.v0+json": {
- "id": "b8718e53-4d2a-4054-b44a-c686c4c0f605"
- }
- },
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- ""
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/javascript": [
- "(function(root) {\n",
- " function now() {\n",
- " return new Date();\n",
- " }\n",
- "\n",
- " const force = false;\n",
- " const version = '3.9.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n",
- " const reloading = true;\n",
- " const Bokeh = root.Bokeh;\n",
- " const BK_RE = /^https:\\/\\/cdn\\.bokeh\\.org\\/bokeh\\/(release|dev)\\/bokeh-/;\n",
- " const PN_RE = /^https:\\/\\/cdn\\.holoviz\\.org\\/panel\\/[^/]+\\/dist\\/panel/i;\n",
- "\n",
- " // Set a timeout for this load but only if we are not already initializing\n",
- " if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n",
- " root._bokeh_timeout = Date.now() + 5000;\n",
- " root._bokeh_failed_load = false;\n",
- " }\n",
- "\n",
- " function run_callbacks() {\n",
- " try {\n",
- " root._bokeh_onload_callbacks.forEach(function(callback) {\n",
- " if (callback != null)\n",
- " callback();\n",
- " });\n",
- " } finally {\n",
- " delete root._bokeh_onload_callbacks;\n",
- " }\n",
- " console.debug(\"Bokeh: all callbacks have finished\");\n",
- " }\n",
- "\n",
- " function load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, callback) {\n",
- " if (css_urls == null) css_urls = [];\n",
- " if (js_urls == null) js_urls = [];\n",
- " if (js_modules == null) js_modules = [];\n",
- " if (js_exports == null) js_exports = {};\n",
- "\n",
- " root._bokeh_onload_callbacks.push(callback);\n",
- "\n",
- " if (root._bokeh_is_loading > 0) {\n",
- " // Don't load bokeh if it is still initializing\n",
- " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
- " return null;\n",
- " } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n",
- " // There is nothing to load\n",
- " run_callbacks();\n",
- " return null;\n",
- " }\n",
- "\n",
- " function on_load() {\n",
- " root._bokeh_is_loading--;\n",
- " if (root._bokeh_is_loading === 0) {\n",
- " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
- " run_callbacks()\n",
- " }\n",
- " }\n",
- " window._bokeh_on_load = on_load\n",
- "\n",
- " function on_error(e) {\n",
- " const src_el = e.srcElement\n",
- " console.error(\"failed to load \" + (src_el.href || src_el.src));\n",
- " }\n",
- "\n",
- " const skip = [];\n",
- " if (window.requirejs) {\n",
- " window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n",
- " root._bokeh_is_loading = css_urls.length + 0;\n",
- " } else {\n",
- " root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n",
- " }\n",
- "\n",
- " const existing_stylesheets = []\n",
- " const links = document.getElementsByTagName('link')\n",
- " for (let i = 0; i < links.length; i++) {\n",
- " const link = links[i]\n",
- " if (link.href != null) {\n",
- " existing_stylesheets.push(link.href)\n",
- " }\n",
- " }\n",
- " for (let i = 0; i < css_urls.length; i++) {\n",
- " const url = css_urls[i];\n",
- " const escaped = encodeURI(url)\n",
- " if (existing_stylesheets.indexOf(escaped) !== -1) {\n",
- " on_load()\n",
- " continue;\n",
- " }\n",
- " const element = document.createElement(\"link\");\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.rel = \"stylesheet\";\n",
- " element.type = \"text/css\";\n",
- " element.href = url;\n",
- " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
- " document.body.appendChild(element);\n",
- " } var existing_scripts = []\n",
- " const scripts = document.getElementsByTagName('script')\n",
- " for (let i = 0; i < scripts.length; i++) {\n",
- " var script = scripts[i]\n",
- " if (script.src != null) {\n",
- " existing_scripts.push(script.src)\n",
- " }\n",
- " }\n",
- " for (let i = 0; i < js_urls.length; i++) {\n",
- " const url = js_urls[i];\n",
- " const escaped = encodeURI(url)\n",
- " const shouldSkip = skip.includes(escaped) || existing_scripts.includes(escaped)\n",
- " const isBokehOrPanel = BK_RE.test(escaped) || PN_RE.test(escaped)\n",
- " const missingOrBroken = Bokeh == null || Bokeh.Panel == null || (Bokeh.version != version && !Bokeh.versions?.has(version)) || Bokeh.versions?.get(version)?.Panel == null;\n",
- " if (shouldSkip && !(isBokehOrPanel && missingOrBroken)) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " const element = document.createElement('script');\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.src = url;\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " for (let i = 0; i < js_modules.length; i++) {\n",
- " const url = js_modules[i];\n",
- " const escaped = encodeURI(url)\n",
- " if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " var element = document.createElement('script');\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.src = url;\n",
- " element.type = \"module\";\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " for (const name in js_exports) {\n",
- " const url = js_exports[name];\n",
- " const escaped = encodeURI(url)\n",
- " if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " var element = document.createElement('script');\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.type = \"module\";\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " element.textContent = `\n",
- " import ${name} from \"${url}\"\n",
- " window.${name} = ${name}\n",
- " window._bokeh_on_load()\n",
- " `\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " if (!js_urls.length && !js_modules.length) {\n",
- " on_load()\n",
- " }\n",
- " };\n",
- "\n",
- " function inject_raw_css(css) {\n",
- " const element = document.createElement(\"style\");\n",
- " element.appendChild(document.createTextNode(css));\n",
- " document.body.appendChild(element);\n",
- " }\n",
- "\n",
- " const js_urls = [\"https://cdn.holoviz.org/panel/1.8.10/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n",
- " const js_modules = [];\n",
- " const js_exports = {};\n",
- " const css_urls = [];\n",
- " const inline_js = [ function(Bokeh) {\n",
- " Bokeh.set_log_level(\"info\");\n",
- " },\n",
- "function(Bokeh) {} // ensure no trailing comma for IE\n",
- " ];\n",
- "\n",
- " function run_inline_js() {\n",
- " if ((root.Bokeh !== undefined) || (force === true)) {\n",
- " for (let i = 0; i < inline_js.length; i++) {\n",
- " try {\n",
- " inline_js[i].call(root, root.Bokeh);\n",
- " } catch(e) {\n",
- " if (!reloading) {\n",
- " throw e;\n",
- " }\n",
- " }\n",
- " }\n",
- " } else if (Date.now() < root._bokeh_timeout) {\n",
- " setTimeout(run_inline_js, 100);\n",
- " } else if (!root._bokeh_failed_load) {\n",
- " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
- " root._bokeh_failed_load = true;\n",
- " }\n",
- " root._bokeh_is_initializing = false;\n",
- " }\n",
- "\n",
- " function load_or_wait() {\n",
- " // Implement a backoff loop that tries to ensure we do not load multiple\n",
- " // versions of Bokeh and its dependencies at the same time.\n",
- " // In recent versions we use the root._bokeh_is_initializing flag\n",
- " // to determine whether there is an ongoing attempt to initialize\n",
- " // bokeh, however for backward compatibility we also try to ensure\n",
- " // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n",
- " // before older versions are fully initialized.\n",
- " if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n",
- " // If the timeout and bokeh was not successfully loaded we reset\n",
- " // everything and try loading again\n",
- " root._bokeh_timeout = Date.now() + 5000;\n",
- " root._bokeh_is_initializing = false;\n",
- " root._bokeh_onload_callbacks = undefined;\n",
- " root._bokeh_is_loading = 0;\n",
- " console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n",
- " load_or_wait();\n",
- " } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n",
- " setTimeout(load_or_wait, 100);\n",
- " } else {\n",
- " root._bokeh_is_initializing = true;\n",
- " root._bokeh_onload_callbacks = [];\n",
- " const bokeh_loaded = Bokeh != null && ((Bokeh.version === version && Bokeh.Panel) || (Bokeh.versions?.has(version) && Bokeh.versions.get(version)?.Panel));\n",
- " if (!reloading && !bokeh_loaded) {\n",
- " if (root.Bokeh) {\n",
- " root.Bokeh = undefined;\n",
- " }\n",
- " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
- " }\n",
- " load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, function() {\n",
- " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
- " run_inline_js();\n",
- " if (Bokeh != undefined && !reloading) {\n",
- " const NewBokeh = root.Bokeh;\n",
- " if (Bokeh.versions === undefined) {\n",
- " Bokeh.versions = new Map();\n",
- " }\n",
- " if (NewBokeh.version !== Bokeh.version) {\n",
- " Bokeh[NewBokeh.version] = NewBokeh;\n",
- " Bokeh.versions.set(NewBokeh.version, NewBokeh);\n",
- " }\n",
- " root.Bokeh = Bokeh;\n",
- " }\n",
- " });\n",
- " }\n",
- " }\n",
- " // Give older versions of the autoload script a head-start to ensure\n",
- " // they initialize before we start loading newer version.\n",
- " setTimeout(load_or_wait, 100)\n",
- "}(window));"
- ],
- "application/vnd.holoviews_load.v0+json": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = false;\n const version = '3.9.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = true;\n const Bokeh = root.Bokeh;\n const BK_RE = /^https:\\/\\/cdn\\.bokeh\\.org\\/bokeh\\/(release|dev)\\/bokeh-/;\n const PN_RE = /^https:\\/\\/cdn\\.holoviz\\.org\\/panel\\/[^/]+\\/dist\\/panel/i;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks;\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n root._bokeh_is_loading = css_urls.length + 0;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n const shouldSkip = skip.includes(escaped) || existing_scripts.includes(escaped)\n const isBokehOrPanel = BK_RE.test(escaped) || PN_RE.test(escaped)\n const missingOrBroken = Bokeh == null || Bokeh.Panel == null || (Bokeh.version != version && !Bokeh.versions?.has(version)) || Bokeh.versions?.get(version)?.Panel == null;\n if (shouldSkip && !(isBokehOrPanel && missingOrBroken)) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.holoviz.org/panel/1.8.10/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\n ];\n\n function run_inline_js() {\n if ((root.Bokeh !== undefined) || (force === true)) {\n for (let i = 0; i < inline_js.length; i++) {\n try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n }\n root._bokeh_is_initializing = false;\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0;\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true;\n root._bokeh_onload_callbacks = [];\n const bokeh_loaded = Bokeh != null && ((Bokeh.version === version && Bokeh.Panel) || (Bokeh.versions?.has(version) && Bokeh.versions.get(version)?.Panel));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n if (Bokeh != undefined && !reloading) {\n const NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh[NewBokeh.version] = NewBokeh;\n Bokeh.versions.set(NewBokeh.version, NewBokeh);\n }\n root.Bokeh = Bokeh;\n }\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));"
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/javascript": [
- "\n",
- "if ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n",
- " window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n",
- "}\n",
- "\n",
- "\n",
- " function JupyterCommManager() {\n",
- " }\n",
- "\n",
- " JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n",
- " if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n",
- " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n",
- " comm_manager.register_target(comm_id, function(comm) {\n",
- " comm.on_msg(msg_handler);\n",
- " });\n",
- " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n",
- " window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n",
- " comm.onMsg = msg_handler;\n",
- " });\n",
- " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n",
- " google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n",
- " var messages = comm.messages[Symbol.asyncIterator]();\n",
- " function processIteratorResult(result) {\n",
- " var message = result.value;\n",
- " var content = {data: message.data, comm_id};\n",
- " var buffers = []\n",
- " for (var buffer of message.buffers || []) {\n",
- " buffers.push(new DataView(buffer))\n",
- " }\n",
- " var metadata = message.metadata || {};\n",
- " var msg = {content, buffers, metadata}\n",
- " msg_handler(msg);\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " return messages.next().then(processIteratorResult);\n",
- " })\n",
- " }\n",
- " }\n",
- "\n",
- " JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n",
- " if (comm_id in window.PyViz.comms) {\n",
- " return window.PyViz.comms[comm_id];\n",
- " } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n",
- " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n",
- " var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n",
- " if (msg_handler) {\n",
- " comm.on_msg(msg_handler);\n",
- " }\n",
- " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n",
- " var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n",
- " let retries = 0;\n",
- " const open = () => {\n",
- " if (comm.active) {\n",
- " comm.open();\n",
- " } else if (retries > 3) {\n",
- " console.warn('Comm target never activated')\n",
- " } else {\n",
- " retries += 1\n",
- " setTimeout(open, 500)\n",
- " }\n",
- " }\n",
- " if (comm.active) {\n",
- " comm.open();\n",
- " } else {\n",
- " setTimeout(open, 500)\n",
- " }\n",
- " if (msg_handler) {\n",
- " comm.onMsg = msg_handler;\n",
- " }\n",
- " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n",
- " var comm_promise = google.colab.kernel.comms.open(comm_id)\n",
- " comm_promise.then((comm) => {\n",
- " window.PyViz.comms[comm_id] = comm;\n",
- " if (msg_handler) {\n",
- " var messages = comm.messages[Symbol.asyncIterator]();\n",
- " function processIteratorResult(result) {\n",
- " var message = result.value;\n",
- " var content = {data: message.data};\n",
- " var metadata = message.metadata || {comm_id};\n",
- " var msg = {content, metadata}\n",
- " msg_handler(msg);\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " })\n",
- " var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n",
- " return comm_promise.then((comm) => {\n",
- " comm.send(data, metadata, buffers, disposeOnDone);\n",
- " });\n",
- " };\n",
- " var comm = {\n",
- " send: sendClosure\n",
- " };\n",
- " }\n",
- " window.PyViz.comms[comm_id] = comm;\n",
- " return comm;\n",
- " }\n",
- " window.PyViz.comm_manager = new JupyterCommManager();\n",
- " \n",
- "\n",
- "\n",
- "var JS_MIME_TYPE = 'application/javascript';\n",
- "var HTML_MIME_TYPE = 'text/html';\n",
- "var EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\n",
- "var CLASS_NAME = 'output';\n",
- "\n",
- "/**\n",
- " * Render data to the DOM node\n",
- " */\n",
- "function render(props, node) {\n",
- " var div = document.createElement(\"div\");\n",
- " var script = document.createElement(\"script\");\n",
- " node.appendChild(div);\n",
- " node.appendChild(script);\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle when a new output is added\n",
- " */\n",
- "function handle_add_output(event, handle) {\n",
- " var output_area = handle.output_area;\n",
- " var output = handle.output;\n",
- " if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
- " return\n",
- " }\n",
- " var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
- " var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
- " if (id !== undefined) {\n",
- " var nchildren = toinsert.length;\n",
- " var html_node = toinsert[nchildren-1].children[0];\n",
- " html_node.innerHTML = output.data[HTML_MIME_TYPE];\n",
- " var scripts = [];\n",
- " var nodelist = html_node.querySelectorAll(\"script\");\n",
- " for (var i in nodelist) {\n",
- " if (nodelist.hasOwnProperty(i)) {\n",
- " scripts.push(nodelist[i])\n",
- " }\n",
- " }\n",
- "\n",
- " scripts.forEach( function (oldScript) {\n",
- " var newScript = document.createElement(\"script\");\n",
- " var attrs = [];\n",
- " var nodemap = oldScript.attributes;\n",
- " for (var j in nodemap) {\n",
- " if (nodemap.hasOwnProperty(j)) {\n",
- " attrs.push(nodemap[j])\n",
- " }\n",
- " }\n",
- " attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n",
- " newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n",
- " oldScript.parentNode.replaceChild(newScript, oldScript);\n",
- " });\n",
- " if (JS_MIME_TYPE in output.data) {\n",
- " toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n",
- " }\n",
- " output_area._hv_plot_id = id;\n",
- " if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n",
- " window.PyViz.plot_index[id] = Bokeh.index[id];\n",
- " } else {\n",
- " window.PyViz.plot_index[id] = null;\n",
- " }\n",
- " } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
- " var bk_div = document.createElement(\"div\");\n",
- " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
- " var script_attrs = bk_div.children[0].attributes;\n",
- " for (var i = 0; i < script_attrs.length; i++) {\n",
- " toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
- " }\n",
- " // store reference to server id on output_area\n",
- " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
- " }\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle when an output is cleared or removed\n",
- " */\n",
- "function handle_clear_output(event, handle) {\n",
- " var id = handle.cell.output_area._hv_plot_id;\n",
- " var server_id = handle.cell.output_area._bokeh_server_id;\n",
- " if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n",
- " var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n",
- " if (server_id !== null) {\n",
- " comm.send({event_type: 'server_delete', 'id': server_id});\n",
- " return;\n",
- " } else if (comm !== null) {\n",
- " comm.send({event_type: 'delete', 'id': id});\n",
- " }\n",
- " delete PyViz.plot_index[id];\n",
- " if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n",
- " var doc = window.Bokeh.index[id].model.document\n",
- " doc.clear();\n",
- " const i = window.Bokeh.documents.indexOf(doc);\n",
- " if (i > -1) {\n",
- " window.Bokeh.documents.splice(i, 1);\n",
- " }\n",
- " }\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle kernel restart event\n",
- " */\n",
- "function handle_kernel_cleanup(event, handle) {\n",
- " delete PyViz.comms[\"hv-extension-comm\"];\n",
- " window.PyViz.plot_index = {}\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle update_display_data messages\n",
- " */\n",
- "function handle_update_output(event, handle) {\n",
- " handle_clear_output(event, {cell: {output_area: handle.output_area}})\n",
- " handle_add_output(event, handle)\n",
- "}\n",
- "\n",
- "function register_renderer(events, OutputArea) {\n",
- " function append_mime(data, metadata, element) {\n",
- " // create a DOM node to render to\n",
- " var toinsert = this.create_output_subarea(\n",
- " metadata,\n",
- " CLASS_NAME,\n",
- " EXEC_MIME_TYPE\n",
- " );\n",
- " this.keyboard_manager.register_events(toinsert);\n",
- " // Render to node\n",
- " var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
- " render(props, toinsert[0]);\n",
- " element.append(toinsert);\n",
- " return toinsert\n",
- " }\n",
- "\n",
- " events.on('output_added.OutputArea', handle_add_output);\n",
- " events.on('output_updated.OutputArea', handle_update_output);\n",
- " events.on('clear_output.CodeCell', handle_clear_output);\n",
- " events.on('delete.Cell', handle_clear_output);\n",
- " events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n",
- "\n",
- " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
- " safe: true,\n",
- " index: 0\n",
- " });\n",
- "}\n",
- "\n",
- "if (window.Jupyter !== undefined) {\n",
- " try {\n",
- " var events = require('base/js/events');\n",
- " var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
- " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
- " register_renderer(events, OutputArea);\n",
- " }\n",
- " } catch(err) {\n",
- " }\n",
- "}\n"
- ],
- "application/vnd.holoviews_load.v0+json": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n let retries = 0;\n const open = () => {\n if (comm.active) {\n comm.open();\n } else if (retries > 3) {\n console.warn('Comm target never activated')\n } else {\n retries += 1\n setTimeout(open, 500)\n }\n }\n if (comm.active) {\n comm.open();\n } else {\n setTimeout(open, 500)\n }\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n })\n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n}\n\n/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n"
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- ""
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/javascript": [
- "(function(root) {\n",
- " function now() {\n",
- " return new Date();\n",
- " }\n",
- "\n",
- " const force = false;\n",
- " const version = '3.9.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n",
- " const reloading = true;\n",
- " const Bokeh = root.Bokeh;\n",
- " const BK_RE = /^https:\\/\\/cdn\\.bokeh\\.org\\/bokeh\\/(release|dev)\\/bokeh-/;\n",
- " const PN_RE = /^https:\\/\\/cdn\\.holoviz\\.org\\/panel\\/[^/]+\\/dist\\/panel/i;\n",
- "\n",
- " // Set a timeout for this load but only if we are not already initializing\n",
- " if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n",
- " root._bokeh_timeout = Date.now() + 5000;\n",
- " root._bokeh_failed_load = false;\n",
- " }\n",
- "\n",
- " function run_callbacks() {\n",
- " try {\n",
- " root._bokeh_onload_callbacks.forEach(function(callback) {\n",
- " if (callback != null)\n",
- " callback();\n",
- " });\n",
- " } finally {\n",
- " delete root._bokeh_onload_callbacks;\n",
- " }\n",
- " console.debug(\"Bokeh: all callbacks have finished\");\n",
- " }\n",
- "\n",
- " function load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, callback) {\n",
- " if (css_urls == null) css_urls = [];\n",
- " if (js_urls == null) js_urls = [];\n",
- " if (js_modules == null) js_modules = [];\n",
- " if (js_exports == null) js_exports = {};\n",
- "\n",
- " root._bokeh_onload_callbacks.push(callback);\n",
- "\n",
- " if (root._bokeh_is_loading > 0) {\n",
- " // Don't load bokeh if it is still initializing\n",
- " console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
- " return null;\n",
- " } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n",
- " // There is nothing to load\n",
- " run_callbacks();\n",
- " return null;\n",
- " }\n",
- "\n",
- " function on_load() {\n",
- " root._bokeh_is_loading--;\n",
- " if (root._bokeh_is_loading === 0) {\n",
- " console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
- " run_callbacks()\n",
- " }\n",
- " }\n",
- " window._bokeh_on_load = on_load\n",
- "\n",
- " function on_error(e) {\n",
- " const src_el = e.srcElement\n",
- " console.error(\"failed to load \" + (src_el.href || src_el.src));\n",
- " }\n",
- "\n",
- " const skip = [];\n",
- " if (window.requirejs) {\n",
- " window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n",
- " root._bokeh_is_loading = css_urls.length + 0;\n",
- " } else {\n",
- " root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n",
- " }\n",
- "\n",
- " const existing_stylesheets = []\n",
- " const links = document.getElementsByTagName('link')\n",
- " for (let i = 0; i < links.length; i++) {\n",
- " const link = links[i]\n",
- " if (link.href != null) {\n",
- " existing_stylesheets.push(link.href)\n",
- " }\n",
- " }\n",
- " for (let i = 0; i < css_urls.length; i++) {\n",
- " const url = css_urls[i];\n",
- " const escaped = encodeURI(url)\n",
- " if (existing_stylesheets.indexOf(escaped) !== -1) {\n",
- " on_load()\n",
- " continue;\n",
- " }\n",
- " const element = document.createElement(\"link\");\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.rel = \"stylesheet\";\n",
- " element.type = \"text/css\";\n",
- " element.href = url;\n",
- " console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
- " document.body.appendChild(element);\n",
- " } var existing_scripts = []\n",
- " const scripts = document.getElementsByTagName('script')\n",
- " for (let i = 0; i < scripts.length; i++) {\n",
- " var script = scripts[i]\n",
- " if (script.src != null) {\n",
- " existing_scripts.push(script.src)\n",
- " }\n",
- " }\n",
- " for (let i = 0; i < js_urls.length; i++) {\n",
- " const url = js_urls[i];\n",
- " const escaped = encodeURI(url)\n",
- " const shouldSkip = skip.includes(escaped) || existing_scripts.includes(escaped)\n",
- " const isBokehOrPanel = BK_RE.test(escaped) || PN_RE.test(escaped)\n",
- " const missingOrBroken = Bokeh == null || Bokeh.Panel == null || (Bokeh.version != version && !Bokeh.versions?.has(version)) || Bokeh.versions?.get(version)?.Panel == null;\n",
- " if (shouldSkip && !(isBokehOrPanel && missingOrBroken)) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " const element = document.createElement('script');\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.src = url;\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " for (let i = 0; i < js_modules.length; i++) {\n",
- " const url = js_modules[i];\n",
- " const escaped = encodeURI(url)\n",
- " if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " var element = document.createElement('script');\n",
- " element.onload = on_load;\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.src = url;\n",
- " element.type = \"module\";\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " for (const name in js_exports) {\n",
- " const url = js_exports[name];\n",
- " const escaped = encodeURI(url)\n",
- " if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n",
- " if (!window.requirejs) {\n",
- " on_load();\n",
- " }\n",
- " continue;\n",
- " }\n",
- " var element = document.createElement('script');\n",
- " element.onerror = on_error;\n",
- " element.async = false;\n",
- " element.type = \"module\";\n",
- " console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
- " element.textContent = `\n",
- " import ${name} from \"${url}\"\n",
- " window.${name} = ${name}\n",
- " window._bokeh_on_load()\n",
- " `\n",
- " document.head.appendChild(element);\n",
- " }\n",
- " if (!js_urls.length && !js_modules.length) {\n",
- " on_load()\n",
- " }\n",
- " };\n",
- "\n",
- " function inject_raw_css(css) {\n",
- " const element = document.createElement(\"style\");\n",
- " element.appendChild(document.createTextNode(css));\n",
- " document.body.appendChild(element);\n",
- " }\n",
- "\n",
- " const js_urls = [\"https://cdn.holoviz.org/panel/1.8.10/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n",
- " const js_modules = [];\n",
- " const js_exports = {};\n",
- " const css_urls = [];\n",
- " const inline_js = [ function(Bokeh) {\n",
- " Bokeh.set_log_level(\"info\");\n",
- " },\n",
- "function(Bokeh) {} // ensure no trailing comma for IE\n",
- " ];\n",
- "\n",
- " function run_inline_js() {\n",
- " if ((root.Bokeh !== undefined) || (force === true)) {\n",
- " for (let i = 0; i < inline_js.length; i++) {\n",
- " try {\n",
- " inline_js[i].call(root, root.Bokeh);\n",
- " } catch(e) {\n",
- " if (!reloading) {\n",
- " throw e;\n",
- " }\n",
- " }\n",
- " }\n",
- " } else if (Date.now() < root._bokeh_timeout) {\n",
- " setTimeout(run_inline_js, 100);\n",
- " } else if (!root._bokeh_failed_load) {\n",
- " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
- " root._bokeh_failed_load = true;\n",
- " }\n",
- " root._bokeh_is_initializing = false;\n",
- " }\n",
- "\n",
- " function load_or_wait() {\n",
- " // Implement a backoff loop that tries to ensure we do not load multiple\n",
- " // versions of Bokeh and its dependencies at the same time.\n",
- " // In recent versions we use the root._bokeh_is_initializing flag\n",
- " // to determine whether there is an ongoing attempt to initialize\n",
- " // bokeh, however for backward compatibility we also try to ensure\n",
- " // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n",
- " // before older versions are fully initialized.\n",
- " if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n",
- " // If the timeout and bokeh was not successfully loaded we reset\n",
- " // everything and try loading again\n",
- " root._bokeh_timeout = Date.now() + 5000;\n",
- " root._bokeh_is_initializing = false;\n",
- " root._bokeh_onload_callbacks = undefined;\n",
- " root._bokeh_is_loading = 0;\n",
- " console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n",
- " load_or_wait();\n",
- " } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n",
- " setTimeout(load_or_wait, 100);\n",
- " } else {\n",
- " root._bokeh_is_initializing = true;\n",
- " root._bokeh_onload_callbacks = [];\n",
- " const bokeh_loaded = Bokeh != null && ((Bokeh.version === version && Bokeh.Panel) || (Bokeh.versions?.has(version) && Bokeh.versions.get(version)?.Panel));\n",
- " if (!reloading && !bokeh_loaded) {\n",
- " if (root.Bokeh) {\n",
- " root.Bokeh = undefined;\n",
- " }\n",
- " console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
- " }\n",
- " load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, function() {\n",
- " console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
- " run_inline_js();\n",
- " if (Bokeh != undefined && !reloading) {\n",
- " const NewBokeh = root.Bokeh;\n",
- " if (Bokeh.versions === undefined) {\n",
- " Bokeh.versions = new Map();\n",
- " }\n",
- " if (NewBokeh.version !== Bokeh.version) {\n",
- " Bokeh[NewBokeh.version] = NewBokeh;\n",
- " Bokeh.versions.set(NewBokeh.version, NewBokeh);\n",
- " }\n",
- " root.Bokeh = Bokeh;\n",
- " }\n",
- " });\n",
- " }\n",
- " }\n",
- " // Give older versions of the autoload script a head-start to ensure\n",
- " // they initialize before we start loading newer version.\n",
- " setTimeout(load_or_wait, 100)\n",
- "}(window));"
- ],
- "application/vnd.holoviews_load.v0+json": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = false;\n const version = '3.9.0'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = true;\n const Bokeh = root.Bokeh;\n const BK_RE = /^https:\\/\\/cdn\\.bokeh\\.org\\/bokeh\\/(release|dev)\\/bokeh-/;\n const PN_RE = /^https:\\/\\/cdn\\.holoviz\\.org\\/panel\\/[^/]+\\/dist\\/panel/i;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks;\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {}, 'shim': {}});\n root._bokeh_is_loading = css_urls.length + 0;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n const shouldSkip = skip.includes(escaped) || existing_scripts.includes(escaped)\n const isBokehOrPanel = BK_RE.test(escaped) || PN_RE.test(escaped)\n const missingOrBroken = Bokeh == null || Bokeh.Panel == null || (Bokeh.version != version && !Bokeh.versions?.has(version)) || Bokeh.versions?.get(version)?.Panel == null;\n if (shouldSkip && !(isBokehOrPanel && missingOrBroken)) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.holoviz.org/panel/1.8.10/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\n ];\n\n function run_inline_js() {\n if ((root.Bokeh !== undefined) || (force === true)) {\n for (let i = 0; i < inline_js.length; i++) {\n try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n }\n root._bokeh_is_initializing = false;\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0;\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true;\n root._bokeh_onload_callbacks = [];\n const bokeh_loaded = Bokeh != null && ((Bokeh.version === version && Bokeh.Panel) || (Bokeh.versions?.has(version) && Bokeh.versions.get(version)?.Panel));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, Bokeh, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n if (Bokeh != undefined && !reloading) {\n const NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh[NewBokeh.version] = NewBokeh;\n Bokeh.versions.set(NewBokeh.version, NewBokeh);\n }\n root.Bokeh = Bokeh;\n }\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));"
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/javascript": [
- "\n",
- "if ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n",
- " window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n",
- "}\n",
- "\n",
- "\n",
- " function JupyterCommManager() {\n",
- " }\n",
- "\n",
- " JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n",
- " if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n",
- " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n",
- " comm_manager.register_target(comm_id, function(comm) {\n",
- " comm.on_msg(msg_handler);\n",
- " });\n",
- " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n",
- " window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n",
- " comm.onMsg = msg_handler;\n",
- " });\n",
- " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n",
- " google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n",
- " var messages = comm.messages[Symbol.asyncIterator]();\n",
- " function processIteratorResult(result) {\n",
- " var message = result.value;\n",
- " var content = {data: message.data, comm_id};\n",
- " var buffers = []\n",
- " for (var buffer of message.buffers || []) {\n",
- " buffers.push(new DataView(buffer))\n",
- " }\n",
- " var metadata = message.metadata || {};\n",
- " var msg = {content, buffers, metadata}\n",
- " msg_handler(msg);\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " return messages.next().then(processIteratorResult);\n",
- " })\n",
- " }\n",
- " }\n",
- "\n",
- " JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n",
- " if (comm_id in window.PyViz.comms) {\n",
- " return window.PyViz.comms[comm_id];\n",
- " } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n",
- " var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n",
- " var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n",
- " if (msg_handler) {\n",
- " comm.on_msg(msg_handler);\n",
- " }\n",
- " } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n",
- " var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n",
- " let retries = 0;\n",
- " const open = () => {\n",
- " if (comm.active) {\n",
- " comm.open();\n",
- " } else if (retries > 3) {\n",
- " console.warn('Comm target never activated')\n",
- " } else {\n",
- " retries += 1\n",
- " setTimeout(open, 500)\n",
- " }\n",
- " }\n",
- " if (comm.active) {\n",
- " comm.open();\n",
- " } else {\n",
- " setTimeout(open, 500)\n",
- " }\n",
- " if (msg_handler) {\n",
- " comm.onMsg = msg_handler;\n",
- " }\n",
- " } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n",
- " var comm_promise = google.colab.kernel.comms.open(comm_id)\n",
- " comm_promise.then((comm) => {\n",
- " window.PyViz.comms[comm_id] = comm;\n",
- " if (msg_handler) {\n",
- " var messages = comm.messages[Symbol.asyncIterator]();\n",
- " function processIteratorResult(result) {\n",
- " var message = result.value;\n",
- " var content = {data: message.data};\n",
- " var metadata = message.metadata || {comm_id};\n",
- " var msg = {content, metadata}\n",
- " msg_handler(msg);\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " return messages.next().then(processIteratorResult);\n",
- " }\n",
- " })\n",
- " var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n",
- " return comm_promise.then((comm) => {\n",
- " comm.send(data, metadata, buffers, disposeOnDone);\n",
- " });\n",
- " };\n",
- " var comm = {\n",
- " send: sendClosure\n",
- " };\n",
- " }\n",
- " window.PyViz.comms[comm_id] = comm;\n",
- " return comm;\n",
- " }\n",
- " window.PyViz.comm_manager = new JupyterCommManager();\n",
- " \n",
- "\n",
- "\n",
- "var JS_MIME_TYPE = 'application/javascript';\n",
- "var HTML_MIME_TYPE = 'text/html';\n",
- "var EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\n",
- "var CLASS_NAME = 'output';\n",
- "\n",
- "/**\n",
- " * Render data to the DOM node\n",
- " */\n",
- "function render(props, node) {\n",
- " var div = document.createElement(\"div\");\n",
- " var script = document.createElement(\"script\");\n",
- " node.appendChild(div);\n",
- " node.appendChild(script);\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle when a new output is added\n",
- " */\n",
- "function handle_add_output(event, handle) {\n",
- " var output_area = handle.output_area;\n",
- " var output = handle.output;\n",
- " if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
- " return\n",
- " }\n",
- " var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
- " var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
- " if (id !== undefined) {\n",
- " var nchildren = toinsert.length;\n",
- " var html_node = toinsert[nchildren-1].children[0];\n",
- " html_node.innerHTML = output.data[HTML_MIME_TYPE];\n",
- " var scripts = [];\n",
- " var nodelist = html_node.querySelectorAll(\"script\");\n",
- " for (var i in nodelist) {\n",
- " if (nodelist.hasOwnProperty(i)) {\n",
- " scripts.push(nodelist[i])\n",
- " }\n",
- " }\n",
- "\n",
- " scripts.forEach( function (oldScript) {\n",
- " var newScript = document.createElement(\"script\");\n",
- " var attrs = [];\n",
- " var nodemap = oldScript.attributes;\n",
- " for (var j in nodemap) {\n",
- " if (nodemap.hasOwnProperty(j)) {\n",
- " attrs.push(nodemap[j])\n",
- " }\n",
- " }\n",
- " attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n",
- " newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n",
- " oldScript.parentNode.replaceChild(newScript, oldScript);\n",
- " });\n",
- " if (JS_MIME_TYPE in output.data) {\n",
- " toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n",
- " }\n",
- " output_area._hv_plot_id = id;\n",
- " if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n",
- " window.PyViz.plot_index[id] = Bokeh.index[id];\n",
- " } else {\n",
- " window.PyViz.plot_index[id] = null;\n",
- " }\n",
- " } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
- " var bk_div = document.createElement(\"div\");\n",
- " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
- " var script_attrs = bk_div.children[0].attributes;\n",
- " for (var i = 0; i < script_attrs.length; i++) {\n",
- " toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
- " }\n",
- " // store reference to server id on output_area\n",
- " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
- " }\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle when an output is cleared or removed\n",
- " */\n",
- "function handle_clear_output(event, handle) {\n",
- " var id = handle.cell.output_area._hv_plot_id;\n",
- " var server_id = handle.cell.output_area._bokeh_server_id;\n",
- " if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n",
- " var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n",
- " if (server_id !== null) {\n",
- " comm.send({event_type: 'server_delete', 'id': server_id});\n",
- " return;\n",
- " } else if (comm !== null) {\n",
- " comm.send({event_type: 'delete', 'id': id});\n",
- " }\n",
- " delete PyViz.plot_index[id];\n",
- " if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n",
- " var doc = window.Bokeh.index[id].model.document\n",
- " doc.clear();\n",
- " const i = window.Bokeh.documents.indexOf(doc);\n",
- " if (i > -1) {\n",
- " window.Bokeh.documents.splice(i, 1);\n",
- " }\n",
- " }\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle kernel restart event\n",
- " */\n",
- "function handle_kernel_cleanup(event, handle) {\n",
- " delete PyViz.comms[\"hv-extension-comm\"];\n",
- " window.PyViz.plot_index = {}\n",
- "}\n",
- "\n",
- "/**\n",
- " * Handle update_display_data messages\n",
- " */\n",
- "function handle_update_output(event, handle) {\n",
- " handle_clear_output(event, {cell: {output_area: handle.output_area}})\n",
- " handle_add_output(event, handle)\n",
- "}\n",
- "\n",
- "function register_renderer(events, OutputArea) {\n",
- " function append_mime(data, metadata, element) {\n",
- " // create a DOM node to render to\n",
- " var toinsert = this.create_output_subarea(\n",
- " metadata,\n",
- " CLASS_NAME,\n",
- " EXEC_MIME_TYPE\n",
- " );\n",
- " this.keyboard_manager.register_events(toinsert);\n",
- " // Render to node\n",
- " var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
- " render(props, toinsert[0]);\n",
- " element.append(toinsert);\n",
- " return toinsert\n",
- " }\n",
- "\n",
- " events.on('output_added.OutputArea', handle_add_output);\n",
- " events.on('output_updated.OutputArea', handle_update_output);\n",
- " events.on('clear_output.CodeCell', handle_clear_output);\n",
- " events.on('delete.Cell', handle_clear_output);\n",
- " events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n",
- "\n",
- " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
- " safe: true,\n",
- " index: 0\n",
- " });\n",
- "}\n",
- "\n",
- "if (window.Jupyter !== undefined) {\n",
- " try {\n",
- " var events = require('base/js/events');\n",
- " var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
- " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
- " register_renderer(events, OutputArea);\n",
- " }\n",
- " } catch(err) {\n",
- " }\n",
- "}\n"
- ],
- "application/vnd.holoviews_load.v0+json": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n let retries = 0;\n const open = () => {\n if (comm.active) {\n comm.open();\n } else if (retries > 3) {\n console.warn('Comm target never activated')\n } else {\n retries += 1\n setTimeout(open, 500)\n }\n }\n if (comm.active) {\n comm.open();\n } else {\n setTimeout(open, 500)\n }\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n })\n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n}\n\n/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n"
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- " "
- ],
- "text/plain": [
- ":Overlay\n",
- " .Path.I :Path [Longitude,Latitude]\n",
- " .Coastline.I :Feature [Longitude,Latitude]"
- ]
- },
- "execution_count": 6,
- "metadata": {
- "application/vnd.holoviews_exec.v0+json": {}
- },
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"uxgrid.plot(\n",
" title=\"Structured Grid loaded using UXarray\",\n",
@@ -4305,7 +168,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": null,
"id": "7ed9a15c25a14c3e",
"metadata": {
"execution": {
@@ -4315,1726 +178,7 @@
"shell.execute_reply": "2026-07-13T21:58:50.540649Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<xarray.UxDataset> Size: 31MB\n",
- "Dimensions: (time: 2920, n_face: 1325)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00\n",
- "Dimensions without coordinates: n_face\n",
- "Data variables:\n",
- " air (time, n_face) float64 31MB 241.2 242.5 243.5 ... 296.5 296.2 295.7\n",
- "Attributes:\n",
- " Conventions: COARDS\n",
- " title: 4x daily NMC reanalysis (1948)\n",
- " description: Data is from NMC initialized reanalysis\\n(4x/day). These a...\n",
- " platform: Model\n",
- " references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly... \n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<xarray.UxDataset> Size: 31MB\n",
- "Dimensions: (time: 2920, n_face: 1325)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00\n",
- "Dimensions without coordinates: n_face\n",
- "Data variables:\n",
- " air (time, n_face) float64 31MB 241.2 242.5 243.5 ... 296.5 296.2 295.7\n",
- "Attributes:\n",
- " Conventions: COARDS\n",
- " title: 4x daily NMC reanalysis (1948)\n",
- " description: Data is from NMC initialized reanalysis\\n(4x/day). These a...\n",
- " platform: Model\n",
- " references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly... Dimensions: Coordinates: (1)
Data variables: (1)
Indexes: (1)
PandasIndex
PandasIndex(DatetimeIndex(['2013-01-01 00:00:00', '2013-01-01 06:00:00',\n",
- " '2013-01-01 12:00:00', '2013-01-01 18:00:00',\n",
- " '2013-01-02 00:00:00', '2013-01-02 06:00:00',\n",
- " '2013-01-02 12:00:00', '2013-01-02 18:00:00',\n",
- " '2013-01-03 00:00:00', '2013-01-03 06:00:00',\n",
- " ...\n",
- " '2014-12-29 12:00:00', '2014-12-29 18:00:00',\n",
- " '2014-12-30 00:00:00', '2014-12-30 06:00:00',\n",
- " '2014-12-30 12:00:00', '2014-12-30 18:00:00',\n",
- " '2014-12-31 00:00:00', '2014-12-31 06:00:00',\n",
- " '2014-12-31 12:00:00', '2014-12-31 18:00:00'],\n",
- " dtype='datetime64[ns]', name='time', length=2920, freq=None)) Attributes: (5)
Conventions : COARDS title : 4x daily NMC reanalysis (1948) description : Data is from NMC initialized reanalysis\n",
- "(4x/day). These are the 0.9950 sigma level values. platform : Model references : http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html Show Grid Information \n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<uxarray.Grid>\n",
- "Original Grid Type: Structured\n",
- "Grid Dimensions:\n",
- " * n_node: 1404\n",
- " * n_face: 1325\n",
- " * n_max_face_nodes: 4\n",
- "Grid Coordinates (Spherical):\n",
- " * node_lon: (1404,)\n",
- " * node_lat: (1404,)\n",
- "Grid Coordinates (Cartesian):\n",
- "Grid Connectivity Variables:\n",
- " * face_node_connectivity: (1325, 4)\n",
- "Grid Descriptor Variables:\n",
- " "
- ],
- "text/plain": [
- " Size: 31MB\n",
- "Dimensions: (time: 2920, n_face: 1325)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00\n",
- "Dimensions without coordinates: n_face\n",
- "Data variables:\n",
- " air (time, n_face) float64 31MB 241.2 242.5 243.5 ... 296.5 296.2 295.7\n",
- "Attributes:\n",
- " Conventions: COARDS\n",
- " title: 4x daily NMC reanalysis (1948)\n",
- " description: Data is from NMC initialized reanalysis\\n(4x/day). These a...\n",
- " platform: Model\n",
- " references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly..."
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"uxds = ux.UxDataset.from_structured(ds_air_temp)\n",
"uxds"
@@ -6042,7 +186,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": null,
"id": "8037fd0309774356",
"metadata": {
"execution": {
@@ -6052,25 +196,7 @@
"shell.execute_reply": "2026-07-13T21:58:53.189080Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- " "
- ],
- "text/plain": [
- ":Overlay\n",
- " .Image.I :Image [Longitude,Latitude] (Longitude_Latitude air)\n",
- " .Coastline.I :Feature [Longitude,Latitude]"
- ]
- },
- "execution_count": 8,
- "metadata": {
- "application/vnd.holoviews_exec.v0+json": {}
- },
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"uxds[\"air\"][0].plot(\n",
" title=\"Structured Grid with Data loaded using UXarray\",\n",
@@ -6080,1792 +206,6 @@
")"
]
},
- {
- "cell_type": "markdown",
- "id": "18e583bd",
- "metadata": {},
- "source": [
- "## Pairing a Structured Grid with an Existing Dataset\n",
- "\n",
- "The examples above build the ``Grid`` and the data together. A common workflow,\n",
- "though, is to keep an *interface layer* that reads either already-unstructured\n",
- "data (e.g. CAM-SE) or structured data (e.g. a regular lat/lon dataset) and\n",
- "standardizes both to UXarray, so everything downstream operates on unstructured\n",
- "data uniformly.\n",
- "\n",
- "For the structured case, build a ``Grid`` from the longitude/latitude\n",
- "coordinates and then attach an existing ``xarray.Dataset`` to it with\n",
- "``ux.UxDataset.from_xarray``. UXarray records the structured source dimensions\n",
- "on the grid, so the ``(lon, lat)`` data variables are automatically flattened\n",
- "onto ``n_face``."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "id": "29a4d6e6",
- "metadata": {
- "execution": {
- "iopub.execute_input": "2026-07-13T21:58:53.191104Z",
- "iopub.status.busy": "2026-07-13T21:58:53.190985Z",
- "iopub.status.idle": "2026-07-13T21:58:53.230695Z",
- "shell.execute_reply": "2026-07-13T21:58:53.230134Z"
- }
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<xarray.UxDataset> Size: 31MB\n",
- "Dimensions: (time: 2920, n_face: 1325)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00\n",
- " * n_face (n_face) object 11kB MultiIndex\n",
- " * lat (n_face) float32 5kB 75.0 75.0 75.0 75.0 ... 15.0 15.0 15.0 15.0\n",
- " * lon (n_face) float32 5kB 200.0 202.5 205.0 207.5 ... 325.0 327.5 330.0\n",
- "Data variables:\n",
- " air (time, n_face) float64 31MB 241.2 242.5 243.5 ... 296.5 296.2 295.7\n",
- "Attributes:\n",
- " Conventions: COARDS\n",
- " title: 4x daily NMC reanalysis (1948)\n",
- " description: Data is from NMC initialized reanalysis\\n(4x/day). These a...\n",
- " platform: Model\n",
- " references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly... \n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<xarray.UxDataset> Size: 31MB\n",
- "Dimensions: (time: 2920, n_face: 1325)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00\n",
- " * n_face (n_face) object 11kB MultiIndex\n",
- " * lat (n_face) float32 5kB 75.0 75.0 75.0 75.0 ... 15.0 15.0 15.0 15.0\n",
- " * lon (n_face) float32 5kB 200.0 202.5 205.0 207.5 ... 325.0 327.5 330.0\n",
- "Data variables:\n",
- " air (time, n_face) float64 31MB 241.2 242.5 243.5 ... 296.5 296.2 295.7\n",
- "Attributes:\n",
- " Conventions: COARDS\n",
- " title: 4x daily NMC reanalysis (1948)\n",
- " description: Data is from NMC initialized reanalysis\\n(4x/day). These a...\n",
- " platform: Model\n",
- " references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly... Dimensions: Coordinates: (4)
time
(time)
datetime64[ns]
2013-01-01 ... 2014-12-31T18:00:00
standard_name : time long_name : Time array(['2013-01-01T00:00:00.000000000', '2013-01-01T06:00:00.000000000',\n",
- " '2013-01-01T12:00:00.000000000', ..., '2014-12-31T06:00:00.000000000',\n",
- " '2014-12-31T12:00:00.000000000', '2014-12-31T18:00:00.000000000'],\n",
- " shape=(2920,), dtype='datetime64[ns]') n_face
(n_face)
object
MultiIndex
[1325 values with dtype=object] lat
(n_face)
float32
75.0 75.0 75.0 ... 15.0 15.0 15.0
standard_name : latitude long_name : Latitude units : degrees_north axis : Y [1325 values with dtype=float32] lon
(n_face)
float32
200.0 202.5 205.0 ... 327.5 330.0
standard_name : longitude long_name : Longitude units : degrees_east axis : X [1325 values with dtype=float32] Data variables: (1)
Indexes: (2)
PandasIndex
PandasIndex(DatetimeIndex(['2013-01-01 00:00:00', '2013-01-01 06:00:00',\n",
- " '2013-01-01 12:00:00', '2013-01-01 18:00:00',\n",
- " '2013-01-02 00:00:00', '2013-01-02 06:00:00',\n",
- " '2013-01-02 12:00:00', '2013-01-02 18:00:00',\n",
- " '2013-01-03 00:00:00', '2013-01-03 06:00:00',\n",
- " ...\n",
- " '2014-12-29 12:00:00', '2014-12-29 18:00:00',\n",
- " '2014-12-30 00:00:00', '2014-12-30 06:00:00',\n",
- " '2014-12-30 12:00:00', '2014-12-30 18:00:00',\n",
- " '2014-12-31 00:00:00', '2014-12-31 06:00:00',\n",
- " '2014-12-31 12:00:00', '2014-12-31 18:00:00'],\n",
- " dtype='datetime64[ns]', name='time', length=2920, freq=None)) PandasMultiIndex
PandasIndex(MultiIndex([(75.0, 200.0),\n",
- " (75.0, 202.5),\n",
- " (75.0, 205.0),\n",
- " (75.0, 207.5),\n",
- " (75.0, 210.0),\n",
- " (75.0, 212.5),\n",
- " (75.0, 215.0),\n",
- " (75.0, 217.5),\n",
- " (75.0, 220.0),\n",
- " (75.0, 222.5),\n",
- " ...\n",
- " (15.0, 307.5),\n",
- " (15.0, 310.0),\n",
- " (15.0, 312.5),\n",
- " (15.0, 315.0),\n",
- " (15.0, 317.5),\n",
- " (15.0, 320.0),\n",
- " (15.0, 322.5),\n",
- " (15.0, 325.0),\n",
- " (15.0, 327.5),\n",
- " (15.0, 330.0)],\n",
- " name='n_face', length=1325)) Attributes: (5)
Conventions : COARDS title : 4x daily NMC reanalysis (1948) description : Data is from NMC initialized reanalysis\n",
- "(4x/day). These are the 0.9950 sigma level values. platform : Model references : http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html Show Grid Information \n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- " \n",
- "
<uxarray.Grid>\n",
- "Original Grid Type: Structured\n",
- "Grid Dimensions:\n",
- " * n_node: 1404\n",
- " * n_face: 1325\n",
- " * n_max_face_nodes: 4\n",
- "Grid Coordinates (Spherical):\n",
- " * node_lon: (1404,)\n",
- " * node_lat: (1404,)\n",
- "Grid Coordinates (Cartesian):\n",
- "Grid Connectivity Variables:\n",
- " * face_node_connectivity: (1325, 4)\n",
- "Grid Descriptor Variables:\n",
- " "
- ],
- "text/plain": [
- " Size: 31MB\n",
- "Dimensions: (time: 2920, n_face: 1325)\n",
- "Coordinates:\n",
- " * time (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00\n",
- " * n_face (n_face) object 11kB MultiIndex\n",
- " * lat (n_face) float32 5kB 75.0 75.0 75.0 75.0 ... 15.0 15.0 15.0 15.0\n",
- " * lon (n_face) float32 5kB 200.0 202.5 205.0 207.5 ... 325.0 327.5 330.0\n",
- "Data variables:\n",
- " air (time, n_face) float64 31MB 241.2 242.5 243.5 ... 296.5 296.2 295.7\n",
- "Attributes:\n",
- " Conventions: COARDS\n",
- " title: 4x daily NMC reanalysis (1948)\n",
- " description: Data is from NMC initialized reanalysis\\n(4x/day). These a...\n",
- " platform: Model\n",
- " references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly..."
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Build the grid from the coordinates, then attach the existing Dataset.\n",
- "uxgrid = ux.Grid.from_structured(lon=ds_air_temp.lon, lat=ds_air_temp.lat)\n",
- "uxds = ux.UxDataset.from_xarray(ds_air_temp, uxgrid=uxgrid)\n",
- "uxds"
- ]
- },
{
"cell_type": "markdown",
"id": "fd230d36",
@@ -7878,7 +218,7 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": null,
"id": "ea421f23",
"metadata": {
"execution": {
@@ -7888,32 +228,7 @@
"shell.execute_reply": "2026-07-13T21:58:55.589853Z"
}
},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.\n"
- ]
- },
- {
- "data": {
- "text/html": [
- " "
- ],
- "text/plain": [
- ":Overlay\n",
- " .Image.I :Image [Longitude,Latitude] (Longitude_Latitude air)\n",
- " .Coastline.I :Feature [Longitude,Latitude]"
- ]
- },
- "execution_count": 10,
- "metadata": {
- "application/vnd.holoviews_exec.v0+json": {}
- },
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"# Regional subset around the central United States, enabled by the n_face mapping.\n",
"regional = uxds[\"air\"][0].subset.bounding_circle((-100.0, 40.0), 15)\n",
@@ -7957,7 +272,7 @@
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": null,
"id": "b6b872c3341c3eba",
"metadata": {
"execution": {
@@ -7982,7 +297,7 @@
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": null,
"id": "dd07e0e5848d5095",
"metadata": {
"execution": {
@@ -7992,25 +307,7 @@
"shell.execute_reply": "2026-07-13T21:58:58.228930Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- " "
- ],
- "text/plain": [
- ":Overlay\n",
- " .Image.I :Image [Longitude,Latitude] (Longitude_Latitude sst)\n",
- " .Coastline.I :Feature [Longitude,Latitude]"
- ]
- },
- "execution_count": 12,
- "metadata": {
- "application/vnd.holoviews_exec.v0+json": {}
- },
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"uxds[\"sst\"][0].plot(\n",
" projection=ccrs.Orthographic(central_latitude=60),\n",
@@ -8031,7 +328,7 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": null,
"id": "f9ded6909c6adc18",
"metadata": {
"execution": {
@@ -8041,25 +338,7 @@
"shell.execute_reply": "2026-07-13T21:59:06.010531Z"
}
},
- "outputs": [
- {
- "data": {
- "text/html": [
- " "
- ],
- "text/plain": [
- ":Overlay\n",
- " .Path.I :Path [Longitude,Latitude]\n",
- " .Coastline.I :Feature [Longitude,Latitude]"
- ]
- },
- "execution_count": 13,
- "metadata": {
- "application/vnd.holoviews_exec.v0+json": {}
- },
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"uxds.uxgrid.plot(\n",
" projection=ccrs.Orthographic(central_latitude=60),\n",
@@ -8074,9 +353,9 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "python314",
"language": "python",
- "name": "python3"
+ "name": "py314"
},
"language_info": {
"codemirror_mode": {
@@ -8088,7 +367,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.11.13"
+ "version": "3.14.6"
}
},
"nbformat": 4,
From 0fb5ef4d9f0339a12594b3519ae4d8945309cd6f Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Fri, 13 Nov 2026 11:51:21 -0500
Subject: [PATCH 08/10] refactor: _map_dims_to_ugrid crash if structured
(instead of putting the crash directly in every method that calls it.) Separately, create _map_structured_dims_to_ugrid, which is now used in UxDataset.from_structured in place of _map_dims_to_ugrid
---
uxarray/core/api.py | 23 ++----------
uxarray/core/dataarray.py | 13 ++-----
uxarray/core/dataset.py | 16 +++-----
uxarray/core/utils.py | 77 +++++++++++++++++++++++++++------------
4 files changed, 65 insertions(+), 64 deletions(-)
diff --git a/uxarray/core/api.py b/uxarray/core/api.py
index e5e7990a6..3170b1b8c 100644
--- a/uxarray/core/api.py
+++ b/uxarray/core/api.py
@@ -14,10 +14,9 @@
from uxarray.core.utils import (
_map_dataset_to_ugrid,
_open_dataset_with_fallback,
- _represents_structured_data,
match_chunks_to_ugrid,
)
-from uxarray.errors import DimensionError, GridInvalidError, GridsMismatchError
+from uxarray.errors import GridInvalidError, GridsMismatchError
from uxarray.grid import Grid
from uxarray.io._scrip import (
_detect_multigrid,
@@ -517,16 +516,8 @@ def open_dataset(
filename_or_obj, chunks=corrected_chunks, **kwargs
)
- if _represents_structured_data(uxgrid):
- raise DimensionError(
- "ux.open_dataset() is not intended for structured (lat/lon) grids or data, "
- f"but received a grid with source_grid_spec={uxgrid.source_grid_spec!r} "
- f"and dims {list(uxgrid._ds.dims)}. "
- "Consider UxDataset.from_structured() or Grid.from_structured() instead."
- )
-
# Map original dimensions to the UGRID conventions
- ds = _map_dataset_to_ugrid(ds, uxgrid)
+ ds = _map_dataset_to_ugrid(ds, uxgrid, _fname="ux.open_dataset")
# Create a UXarray Dataset by linking the Xarray Dataset with a UXarray Grid
source_datasets = (
@@ -632,19 +623,11 @@ def open_mfdataset(
grid_kwargs,
)
- if _represents_structured_data(uxgrid):
- raise DimensionError(
- "ux.open_mfdataset() is not intended for structured (lat/lon) grids or data, "
- f"but received a grid with source_grid_spec={uxgrid.source_grid_spec!r} "
- f"and dims {list(uxgrid._ds.dims)}. "
- "Consider UxDataset.from_structured(xarray.open_mfdataset(...)) instead."
- )
-
# Load the data as a Xarray Dataset
ds = xr.open_mfdataset(paths, chunks=corrected_chunks, **kwargs)
# Map original dimensions to the UGRID conventions
- ds = _map_dataset_to_ugrid(ds, uxgrid)
+ ds = _map_dataset_to_ugrid(ds, uxgrid, _fname="ux.open_mfdataset")
# Create a UXarray Dataset by linking the Xarray Dataset with a UXarray Grid
return UxDataset(ds, uxgrid=uxgrid, source_datasets=str(paths))
diff --git a/uxarray/core/dataarray.py b/uxarray/core/dataarray.py
index 2db25e56c..43ebd23ab 100644
--- a/uxarray/core/dataarray.py
+++ b/uxarray/core/dataarray.py
@@ -22,7 +22,6 @@
)
from uxarray.core.utils import (
_map_dims_to_ugrid,
- _represents_structured_data,
_resolve_coordinate_labels_to_indices,
_validate_indexers,
)
@@ -2432,16 +2431,10 @@ def from_xarray(cls, da: xr.DataArray, uxgrid: Grid, ugrid_dims: dict = None):
if ugrid_dims is None:
ugrid_dims = uxgrid._source_dims_dict
- if _represents_structured_data(uxgrid):
- raise DimensionError(
- "UxDataArray.from_xarray() is not intended for structured (lat/lon) grids or data, "
- f"but received a grid with source_grid_spec={uxgrid.source_grid_spec!r} "
- f"and dims {list(uxgrid._ds.dims)}. "
- "Consider UxDataset.from_structured(arr.to_dataset()).to_dataarray() instead."
- )
-
# map each dimension to its UGRID equivalent
- da = _map_dims_to_ugrid(da, ugrid_dims, uxgrid)
+ da = _map_dims_to_ugrid(
+ da, ugrid_dims, uxgrid, _fname="UxDataArray.from_xarray"
+ )
return cls(da, uxgrid=uxgrid)
diff --git a/uxarray/core/dataset.py b/uxarray/core/dataset.py
index 9836fc26f..1240ced89 100644
--- a/uxarray/core/dataset.py
+++ b/uxarray/core/dataset.py
@@ -16,8 +16,8 @@
from uxarray.core.dataarray import UxDataArray
from uxarray.core.utils import (
_map_dims_to_ugrid,
+ _map_structured_dims_to_ugrid,
_open_dataset_with_fallback,
- _represents_structured_data,
_resolve_coordinate_labels_to_indices,
_validate_indexers,
)
@@ -329,7 +329,9 @@ def from_structured(cls, ds: xr.Dataset):
uxgrid = Grid.from_dataset(ds)
- ds = _map_dims_to_ugrid(ds, uxgrid._source_dims_dict, uxgrid)
+ ds = _map_structured_dims_to_ugrid(
+ ds, uxgrid._source_dims_dict, uxgrid, _fname="UxDataset.from_structured"
+ )
# Drop spatial coordinates
coords_to_drop = [
@@ -369,16 +371,8 @@ def from_xarray(cls, ds: xr.Dataset, uxgrid: Grid = None, ugrid_dims: dict = Non
uxgrid = Grid.from_dataset(ds)
ugrid_dims = uxgrid._source_dims_dict
- if _represents_structured_data(uxgrid):
- raise DimensionError(
- "UxDataset.from_xarray() is not intended for structured (lat/lon) grids or data, "
- f"but received a grid with source_grid_spec={uxgrid.source_grid_spec!r} "
- f"and dims {list(uxgrid._ds.dims)}. "
- "Consider UxDataset.from_structured() instead."
- )
-
# map each dimension to its UGRID equivalent
- ds = _map_dims_to_ugrid(ds, ugrid_dims, uxgrid)
+ ds = _map_dims_to_ugrid(ds, ugrid_dims, uxgrid, _fname="UxDataset.from_xarray")
return cls(ds, uxgrid=uxgrid)
diff --git a/uxarray/core/utils.py b/uxarray/core/utils.py
index dd9cadbe7..f68d1c385 100644
--- a/uxarray/core/utils.py
+++ b/uxarray/core/utils.py
@@ -51,46 +51,43 @@ def _open_dataset_with_fallback(filename_or_obj, chunks=None, **kwargs):
raise fallback_error from default_engine_error
-def _represents_structured_data(grid):
- """returns whether this Grid corresponds with structured data,
- based on grid.source_grid_spec.
+def _map_dataset_to_ugrid(ds, grid, _fname):
+ """Map member dimensions without modifying the Grid's source mapping.
+ _fname: str
+ function name to use in error message, if received a structured grid.
"""
- return grid.source_grid_spec == "Structured"
-
-
-def _map_dataset_to_ugrid(ds, grid):
- """Map member dimensions without modifying the Grid's source mapping."""
source_dims = grid._source_dims_dict.copy()
# Already-standardized dimensions must not be inferred by size: nodes and
# faces can have equal counts. Preserve any explicit source mapping.
for dim in ("n_face", "n_node", "n_edge"):
if dim in ds.dims:
source_dims.setdefault(dim, dim)
- return _map_dims_to_ugrid(ds, source_dims, grid)
+ return _map_dims_to_ugrid(ds, source_dims, grid, _fname)
def _map_dims_to_ugrid(
ds,
_source_dims_dict,
grid,
+ _fname,
):
"""Given a dataset containing variables residing on an unstructured grid,
- remaps the original dimension name to match the UGRID conventions (i.e.
- "nCell": "n_face")"""
-
- if grid.source_grid_spec == "Structured":
- # Case for structured grids, flatten bottom two sptial dimensions
-
- lon_name, lat_name = _source_dims_dict["n_face"]
+ remaps the original dimension name to match the UGRID conventions (e.g.,
+ "nCell": "n_face")
- for var_name in ds.data_vars:
- if lon_name in ds[var_name].dims and lat_name in ds[var_name].dims:
- if ds[var_name].dims[-1] == lon_name:
- dim_ordered = [lat_name, lon_name]
- else:
- dim_ordered = [lon_name, lat_name]
+ _fname: str
+ function name to use in error message, if received a structured grid.
+ Error message starts like f"{_fname}() is not intended for structured grids or data"
+ """
- ds = ds.stack(n_face=dim_ordered)
+ if grid.source_grid_spec == "Structured":
+ # structured grids not supported here.
+ raise DimensionError(
+ f"{_fname}() is not intended for structured (lat/lon) grids or data, "
+ f"but received a grid with source_grid_spec={grid.source_grid_spec!r} "
+ f"and source dims mapping {_source_dims_dict}. For structured grids or data, "
+ "consider ux.UxDataset.from_structured() or ux.Grid.from_structured() instead."
+ )
elif grid.source_grid_spec == "GEOS-CS":
# stack dimensions to flatten them to map to nodes or faces
@@ -128,6 +125,40 @@ def _map_dims_to_ugrid(
return ds
+def _map_structured_dims_to_ugrid(ds, _source_dims_dict, grid, _fname):
+ """Given a dataset containing variables residing on a structured (lat/lon) grid,
+ remaps to an unstructured grid following UGRID conventions, by stacking lat/lon dims
+ according to _source_dims_dict.
+
+ _fname: str
+ function name to use in error message, if received an unstructured grid;
+ error message starts like f"{_fname}() is not intended for unstructured grids or data"
+ """
+
+ if grid.source_grid_spec == "Structured":
+ # Flatten bottom two sptial dimensions
+ lon_name, lat_name = _source_dims_dict["n_face"]
+
+ for var_name in ds.data_vars:
+ if lon_name in ds[var_name].dims and lat_name in ds[var_name].dims:
+ if ds[var_name].dims[-1] == lon_name:
+ dim_ordered = [lat_name, lon_name]
+ else:
+ dim_ordered = [lon_name, lat_name]
+
+ ds = ds.stack(n_face=dim_ordered)
+ else:
+ raise DimensionError(
+ f"{_fname}() is not intended for unstructured grids or data; "
+ f"expected a grid with source_grid_spec='Structured', "
+ f"but got source_grid_spec={grid.source_grid_spec!r}. "
+ "For unstructured grids or data, consider using other parts of the core API, "
+ "such as uxarray.open_dataset(), uxarray.open_grid(), UxDataset(), UxDataArray(), "
+ "UxDataset.from_xarray(), or UxDataArray.from_xarray(), instead."
+ )
+ return ds
+
+
def match_chunks_to_ugrid(grid_filename_or_obj, chunks):
"""Matches chunks to of the original dimensions to the UGRID conventions."""
From 4d729f0940fea77bd487dc4d33bcfd87ba054a82 Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Fri, 13 Nov 2026 12:38:16 -0500
Subject: [PATCH 09/10] open_grid GridStructureError if structured
- Adds GridStructureError, replacing DimensionError in _map_dims_to_ugrid and _map_structured_dims_to_ugrid.
- Ensures open_grid also crashes with GridStructureError if receiving structured inputs.
- moves _get_grid out of api.py, since the rest of api.py is just the public methods.
- renames test_from_xarray_with_grid_from_latlon to test_from_xarray_fails_with_grid_from_latlon as per reviewer request.
---
test/core/test_api.py | 37 +++++++++++---------
test/io/test_structured.py | 2 +-
uxarray/core/api.py | 65 ++++++++++------------------------
uxarray/core/utils.py | 72 ++++++++++++++++++++++++++++++++++++--
uxarray/errors.py | 4 +++
5 files changed, 113 insertions(+), 67 deletions(-)
diff --git a/test/core/test_api.py b/test/core/test_api.py
index defe0da05..714742e32 100644
--- a/test/core/test_api.py
+++ b/test/core/test_api.py
@@ -564,9 +564,10 @@ def test_open_dataset_with_fallback_chains_both_engine_errors(tmp_path):
)
-def test_open_dataset_fails_for_structured_inputs():
- """open_dataset() must crash with DimensionError when provided structured data."""
- ds = xr.Dataset(
+@pytest.fixture
+def _small_structured_dataset():
+ """Return a small structured dataset for testing."""
+ return xr.Dataset(
{
"var": (("lat", "lon"), np.arange(4*8).reshape(4, 8)),
},
@@ -576,27 +577,29 @@ def test_open_dataset_fails_for_structured_inputs():
},
)
- with pytest.raises(ux.errors.DimensionError, match=r"open_dataset\(\) is not intended for structured"):
- uxds = ux.open_dataset(ds, ds) # grid, data
+def test_open_grid_fails_for_structured_inputs(_small_structured_dataset):
+ """open_grid() must crash with GridStructureError when provided structured data."""
+ ds = _small_structured_dataset
+ with pytest.raises(ux.errors.GridStructureError, match=r"open_grid\(\) is not intended for structured"):
+ uxgrid = ux.open_grid(ds)
+
+
+def test_open_dataset_fails_for_structured_inputs(_small_structured_dataset):
+ """open_dataset() must crash with GridStructureError when provided structured data."""
+ ds = _small_structured_dataset
+ with pytest.raises(ux.errors.GridStructureError, match=r"open_dataset\(\) is not intended for structured"):
+ uxds = ux.open_dataset(ds, ds) # grid, data
-def test_open_mfdataset_warns_for_structured_inputs(tmp_path):
- """open_mfdataset() must raise a DimensionError when provided structured data."""
- ds = xr.Dataset(
- {
- "var": (("lat", "lon"), np.arange(4*8).reshape(4, 8)),
- },
- coords={
- "lat": ("lat", np.linspace(-80, 80, 4), {"standard_name": "latitude"}),
- "lon": ("lon", np.linspace(0, 350, 8), {"standard_name": "longitude"}),
- },
- )
+def test_open_mfdataset_warns_for_structured_inputs(tmp_path, _small_structured_dataset):
+ """open_mfdataset() must raise a GridStructureError when provided structured data."""
+ ds = _small_structured_dataset
# Write the dataset to a temporary netCDF file
temp_file = tmp_path / "temp.nc"
ds.to_netcdf(temp_file)
- with pytest.raises(ux.errors.DimensionError, match=r"open_mfdataset\(\) is not intended for structured"):
+ with pytest.raises(ux.errors.GridStructureError, match=r"open_mfdataset\(\) is not intended for structured"):
uxds = ux.open_mfdataset(ds, [temp_file]) # grid, [paths to data files]
diff --git a/test/io/test_structured.py b/test/io/test_structured.py
index 9a1e9c800..6a60a2612 100644
--- a/test/io/test_structured.py
+++ b/test/io/test_structured.py
@@ -39,7 +39,7 @@ def test_read_structured_uxds_from_ds(ds_name):
assert uxds.uxgrid.validate()
-def test_from_xarray_with_grid_from_latlon():
+def test_from_xarray_fails_with_grid_from_latlon():
"""from_xarray must crash upon receiving structured data; see PR #1887."""
ds = xr.tutorial.open_dataset("air_temperature")
diff --git a/uxarray/core/api.py b/uxarray/core/api.py
index 3170b1b8c..41d59b0a7 100644
--- a/uxarray/core/api.py
+++ b/uxarray/core/api.py
@@ -12,11 +12,12 @@
from uxarray.core.dataarray import UxDataArray
from uxarray.core.dataset import UxDataset
from uxarray.core.utils import (
+ _get_grid,
_map_dataset_to_ugrid,
_open_dataset_with_fallback,
match_chunks_to_ugrid,
)
-from uxarray.errors import GridInvalidError, GridsMismatchError
+from uxarray.errors import GridInvalidError, GridsMismatchError, GridStructureError
from uxarray.grid import Grid
from uxarray.io._scrip import (
_detect_multigrid,
@@ -137,6 +138,13 @@ def open_grid(
)
grid = Grid.from_dataset(grid_ds, use_dual=use_dual)
+ if grid.source_grid_spec == "Structured":
+ raise GridStructureError(
+ f"open_grid() is not intended for structured (lat/lon) grids or data, but "
+ f"received a grid with source_grid_spec={grid.source_grid_spec!r}. "
+ f"For structured grids, consider ux.Grid.from_structured() instead."
+ )
+
# Return the grid (and chunks, if requested) in a consistent manner.
if return_chunks:
return grid, chunks
@@ -493,12 +501,19 @@ def open_dataset(
"in ux.open_dataset(grid_filename_or_obj, filename_or_obj=None)."
)
- uxgrid, _ = _get_grid(ds, chunks, chunk_grid, use_dual, grid_kwargs)
+ uxgrid, _ = _get_grid(
+ ds, chunks, chunk_grid, use_dual, grid_kwargs, _fname="ux.open_dataset"
+ )
filename_or_obj = grid_filename_or_obj
else:
# Construct a Grid, validate parameters, and correct chunks
uxgrid, corrected_chunks = _get_grid(
- grid_filename_or_obj, chunks, chunk_grid, use_dual, grid_kwargs
+ grid_filename_or_obj,
+ chunks,
+ chunk_grid,
+ use_dual,
+ grid_kwargs,
+ _fname="ux.open_dataset",
)
# Load the data as a Xarray Dataset
@@ -621,6 +636,7 @@ def open_mfdataset(
chunk_grid,
use_dual,
grid_kwargs,
+ _fname="ux.open_mfdataset",
)
# Load the data as a Xarray Dataset
@@ -633,49 +649,6 @@ def open_mfdataset(
return UxDataset(ds, uxgrid=uxgrid, source_datasets=str(paths))
-def _get_grid(
- grid_filename_or_obj,
- chunks,
- chunk_grid,
- use_dual,
- grid_kwargs,
-):
- """Validate input parameters and return the ``(grid, chunks)`` tuple."""
- if isinstance(grid_filename_or_obj, Grid):
- if use_dual:
- raise ValueError(
- "use_dual=True is not supported with an existing Grid. "
- "Select the desired mesh when constructing the Grid."
- )
- if grid_kwargs:
- raise ValueError(
- "grid_kwargs must be empty when passing an existing Grid. "
- "Apply these options when constructing the Grid."
- )
- if chunks is not None and chunk_grid:
- raise ValueError(
- "Providing Grid, non-None chunks, and chunk_grid=True simultaneously "
- "is not supported. Call Grid.chunk() explicitly to change the grid's "
- "chunking, or set chunk_grid=False to chunk only the data."
- )
- if isinstance(chunks, dict):
- # Keep the caller's options and the shared Grid unchanged. Match
- # UGRID chunk keys to the data's source dimensions without grid I/O.
- requested_chunks = chunks
- chunks = chunks.copy()
- for source_dim, ugrid_dim in grid_filename_or_obj._source_dims_dict.items():
- if isinstance(ugrid_dim, str) and ugrid_dim in requested_chunks:
- chunks[source_dim] = requested_chunks[ugrid_dim]
- return grid_filename_or_obj, chunks
-
- grid_kwargs["data_chunks"] = chunks
- grid_kwargs["chunk_grid"] = chunk_grid
- grid_kwargs["return_chunks"] = True
-
- # Create a Grid
- return open_grid(grid_filename_or_obj, use_dual=use_dual, **grid_kwargs)
-
-
def concat(
objs: Iterable[UxDataArray | UxDataset],
dim: Hashable | xr.Variable | xr.DataArray | pd.Index,
diff --git a/uxarray/core/utils.py b/uxarray/core/utils.py
index f68d1c385..90261223b 100644
--- a/uxarray/core/utils.py
+++ b/uxarray/core/utils.py
@@ -5,7 +5,12 @@
from xarray.core.utils import either_dict_or_kwargs
from uxarray.constants import GRID_DIMS
-from uxarray.errors import DataCenteringError, DimensionError, GridsMismatchError
+from uxarray.errors import (
+ DataCenteringError,
+ DimensionError,
+ GridsMismatchError,
+ GridStructureError,
+)
from uxarray.io.utils import _get_source_dims_dict, _parse_grid_type
@@ -51,6 +56,67 @@ def _open_dataset_with_fallback(filename_or_obj, chunks=None, **kwargs):
raise fallback_error from default_engine_error
+def _get_grid(
+ grid_filename_or_obj,
+ chunks,
+ chunk_grid,
+ use_dual,
+ grid_kwargs,
+ _fname=None,
+):
+ """Validate input parameters and return the ``(grid, chunks)`` tuple.
+ _fname: None or str
+ function name to use in error message, if open_grid crashes with GridStructureError.
+ None --> simply re-raise the original GridStructureError.
+ str --> raise a new GridStructureError with a (hopefully) more helpful message.
+ """
+ from uxarray import Grid, open_grid
+
+ if isinstance(grid_filename_or_obj, Grid):
+ if use_dual:
+ raise ValueError(
+ "use_dual=True is not supported with an existing Grid. "
+ "Select the desired mesh when constructing the Grid."
+ )
+ if grid_kwargs:
+ raise ValueError(
+ "grid_kwargs must be empty when passing an existing Grid. "
+ "Apply these options when constructing the Grid."
+ )
+ if chunks is not None and chunk_grid:
+ raise ValueError(
+ "Providing Grid, non-None chunks, and chunk_grid=True simultaneously "
+ "is not supported. Call Grid.chunk() explicitly to change the grid's "
+ "chunking, or set chunk_grid=False to chunk only the data."
+ )
+ if isinstance(chunks, dict):
+ # Keep the caller's options and the shared Grid unchanged. Match
+ # UGRID chunk keys to the data's source dimensions without grid I/O.
+ requested_chunks = chunks
+ chunks = chunks.copy()
+ for source_dim, ugrid_dim in grid_filename_or_obj._source_dims_dict.items():
+ if isinstance(ugrid_dim, str) and ugrid_dim in requested_chunks:
+ chunks[source_dim] = requested_chunks[ugrid_dim]
+ return grid_filename_or_obj, chunks
+
+ grid_kwargs["data_chunks"] = chunks
+ grid_kwargs["chunk_grid"] = chunk_grid
+ grid_kwargs["return_chunks"] = True
+
+ # Create a Grid
+ try:
+ return open_grid(grid_filename_or_obj, use_dual=use_dual, **grid_kwargs)
+ except GridStructureError:
+ if _fname is None:
+ raise
+ else:
+ raise GridStructureError(
+ f"{_fname}() is not intended for structured (lat/lon) grids or data, but "
+ f"received a grid with source_grid_spec='Structured'. For structured grids or data, "
+ "consider ux.UxDataset.from_structured() or ux.Grid.from_structured() instead."
+ )
+
+
def _map_dataset_to_ugrid(ds, grid, _fname):
"""Map member dimensions without modifying the Grid's source mapping.
_fname: str
@@ -82,7 +148,7 @@ def _map_dims_to_ugrid(
if grid.source_grid_spec == "Structured":
# structured grids not supported here.
- raise DimensionError(
+ raise GridStructureError(
f"{_fname}() is not intended for structured (lat/lon) grids or data, "
f"but received a grid with source_grid_spec={grid.source_grid_spec!r} "
f"and source dims mapping {_source_dims_dict}. For structured grids or data, "
@@ -148,7 +214,7 @@ def _map_structured_dims_to_ugrid(ds, _source_dims_dict, grid, _fname):
ds = ds.stack(n_face=dim_ordered)
else:
- raise DimensionError(
+ raise GridStructureError(
f"{_fname}() is not intended for unstructured grids or data; "
f"expected a grid with source_grid_spec='Structured', "
f"but got source_grid_spec={grid.source_grid_spec!r}. "
diff --git a/uxarray/errors.py b/uxarray/errors.py
index c1f3b5131..d4650f264 100644
--- a/uxarray/errors.py
+++ b/uxarray/errors.py
@@ -33,6 +33,10 @@ class GridsMismatchError(ValueError):
"""attempted to perform an operation involving two incompatible uxarray.Grid objects"""
+class GridStructureError(DimensionError):
+ """received structured grid/data but expected unstructured grid/data, or vice versa."""
+
+
# # # ----- Io-type-specific Errors ----- # # #
From 563e94a73bb609e4ff5579229fa8b531e19b1f61 Mon Sep 17 00:00:00 2001
From: Sam Evans <47793072+Sevans711@users.noreply.github.com>
Date: Fri, 13 Nov 2026 12:49:35 -0500
Subject: [PATCH 10/10] (readthedocs didn't auto-fix jupyer kernel)
(and, saving an open notebook leaks your environment name / kernel into the save file, so when I saved in a previous commit it overwrote the original.)
---
docs/user-guide/structured.ipynb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/user-guide/structured.ipynb b/docs/user-guide/structured.ipynb
index 121b8dadd..c95cda042 100644
--- a/docs/user-guide/structured.ipynb
+++ b/docs/user-guide/structured.ipynb
@@ -353,9 +353,9 @@
],
"metadata": {
"kernelspec": {
- "display_name": "python314",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
- "name": "py314"
+ "name": "python3"
},
"language_info": {
"codemirror_mode": {
@@ -367,7 +367,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.14.6"
+ "version": "3.11.15"
}
},
"nbformat": 4,