Beispiel #1
0
    def test_write_to_rootgrp(self):
        meta = self.archetype_minimal_metadata
        crs = CFLambertConformal.load_from_metadata('pr', meta)
        path = os.path.join(self.current_dir_output, 'foo.nc')
        with nc_scope(path, 'w') as ds:
            variable = crs.write_to_rootgrp(ds)
            self.assertEqual(variable.grid_mapping_name, crs.grid_mapping_name)
            for k, v in crs.map_parameters_values.items():
                variable_v = variable.__dict__[k]
                try:
                    self.assertEqual(variable_v, v)
                except ValueError:
                    # Some values come back as NumPy arrays.
                    self.assertEqual(variable_v.tolist(), v)

        with nc_scope(path) as ds:
            meta2 = {'variables': {'Lambert_Conformal': {'attrs': dict(ds.variables['Lambert_Conformal'].__dict__),
                                                         'name': 'Lambert_Conformal'}}}
        meta['variables']['Lambert_Conformal'] = meta2['variables']['Lambert_Conformal']
        crs2 = CFLambertConformal.load_from_metadata('pr', meta)
        self.assertEqual(crs, crs2)

        path2 = os.path.join(self.current_dir_output, 'foo2.nc')
        with nc_scope(path2, 'w') as ds:
            crs2.write_to_rootgrp(ds)
Beispiel #2
0
    def test_write_to_rootgrp(self):
        meta = self.archetype_minimal_metadata
        crs = CFLambertConformal.load_from_metadata('pr', meta)
        path = os.path.join(self.current_dir_output, 'foo.nc')
        with nc_scope(path, 'w') as ds:
            variable = crs.write_to_rootgrp(ds)
            self.assertEqual(variable.grid_mapping_name, crs.grid_mapping_name)
            for k, v in crs.map_parameters_values.items():
                variable_v = variable.__dict__[k]
                try:
                    self.assertEqual(variable_v, v)
                except ValueError:
                    # Some values come back as NumPy arrays.
                    self.assertEqual(variable_v.tolist(), v)

        with nc_scope(path) as ds:
            meta2 = {
                'variables': {
                    'Lambert_Conformal': {
                        'attrs':
                        dict(ds.variables['Lambert_Conformal'].__dict__),
                        'name': 'Lambert_Conformal'
                    }
                }
            }
        meta['variables']['Lambert_Conformal'] = meta2['variables'][
            'Lambert_Conformal']
        crs2 = CFLambertConformal.load_from_metadata('pr', meta)
        self.assertEqual(crs, crs2)

        path2 = os.path.join(self.current_dir_output, 'foo2.nc')
        with nc_scope(path2, 'w') as ds:
            crs2.write_to_rootgrp(ds)
Beispiel #3
0
 def test_load_from_metadata(self):
     crs = CFLambertConformal.load_from_metadata(
         'pr', self.archetype_minimal_metadata)
     self.assertEqual(crs.name, 'Lambert_Conformal')
     self.assertEqual(
         crs.value, {
             'lon_0': -97,
             'ellps': 'WGS84',
             'y_0': 2700000,
             'no_defs': True,
             'proj': 'lcc',
             'x_0': 3325000,
             'units': 'm',
             'lat_2': 60,
             'lat_1': 30,
             'lat_0': 47.5
         })
     self.assertIsInstance(crs, CFLambertConformal)
     self.assertEqual(
         ['xc', 'yc'],
         [crs.projection_x_coordinate, crs.projection_y_coordinate])
     self.assertEqual([30., 60.],
                      crs.map_parameters_values.pop('standard_parallel'))
     self.assertEqual(
         crs.map_parameters_values, {
             'latitude_of_projection_origin': 47.5,
             'longitude_of_central_meridian': -97.0,
             'false_easting': 3325000.0,
             'false_northing': 2700000.0,
             'units': 'm'
         })
Beispiel #4
0
 def test_load_from_metadata(self):
     crs = CFLambertConformal.load_from_metadata('pr', self.archetype_minimal_metadata)
     self.assertEqual(crs.name, 'Lambert_Conformal')
     self.assertEqual(crs.value, {'lon_0': -97, 'ellps': 'WGS84', 'y_0': 2700000, 'no_defs': True, 'proj': 'lcc',
                                  'x_0': 3325000, 'units': 'm', 'lat_2': 60, 'lat_1': 30, 'lat_0': 47.5})
     self.assertIsInstance(crs, CFLambertConformal)
     self.assertEqual(['xc', 'yc'], [crs.projection_x_coordinate, crs.projection_y_coordinate])
     self.assertEqual([30., 60.], crs.map_parameters_values.pop('standard_parallel'))
     self.assertEqual(crs.map_parameters_values,
                      {'latitude_of_projection_origin': 47.5, 'longitude_of_central_meridian': -97.0,
                       'false_easting': 3325000.0, 'false_northing': 2700000.0, 'units': 'm'})
Beispiel #5
0
    def test_load_from_metadata_no_falses(self):
        """Test without false easting and false northing in attributes."""

        meta = self.archetype_minimal_metadata
        to_pop = ['false_easting', 'false_northing']
        for t in to_pop:
            meta['variables']['Lambert_Conformal']['attrs'].pop(t)

        crs = CFLambertConformal.load_from_metadata('pr', meta)
        self.assertIsInstance(crs, CFLambertConformal)

        for proj_parm in ['x_0', 'y_0']:
            self.assertEqual(crs.value[proj_parm], 0)
Beispiel #6
0
    def test_load_from_metadata_no_falses(self):
        """Test without false easting and false northing in attributes."""

        meta = self.archetype_minimal_metadata
        to_pop = ['false_easting', 'false_northing']
        for t in to_pop:
            meta['variables']['Lambert_Conformal']['attrs'].pop(t)

        crs = CFLambertConformal.load_from_metadata('pr', meta)
        self.assertIsInstance(crs, CFLambertConformal)

        for proj_parm in ['x_0', 'y_0']:
            self.assertEqual(crs.value[proj_parm], 0)