コード例 #1
0
ファイル: test_viirs.py プロジェクト: pepephillips/satpy
    def test_erf_dnb(self):
        """Test the 'dynamic_dnb' or ERF DNB compositor."""
        import dask.array as da
        import numpy as np
        import xarray as xr
        from pyresample.geometry import AreaDefinition

        from satpy.composites.viirs import ERFDNB
        rows = 5
        cols = 10
        area = AreaDefinition(
            'test', 'test', 'test',
            {'proj': 'eqc', 'lon_0': 0.0,
             'lat_0': 0.0},
            cols, rows,
            (-20037508.34, -10018754.17, 20037508.34, 10018754.17))

        comp = ERFDNB('dynamic_dnb', prerequisites=('dnb',),
                      standard_name='toa_outgoing_radiance_per_'
                                    'unit_wavelength')
        dnb = np.zeros((rows, cols)) + 0.25
        dnb[3, :] += 0.25
        dnb[4:, :] += 0.5
        dnb = da.from_array(dnb, chunks=25)
        c01 = xr.DataArray(dnb,
                           dims=('y', 'x'),
                           attrs={'name': 'DNB', 'area': area})
        sza = np.zeros((rows, cols)) + 70.0
        sza[:, 3] += 20.0
        sza[:, 4:] += 45.0
        sza = da.from_array(sza, chunks=25)
        c02 = xr.DataArray(sza,
                           dims=('y', 'x'),
                           attrs={'name': 'solar_zenith_angle', 'area': area})
        lza = np.zeros((rows, cols)) + 70.0
        lza[:, 3] += 20.0
        lza[:, 4:] += 45.0
        lza = da.from_array(lza, chunks=25)
        c03 = xr.DataArray(lza,
                           dims=('y', 'x'),
                           attrs={'name': 'lunar_zenith_angle', 'area': area})
        mif = xr.DataArray(da.zeros((5,), chunks=5) + 0.1,
                           dims=('y',),
                           attrs={'name': 'moon_illumination_fraction', 'area': area})
        res = comp((c01, c02, c03, mif))
        self.assertIsInstance(res, xr.DataArray)
        self.assertIsInstance(res.data, da.Array)
        self.assertEqual(res.attrs['name'], 'dynamic_dnb')
        self.assertEqual(res.attrs['standard_name'],
                         'equalized_radiance')
        data = res.compute()
        unique = np.unique(data)
        np.testing.assert_allclose(unique, [0.00000000e+00, 1.00446703e-01, 1.64116082e-01, 2.09233451e-01,
                                            1.43916324e+02, 2.03528498e+02, 2.49270516e+02])
