コード例 #1
0
ファイル: test_dimension_map.py プロジェクト: moghimis/ocgis
    def test_set_spatial_mask(self):
        dmap = DimensionMap()
        dims = Dimension('x', 3), Dimension('y', 7)
        mask_var = create_spatial_mask_variable('a_mask', None, dims)
        self.assertFalse(np.any(mask_var.get_mask()))
        dmap.set_spatial_mask(mask_var)
        self.assertEqual(dmap.get_spatial_mask(), mask_var.name)

        with self.assertRaises(DimensionMapError):
            dmap.set_variable(DMK.SPATIAL_MASK, mask_var)

        # Test custom variables may be used.
        dmap = DimensionMap()
        dims = Dimension('x', 3), Dimension('y', 7)
        mask_var = create_spatial_mask_variable('a_mask', None, dims)
        attrs = {'please keep me': 'no overwriting'}
        dmap.set_spatial_mask(mask_var, attrs=attrs)
        attrs = dmap.get_attrs(DMK.SPATIAL_MASK)
        self.assertIn('please keep me', attrs)

        # Test default attributes are not added.
        dmap = DimensionMap()
        dmap.set_spatial_mask('foo', default_attrs={'blue': 'world'})
        prop = dmap.get_property(DMK.SPATIAL_MASK)
        self.assertEqual(prop['attrs'], {'blue': 'world'})
コード例 #2
0
ファイル: test_dimension_map.py プロジェクト: NCPP/ocgis
    def test_set_spatial_mask(self):
        dmap = DimensionMap()
        dims = Dimension('x', 3), Dimension('y', 7)
        mask_var = create_spatial_mask_variable('a_mask', None, dims)
        self.assertFalse(np.any(mask_var.get_mask()))
        dmap.set_spatial_mask(mask_var)
        self.assertEqual(dmap.get_spatial_mask(), mask_var.name)

        with self.assertRaises(DimensionMapError):
            dmap.set_variable(DMK.SPATIAL_MASK, mask_var)

        # Test custom variables may be used.
        dmap = DimensionMap()
        dims = Dimension('x', 3), Dimension('y', 7)
        mask_var = create_spatial_mask_variable('a_mask', None, dims)
        attrs = {'please keep me': 'no overwriting'}
        dmap.set_spatial_mask(mask_var, attrs=attrs)
        attrs = dmap.get_attrs(DMK.SPATIAL_MASK)
        self.assertIn('please keep me', attrs)

        # Test default attributes are not added.
        dmap = DimensionMap()
        dmap.set_spatial_mask('foo', default_attrs={'blue': 'world'})
        prop = dmap.get_property(DMK.SPATIAL_MASK)
        self.assertEqual(prop['attrs'], {'blue': 'world'})
コード例 #3
0
    def test_set_spatial_mask(self):
        dmap = DimensionMap()
        dims = Dimension('x', 3), Dimension('y', 7)
        mask_var = create_grid_mask_variable('a_mask', None, dims)
        self.assertFalse(np.any(mask_var.get_mask()))
        dmap.set_spatial_mask(mask_var)
        self.assertEqual(dmap.get_spatial_mask(), mask_var.name)

        with self.assertRaises(DimensionMapError):
            dmap.set_variable(DMK.SPATIAL_MASK, mask_var)

        # Test custom variables may be used.
        dmap = DimensionMap()
        dims = Dimension('x', 3), Dimension('y', 7)
        mask_var = create_grid_mask_variable('a_mask', None, dims)
        attrs = {'please keep me': 'no overwriting'}
        dmap.set_spatial_mask(mask_var, attrs=attrs)
        attrs = dmap.get_attrs(DMK.SPATIAL_MASK)
        self.assertIn('please keep me', attrs)
コード例 #4
0
ファイル: test_dimension_map.py プロジェクト: NCPP/ocgis
    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)
コード例 #5
0
    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)