예제 #1
0
    def test_sample_files(self):
        """should be able to load hdfeos files, whether grid files or not

        Issue 16
        """
        GridFile(self.test_driver_grid_file)
        GridFile(self.test_driver_gridfile4)
        GridFile(self.test_driver_swathfile4)
        GridFile(self.test_driver_pointfile4)
        self.assertTrue(True)
예제 #2
0
 def test_he5(self):
     """
     make sure that long * is cast correctly.
     """
     g4 = GridFile(self.test_driver_gridfile4)
     lat4, lon4 = g4.grids['UTMGrid'][:]
     g5 = GridFile(self.test_driver_gridfile5)
     lat5, lon5 = g5.grids['UTMGrid'][:]
     self.assertTrue(True)
     np.testing.assert_array_equal(lon4, lon5)
     np.testing.assert_array_equal(lat4, lat5)
예제 #3
0
 def test_explicit_del_he5(self):
     """
     should not generate a ReferenceError when del is explicitly used
     """
     gdf = GridFile(self.test_driver_grid_file)
     utm = gdf.grids['UTMGrid']
     del gdf
예제 #4
0
 def test_too_many_slices(self):
     """
     maximum of two slices
     """
     gdf = GridFile(self.test_driver_grid_file)
     with self.assertRaises(RuntimeError):
         gdf.grids['UTMGrid'][:, :, :]
예제 #5
0
    def test_zonal_average_file(self):
        """should be able to open zonal average file

        Issue #15
        """
        gdf = GridFile(self.test_driver_zonal_average_file)
        self.assertTrue(True)
예제 #6
0
    def test_colon_complete_grid(self):
        file = 'MISR_AM1_GRP_ELLIPSOID_GM_P117_O058421_BA_F03_0024.hdf'
        som_file = fixtures.test_file_path(file)
        gdf = GridFile(som_file)

        lat, lon = gdf.grids['GeometricParameters'][:]
        self.assertEqual(lat.shape, (180, 8, 32))
예제 #7
0
 def test_ps_grid_he5(self):
     with GridFile(self.test_driver_file) as gdf:
         with patch('sys.stdout', new=StringIO()) as fake_out:
             print(gdf.grids['PolarGrid'])
             actual = fake_out.getvalue().strip()
     expected = fixtures.polar_stereographic_grid
     self.assertEqual(actual, expected)
예제 #8
0
 def test_repr_gridfile(self):
     with GridFile(self.test_driver_file) as gdf1:
         gdf2 = eval(repr(gdf1))
         self.assertEqual(gdf1.filename, gdf2.filename)
         glist1 = [grid for grid in gdf1.grids.keys()]
         glist2 = [grid for grid in gdf2.grids.keys()]
         self.assertEqual(glist1, glist2)
예제 #9
0
    def test_strides(self):
        """
        array-style indexing case of [::rs, ::cs]
        """
        with GridFile(self.test_driver_gridfile4) as gdf:
            actual = gdf.grids['UTMGrid'].fields['Vegetation'][::10, ::10]

        self.assertEqual(actual.shape, (20, 12))
예제 #10
0
    def test_first_point_first_block(self):
        file = 'MISR_AM1_GRP_ELLIPSOID_GM_P117_O058421_BA_F03_0024.hdf'
        som_file = fixtures.test_file_path(file)
        gdf = GridFile(som_file)

        lat, lon = gdf.grids['BlueBand'][0, 0, 0]
        np.testing.assert_almost_equal(lat, 66.226321, 5)
        np.testing.assert_almost_equal(lon, -68.775228, 5)
예제 #11
0
 def test_ellipsis_slice(self):
     """
     combine Ellipsis with slice 
     """
     gdf = GridFile(self.test_driver_gridfile4)
     lat, lon = gdf.grids['UTMGrid'][:, ...]
     self.assertEqual(lat.shape, (200, 120))
     self.assertEqual(lon.shape, (200, 120))
예제 #12
0
 def test_colon_slice(self):
     """
     using : should retrieve the entire grid
     """
     gdf = GridFile(self.test_driver_grid_file)
     lat, lon = gdf.grids['UTMGrid'][:]
     self.assertEqual(lat.shape, (200, 120))
     self.assertEqual(lon.shape, (200, 120))