コード例 #2
0
ファイル: test_viirs.py プロジェクト: JohannesSMHI/satpy
    def test_erf_dnb(self, dnb_units, saturation_correction, area, c02, c03):
        """Test the 'dynamic_dnb' or ERF DNB compositor."""
        from satpy.composites.viirs import ERFDNB

        comp = ERFDNB('dynamic_dnb',
                      prerequisites=('dnb', ),
                      saturation_correction=saturation_correction,
                      standard_name='toa_outgoing_radiance_per_'
                      'unit_wavelength')
        # c01 is different from in the other tests, so don't use the fixture
        # here
        dnb = np.zeros(area.shape) + 0.25
        cols = area.shape[1]
        dnb[2, :cols // 2] = np.nan
        dnb[3, :] += 0.25
        dnb[4:, :] += 0.5
        if dnb_units == "W cm-2 sr-1":
            dnb /= 10000.0
        dnb = da.from_array(dnb, chunks=25)
        c01 = xr.DataArray(dnb,
                           dims=('y', 'x'),
                           attrs={
                               'name': 'DNB',
                               'area': area,
                               'units': dnb_units
                           })
        mif = xr.DataArray(da.zeros((5, ), chunks=5) + 0.1,
                           dims=('y', ),
                           attrs={
                               'name': 'moon_illumination_fraction',
                               'area': area
                           })
        res = comp((c01, c02, c03, mif))
        assert isinstance(res, xr.DataArray)
        assert isinstance(res.data, da.Array)
        assert res.attrs['name'] == 'dynamic_dnb'
        assert res.attrs['standard_name'] == 'equalized_radiance'
        data = res.compute()
        unique = np.unique(data)
        assert np.isnan(unique).any()
        nonnan_unique = unique[~np.isnan(unique)]
        if saturation_correction:
            exp_unique = [
                0.000000e+00, 3.978305e-04, 6.500003e-04, 8.286927e-04,
                5.628335e-01, 7.959671e-01, 9.748567e-01
            ]
        else:
            exp_unique = [
                0.00000000e+00, 1.00446703e-01, 1.64116082e-01, 2.09233451e-01,
                1.43916324e+02, 2.03528498e+02, 2.49270516e+02
            ]
            np.testing.assert_allclose(nonnan_unique, exp_unique)
コード例 #3
0
    def test_erf_dnb(self, dnb_units, saturation_correction):
        """Test the 'dynamic_dnb' or ERF DNB compositor."""
        from satpy.composites.viirs import ERFDNB
        rows = 5
        cols = 10
        area = AreaDefinition('test', 'test', 'test', {
            'proj': 'eqc',
            'lon_0': 0.0,
            'lat_0': 0.0
        }, cols, rows, (-20037508.34, -10018754.17, 20037508.34, 10018754.17))

        comp = ERFDNB('dynamic_dnb',
                      prerequisites=('dnb', ),
                      saturation_correction=saturation_correction,
                      standard_name='toa_outgoing_radiance_per_'
                      'unit_wavelength')
        dnb = np.zeros((rows, cols)) + 0.25
        dnb[2, :cols // 2] = np.nan
        dnb[3, :] += 0.25
        dnb[4:, :] += 0.5
        if dnb_units == "W cm-2 sr-1":
            dnb /= 10000.0
        dnb = da.from_array(dnb, chunks=25)
        c01 = xr.DataArray(dnb,
                           dims=('y', 'x'),
                           attrs={
                               'name': 'DNB',
                               'area': area,
                               'units': dnb_units
                           })
        sza = np.zeros((rows, cols)) + 70.0
        sza[:, 3] += 20.0
        sza[:, 4:] += 45.0
        sza = da.from_array(sza, chunks=25)
        c02 = xr.DataArray(sza,
                           dims=('y', 'x'),
                           attrs={
                               'name': 'solar_zenith_angle',
                               'area': area
                           })
        lza = np.zeros((rows, cols)) + 70.0
        lza[:, 3] += 20.0
        lza[:, 4:] += 45.0
        lza = da.from_array(lza, chunks=25)
        c03 = xr.DataArray(lza,
                           dims=('y', 'x'),
                           attrs={
                               'name': 'lunar_zenith_angle',
                               'area': area
                           })
        mif = xr.DataArray(da.zeros((5, ), chunks=5) + 0.1,
                           dims=('y', ),
                           attrs={
                               'name': 'moon_illumination_fraction',
                               'area': area
                           })
        res = comp((c01, c02, c03, mif))
        assert isinstance(res, xr.DataArray)
        assert isinstance(res.data, da.Array)
        assert res.attrs['name'] == 'dynamic_dnb'
        assert res.attrs['standard_name'] == 'equalized_radiance'
        data = res.compute()
        unique = np.unique(data)
        assert np.isnan(unique).any()
        nonnan_unique = unique[~np.isnan(unique)]
        if saturation_correction:
            exp_unique = [
                0.000000e+00, 3.978305e-04, 6.500003e-04, 8.286927e-04,
                5.628335e-01, 7.959671e-01, 9.748567e-01
            ]
        else:
            exp_unique = [
                0.00000000e+00, 1.00446703e-01, 1.64116082e-01, 2.09233451e-01,
                1.43916324e+02, 2.03528498e+02, 2.49270516e+02
            ]
            np.testing.assert_allclose(nonnan_unique, exp_unique)