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

Class SimpleCoordinateTransform

xarray/tests/test_coordinate_transform.py:13–43  ·  view source on GitHub ↗

Simple uniform scale transform in a 2D space (x/y coordinates).

Source from the content-addressed store, hash-verified

11
12
13class SimpleCoordinateTransform(CoordinateTransform):
14 """Simple uniform scale transform in a 2D space (x/y coordinates)."""
15
16 def __init__(self, shape: tuple[int, int], scale: float, dtype: Any = None):
17 super().__init__(("x", "y"), {"x": shape[1], "y": shape[0]}, dtype=dtype)
18
19 self.scale = scale
20
21 # array dimensions in reverse order (y = rows, x = cols)
22 self.xy_dims = tuple(self.dims)
23 self.dims = (self.dims[1], self.dims[0])
24
25 def forward(self, dim_positions: dict[str, Any]) -> dict[Hashable, Any]:
26 assert set(dim_positions) == set(self.dims)
27 return {
28 name: dim_positions[dim] * self.scale
29 for name, dim in zip(self.coord_names, self.xy_dims, strict=False)
30 }
31
32 def reverse(self, coord_labels: dict[Hashable, Any]) -> dict[str, Any]:
33 return {dim: coord_labels[dim] / self.scale for dim in self.xy_dims}
34
35 def equals(
36 self, other: CoordinateTransform, exclude: frozenset[Hashable] | None = None
37 ) -> bool:
38 if not isinstance(other, SimpleCoordinateTransform):
39 return False
40 return self.scale == other.scale
41
42 def __repr__(self) -> str:
43 return f"Scale({self.scale})"
44
45
46def test_abstract_coordinate_transform() -> None:

Callers 3

create_coordsFunction · 0.85

Calls

no outgoing calls

Tested by 3

create_coordsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…