예제 #13
0
 def test_ellipsis(self):
     """
     using an ellipsis should retrieve the entire grid
     """
     gdf = GridFile(self.test_driver_grid_file)
     lat, lon = gdf.grids['UTMGrid'][...]
     self.assertEqual(lat.shape, (200, 120))
     self.assertEqual(lon.shape, (200, 120))
예제 #14
0
 def test_projinfo(self):
     gdf = GridFile(self.test_driver_gridfile4)
     self.assertEqual(gdf.grids['UTMGrid'].projcode, 1)
     self.assertEqual(gdf.grids['UTMGrid'].zonecode, 40)
     self.assertEqual(gdf.grids['UTMGrid'].spherecode, 0)
     projparms = gdf.grids['UTMGrid'].projparms,
     np.testing.assert_array_equal(projparms,
                                   np.zeros((1, 13), dtype=np.float64))
예제 #15
0
    def test_testdriver_he2_polar(self):
        with GridFile(self.test_driver_gridfile4) as gdf:
            with patch('sys.stdout', new=StringIO()) as fake_out:
                print(gdf.grids['PolarGrid'])
                actual = fake_out.getvalue().strip()

        expected = fixtures.he2_polar
        self.assertEqual(actual, expected)
예제 #16
0
    def test_getitem_int(self):
        """
        a single integer argument is not allowed

        Doesn't make a lot of sense
        """
        gdf = GridFile(self.test_driver_grid_file)
        with self.assertRaises(RuntimeError):
            gdf.grids['UTMGrid'][5]
예제 #17
0
    def test_read_he4_2d_int_int(self):
        """
        array-style indexing case of [scalar, scalar]
        """
        with GridFile(self.test_driver_gridfile4) as gdf:
            actual = gdf.grids['UTMGrid'].fields['Vegetation'][3, 4]

        expected = 13
        np.testing.assert_array_equal(actual, expected)
예제 #18
0
    def test_read_he4_2d_int_slice(self):
        """
        array-style indexing case of [scalar, :]
        """
        with GridFile(self.test_driver_gridfile4) as gdf:
            actual = gdf.grids['UTMGrid'].fields['Vegetation'][3, :]

        expected = np.ones(120, dtype=np.float32) * 13
        np.testing.assert_array_equal(actual, expected)
예제 #19
0
    def test_read_he5_2d_full(self):
        """
        array-style indexing case of [:]
        """
        with GridFile(self.test_driver_gridfile5) as gdf:
            actual = gdf.grids['UTMGrid'].fields['Vegetation'][:]

        expected = np.array([[10, 0], [0, 76]], dtype=np.float32)
        np.testing.assert_array_equal(actual[0:280:279, 0:180:179], expected)
예제 #20
0
    def test_som_grid(self):
        file = test_file_path(somfile)
        gdf = GridFile(file)
        with patch('sys.stdout', new=StringIO()) as fake_out:
            print(gdf.grids['GeometricParameters'])
            actual = fake_out.getvalue().strip()

        expected = fixtures.som_grid
        self.assertEqual(actual, expected)
예제 #21
0
    def test_cea_grid(self):
        file = test_file_path(ceafile)
        gdf = GridFile(file)
        with patch('sys.stdout', new=StringIO()) as fake_out:
            print(gdf.grids['Ascending_Land_Grid'])
            actual = fake_out.getvalue().strip()

        expected = fixtures.cea_grid
        self.assertEqual(actual, expected)
예제 #22
0
 def test_corners(self):
     """
     should be able to supply two slice arguments
     """
     gdf = GridFile(self.test_driver_grid_file)
     rows = slice(0, 200, 199)
     cols = slice(0, 120, 119)
     lat, lon = gdf.grids['UTMGrid'][rows, cols]
     self.assertEqual(lat.shape, (2, 2))
     self.assertEqual(lon.shape, (2, 2))
예제 #23
0
    def test_read_he5_2d_row(self):
        """
        array-style indexing case of [scalar int]
        """
        with GridFile(self.test_driver_gridfile5) as gdf:
            actual = gdf.grids['UTMGrid'].fields['Vegetation'][1]

        expected = np.ones(180, dtype=np.float32) * 11
        expected[120:180] = 0
        np.testing.assert_array_equal(actual, expected)
