MCPcopy Index your code
hub / github.com/pydata/xarray / _Normalize

Class _Normalize

xarray/plot/utils.py:1367–1679  ·  view source on GitHub ↗

Normalize numerical or categorical values to numerical values. The class includes helper methods that simplifies transforming to and from normalized values. Parameters ---------- data : DataArray DataArray to normalize. width : Sequence of three numbers, option

Source from the content-addressed store, hash-verified

1365
1366
1367class _Normalize(Sequence):
1368 """
1369 Normalize numerical or categorical values to numerical values.
1370
1371 The class includes helper methods that simplifies transforming to
1372 and from normalized values.
1373
1374 Parameters
1375 ----------
1376 data : DataArray
1377 DataArray to normalize.
1378 width : Sequence of three numbers, optional
1379 Normalize the data to these (min, default, max) values.
1380 The default is None.
1381 """
1382
1383 _data: DataArray | None
1384 _data_unique: np.ndarray
1385 _data_unique_index: np.ndarray
1386 _data_unique_inverse: np.ndarray
1387 _data_is_numeric: bool
1388 _width: tuple[float, float, float] | None
1389
1390 __slots__ = (
1391 "_data",
1392 "_data_is_numeric",
1393 "_data_unique",
1394 "_data_unique_index",
1395 "_data_unique_inverse",
1396 "_width",
1397 )
1398
1399 def __init__(
1400 self,
1401 data: DataArray | None,
1402 width: tuple[float, float, float] | None = None,
1403 _is_facetgrid: bool = False,
1404 ) -> None:
1405 self._data = data
1406 self._width = width if not _is_facetgrid else None
1407
1408 pint_array_type = DuckArrayModule("pint").type
1409 to_unique = (
1410 data.to_numpy() # type: ignore[union-attr]
1411 if isinstance(data if data is None else data.data, pint_array_type)
1412 else data
1413 )
1414 data_unique, data_unique_inverse = np.unique(to_unique, return_inverse=True) # type: ignore[call-overload]
1415 self._data_unique = data_unique
1416 self._data_unique_index = np.arange(0, data_unique.size)
1417 self._data_unique_inverse = data_unique_inverse
1418 self._data_is_numeric = False if data is None else _is_numeric(data)
1419
1420 def __repr__(self) -> str:
1421 with np.printoptions(precision=4, suppress=True, threshold=5):
1422 return (
1423 f"<_Normalize(data, width={self._width})>\n"
1424 f"{self._data_unique} -> {self._values_unique}"

Callers 2

newplotfuncFunction · 0.90
map_plot1dMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…