def _xarray_affine_impl(obj): sdims = spatial_dims(obj, relaxed=True) if sdims is None: return None, None yy, xx = (obj[dim] for dim in sdims) fallback_res = (coord.attrs.get('resolution', None) for coord in (xx, yy)) return affine_from_axis(xx.values, yy.values, fallback_res), sdims
def test_utils_affine_from_axis(): assert affine_from_axis(np.asarray([1.5, 2.5, 3.5]), np.asarray([10.5, 11.5])) * (0, 0) == (1.0, 10.0) assert affine_from_axis(np.asarray([1.5, 2.5, 3.5]), np.asarray([10.5, 11.5])) * (2, 1) == (3, 11) (sx, z1, tx, z2, sy, ty, *_) = affine_from_axis(np.asarray([1, 2, 3]), np.asarray([10, 20])) assert z1 == 0 and z2 == 0 assert sx == 1 and sy == 10 assert tx == 0.5 and ty == 5 (sx, _, tx, _, sy, ty, *_) = affine_from_axis(np.asarray([1]), np.asarray([10, 20]), 1) assert sx == 1 and sy == 10 assert tx == 0.5 and ty == 5 (sx, _, tx, _, sy, ty, *_) = affine_from_axis(np.asarray([1]), np.asarray([10, 20]), (1, 1)) assert sx == 1 and sy == 10 assert tx == 0.5 and ty == 5 (sx, _, tx, _, sy, ty, *_) = affine_from_axis(np.asarray([1]), np.asarray([10]), (2, 10)) assert sx == 2 and sy == 10 assert tx == 0 and ty == 5