Beispiel #1
0
 def test_linint2pts_non_monotonic_np(self):
     import warnings
     with self.assertWarns(Warning):
         linint2pts(self._fi_np[:, :, ::-1, :],
                    self._xo,
                    self._yo,
                    0,
                    xi=self._xi,
                    yi=self._yi_reverse)
Beispiel #2
0
    def test_linint2pts_non_monotonic_xr(self):
        fi = xr.DataArray(self._fi_np[:, :, ::-1, :],
                          dims=['time', 'level', 'lat', 'lon'],
                          coords={
                              'lat': self._yi_reverse,
                              'lon': self._xi
                          }).chunk(self._chunks)

        import warnings
        with self.assertWarns(Warning):
            linint2pts(fi, self._xo, self._yo, 0).compute()
Beispiel #3
0
    def test_linint2pts_fi_np(self):
        fo = linint2pts(self._fi_np,
                        self._xo,
                        self._yo,
                        0,
                        xi=self._xi,
                        yi=self._yi)

        self.assertEqual((self._shape0, self._shape1), fo.shape[:-1])

        self.assertEqual(np.float64, fo.dtype)

        newshape = (self._shape0 * self._shape1 * self._no, )

        fo_vals = fo.values.reshape(newshape).tolist()

        print(
            self._fi_np.reshape(
                (self._shape0 * self._shape1 * self._ni * self._ni, )))

        print(fo_vals)

        print(self._xo)

        # Use numpy.testing.assert_almost_equal() instead of ut.TestCase.assertAlmostEqual() because the former can
        # handle NaNs but the latter cannot.
        # Compare the function-generated fo array to NCL ground-truth up to 5 decimal points
        np.testing.assert_almost_equal(self._ncl_truth, fo_vals, decimal=5)
Beispiel #4
0
    def test_linint2pts_msg_99(self):
        # fi_msg_99 = xr.DataArray(self._fi_np_msg_nan, dims=['time', 'level', 'lat', 'lon'], coords={'lat': self._yi, 'lon': self._xi}).chunk(self._chunks)
        fi_msg_99 = xr.DataArray(self._fi_np_msg_99,
                                 dims=['time', 'level', 'lat', 'lon'],
                                 coords={
                                     'lat': self._yi,
                                     'lon': self._xi
                                 }).chunk(self._chunks)

        fo = linint2pts(fi_msg_99,
                        self._xo,
                        self._yo,
                        0,
                        msg_py=self._fi_np_msg_99[0, 0, 0, 0])

        self.assertEqual((self._shape0, self._shape1), fo.shape[:-1])

        self.assertEqual(np.float64, fo.dtype)

        newshape = (self._shape0 * self._shape1 * self._no, )

        fo_vals = fo.values.reshape(newshape).tolist()

        # Use numpy.testing.assert_almost_equal() instead of ut.TestCase.assertAlmostEqual() because the former can
        # handle NaNs but the latter cannot.
        # Compare the function-generated fo array to NCL ground-truth up to 5 decimal points
        np.testing.assert_almost_equal(self.groundtruth_msg_99,
                                       fo_vals,
                                       decimal=5)
Beispiel #5
0
 def test_linint2pts_chunked_interp(self):
     # use 1 for interpolated dimension chunk sizes -- this should throw a ChunkError
     wrong_chunks = {'time': 1, 'level': 1, 'lat': 1, 'lon': 1}
     fi = xr.DataArray(self._fi_np,
                       dims=['time', 'level', 'lat', 'lon'],
                       coords={
                           'lat': self._yi,
                           'lon': self._xi
                       }).chunk(wrong_chunks)
     with self.assertRaises(ChunkError):
         fo = linint2pts(fi, self._xo, self._yo, 0)
Beispiel #6
0
    def test_linint2pts_chunked_leftmost(self):
        # use 1 for time and level chunk sizes
        custom_chunks = {
            'time': 1,
            'level': 1,
            'lat': self._fi_np.shape[2],
            'lon': self._fi_np.shape[3]
        }
        fi = xr.DataArray(self._fi_np,
                          dims=['time', 'level', 'lat', 'lon'],
                          coords={
                              'lat': self._yi,
                              'lon': self._xi
                          }).chunk(custom_chunks)
        fo = linint2pts(fi, self._xo, self._yo, 0)

        newshape = (self._shape0 * self._shape1 * self._no, )

        fo_vals = fo.values.reshape(newshape).tolist()

        # Use numpy.testing.assert_almost_equal() instead of ut.TestCase.assertAlmostEqual() because the former can
        # handle NaNs but the latter cannot.
        # Compare the function-generated fo array to NCL ground-truth up to 5 decimal points
        np.testing.assert_almost_equal(self._ncl_truth, fo_vals, decimal=5)
Beispiel #7
0
 def test_linint2pts_fi_np_no_xi(self):
     with self.assertRaises(CoordinateError):
         fo = linint2pts(self._fi_np, self._xo, self._yo, 0, yi=self._yi)