コード例 #1
0
ファイル: test_swath.py プロジェクト: cpaulik/pyresample
    def test_self_map_multi(self):
        data = np.column_stack((self.tb37v, self.tb37v, self.tb37v))
        swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)

        if (sys.version_info < (2, 6) or
                (sys.version_info >= (3, 0) and sys.version_info < (3, 4))):
            res = kd_tree.resample_gauss(swath_def, data, swath_def,
                                         radius_of_influence=70000, sigmas=[56500, 56500, 56500])
        else:
            with warnings.catch_warnings(record=True) as w:
                res = kd_tree.resample_gauss(swath_def, data, swath_def,
                                             radius_of_influence=70000, sigmas=[56500, 56500, 56500])
                self.assertFalse(
                    len(w) != 1, 'Failed to create neighbour radius warning')
                self.assertFalse(('Possible more' not in str(
                    w[0].message)), 'Failed to create correct neighbour radius warning')

        if sys.platform == 'darwin':
            # OSX seems to get slightly different results for `_spatial_mp.Cartesian`
            truth_value = 668848.144817
        else:
            truth_value = 668848.082208
        self.assertAlmostEqual(res[:, 0].sum() / 100., truth_value, 1,
                               msg='Failed self mapping swath multi for channel 1')
        self.assertAlmostEqual(res[:, 1].sum() / 100., truth_value, 1,
                               msg='Failed self mapping swath multi for channel 2')
        self.assertAlmostEqual(res[:, 2].sum() / 100., truth_value, 1,
                               msg='Failed self mapping swath multi for channel 3')
コード例 #2
0
    def test_gauss_uncert(self):
        sigma = utils.fwhm2sigma(41627.730557884883)
        if (sys.version_info < (2, 6) or
                (sys.version_info >= (3, 0) and sys.version_info < (3, 4))):
            res, stddev, count = kd_tree.resample_gauss(self.tswath, self.tdata,
                                                        self.tgrid, 100000, sigma,
                                                        with_uncert=True)
        else:
            with warnings.catch_warnings(record=True) as w:
                res, stddev, count = kd_tree.resample_gauss(self.tswath, self.tdata,
                                                            self.tgrid, 100000, sigma,
                                                            with_uncert=True)
                self.assertFalse(
                    len(w) != 1, 'Failed to create neighbour warning')
                self.assertFalse(('Searching' not in str(
                    w[0].message)), 'Failed to create correct neighbour warning')

        expected_res = 2.20206560694
        expected_stddev = 0.707115076173
        expected_count = 3
        self.assertAlmostEqual(res[0], expected_res, 5,
                               'Failed to calculate gaussian weighting with uncertainty')
        self.assertAlmostEqual(stddev[0], expected_stddev, 5,
                               'Failed to calculate uncertainty for gaussian weighting')
        self.assertEqual(
            count[0], expected_count, 'Wrong data point count for gaussian weighting with uncertainty')