예제 #24
0
    def test_read_he4_2d_full_full(self):
        """
        array-style indexing case of [:,:]
        """
        with GridFile(self.test_driver_gridfile4) as gdf:
            actual = gdf.grids['UTMGrid'].fields['Vegetation'][:, :]

        expected = np.zeros((200, 120), dtype=np.float32)
        for j in range(200):
            expected[j] = j + 10
        np.testing.assert_array_equal(actual, expected)
예제 #25
0
    def test_read_he4_2d_slice_slice(self):
        """
        array-style indexing case of [r1;r2, c1:c2]
        """
        with GridFile(self.test_driver_gridfile4) as gdf:
            actual = gdf.grids['UTMGrid'].fields['Vegetation'][3:5, 4:7]

        expected = np.zeros((2, 3), dtype=np.float32)
        for j in range(2):
            expected[j] = j + 13
        np.testing.assert_array_equal(actual, expected)
예제 #26
0
    def test_square_last_block(self):
        file = 'MISR_AM1_GRP_ELLIPSOID_GM_P117_O058421_BA_F03_0024.hdf'
        som_file = fixtures.test_file_path(file)
        gdf = GridFile(som_file)

        lat, lon = gdf.grids['BlueBand'][179, 0:2, 0:2]

        expected = np.array([[-65.731, -65.735], [-65.722, -65.726]])
        np.testing.assert_almost_equal(lat, expected, 3)

        expected = np.array([[-46.159, -46.181], [-46.170, -46.191]])
        np.testing.assert_almost_equal(lon, expected, 3)
예제 #27
0
    def test_gridinfo(self):
        gdf = GridFile(self.test_driver_gridfile4)
        self.assertEqual(gdf.grids['UTMGrid'].xdimsize, 120)
        self.assertEqual(gdf.grids['UTMGrid'].ydimsize, 200)

        upleft = gdf.grids['UTMGrid'].upleft
        np.testing.assert_array_equal(upleft,
                                      np.array([210584.50041, 3322395.95445]))

        lowright = gdf.grids['UTMGrid'].lowright
        np.testing.assert_array_equal(lowright,
                                      np.array([813931.10959, 2214162.53278]))
예제 #28
0
    def test_ellipsis_1D(self):
        file = 'MISR_AM1_GRP_ELLIPSOID_GM_P117_O058421_BA_F03_0024.hdf'
        som_file = fixtures.test_file_path(file)
        gdf = GridFile(som_file)

        lat, lon = gdf.grids['GeometricParameters'][..., 0, 0]
        self.assertEqual(lat.shape, (180, ))

        lat, lon = gdf.grids['GeometricParameters'][0, ..., 0]
        self.assertEqual(lat.shape, (8, ))

        lat, lon = gdf.grids['GeometricParameters'][0, 0, ...]
        self.assertEqual(lat.shape, (32, ))
예제 #29
0
 def test_slice_out_of_bounds(self):
     """
     slice arguments should not exceed grid boundaries 
     """
     gdf = GridFile(self.test_driver_grid_file)
     with self.assertRaises(RuntimeError):
         gdf.grids['UTMGrid'][-1:25, 8:25]
     with self.assertRaises(RuntimeError):
         gdf.grids['UTMGrid'][8:25, -1:25]
     with self.assertRaises(RuntimeError):
         gdf.grids['UTMGrid'][8:700, 8:25]
     with self.assertRaises(RuntimeError):
         gdf.grids['UTMGrid'][8:100, 8:2500]
예제 #30
0
    def test_testdriver_he2_geo(self):
        with GridFile(self.test_driver_gridfile4) as gdf:
            with patch('sys.stdout', new=StringIO()) as fake_out:
                print(gdf.grids['GEOGrid'])
                actual = fake_out.getvalue().strip()

        # Trim off last two lines, gets rid of a floating point value that is
        # hard to match.
        actual = actual.split('\n')
        actual = '\n'.join(actual[:-2])

        expected = fixtures.he2_geo
        expected = expected.split('\n')
        expected = '\n'.join(expected[:-2])

        self.assertEqual(actual, expected)