def test_set_variable(self): var = Variable(name='test', value=[1, 2], dimensions='two') dmap = DimensionMap() dmap.set_variable(DMK.X, var, dimension='not_two') actual = dmap.get_dimension(DMK.X) desired = ['not_two'] self.assertEqual(actual, desired) # Test setting with a variable and bounds. var = Variable(name='center', value=[1, 2, 3], dtype=float, dimensions='one') var.set_extrapolated_bounds('bounds_data', 'bounds') dmap = DimensionMap() dmap.set_variable(DMK.Y, var) self.assertEqual(dmap.get_bounds(DMK.Y), var.bounds.name) new_var = Variable(name='new_center', value=[1, 2, 3], dtype=float, dimensions='one') dmap.set_variable(DMK.Y, new_var) self.assertIsNone(dmap.get_bounds(DMK.Y)) # Test a dimension position argument is needed if the variable has more than one dimension. var = Variable(name='two_dims', value=np.zeros((4, 5)), dimensions=['one', 'two']) dmap = DimensionMap() with self.assertRaises(DimensionMapError): dmap.set_variable(DMK.X, var) dmap.set_variable(DMK.X, var, pos=1) self.assertEqual(dmap.get_dimension(DMK.X), ['two']) # Test a scalar dimension. var = Variable(name='scalar_dimension', dimensions=[]) dmap = DimensionMap() dmap.set_variable(DMK.LEVEL, var) self.assertEqual(dmap.get_variable(DMK.LEVEL), 'scalar_dimension') self.assertIsNone(dmap.get_bounds(DMK.LEVEL)) self.assertEqual(dmap.get_dimension(DMK.LEVEL), []) # Test dimensionless variable. var = Variable(name='two_dims', value=np.zeros((4, 5)), dimensions=['one', 'two']) dmap = DimensionMap() dmap.set_variable(DMK.X, var, dimensionless=True) self.assertEqual(dmap.get_dimension(DMK.X), [])
def test(self): dmap = DimensionMap() _ = dmap.get_variable('x') _ = dmap.get_dimension('x') _ = dmap.get_attrs('x') _ = dmap.get_bounds('x') dmap.set_variable('y', 'latitude', dimension='ache', bounds='lat_bounds') _ = dmap.get_crs() dmap.set_crs('latitude_longitude') desired = {'crs': {'variable': 'latitude_longitude'}, 'x': {'attrs': {}, 'bounds': None, 'dimension': [], 'variable': None}, 'y': {'attrs': {}, 'bounds': 'lat_bounds', 'dimension': ['ache'], 'variable': 'latitude'}} self.assertDictEqual(dmap._storage, desired)
def test(self): dmap = DimensionMap() _ = dmap.get_variable('x') _ = dmap.get_dimension('x') _ = dmap.get_attrs('x') _ = dmap.get_bounds('x') dmap.set_variable('y', 'latitude', dimension='ache', bounds='lat_bounds') _ = dmap.get_crs() dmap.set_crs('latitude_longitude') desired = { 'crs': { 'variable': 'latitude_longitude' }, 'x': { 'attrs': {}, 'bounds': None, 'dimension': [], 'variable': None }, 'y': { 'attrs': { 'axis': 'Y' }, 'bounds': 'lat_bounds', 'dimension': ['ache'], 'variable': 'latitude' } } self.assertDictEqual(dmap._storage, desired)