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

Function create_transform_da

properties/test_coordinate_transform.py:42–59  ·  view source on GitHub ↗

Create a DataArray with IdentityTransform CoordinateTransformIndex.

(sizes: dict[str, int])

Source from the content-addressed store, hash-verified

40
41
42def create_transform_da(sizes: dict[str, int]) -> xr.DataArray:
43 """Create a DataArray with IdentityTransform CoordinateTransformIndex."""
44 dims = list(sizes.keys())
45 shape = tuple(sizes.values())
46 data = np.arange(np.prod(shape)).reshape(shape)
47
48 # Create dataset with transform index for each dimension
49 ds = xr.Dataset({DATA_VAR_NAME: (dims, data)})
50 indexes = [
51 xr.Coordinates.from_xindex(
52 CoordinateTransformIndex(
53 IdentityTransform((dim,), {dim: size}, dtype=np.dtype(np.int64))
54 )
55 )
56 for dim, size in sizes.items()
57 ]
58 coords = functools.reduce(operator.or_, indexes)
59 return ds.assign_coords(coords).get(DATA_VAR_NAME)
60
61
62def create_pandas_da(sizes: dict[str, int]) -> xr.DataArray:

Callers 3

test_basic_indexingFunction · 0.85
test_outer_indexingFunction · 0.85
test_vectorized_indexingFunction · 0.85

Calls 12

IdentityTransformClass · 0.85
keysMethod · 0.80
arangeMethod · 0.80
from_xindexMethod · 0.80
itemsMethod · 0.80
valuesMethod · 0.45
prodMethod · 0.45
dtypeMethod · 0.45
reduceMethod · 0.45
getMethod · 0.45
assign_coordsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…