Return a normalized number array for the unique levels. Examples -------- >>> a = xr.DataArray(["b", "a", "a", "b", "c"]) >>> _Normalize(a).values Size: 40B array([3, 1, 1, 3, 5]) Dimensions without coord
(self)
| 1501 | |
| 1502 | @property |
| 1503 | def values(self) -> DataArray | None: |
| 1504 | """ |
| 1505 | Return a normalized number array for the unique levels. |
| 1506 | |
| 1507 | Examples |
| 1508 | -------- |
| 1509 | >>> a = xr.DataArray(["b", "a", "a", "b", "c"]) |
| 1510 | >>> _Normalize(a).values |
| 1511 | <xarray.DataArray (dim_0: 5)> Size: 40B |
| 1512 | array([3, 1, 1, 3, 5]) |
| 1513 | Dimensions without coordinates: dim_0 |
| 1514 | |
| 1515 | >>> _Normalize(a, width=(18, 36, 72)).values |
| 1516 | <xarray.DataArray (dim_0: 5)> Size: 40B |
| 1517 | array([45., 18., 18., 45., 72.]) |
| 1518 | Dimensions without coordinates: dim_0 |
| 1519 | |
| 1520 | >>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3]) |
| 1521 | >>> _Normalize(a).values |
| 1522 | <xarray.DataArray (dim_0: 6)> Size: 48B |
| 1523 | array([0.5, 0. , 0. , 0.5, 2. , 3. ]) |
| 1524 | Dimensions without coordinates: dim_0 |
| 1525 | |
| 1526 | >>> _Normalize(a, width=(18, 36, 72)).values |
| 1527 | <xarray.DataArray (dim_0: 6)> Size: 48B |
| 1528 | array([27., 18., 18., 27., 54., 72.]) |
| 1529 | Dimensions without coordinates: dim_0 |
| 1530 | |
| 1531 | >>> _Normalize(a * 0, width=(18, 36, 72)).values |
| 1532 | <xarray.DataArray (dim_0: 6)> Size: 48B |
| 1533 | array([36., 36., 36., 36., 36., 36.]) |
| 1534 | Dimensions without coordinates: dim_0 |
| 1535 | |
| 1536 | """ |
| 1537 | if self.data is None: |
| 1538 | return None |
| 1539 | |
| 1540 | val: DataArray |
| 1541 | if self.data_is_numeric: |
| 1542 | val = self.data |
| 1543 | else: |
| 1544 | arr = self._indexes_centered(self._data_unique_inverse) |
| 1545 | val = self.data.copy(data=arr.reshape(self.data.shape)) |
| 1546 | |
| 1547 | return self._calc_widths(val) |
| 1548 | |
| 1549 | @property |
| 1550 | def _values_unique(self) -> np.ndarray | None: |