Ejemplo n.º 1
0
    def test_read_2points_cell_switch(self):
        """
        Test reading of two points in two different cells.
        This did not work in the past when the static layer class
        was closed too soon.
        """
        self.h111 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h111'), self.grid_path,
            static_layer_path=self.static_layer_path)

        gpi = 3066159
        data = self.h111.read(gpi, absolute_sm=True)
        assert data.attrs['gpi'] == gpi

        gpi = 2577735
        data = self.h111.read(gpi, absolute_sm=True)
        assert data.attrs['gpi'] == gpi
Ejemplo n.º 2
0
    def test_read_h110(self):
        """
        Test read H110.
        """
        self.h110 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h110'), self.grid_path,
            static_layer_path=self.static_layer_path)

        data = self.h110.read(self.gpi, absolute_sm=True)
        assert data.attrs['gpi'] == self.gpi

        np.testing.assert_approx_equal(data.attrs['lon'], 19.03533,
                                       significant=4)
        np.testing.assert_approx_equal(data.attrs['lat'], 70.05438,
                                       significant=4)

        assert len(data) == 1148
        assert data.iloc[15].name.to_pydatetime() == datetime(
            2016, 1, 3, 19, 34, 28, 99200)
        assert data.iloc[15]['sm'] == 48
        assert data.iloc[15]['ssf'] == 1
        assert data.iloc[15]['sm_noise'] == 5
        assert data.iloc[15]['frozen_prob'] == 0
        assert data.iloc[15]['snow_prob'] == 127
        assert data.iloc[15]['dir'] == 0
        assert data.iloc[15]['proc_flag'] == 0
        assert data.iloc[15]['corr_flag'] == 0
        assert data.iloc[15]['sat_id'] == 4

        np.testing.assert_equal(
            data.iloc[15]['abs_sm_gldas'], np.nan)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_gldas'], np.nan)

        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_hwsd'], 0.2352, significant=6)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_hwsd'], 0.0245, significant=6)

        assert data.attrs['topo_complex'] == 9
        assert data.attrs['wetland_frac'] == 41

        np.testing.assert_equal(data.attrs['porosity_gldas'], np.nan)
        np.testing.assert_approx_equal(data.attrs['porosity_hwsd'],
                                       0.49000001, significant=5)
Ejemplo n.º 3
0
    def test_read_h25(self):
        """
        Test read H25.
        """
        self.h25 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h25'), self.grid_path,
            static_layer_path=self.static_layer_path)

        data = self.h25.read(self.gpi, absolute_sm=True)
        assert data.attrs['gpi'] == self.gpi

        np.testing.assert_approx_equal(
            data.attrs['lon'], 19.03533, significant=4)
        np.testing.assert_approx_equal(
            data.attrs['lat'], 70.05438, significant=4)

        assert len(data) == 7737
        assert data.iloc[15].name.to_pydatetime() == datetime(
            2007, 1, 7, 10, 49, 9, 4)
        assert data.iloc[15]['sm'] == 22
        assert data.iloc[15]['ssf'] == 1
        assert data.iloc[15]['sm_noise'] == 6
        assert data.iloc[15]['frozen_prob'] == 0
        assert data.iloc[15]['snow_prob'] == 127
        assert data.iloc[15]['orbit_dir'].decode('utf-8') == 'D'
        assert data.iloc[15]['proc_flag'] == 0

        np.testing.assert_equal(
            data.iloc[15]['abs_sm_gldas'], np.nan)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_gldas'], np.nan)

        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_hwsd'], 0.1078, significant=6)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_hwsd'], 0.0294, significant=6)

        assert data.attrs['topo_complex'] == 9
        assert data.attrs['wetland_frac'] == 41

        np.testing.assert_approx_equal(
            data.attrs['porosity_gldas'], np.nan, significant=5)
        np.testing.assert_approx_equal(
            data.attrs['porosity_hwsd'], 0.49000001, significant=5)