コード例 #3
0
 def test_gauss_multi_uncert(self):
     data = numpy.fromfunction(lambda y, x: (y + x)*10**-6, (5000, 100))        
     lons = numpy.fromfunction(lambda y, x: 3 + (10.0/100)*x, (5000, 100))
     lats = numpy.fromfunction(lambda y, x: 75 - (50.0/5000)*y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack((data.ravel(), data.ravel(),\
                                      data.ravel()))
     if sys.version_info < (2, 6):
         res, stddev, counts = kd_tree.resample_gauss(swath_def, data_multi,\
                                             self.area_def, 50000, [25000, 15000, 10000], 
                                             segments=1, with_uncert=True)
     else:
         with warnings.catch_warnings(record=True) as w:
             res, stddev, counts = kd_tree.resample_gauss(swath_def, data_multi,\
                                                 self.area_def, 50000, [25000, 15000, 10000], 
                                                 segments=1, with_uncert=True)
             self.failIf(len(w) != 1, 'Failed to create neighbour radius warning')
             self.failIf(('Possible more' not in str(w[0].message)), 'Failed to create correct neighbour radius warning') 
     cross_sum = res.sum()
     cross_sum_stddev = stddev.sum()
     cross_sum_counts = counts.sum()
     expected = 1461.84313918
     expected_stddev = 0.446204424799
     expected_counts = 4934802.0
     self.assertTrue(res.shape == stddev.shape and stddev.shape == counts.shape and counts.shape == (800, 800, 3))
     self.assertAlmostEqual(cross_sum, expected,
                             msg='Swath multi channel resampling gauss failed on data')
     self.assertAlmostEqual(cross_sum_stddev, expected_stddev,
                             msg='Swath multi channel resampling gauss failed on stddev')
     self.assertAlmostEqual(cross_sum_counts, expected_counts,
                             msg='Swath multi channel resampling gauss failed on counts')
コード例 #4
0
 def test_gauss_multi_mp_segments(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack((data.ravel(), data.ravel(),
                                      data.ravel()))
     if (sys.version_info < (2, 6) or
             (sys.version_info >= (3, 0) and sys.version_info < (3, 4))):
         res = kd_tree.resample_gauss(swath_def, data_multi,
                                      self.area_def, 50000, [
                                          25000, 15000, 10000],
                                      nprocs=2, segments=1)
     else:
         with warnings.catch_warnings(record=True) as w:
             res = kd_tree.resample_gauss(swath_def, data_multi,
                                          self.area_def, 50000, [
                                              25000, 15000, 10000],
                                          nprocs=2, segments=1)
             self.assertFalse(
                 len(w) != 1, 'Failed to create neighbour radius warning')
             self.assertFalse(('Possible more' not in str(
                 w[0].message)), 'Failed to create correct neighbour radius warning')
     cross_sum = res.sum()
     expected = 1461.84313918
     self.assertAlmostEqual(cross_sum, expected,
                            msg='Swath multi channel segments resampling gauss failed')
コード例 #5
0
ファイル: test_kd_tree.py プロジェクト: cpaulik/pyresample
 def test_gauss_multi_uncert(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack((data.ravel(), data.ravel(),
                                      data.ravel()))
     if (sys.version_info < (2, 6) or
             (sys.version_info >= (3, 0) and sys.version_info < (3, 4))):
         res, stddev, counts = kd_tree.resample_gauss(swath_def, data_multi,
                                                      self.area_def, 50000, [
                                                          25000, 15000, 10000],
                                                      segments=1, with_uncert=True)
     else:
         with warnings.catch_warnings(record=True) as w:
             # The assertion below checks if there is only one warning raised
             # and whether it contains a specific message from pyresample
             # On python 2.7.9+ the resample_gauss method raises multiple deprecation warnings
             # that cause to fail, so we ignore the unrelated warnings.
             # TODO: better way would be to filter UserWarning correctly
             ignore_list = [DeprecationWarning]
             try:
                 from numpy import VisibleDeprecationWarning
             except ImportError:
                 pass
             else:
                 ignore_list.append(VisibleDeprecationWarning)
             warnings.simplefilter('ignore', tuple(ignore_list))
             res, stddev, counts = kd_tree.resample_gauss(swath_def, data_multi,
                                                          self.area_def, 50000, [
                                                              25000, 15000, 10000],
                                                          segments=1, with_uncert=True)
             self.assertFalse(
                 len(w) != 1, 'Failed to create neighbour radius warning')
             self.assertFalse(('Possible more' not in str(
                 w[0].message)), 'Failed to create correct neighbour radius warning')
     cross_sum = res.sum()
     cross_sum_stddev = stddev.sum()
     cross_sum_counts = counts.sum()
     expected = 1461.84313918
     expected_stddev = 0.446204424799
     expected_counts = 4934802.0
     self.assertTrue(res.shape == stddev.shape and stddev.shape ==
                     counts.shape and counts.shape == (800, 800, 3))
     self.assertAlmostEqual(cross_sum, expected,
                            msg='Swath multi channel resampling gauss failed on data')
     self.assertAlmostEqual(cross_sum_stddev, expected_stddev,
                            msg='Swath multi channel resampling gauss failed on stddev')
     self.assertAlmostEqual(cross_sum_counts, expected_counts,
                            msg='Swath multi channel resampling gauss failed on counts')
コード例 #6
0
 def test_gauss_base(self):
     if sys.version_info < (2, 6):
         res = kd_tree.resample_gauss(self.tswath, \
                                          self.tdata.ravel(), self.tgrid,\
                                          50000, 25000, reduce_data=False, segments=1)
     else:
         with warnings.catch_warnings(record=True) as w:
             res = kd_tree.resample_gauss(self.tswath, \
                                          self.tdata.ravel(), self.tgrid,\
                                          50000, 25000, reduce_data=False, segments=1)
             self.failIf(len(w) != 1, 'Failed to create neighbour warning')
             self.failIf(('Searching' not in str(w[0].message)), 'Failed to create correct neighbour warning')    
     self.assertAlmostEqual(res[0], 2.2020729, 5, \
                                'Failed to calculate gaussian weighting')
コード例 #7
0
ファイル: test_swath.py プロジェクト: valgur/pyresample
 def test_self_map(self):
     swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)
     if sys.version_info < (2, 6):
         res = kd_tree.resample_gauss(swath_def, self.tb37v.copy(), swath_def, 
                                      radius_of_influence=70000, sigmas=56500)
     else:
         with warnings.catch_warnings(record=True) as w:
             res = kd_tree.resample_gauss(swath_def, self.tb37v.copy(), swath_def,
                                          radius_of_influence=70000, sigmas=56500)
             self.assertFalse(len(w) != 1, 'Failed to create neighbour radius warning')
             self.assertFalse(('Possible more' not in str(w[0].message)), 'Failed to create correct neighbour radius warning')
    
     self.assertAlmostEqual(res.sum() / 100., 668848.082208, 1, 
                             msg='Failed self mapping swath for 1 channel')
コード例 #8
0
ファイル: test_kd_tree.py プロジェクト: pytroll/pyresample
    def test_gauss_multi_uncert(self):
        data = np.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
        lons = np.fromfunction(
            lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
        lats = np.fromfunction(
            lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
        swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
        data_multi = np.column_stack((data.ravel(), data.ravel(),
                                      data.ravel()))
        with catch_warnings(UserWarning) as w:
            # The assertion below checks if there is only one warning raised
            # and whether it contains a specific message from pyresample
            # On python 2.7.9+ the resample_gauss method raises multiple deprecation warnings
            # that cause to fail, so we ignore the unrelated warnings.
            res, stddev, counts = kd_tree.resample_gauss(swath_def, data_multi,
                                                         self.area_def, 50000, [
                                                             25000, 15000, 10000],
                                                         segments=1, with_uncert=True)
            self.assertTrue(len(w) >= 1)
            self.assertTrue(
                any(['Possible more' in str(x.message) for x in w]))
        cross_sum = res.sum()
        cross_sum_counts = counts.sum()
        expected = 1461.8429990248171
        expected_stddev = [0.44621800779801657, 0.44363137712896705,
                           0.43861019464274459]
        expected_counts = 4934802.0
        self.assertTrue(res.shape == stddev.shape and stddev.shape ==
                        counts.shape and counts.shape == (800, 800, 3))
        self.assertAlmostEqual(cross_sum, expected)

        for i, e_stddev in enumerate(expected_stddev):
            cross_sum_stddev = stddev[:, :, i].sum()
            self.assertAlmostEqual(cross_sum_stddev, e_stddev)
        self.assertAlmostEqual(cross_sum_counts, expected_counts)
コード例 #9
0
    def test_self_map(self):
        swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)
        if sys.version_info < (2, 6):
            res = kd_tree.resample_gauss(swath_def, self.tb37v.copy(), swath_def,
                                         radius_of_influence=70000, sigmas=56500)
        else:
            with warnings.catch_warnings(record=True) as w:
                res = kd_tree.resample_gauss(swath_def, self.tb37v.copy(), swath_def,
                                             radius_of_influence=70000, sigmas=56500)
                self.assertFalse(
                    len(w) != 1, 'Failed to create neighbour radius warning')
                self.assertFalse(('Possible more' not in str(
                    w[0].message)), 'Failed to create correct neighbour radius warning')

        self.assertAlmostEqual(res.sum() / 100., 668848.082208, 1,
                               msg='Failed self mapping swath for 1 channel')
コード例 #10
0
ファイル: test_kd_tree.py プロジェクト: agoodm/pyresample
    def test_masked_gauss(self):
        data = numpy.ones((50, 10))
        data[:, 5:] = 2
        lons = numpy.fromfunction(lambda y, x: 3 + x, (50, 10))
        lats = numpy.fromfunction(lambda y, x: 75 - y, (50, 10))
        swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
        mask = numpy.ones((50, 10))
        mask[:, :5] = 0
        masked_data = numpy.ma.array(data, mask=mask)
        res = kd_tree.resample_gauss(swath_def, masked_data.ravel(),
                                     self.area_def, 50000, 25000, segments=1)
        expected_mask = numpy.fromfile(os.path.join(os.path.dirname(__file__),
                                                    'test_files',
                                                    'mask_test_mask.dat'),
                                       sep=' ').reshape((800, 800))
        expected_data = numpy.fromfile(os.path.join(os.path.dirname(__file__),
                                                    'test_files',
                                                    'mask_test_data.dat'),
                                       sep=' ').reshape((800, 800))
        expected = expected_data.sum()
        cross_sum = res.data.sum()

        self.assertTrue(numpy.array_equal(expected_mask, res.mask),
                        msg='Gauss resampling of swath mask failed')
        self.assertAlmostEqual(cross_sum, expected, places=3,
                               msg='Gauss resampling of swath masked data failed')
コード例 #11
0
    def test_masked_gauss(self):
        data = numpy.ones((50, 10))
        data[:, 5:] = 2
        lons = numpy.fromfunction(lambda y, x: 3 + x, (50, 10))
        lats = numpy.fromfunction(lambda y, x: 75 - y, (50, 10))
        swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
        mask = numpy.ones((50, 10))
        mask[:, :5] = 0
        masked_data = numpy.ma.array(data, mask=mask)
        res = kd_tree.resample_gauss(swath_def, masked_data.ravel(),
                                     self.area_def, 50000, 25000, segments=1)
        expected_mask = numpy.fromfile(os.path.join(os.path.dirname(__file__),
                                                    'test_files',
                                                    'mask_test_mask.dat'),
                                       sep=' ').reshape((800, 800))
        expected_data = numpy.fromfile(os.path.join(os.path.dirname(__file__),
                                                    'test_files',
                                                    'mask_test_data.dat'),
                                       sep=' ').reshape((800, 800))
        expected = expected_data.sum()
        cross_sum = res.data.sum()

        self.assertTrue(numpy.array_equal(expected_mask, res.mask),
                        msg='Gauss resampling of swath mask failed')
        self.assertAlmostEqual(cross_sum, expected, places=3,
                               msg='Gauss resampling of swath masked data failed')
コード例 #12
0
ファイル: test_kd_tree.py プロジェクト: goodsonr/pyresample
 def test_gauss_multi(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10**-6, (5000, 100))
     lons = numpy.fromfunction(lambda y, x: 3 + (10.0 / 100) * x,
                               (5000, 100))
     lats = numpy.fromfunction(lambda y, x: 75 - (50.0 / 5000) * y,
                               (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack(
         (data.ravel(), data.ravel(), data.ravel()))
     with catch_warnings() as w:
         res = kd_tree.resample_gauss(swath_def,
                                      data_multi,
                                      self.area_def,
                                      50000, [25000, 15000, 10000],
                                      segments=1)
         self.assertFalse(
             len(w) != 1, 'Failed to create neighbour radius warning')
         self.assertFalse(
             ('Possible more' not in str(w[0].message)),
             'Failed to create correct neighbour radius warning')
     cross_sum = res.sum()
     expected = 1461.84313918
     self.assertAlmostEqual(
         cross_sum,
         expected,
         msg='Swath multi channel resampling gauss failed')
コード例 #13
0
ファイル: test_kd_tree.py プロジェクト: sebastic/pyresample
    def test_gauss_multi_uncert(self):
        data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
        lons = numpy.fromfunction(
            lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
        lats = numpy.fromfunction(
            lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
        swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
        data_multi = numpy.column_stack((data.ravel(), data.ravel(),
                                         data.ravel()))
        with catch_warnings() as w:
            # The assertion below checks if there is only one warning raised
            # and whether it contains a specific message from pyresample
            # On python 2.7.9+ the resample_gauss method raises multiple deprecation warnings
            # that cause to fail, so we ignore the unrelated warnings.
            res, stddev, counts = kd_tree.resample_gauss(swath_def, data_multi,
                                                         self.area_def, 50000, [
                                                             25000, 15000, 10000],
                                                         segments=1, with_uncert=True)
            self.assertTrue(len(w) >= 1)
            self.assertTrue(
                any(['Possible more' in str(x.message) for x in w]))
        cross_sum = res.sum()
        cross_sum_counts = counts.sum()
        expected = 1461.8429990248171
        expected_stddev = [0.44621800779801657, 0.44363137712896705,
                           0.43861019464274459]
        expected_counts = 4934802.0
        self.assertTrue(res.shape == stddev.shape and stddev.shape ==
                        counts.shape and counts.shape == (800, 800, 3))
        self.assertAlmostEqual(cross_sum, expected)

        for i, e_stddev in enumerate(expected_stddev):
            cross_sum_stddev = stddev[:, :, i].sum()
            self.assertAlmostEqual(cross_sum_stddev, e_stddev)
        self.assertAlmostEqual(cross_sum_counts, expected_counts)
コード例 #14
0
ファイル: test_swath.py プロジェクト: pytroll/pyresample
    def test_self_map_multi(self):
        data = np.column_stack((self.tb37v, self.tb37v, self.tb37v))
        swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)

        with catch_warnings() as w:
            res = kd_tree.resample_gauss(
                swath_def, data, swath_def, radius_of_influence=70000, sigmas=[56500, 56500, 56500]
            )
            self.assertFalse(len(w) != 1, "Failed to create neighbour radius warning")
            self.assertFalse(
                ("Possible more" not in str(w[0].message)), "Failed to create correct neighbour radius warning"
            )

        if sys.platform == "darwin":
            # OSX seems to get slightly different results for `_spatial_mp.Cartesian`
            truth_value = 668848.144817
        else:
            truth_value = 668848.082208
        self.assertAlmostEqual(
            res[:, 0].sum() / 100.0, truth_value, 1, msg="Failed self mapping swath multi for channel 1"
        )
        self.assertAlmostEqual(
            res[:, 1].sum() / 100.0, truth_value, 1, msg="Failed self mapping swath multi for channel 2"
        )
        self.assertAlmostEqual(
            res[:, 2].sum() / 100.0, truth_value, 1, msg="Failed self mapping swath multi for channel 3"
        )
コード例 #15
0
ファイル: test_kd_tree.py プロジェクト: GEOGUXM/pyresample
    def test_gauss_uncert(self):
        sigma = utils.fwhm2sigma(41627.730557884883)
        with catch_warnings() as w:
            res, stddev, count = kd_tree.resample_gauss(self.tswath,
                                                        self.tdata,
                                                        self.tgrid,
                                                        100000,
                                                        sigma,
                                                        with_uncert=True)
            self.assertTrue(len(w) > 0, 'Failed to create neighbour warning')
            self.assertTrue((any('Searching' in str(_w.message) for _w in w)),
                            'Failed to create correct neighbour warning')

        expected_res = 2.20206560694
        expected_stddev = 0.707115076173
        expected_count = 3
        self.assertAlmostEqual(
            res[0], expected_res, 5,
            'Failed to calculate gaussian weighting with uncertainty')
        self.assertAlmostEqual(
            stddev[0], expected_stddev, 5,
            'Failed to calculate uncertainty for gaussian weighting')
        self.assertEqual(
            count[0], expected_count,
            'Wrong data point count for gaussian weighting with uncertainty')
コード例 #16
0
ファイル: test_kd_tree.py プロジェクト: pytroll/pyresample
 def test_gauss_base(self):
     with catch_warnings(UserWarning) as w:
         res = kd_tree.resample_gauss(self.tswath,
                                      self.tdata.ravel(), self.tgrid,
                                      50000, 25000, reduce_data=False, segments=1)
         self.assertFalse(len(w) != 1)
         self.assertFalse(('Searching' not in str(w[0].message)))
     self.assertAlmostEqual(res[0], 2.2020729, 5)
コード例 #17
0
 def test_gauss(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -5, (5000, 100))
     lons = numpy.fromfunction(lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     if sys.version_info < (2, 6) or (sys.version_info >= (3, 0) and sys.version_info < (3, 4)):
         res = kd_tree.resample_gauss(swath_def, data.ravel(), self.area_def, 50000, 25000, segments=1)
     else:
         with warnings.catch_warnings(record=True) as w:
             res = kd_tree.resample_gauss(swath_def, data.ravel(), self.area_def, 50000, 25000, segments=1)
             self.assertFalse(len(w) != 1, "Failed to create neighbour radius warning")
             self.assertFalse(
                 ("Possible more" not in str(w[0].message)), "Failed to create correct neighbour radius warning"
             )
     cross_sum = res.sum()
     expected = 4872.81050892
     self.assertAlmostEqual(cross_sum, expected, msg="Swath resampling gauss failed")
コード例 #18
0
ファイル: test_kd_tree.py プロジェクト: sebastic/pyresample
 def test_gauss_base(self):
     with catch_warnings() as w:
         res = kd_tree.resample_gauss(self.tswath,
                                      self.tdata.ravel(), self.tgrid,
                                      50000, 25000, reduce_data=False, segments=1)
         self.assertFalse(len(w) != 1)
         self.assertFalse(('Searching' not in str(w[0].message)))
     self.assertAlmostEqual(res[0], 2.2020729, 5)
コード例 #19
0
 def test_gauss_sparse(self):
     data = numpy.fromfunction(lambda y, x: y * x, (50, 10))
     lons = numpy.fromfunction(lambda y, x: 3 + x, (50, 10))
     lats = numpy.fromfunction(lambda y, x: 75 - y, (50, 10))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     res = kd_tree.resample_gauss(swath_def, data.ravel(), self.area_def, 50000, 25000, fill_value=-1, segments=1)
     cross_sum = res.sum()
     expected = 15387753.9852
     self.assertAlmostEqual(cross_sum, expected, places=3, msg="Swath gauss sparse nearest failed")
コード例 #20
0
 def test_gauss_fwhm(self):
     data = numpy.fromfunction(lambda y, x: (y + x)*10**-5, (5000, 100))        
     lons = numpy.fromfunction(lambda y, x: 3 + (10.0/100)*x, (5000, 100))
     lats = numpy.fromfunction(lambda y, x: 75 - (50.0/5000)*y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     if sys.version_info < (2, 6):
         res = kd_tree.resample_gauss(swath_def, data.ravel(),\
                                      self.area_def, 50000, utils.fwhm2sigma(41627.730557884883), segments=1)
     else:
         with warnings.catch_warnings(record=True) as w:
             res = kd_tree.resample_gauss(swath_def, data.ravel(),\
                                          self.area_def, 50000, utils.fwhm2sigma(41627.730557884883), segments=1)
             self.failIf(len(w) != 1, 'Failed to create neighbour radius warning')
             self.failIf(('Possible more' not in str(w[0].message)), 'Failed to create correct neighbour radius warning')        
     cross_sum = res.sum()        
     expected = 4872.81050892
     self.assertAlmostEqual(cross_sum, expected,\
                                msg='Swath resampling gauss failed')
コード例 #21
0
ファイル: test_kd_tree.py プロジェクト: cpaulik/pyresample
    def test_gauss_base(self):
        if (sys.version_info < (2, 6) or
                (sys.version_info >= (3, 0) and sys.version_info < (3, 4))):

            res = kd_tree.resample_gauss(self.tswath,
                                         self.tdata.ravel(), self.tgrid,
                                         50000, 25000, reduce_data=False, segments=1)
        else:
            with warnings.catch_warnings(record=True) as w:
                res = kd_tree.resample_gauss(self.tswath,
                                             self.tdata.ravel(), self.tgrid,
                                             50000, 25000, reduce_data=False, segments=1)
                self.assertFalse(
                    len(w) != 1, 'Failed to create neighbour warning')
                self.assertFalse(('Searching' not in str(
                    w[0].message)), 'Failed to create correct neighbour warning')
        self.assertAlmostEqual(res[0], 2.2020729, 5,
                               'Failed to calculate gaussian weighting')
コード例 #22
0
    def test_self_map_multi(self):
        data = np.column_stack((self.tb37v, self.tb37v, self.tb37v))
        swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)

        if (sys.version_info < (2, 6)
                or (sys.version_info >= (3, 0) and sys.version_info < (3, 4))):
            res = kd_tree.resample_gauss(swath_def,
                                         data,
                                         swath_def,
                                         radius_of_influence=70000,
                                         sigmas=[56500, 56500, 56500])
        else:
            with warnings.catch_warnings(record=True) as w:
                res = kd_tree.resample_gauss(swath_def,
                                             data,
                                             swath_def,
                                             radius_of_influence=70000,
                                             sigmas=[56500, 56500, 56500])
                self.assertFalse(
                    len(w) != 1, 'Failed to create neighbour radius warning')
                self.assertFalse(
                    ('Possible more' not in str(w[0].message)),
                    'Failed to create correct neighbour radius warning')

        if sys.platform == 'darwin':
            # OSX seems to get slightly different results for `_spatial_mp.Cartesian`
            truth_value = 668848.144817
        else:
            truth_value = 668848.082208
        self.assertAlmostEqual(
            res[:, 0].sum() / 100.,
            truth_value,
            1,
            msg='Failed self mapping swath multi for channel 1')
        self.assertAlmostEqual(
            res[:, 1].sum() / 100.,
            truth_value,
            1,
            msg='Failed self mapping swath multi for channel 2')
        self.assertAlmostEqual(
            res[:, 2].sum() / 100.,
            truth_value,
            1,
            msg='Failed self mapping swath multi for channel 3')
コード例 #23
0
ファイル: test_kd_tree.py プロジェクト: sebastic/pyresample
 def test_gauss_sparse(self):
     data = numpy.fromfunction(lambda y, x: y * x, (50, 10))
     lons = numpy.fromfunction(lambda y, x: 3 + x, (50, 10))
     lats = numpy.fromfunction(lambda y, x: 75 - y, (50, 10))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     res = kd_tree.resample_gauss(swath_def, data.ravel(),
                                  self.area_def, 50000, 25000, fill_value=-1, segments=1)
     cross_sum = res.sum()
     expected = 15387753.9852
     self.assertAlmostEqual(cross_sum, expected, places=3)
コード例 #24
0
ファイル: test_swath.py プロジェクト: valgur/pyresample
 def test_self_map_multi(self):
     data = np.column_stack((self.tb37v, self.tb37v, self.tb37v))
     swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)
     if sys.version_info < (2, 6):
         res = kd_tree.resample_gauss(swath_def, data, swath_def, 
                                      radius_of_influence=70000, sigmas=[56500, 56500, 56500])
     else:
         with warnings.catch_warnings(record=True) as w:
             res = kd_tree.resample_gauss(swath_def, data, swath_def, 
                                          radius_of_influence=70000, sigmas=[56500, 56500, 56500])
             self.assertFalse(len(w) != 1, 'Failed to create neighbour radius warning')
             self.assertFalse(('Possible more' not in str(w[0].message)), 'Failed to create correct neighbour radius warning')
             
     self.assertAlmostEqual(res[:, 0].sum() / 100., 668848.082208, 1, 
                                msg='Failed self mapping swath multi for channel 1')
     self.assertAlmostEqual(res[:, 1].sum() / 100., 668848.082208, 1, 
                                msg='Failed self mapping swath multi for channel 2')
     self.assertAlmostEqual(res[:, 2].sum() / 100., 668848.082208, 1, 
                                msg='Failed self mapping swath multi for channel 3')            
コード例 #25
0
ファイル: test_kd_tree.py プロジェクト: agoodm/pyresample
 def test_gauss_base(self):
     with catch_warnings() as w:
         res = kd_tree.resample_gauss(self.tswath,
                                      self.tdata.ravel(), self.tgrid,
                                      50000, 25000, reduce_data=False, segments=1)
         self.assertFalse(
             len(w) != 1, 'Failed to create neighbour warning')
         self.assertFalse(('Searching' not in str(
             w[0].message)), 'Failed to create correct neighbour warning')
     self.assertAlmostEqual(res[0], 2.2020729, 5,
                            'Failed to calculate gaussian weighting')
コード例 #26
0
 def test_gauss_multi_mp_segments_empty(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
     lons = numpy.fromfunction(lambda y, x: 165 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack((data.ravel(), data.ravel(), data.ravel()))
     res = kd_tree.resample_gauss(
         swath_def, data_multi, self.area_def, 50000, [25000, 15000, 10000], nprocs=2, segments=1
     )
     cross_sum = res.sum()
     self.assertTrue(cross_sum == 0, msg=("Swath multi channel segments empty " "resampling gauss failed"))
コード例 #27
0
 def test_gauss_base(self):
     with catch_warnings() as w:
         res = kd_tree.resample_gauss(self.tswath,
                                      self.tdata.ravel(), self.tgrid,
                                      50000, 25000, reduce_data=False, segments=1)
         self.assertFalse(
             len(w) != 1, 'Failed to create neighbour warning')
         self.assertFalse(('Searching' not in str(
             w[0].message)), 'Failed to create correct neighbour warning')
     self.assertAlmostEqual(res[0], 2.2020729, 5,
                            'Failed to calculate gaussian weighting')
コード例 #28
0
ファイル: mask.py プロジェクト: cherishing99/pysiral
    def export_l3_mask(self, griddef, nc_filepath=None):
        """ Create a gridded mask product in pysiral compliant filenaming.
        The argument griddef is needs to be a pysiral.grid.GridDefinition
        instance """

        # Get the area definition for the grid
        if not isinstance(griddef, GridDefinition):
            msg = "griddef needs to be of type pysiral.grid.GridDefinition"
            self.error.add_error("value-error", msg)

        # Resample the mask
        if self.cfg.pyresample_method == "ImageContainerNearest":
            resample = image.ImageContainerNearest(self.source_mask,
                                                   self.source_area_def,
                                                   **self.cfg.pyresample_keyw)
            resample_result = resample.resample(griddef.pyresample_area_def)
            target_mask = resample_result.image_data

        elif self.cfg.pyresample_method == "resample_gauss":

            result, stddev, count = kd_tree.resample_gauss(
                self.source_area_def,
                self.source_mask,
                griddef.pyresample_area_def,
                with_uncert=True,
                **self.cfg.pyresample_keyw)
            target_mask = result

        else:
            msg = "Unrecognized opt pyresample_method: %s need to be %s" % (
                str(self.cfg.pyresample_method),
                "(ImageContainerNearest, resample_gauss)")
            self.error.add_error("invalid-pr-method", msg)
            self.error.add_error()

        # pyresample may use masked arrays -> set nan's to missing data
        try:
            target_mask[np.where(target_mask.mask)] = np.nan
        except AttributeError:
            pass

        if "post_processing" in self.cfg:
            pp_method = getattr(self, self.cfg.post_processing)
            target_mask = pp_method(target_mask, griddef)

        # Write the mask to a netCDF file
        # (the filename will be automatically generated if not specifically
        # passed to this method
        if nc_filepath is None:
            nc_filename = "%s_%s.nc" % (self.mask_name, griddef.grid_id)
            nc_filepath = os.path.join(self.mask_dir, nc_filename)
        self.log.info("Export mask file: %s" % nc_filepath)
        self._write_netcdf(nc_filepath, griddef, target_mask)
コード例 #29
0
ファイル: test_swath.py プロジェクト: cpaulik/pyresample
    def test_self_map(self):
        swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)
        if sys.version_info < (2, 6):
            res = kd_tree.resample_gauss(swath_def, self.tb37v.copy(), swath_def,
                                         radius_of_influence=70000, sigmas=56500)
        else:
            with warnings.catch_warnings(record=True) as w:
                res = kd_tree.resample_gauss(swath_def, self.tb37v.copy(), swath_def,
                                             radius_of_influence=70000, sigmas=56500)
                self.assertFalse(
                    len(w) != 1, 'Failed to create neighbour radius warning')
                self.assertFalse(('Possible more' not in str(
                    w[0].message)), 'Failed to create correct neighbour radius warning')

        if sys.platform == 'darwin':
            # OSX seems to get slightly different results for `_spatial_mp.Cartesian`
            truth_value = 668848.144817
        else:
            truth_value = 668848.082208
        self.assertAlmostEqual(res.sum() / 100., truth_value, 1,
                               msg='Failed self mapping swath for 1 channel')
コード例 #30
0
ファイル: test_kd_tree.py プロジェクト: goodsonr/pyresample
 def test_gauss_multi_uncert(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10**-6, (5000, 100))
     lons = numpy.fromfunction(lambda y, x: 3 + (10.0 / 100) * x,
                               (5000, 100))
     lats = numpy.fromfunction(lambda y, x: 75 - (50.0 / 5000) * y,
                               (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack(
         (data.ravel(), data.ravel(), data.ravel()))
     with catch_warnings() as w:
         # The assertion below checks if there is only one warning raised
         # and whether it contains a specific message from pyresample
         # On python 2.7.9+ the resample_gauss method raises multiple deprecation warnings
         # that cause to fail, so we ignore the unrelated warnings.
         res, stddev, counts = kd_tree.resample_gauss(swath_def,
                                                      data_multi,
                                                      self.area_def,
                                                      50000,
                                                      [25000, 15000, 10000],
                                                      segments=1,
                                                      with_uncert=True)
         self.assertTrue(
             len(w) >= 1, 'Failed to create neighbour radius warning')
         self.assertTrue(
             any(['Possible more' in str(x.message) for x in w]),
             'Failed to create correct neighbour radius warning')
     cross_sum = res.sum()
     cross_sum_counts = counts.sum()
     expected = 1461.84313918
     expected_stddev = [0.446193170875, 0.443606880035, 0.438586349519]
     expected_counts = 4934802.0
     self.assertTrue(res.shape == stddev.shape
                     and stddev.shape == counts.shape
                     and counts.shape == (800, 800, 3))
     self.assertAlmostEqual(
         cross_sum,
         expected,
         msg='Swath multi channel resampling gauss failed on data')
     for i, e_stddev in enumerate(expected_stddev):
         cross_sum_stddev = stddev[:, :, i].sum()
         print(cross_sum_stddev, e_stddev)
         self.assertAlmostEqual(
             cross_sum_stddev,
             e_stddev,
             msg=
             'Swath multi channel resampling gauss failed on stddev (channel {})'
             .format(i))
     self.assertAlmostEqual(
         cross_sum_counts,
         expected_counts,
         msg='Swath multi channel resampling gauss failed on counts')
コード例 #31
0
ファイル: test_kd_tree.py プロジェクト: cpaulik/pyresample
 def test_gauss_fwhm(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -5, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     if (sys.version_info < (2, 6) or
             (sys.version_info >= (3, 0) and sys.version_info < (3, 4))):
         res = kd_tree.resample_gauss(swath_def, data.ravel(),
                                      self.area_def, 50000, utils.fwhm2sigma(41627.730557884883), segments=1)
     else:
         with warnings.catch_warnings(record=True) as w:
             res = kd_tree.resample_gauss(swath_def, data.ravel(),
                                          self.area_def, 50000, utils.fwhm2sigma(41627.730557884883), segments=1)
             self.assertFalse(
                 len(w) != 1, 'Failed to create neighbour radius warning')
             self.assertFalse(('Possible more' not in str(
                 w[0].message)), 'Failed to create correct neighbour radius warning')
     cross_sum = res.sum()
     expected = 4872.81050892
     self.assertAlmostEqual(cross_sum, expected,
                            msg='Swath resampling gauss failed')
コード例 #32
0
ファイル: test_kd_tree.py プロジェクト: pytroll/pyresample
    def test_gauss_uncert(self):
        sigma = utils.fwhm2sigma(41627.730557884883)
        with catch_warnings(UserWarning) as w:
            res, stddev, count = kd_tree.resample_gauss(self.tswath, self.tdata,
                                                        self.tgrid, 100000, sigma,
                                                        with_uncert=True)
            self.assertTrue(len(w) > 0)
            self.assertTrue((any('Searching' in str(_w.message) for _w in w)))

        expected_res = 2.20206560694
        expected_stddev = 0.707115076173
        expected_count = 3
        self.assertAlmostEqual(res[0], expected_res, 5)
        self.assertAlmostEqual(stddev[0], expected_stddev, 5)
        self.assertEqual(count[0], expected_count)
コード例 #33
0
ファイル: test_kd_tree.py プロジェクト: pytroll/pyresample
 def test_gauss_fwhm(self):
     data = np.fromfunction(lambda y, x: (y + x) * 10 ** -5, (5000, 100))
     lons = np.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = np.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     with catch_warnings(UserWarning) as w:
         res = kd_tree.resample_gauss(swath_def, data.ravel(),
                                      self.area_def, 50000, utils.fwhm2sigma(41627.730557884883), segments=1)
         self.assertFalse(len(w) != 1)
         self.assertFalse(('Possible more' not in str(w[0].message)))
     cross_sum = res.sum()
     expected = 4872.8100353517921
     self.assertAlmostEqual(cross_sum, expected)
コード例 #34
0
ファイル: test_swath.py プロジェクト: ibrewster/pyresample
    def test_self_map(self):
        swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)
        with catch_warnings() as w:
            res = kd_tree.resample_gauss(swath_def, self.tb37v.copy(), swath_def,
                                         radius_of_influence=70000, sigmas=56500)
            self.assertEqual(len(w), 1,
                             'Failed to create neighbour radius warning')
            self.assertFalse(('Possible more' not in str(
                w[0].message)), 'Failed to create correct neighbour radius warning')

        # only compare the whole number as different OSes and versions of numpy
        # can produce slightly different results
        truth_value = 668848.0
        self.assertAlmostEqual(res.sum() / 100., truth_value, 0,
                               msg='Failed self mapping swath for 1 channel')
コード例 #35
0
ファイル: test_kd_tree.py プロジェクト: sebastic/pyresample
 def test_gauss_fwhm(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -5, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     with catch_warnings() as w:
         res = kd_tree.resample_gauss(swath_def, data.ravel(),
                                      self.area_def, 50000, utils.fwhm2sigma(41627.730557884883), segments=1)
         self.assertFalse(len(w) != 1)
         self.assertFalse(('Possible more' not in str(w[0].message)))
     cross_sum = res.sum()
     expected = 4872.8100353517921
     self.assertAlmostEqual(cross_sum, expected)
コード例 #36
0
ファイル: test_kd_tree.py プロジェクト: sebastic/pyresample
 def test_gauss_multi_mp_segments_empty(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 165 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack((data.ravel(), data.ravel(),
                                      data.ravel()))
     res = kd_tree.resample_gauss(swath_def, data_multi,
                                  self.area_def, 50000, [
                                      25000, 15000, 10000],
                                  nprocs=2, segments=1)
     cross_sum = res.sum()
     self.assertTrue(cross_sum == 0)
コード例 #37
0
ファイル: test_kd_tree.py プロジェクト: sebastic/pyresample
    def test_gauss_uncert(self):
        sigma = utils.fwhm2sigma(41627.730557884883)
        with catch_warnings() as w:
            res, stddev, count = kd_tree.resample_gauss(self.tswath, self.tdata,
                                                        self.tgrid, 100000, sigma,
                                                        with_uncert=True)
            self.assertTrue(len(w) > 0)
            self.assertTrue((any('Searching' in str(_w.message) for _w in w)))

        expected_res = 2.20206560694
        expected_stddev = 0.707115076173
        expected_count = 3
        self.assertAlmostEqual(res[0], expected_res, 5)
        self.assertAlmostEqual(stddev[0], expected_stddev, 5)
        self.assertEqual(count[0], expected_count)
コード例 #38
0
ファイル: test_kd_tree.py プロジェクト: sebastic/pyresample
 def test_gauss_multi(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack((data.ravel(), data.ravel(),
                                      data.ravel()))
     with catch_warnings() as w:
         res = kd_tree.resample_gauss(swath_def, data_multi,
                                      self.area_def, 50000, [25000, 15000, 10000], segments=1)
         self.assertFalse(len(w) != 1)
         self.assertFalse(('Possible more' not in str(w[0].message)))
     cross_sum = res.sum()
     expected = 1461.8429990248171
     self.assertAlmostEqual(cross_sum, expected)
コード例 #39
0
ファイル: test_kd_tree.py プロジェクト: pytroll/pyresample
 def test_gauss_multi(self):
     data = np.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
     lons = np.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = np.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = np.column_stack((data.ravel(), data.ravel(),
                                   data.ravel()))
     with catch_warnings(UserWarning) as w:
         res = kd_tree.resample_gauss(swath_def, data_multi,
                                      self.area_def, 50000, [25000, 15000, 10000], segments=1)
         self.assertFalse(len(w) != 1)
         self.assertFalse(('Possible more' not in str(w[0].message)))
     cross_sum = res.sum()
     expected = 1461.8429990248171
     self.assertAlmostEqual(cross_sum, expected)
コード例 #40
0
ファイル: test_kd_tree.py プロジェクト: agoodm/pyresample
 def test_gauss(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -5, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     with catch_warnings() as w:
         res = kd_tree.resample_gauss(swath_def, data.ravel(),
                                      self.area_def, 50000, 25000, segments=1)
         self.assertFalse(
             len(w) != 1, 'Failed to create neighbour radius warning')
         self.assertFalse(('Possible more' not in str(
             w[0].message)), 'Failed to create correct neighbour radius warning')
     cross_sum = res.sum()
     expected = 4872.81050892
     self.assertAlmostEqual(cross_sum, expected,
                            msg='Swath resampling gauss failed')
コード例 #41
0
 def test_gauss(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -5, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     with catch_warnings() as w:
         res = kd_tree.resample_gauss(swath_def, data.ravel(),
                                      self.area_def, 50000, 25000, segments=1)
         self.assertFalse(
             len(w) != 1, 'Failed to create neighbour radius warning')
         self.assertFalse(('Possible more' not in str(
             w[0].message)), 'Failed to create correct neighbour radius warning')
     cross_sum = res.sum()
     expected = 4872.81050892
     self.assertAlmostEqual(cross_sum, expected,
                            msg='Swath resampling gauss failed')
コード例 #42
0
ファイル: test_swath.py プロジェクト: ibrewster/pyresample
    def test_self_map_multi(self):
        data = np.column_stack((self.tb37v, self.tb37v, self.tb37v))
        swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)

        with catch_warnings() as w:
            res = kd_tree.resample_gauss(swath_def, data, swath_def,
                                         radius_of_influence=70000, sigmas=[56500, 56500, 56500])
            self.assertEqual(len(w), 1,
                             'Failed to create neighbour radius warning')
            self.assertFalse(('Possible more' not in str(
                w[0].message)), 'Failed to create correct neighbour radius warning')

        truth_value = 668848.0
        self.assertAlmostEqual(res[:, 0].sum() / 100., truth_value, 0,
                               msg='Failed self mapping swath multi for channel 1')
        self.assertAlmostEqual(res[:, 1].sum() / 100., truth_value, 0,
                               msg='Failed self mapping swath multi for channel 2')
        self.assertAlmostEqual(res[:, 2].sum() / 100., truth_value, 0,
                               msg='Failed self mapping swath multi for channel 3')
コード例 #43
0
    def test_gauss_uncert(self):
        sigma = utils.fwhm2sigma(41627.730557884883)
        with catch_warnings() as w:
            res, stddev, count = kd_tree.resample_gauss(self.tswath, self.tdata,
                                                        self.tgrid, 100000, sigma,
                                                        with_uncert=True)
            self.assertTrue(
                len(w) > 0, 'Failed to create neighbour warning')
            self.assertTrue((any('Searching' in str(_w.message) for _w in w)),
                'Failed to create correct neighbour warning')

        expected_res = 2.20206560694
        expected_stddev = 0.707115076173
        expected_count = 3
        self.assertAlmostEqual(res[0], expected_res, 5,
                               'Failed to calculate gaussian weighting with uncertainty')
        self.assertAlmostEqual(stddev[0], expected_stddev, 5,
                               'Failed to calculate uncertainty for gaussian weighting')
        self.assertEqual(
            count[0], expected_count, 'Wrong data point count for gaussian weighting with uncertainty')
コード例 #44
0
def resample_gauss(lon, lat, var, rsplon, rsplat, radius, sigma,
                   fill_value=None, nprocs=1, show=False):
    """
    """
    swath = geometry.SwathDefinition(lons=lon, lats=lat)
    rspswath = geometry.SwathDefinition(lons=rsplon, lats=rsplat)
    rspvar = kd_tree.resample_gauss(swath, var, rspswath, radius, sigma,
                                    fill_value=fill_value, nprocs=nprocs,
                                    with_uncert=show)
    if show == True:
        import matplotlib.pyplot as plt
        imgs = rspvar
        if len(var.shape) == 2:
            imgs = (var,) + imgs
        for img in imgs:
            plt.figure()
            plt.imshow(img, interpolation='nearest')
            plt.colorbar()
        plt.show()
        rspvar = rspvar[0]
    return rspvar.astype(var.dtype)
コード例 #45
0
ファイル: test_swath.py プロジェクト: wroberts4/Homework
    def test_self_map(self):
        swath_def = geometry.SwathDefinition(lons=self.lons, lats=self.lats)
        with catch_warnings() as w:
            res = kd_tree.resample_gauss(swath_def,
                                         self.tb37v.copy(),
                                         swath_def,
                                         radius_of_influence=70000,
                                         sigmas=56500)
            self.assertFalse(
                len(w) != 1, 'Failed to create neighbour radius warning')
            self.assertFalse(
                ('Possible more' not in str(w[0].message)),
                'Failed to create correct neighbour radius warning')

        if sys.platform == 'darwin':
            # OSX seems to get slightly different results for `_spatial_mp.Cartesian`
            truth_value = 668848.144817
        else:
            truth_value = 668848.082208
        self.assertAlmostEqual(res.sum() / 100.,
                               truth_value,
                               1,
                               msg='Failed self mapping swath for 1 channel')
コード例 #46
0
ファイル: reproject2.py プロジェクト: lookie121/acolite_mr
def reproject2(data, lon0, lat0, lon1, lat1, fill=-9999, nearest=True):
    from pyresample import image, geometry

    source_def = geometry.SwathDefinition(lons=lon0, lats=lat0)
    target_def = geometry.SwathDefinition(lons=lon1, lats=lat1)

    if nearest:
        source_con = image.ImageContainerNearest(data,
                                                 source_def,
                                                 radius_of_influence=100)
        target_con = source_con.resample(target_def)
        target_con.fill_value = fill
        result = target_con.image_data
    else:
        from pyresample import kd_tree
        result = kd_tree.resample_gauss(source_def,
                                        data,
                                        target_def,
                                        radius_of_influence=100,
                                        neighbours=1,
                                        sigmas=0,
                                        fill_value=fill)

    return result
コード例 #47
0
 def test_gauss_multi_uncert(self):
     data = numpy.fromfunction(lambda y, x: (y + x) * 10 ** -6, (5000, 100))
     lons = numpy.fromfunction(
         lambda y, x: 3 + (10.0 / 100) * x, (5000, 100))
     lats = numpy.fromfunction(
         lambda y, x: 75 - (50.0 / 5000) * y, (5000, 100))
     swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
     data_multi = numpy.column_stack((data.ravel(), data.ravel(),
                                      data.ravel()))
     with catch_warnings() as w:
         # The assertion below checks if there is only one warning raised
         # and whether it contains a specific message from pyresample
         # On python 2.7.9+ the resample_gauss method raises multiple deprecation warnings
         # that cause to fail, so we ignore the unrelated warnings.
         res, stddev, counts = kd_tree.resample_gauss(swath_def, data_multi,
                                                      self.area_def, 50000, [
                                                          25000, 15000, 10000],
                                                      segments=1, with_uncert=True)
         self.assertTrue(
             len(w) >= 1, 'Failed to create neighbour radius warning')
         self.assertTrue(any(['Possible more' in str(
             x.message) for x in w]), 'Failed to create correct neighbour radius warning')
     cross_sum = res.sum()
     cross_sum_stddev = stddev.sum()
     cross_sum_counts = counts.sum()
     expected = 1461.84313918
     expected_stddev = 0.446204424799
     expected_counts = 4934802.0
     self.assertTrue(res.shape == stddev.shape and stddev.shape ==
                     counts.shape and counts.shape == (800, 800, 3))
     self.assertAlmostEqual(cross_sum, expected,
                            msg='Swath multi channel resampling gauss failed on data')
     self.assertAlmostEqual(cross_sum_stddev, expected_stddev,
                            msg='Swath multi channel resampling gauss failed on stddev')
     self.assertAlmostEqual(cross_sum_counts, expected_counts,
                            msg='Swath multi channel resampling gauss failed on counts')
コード例 #48
0
def main():
 
  # ----------------------------------------------
  # read 3 different float arrays from 3 a netcdf:
  #   (1) latitudes
  #   (2) longitudes
  #   (3) temperatures (degrees Kelvin)
  # ----------------------------------------------
 
  ncReader      = Dataset(filename,'r')
  temperatures  = ncReader['dX'][:]
  latitudes     = ncReader['lat'][:]
  longitudes    = ncReader['lon'][:]
  ncReader.close()
 
  # plot the X,Y,Z (Longitudes,Latitudes,Tempeatures)
  # using Python's basemap library
  plotBasemap( longitudes,latitudes,temperatures )
 
  # manually define Polar-stereographic projection
  # using a Python dictionary{}
 
  projection = 'stere'
  areaDict = dict(
    lat_0=90,
    lon_0=-45,
    k=1, x_0=0, y_0=0,
    a=6378273, b=6356889.449 ,
    proj=projection,units='m'
  )
 
  # define rectangular bounds for domain of output Geotiff
  areaExtent = (-3850000.0, -5350000.0, 3750000.0, 5850000.0)
 
  # names-strings for Pyresample regridding objects
  # (could be anything)
  areaID = 'nucaps swath data'
  areaName = 'nucaps granules'
 
  # create a Pyresample AreaDefinition() object
  # by passing-in output regridding dimensions (2000x2000),
  # projection object, area-bounds
 
  areaDef = geometry.AreaDefinition(
    areaID,
    areaName,
    projection,
    areaDict ,
    2000,
    2000,
    areaExtent
  )
 
  # create Pyresample SwathDefinition object, passing in
  # 1D NumPy arrays of longitudes and latitudes
  swathDef = geometry.SwathDefinition(lons=longitudes,lats=latitudes)
 
  # using Pyresample's resample_gauss() method to regrid satellite data
  # into polar stereographic projection
 
  regridding_result = kd_tree.resample_gauss(swathDef, temperatures.ravel(), \
  areaDef, radius_of_influence=70000, sigmas=25000)#fill_value=None)
 
  # write result to Geotiff
  toGeotiff(regridding_result,areaDef)
コード例 #49
0
ファイル: of_grid.py プロジェクト: loniitkina/ALS_overflight
tm = tm.tolist()
tm_hr = np.array(map(lambda x: x.hour + (x.minute)/60. + (x.second)/3600., tm))
lons = np.array(getColumn(alsfile,4),dtype=float)
lats = np.array(getColumn(alsfile,2),dtype=float)
xshift = np.array(getColumn(alsfile,10),dtype=float)
yshift = np.array(getColumn(alsfile,9),dtype=float)

#get the virtual buoy data
data = np.loadtxt(vbuoys, dtype=np.str,delimiter=',', skiprows=1)
latitude1 = np.ma.array(data[:,1],mask=data[:,1]=='0',dtype=float)
longitude1 = np.ma.array(data[:,0],mask=data[:,2]=='0',dtype=float)

#define projection and interpolate to regular grid
area_def = pr.utils.load_area('area.cfg', reg)
swath_def = geometry.SwathDefinition(lons=lons, lats=lats)
als_map = kd_tree.resample_gauss(swath_def, als,area_def, radius_of_influence=10, sigmas=5)
#als_map = kd_tree.resample_nearest(swath_def, als,area_def, radius_of_influence=10)
#time_map = kd_tree.resample_gauss(swath_def, time,area_def, radius_of_influence=10, sigmas=5)
time_map = kd_tree.resample_nearest(swath_def, tm_hr,area_def, radius_of_influence=10)
xshift_map = kd_tree.resample_nearest(swath_def, xshift,area_def, radius_of_influence=10)
yshift_map = kd_tree.resample_nearest(swath_def, yshift,area_def, radius_of_influence=10)

#mask irrelevant and extreme data
#mask_bad = (time_map<10)|(time_map>14)|(als_map<-1)|(als_map>2)
#mask_bad = (als_map==0)
#als_map = np.ma.array(als_map, mask=mask_bad)
#time_map = np.ma.array(time_map, mask=mask_bad)


##plotting
#pr.plot.save_quicklook(outpath+'als14_quick.png', area_def, result, label='ALS freeboard (m)')
コード例 #50
0
def interp_kd_tree(list_of_arrays,
                   area_definition,
                   data_box_definition,
                   radius_of_influence,
                   interp_type='nearest',
                   sigmas=None):
    ''' Perform interpolation using pyresample's kd_tree.resample_nearest method
    +-----------------------+-----------+---------------------------------------------------+
    | Parameters:           | Type:     | Description:                                      |
    +=======================+===========+===================================================+
    | list_of_array:        | *list*    | list of arrays to be interpolated                 |
    |                       |   of      |                                                   |
    |                       |*ndarray*  |                                                   |
    +-----------------------+-----------+---------------------------------------------------+
    | area_definition:      |*areadef*  | pyresample area_definition object of current      |
    |                       |           |    region of interest                             |
    |                       |           |                                                   |
    +-----------------------+-----------+---------------------------------------------------+
    | data_box_definition:  } *datadef* | pyresample/geoips data_box_definition specifying  |
    |                       |           |    region covered by source data                  |
    +-----------------------+-----------+---------------------------------------------------+
    | radius_of_influence:  | *float*   | radius of influence for interpolation             |
    +-----------------------+-----------+---------------------------------------------------+
    +-----------------------+-----------+---------------------------------------------------+
    | Key Words:            | Type:     | Description:                                      |
    +================-----==+===========+===================================================+
    | interp_type:          | *string*  | One of 'nearest' or 'gauss' - kd_tree resampling  |
    |                       |           |    methods                                        |
    |                       |           |    *DEFAULT* 'nearest'                            |
    +-----------------------+-----------+---------------------------------------------------+
    | sigmas:               | *int*     | Used for interp_type 'gauss' - multiplication     |
    |                       |           |    factor for sigmas option:                      |
    |                       |           |    sigmas = [sigmas]*len(list_of_arrays)          |
    +-----------------------+-----------+---------------------------------------------------+
    '''

    dstacked_arrays = numpy.ma.dstack(list_of_arrays)

    if interp_type == 'nearest':
        LOG.info('Using interp_type %s', interp_type)
        dstacked_arrays = kd_tree.resample_nearest(
            data_box_definition,
            dstacked_arrays,
            area_definition,
            radius_of_influence=radius_of_influence,
            fill_value=None)
    elif interp_type == 'gauss':
        if sigmas is None:
            sigmas = 4000

        LOG.info('Using interp_type %s %s', interp_type, sigmas)
        dstacked_arrays = kd_tree.resample_gauss(
            data_box_definition,
            dstacked_arrays,
            area_definition,
            radius_of_influence=radius_of_influence,
            sigmas=[sigmas] * len(list_of_arrays),
            fill_value=None)
    else:
        raise TypeError('Unknown interp_type {0}, failing'.format(interp_type))

    interpolated_arrays = []
    # We are explicitly expecting 2d arrays back, so if 3d, break it down.
    for arrind in range(len(list_of_arrays)):
        if len(dstacked_arrays.shape) == 3:
            interpolated_arrays += [dstacked_arrays[:, :, arrind]]
        else:
            interpolated_arrays += [dstacked_arrays]

    return interpolated_arrays