MCPcopy
hub / github.com/pydata/xarray / _temp_dataarray

Function _temp_dataarray

xarray/plot/dataset_plot.py:725–752  ·  view source on GitHub ↗

Create a temporary datarray with extra coords.

(ds: Dataset, y: Hashable, locals_: dict[str, Any])

Source from the content-addressed store, hash-verified

723
724
725def _temp_dataarray(ds: Dataset, y: Hashable, locals_: dict[str, Any]) -> DataArray:
726 """Create a temporary datarray with extra coords."""
727 from xarray.core.dataarray import DataArray
728
729 coords = dict(ds[y].coords)
730 dims = set(ds[y].dims)
731
732 # Add extra coords to the DataArray from valid kwargs, if using all
733 # kwargs there is a risk that we add unnecessary dataarrays as
734 # coords straining RAM further for example:
735 # ds.both and extend="both" would add ds.both to the coords:
736 valid_coord_kwargs = {"x", "z", "markersize", "hue", "row", "col", "u", "v"}
737 coord_kwargs = locals_.keys() & valid_coord_kwargs
738 for k in coord_kwargs:
739 key = locals_[k]
740 darray = ds.get(key)
741 if darray is not None:
742 coords[key] = darray
743 dims.update(darray.dims)
744
745 # Trim dataset from unnecessary dims:
746 ds_trimmed = ds.drop_dims(ds.sizes.keys() - dims) # TODO: Use ds.dims in the future
747
748 # The dataarray has to include all the dims. Broadcast to that shape
749 # and add the additional coords:
750 _y = ds[y].broadcast_like(ds_trimmed)
751
752 return DataArray(_y, coords=coords)
753
754
755@overload

Callers 2

test_temp_dataarrayFunction · 0.90
scatterFunction · 0.85

Calls 6

DataArrayClass · 0.90
keysMethod · 0.80
getMethod · 0.45
updateMethod · 0.45
drop_dimsMethod · 0.45
broadcast_likeMethod · 0.45

Tested by 1

test_temp_dataarrayFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…