Ejemplo n.º 4
0
class Test_AscatSsmDataRecord(unittest.TestCase):

    def setUp(self):

        path = os.path.dirname(__file__)

        self.gpi = 3066159
        self.cdr_path = os.path.join(path, 'ascat_test_data', 'hsaf')
        self.grid_path = os.path.join(path, 'ascat_test_data', 'hsaf', 'grid')
        self.static_layer_path = os.path.join(path, 'ascat_test_data', 'hsaf',
                                              'static_layer')

    def test_read_h25(self):
        """
        Test read H25.
        """
        self.h25 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h25'), self.grid_path,
            static_layer_path=self.static_layer_path)

        data = self.h25.read(self.gpi, absolute_sm=True)
        assert data.attrs['gpi'] == self.gpi

        np.testing.assert_approx_equal(
            data.attrs['lon'], 19.03533, significant=4)
        np.testing.assert_approx_equal(
            data.attrs['lat'], 70.05438, significant=4)

        assert len(data) == 7737
        assert data.iloc[15].name.to_pydatetime() == datetime(
            2007, 1, 7, 10, 49, 9, 4)
        assert data.iloc[15]['sm'] == 22
        assert data.iloc[15]['ssf'] == 1
        assert data.iloc[15]['sm_noise'] == 6
        assert data.iloc[15]['frozen_prob'] == 0
        assert data.iloc[15]['snow_prob'] == 127
        assert data.iloc[15]['orbit_dir'].decode('utf-8') == 'D'
        assert data.iloc[15]['proc_flag'] == 0

        np.testing.assert_equal(
            data.iloc[15]['abs_sm_gldas'], np.nan)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_gldas'], np.nan)

        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_hwsd'], 0.1078, significant=6)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_hwsd'], 0.0294, significant=6)

        assert data.attrs['topo_complex'] == 9
        assert data.attrs['wetland_frac'] == 41

        np.testing.assert_approx_equal(
            data.attrs['porosity_gldas'], np.nan, significant=5)
        np.testing.assert_approx_equal(
            data.attrs['porosity_hwsd'], 0.49000001, significant=5)

    def test_read_h108(self):
        """
        Test read H108.
        """
        self.h108 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h108'), self.grid_path,
            static_layer_path=self.static_layer_path)

        data = self.h108.read(self.gpi, absolute_sm=True)
        assert data.attrs['gpi'] == self.gpi

        np.testing.assert_approx_equal(data.attrs['lon'], 19.03533,
                                       significant=4)
        np.testing.assert_approx_equal(data.attrs['lat'], 70.05438,
                                       significant=4)

        assert len(data) == 8222
        assert data.iloc[15].name.to_pydatetime() == datetime(
            2007, 1, 7, 10, 49, 9, 4)
        assert data.iloc[15]['sm'] == 22
        assert data.iloc[15]['ssf'] == 2
        assert data.iloc[15]['sm_noise'] == 6
        assert data.iloc[15]['frozen_prob'] == 0
        assert data.iloc[15]['snow_prob'] == 127
        assert data.iloc[15]['orbit_dir'].decode('utf-8') == 'D'
        assert data.iloc[15]['proc_flag'] == 0

        np.testing.assert_equal(
            data.iloc[15]['abs_sm_gldas'], np.nan)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_gldas'], np.nan)

        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_hwsd'], 0.1078, significant=6)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_hwsd'], 0.0294, significant=6)

        assert data.attrs['topo_complex'] == 9
        assert data.attrs['wetland_frac'] == 41

        np.testing.assert_equal(data.attrs['porosity_gldas'], np.nan)
        np.testing.assert_approx_equal(data.attrs['porosity_hwsd'],
                                       0.49000001, significant=5)

    def test_read_h109(self):
        """
        Test read H109.
        """
        self.h109 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h109'), self.grid_path,
            static_layer_path=self.static_layer_path)

        data = self.h109.read(self.gpi, absolute_sm=True)
        assert data.attrs['gpi'] == self.gpi

        np.testing.assert_approx_equal(data.attrs['lon'], 19.03533,
                                       significant=4)
        np.testing.assert_approx_equal(data.attrs['lat'], 70.05438,
                                       significant=4)

        assert len(data) == 11736
        assert data.iloc[15].name.to_pydatetime() == \
            datetime(2007, 1, 7, 10, 49, 9, 379200)
        assert data.iloc[15]['sm'] == 27
        assert data.iloc[15]['ssf'] == 1
        assert data.iloc[15]['sm_noise'] == 5
        assert data.iloc[15]['frozen_prob'] == 0
        assert data.iloc[15]['snow_prob'] == 127
        assert data.iloc[15]['dir'] == 1
        assert data.iloc[15]['proc_flag'] == 0
        assert data.iloc[15]['corr_flag'] == 16
        assert data.iloc[15]['sat_id'] == 3

        np.testing.assert_equal(
            data.iloc[15]['abs_sm_gldas'], np.nan)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_gldas'], np.nan)

        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_hwsd'], 0.1323, significant=6)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_hwsd'], 0.0245, significant=6)

        assert data.attrs['topo_complex'] == 9
        assert data.attrs['wetland_frac'] == 41

        np.testing.assert_equal(data.attrs['porosity_gldas'], np.nan)
        np.testing.assert_approx_equal(data.attrs['porosity_hwsd'],
                                       0.49000001, significant=5)

    def test_read_h110(self):
        """
        Test read H110.
        """
        self.h110 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h110'), self.grid_path,
            static_layer_path=self.static_layer_path)

        data = self.h110.read(self.gpi, absolute_sm=True)
        assert data.attrs['gpi'] == self.gpi

        np.testing.assert_approx_equal(data.attrs['lon'], 19.03533,
                                       significant=4)
        np.testing.assert_approx_equal(data.attrs['lat'], 70.05438,
                                       significant=4)

        assert len(data) == 1148
        assert data.iloc[15].name.to_pydatetime() == datetime(
            2016, 1, 3, 19, 34, 28, 99200)
        assert data.iloc[15]['sm'] == 48
        assert data.iloc[15]['ssf'] == 1
        assert data.iloc[15]['sm_noise'] == 5
        assert data.iloc[15]['frozen_prob'] == 0
        assert data.iloc[15]['snow_prob'] == 127
        assert data.iloc[15]['dir'] == 0
        assert data.iloc[15]['proc_flag'] == 0
        assert data.iloc[15]['corr_flag'] == 0
        assert data.iloc[15]['sat_id'] == 4

        np.testing.assert_equal(
            data.iloc[15]['abs_sm_gldas'], np.nan)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_gldas'], np.nan)

        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_hwsd'], 0.2352, significant=6)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_hwsd'], 0.0245, significant=6)

        assert data.attrs['topo_complex'] == 9
        assert data.attrs['wetland_frac'] == 41

        np.testing.assert_equal(data.attrs['porosity_gldas'], np.nan)
        np.testing.assert_approx_equal(data.attrs['porosity_hwsd'],
                                       0.49000001, significant=5)

    def test_read_h111(self):
        """
        Test read H111.
        """
        self.h111 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h111'), self.grid_path,
            static_layer_path=self.static_layer_path)

        data = self.h111.read(self.gpi, absolute_sm=True)
        assert data.attrs['gpi'] == self.gpi

        np.testing.assert_approx_equal(data.attrs['lon'], 19.03533,
                                       significant=4)
        np.testing.assert_approx_equal(data.attrs['lat'], 70.05438,
                                       significant=4)

        assert len(data) == 13715
        assert data.iloc[15].name.to_pydatetime() == datetime(
            2007, 1, 7, 10, 49, 9, 379200)
        assert data.iloc[15]['sm'] == 28
        assert data.iloc[15]['ssf'] == 1
        assert data.iloc[15]['sm_noise'] == 5
        assert data.iloc[15]['frozen_prob'] == 0
        assert data.iloc[15]['snow_prob'] == 127
        assert data.iloc[15]['dir'] == 1
        assert data.iloc[15]['proc_flag'] == 0
        assert data.iloc[15]['corr_flag'] == 4
        assert data.iloc[15]['sat_id'] == 3

        np.testing.assert_equal(data.iloc[15]['abs_sm_gldas'], np.nan)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_gldas'], np.nan)

        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_hwsd'], 0.1372, significant=6)
        np.testing.assert_approx_equal(
            data.iloc[15]['abs_sm_noise_hwsd'], 0.0245, significant=6)

        assert data.attrs['topo_complex'] == 9
        assert data.attrs['wetland_frac'] == 41

        np.testing.assert_equal(data.attrs['porosity_gldas'], np.nan)
        np.testing.assert_approx_equal(data.attrs['porosity_hwsd'],
                                       0.49000001, significant=5)

    def test_read_2points_cell_switch(self):
        """
        Test reading of two points in two different cells.
        This did not work in the past when the static layer class
        was closed too soon.
        """
        self.h111 = AscatSsmDataRecord(
            os.path.join(self.cdr_path, 'h111'), self.grid_path,
            static_layer_path=self.static_layer_path)

        gpi = 3066159
        data = self.h111.read(gpi, absolute_sm=True)
        assert data.attrs['gpi'] == gpi

        gpi = 2577735
        data = self.h111.read(gpi, absolute_sm=True)
        assert data.attrs['gpi'] == gpi