def test_transform_coordinates(self): desired_min_maxes = [[-0.9330127018922193, 0.93301270189221941], [-0.93301270189221941, 0.93301270189221941], [-0.96592582628906831, 0.96592582628906831]] keywords = {'wrapped': [ False, True ], 'angular_units': [ OcgisUnits.DEGREES, OcgisUnits.RADIANS ], 'other_crs': [ Cartesian(), WGS84() ] } for k in self.iter_product_keywords(keywords): spherical = Spherical(angular_units=k.angular_units) tp = Tripole(spherical=spherical) grid = create_gridxy_global(resolution=30.0, wrapped=k.wrapped) if not k.wrapped: x_value = grid.x.get_value() select = x_value > 180. x_value[select] -= 360. grid.expand() x = grid.x.get_value() y = grid.y.get_value() if k.angular_units == OcgisUnits.RADIANS: x *= ConversionFactor.DEG_TO_RAD y *= ConversionFactor.DEG_TO_RAD z = np.ones(x.shape, dtype=x.dtype) desired = (x, y, z) try: as_cart = tp.transform_coordinates(k.other_crs, x, y, z) except CRSNotEquivalenError: self.assertNotEqual(k.other_crs, Cartesian()) continue x_cart, y_cart, z_cart = as_cart for idx, ii in enumerate(as_cart): actual_min_max = [ii.min(), ii.max()] self.assertNumpyAllClose(np.array(actual_min_max), np.array(desired_min_maxes[idx])) actual = tp.transform_coordinates(k.other_crs, x_cart, y_cart, z_cart, inverse=True) for a, d in zip(actual, desired): are = np.abs(a - d) self.assertLessEqual(are.max(), 1e-6)
def test_transform_coordinates(self): desired_min_maxes = [[-0.9330127018922193, 0.93301270189221941], [-0.93301270189221941, 0.93301270189221941], [-0.96592582628906831, 0.96592582628906831]] keywords = { 'wrapped': [False, True], 'angular_units': [OcgisUnits.DEGREES, OcgisUnits.RADIANS], 'other_crs': [Cartesian(), WGS84()] } for k in self.iter_product_keywords(keywords): spherical = Spherical(angular_units=k.angular_units) tp = Tripole(spherical=spherical) grid = create_gridxy_global(resolution=30.0, wrapped=k.wrapped) if not k.wrapped: x_value = grid.x.get_value() select = x_value > 180. x_value[select] -= 360. grid.expand() x = grid.x.get_value() y = grid.y.get_value() if k.angular_units == OcgisUnits.RADIANS: x *= ConversionFactor.DEG_TO_RAD y *= ConversionFactor.DEG_TO_RAD z = np.ones(x.shape, dtype=x.dtype) desired = (x, y, z) try: as_cart = tp.transform_coordinates(k.other_crs, x, y, z) except CRSNotEquivalenError: self.assertNotEqual(k.other_crs, Cartesian()) continue x_cart, y_cart, z_cart = as_cart for idx, ii in enumerate(as_cart): actual_min_max = [ii.min(), ii.max()] self.assertNumpyAllClose(np.array(actual_min_max), np.array(desired_min_maxes[idx])) actual = tp.transform_coordinates(k.other_crs, x_cart, y_cart, z_cart, inverse=True) for a, d in zip(actual, desired): are = np.abs(a - d) self.assertLessEqual(are.max(), 1e-6)
def test_crs_with_dimension_map(self): """Test CRS overloading in the presence of a dimension map.""" field = self.get_field() path = self.get_temporary_file_path('foo.nc') field.write(path) dmap = {DimensionMapKey.X: {DimensionMapKey.VARIABLE: 'col'}, DimensionMapKey.Y: {DimensionMapKey.VARIABLE: 'row'}} rd = RequestDataset(path, dimension_map=dmap, crs=Tripole()) field = rd.get() self.assertIsInstance(field.crs, Tripole)
def test_init(self): Tripole()