Beispiel #1
0
 def construct_new_coord_given_points(coord, points):
     # Handle what was previously a DimCoord which may no longer be
     # monotonic.
     try:
         return coord.copy(points)
     except ValueError:
         return AuxCoord.from_coord(coord).copy(points)
Beispiel #2
0
 def construct_new_coord_given_points(coord, points):
     # Handle what was previously a DimCoord which may no longer be
     # monotonic.
     try:
         return coord.copy(points)
     except ValueError:
         return AuxCoord.from_coord(coord).copy(points)
Beispiel #3
0
 def test_no_slider_from_aux(self):
     coords = ('grid_longitude', 'grid_latitude')
     self.cube.remove_coord('time')
     fp = self.cube.coord('forecast_period')
     self.cube.remove_coord('forecast_period')
     aux = AuxCoord.from_coord(fp)
     self.cube.add_aux_coord(aux, 0)
     plot = Plot2D(self.cube, self.axes, coords=coords)
     self.assertEqual(plot._slider_dim_by_name, {})
Beispiel #4
0
 def test_basic(self):
     meshcoord = sample_meshcoord()
     auxcoord = AuxCoord.from_coord(meshcoord)
     for propname, auxval in auxcoord.metadata._asdict().items():
         meshval = getattr(meshcoord, propname)
         self.assertEqual(auxval, meshval)
     # Also check array content.
     self.assertArrayAllClose(auxcoord.points, meshcoord.points)
     self.assertArrayAllClose(auxcoord.bounds, meshcoord.bounds)
Beispiel #5
0
 def test_no_slider_from_aux(self):
     coords = ('grid_longitude', 'grid_latitude')
     self.cube.remove_coord('time')
     fp = self.cube.coord('forecast_period')
     self.cube.remove_coord('forecast_period')
     aux = AuxCoord.from_coord(fp)
     self.cube.add_aux_coord(aux, 0)
     plot = Plot2D(self.cube, self.axes, coords=coords)
     self.assertEqual(plot._slider_dim_by_name, {})
 def ok_bad(self, coord_name):
     # Demotes the named DimCoord on `bad` to an AuxCoord.
     ok = lat_lon_cube()
     bad = lat_lon_cube()
     coord = bad.coord(coord_name)
     dims = bad.coord_dims(coord)
     bad.remove_coord(coord_name)
     aux_coord = AuxCoord.from_coord(coord)
     bad.add_aux_coord(aux_coord, dims)
     return ok, bad
 def ok_bad(self, coord_name):
     # Demotes the named DimCoord on `bad` to an AuxCoord.
     ok = lat_lon_cube()
     bad = lat_lon_cube()
     coord = bad.coord(coord_name)
     dims = bad.coord_dims(coord)
     bad.remove_coord(coord_name)
     aux_coord = AuxCoord.from_coord(coord)
     bad.add_aux_coord(aux_coord, dims)
     return ok, bad
 def demote_coord(coord_name):
     bad = global_pp()
     coord = bad.coord(coord_name)
     dims = bad.coord_dims(coord)
     bad.remove_coord(coord_name)
     aux_coord = AuxCoord.from_coord(coord)
     bad.add_aux_coord(aux_coord, dims)
     with self.assertRaises(ValueError):
         regrid(bad, ok)
     with self.assertRaises(ValueError):
         regrid(ok, bad)
 def demote_coord(coord_name):
     bad = global_pp()
     coord = bad.coord(coord_name)
     dims = bad.coord_dims(coord)
     bad.remove_coord(coord_name)
     aux_coord = AuxCoord.from_coord(coord)
     bad.add_aux_coord(aux_coord, dims)
     with self.assertRaises(ValueError):
         regrid(bad, ok)
     with self.assertRaises(ValueError):
         regrid(ok, bad)
    def test_mixed_shapes(self):
        self.lon = AuxCoord.from_coord(self.lon)
        lon_bounds = np.array([[0, 0, 1, 1], [1, 1, 2, 2], [2, 3, 2.5, 999]])
        self.lon.bounds = np.ma.masked_equal(lon_bounds, 999)

        lat_bounds = np.array([[0, 1, 1, 0], [1, 2, 2, 1], [2, 2, 3, 999]])
        self.lat.bounds = np.ma.masked_equal(lat_bounds, 999)

        mesh = self.create()
        self.assertArrayEqual(mesh.face_node_connectivity.location_lengths(),
                              [4, 4, 3])
        self.assertEqual(mesh.node_coords.node_x.points[-1], 0.0)
        self.assertEqual(mesh.node_coords.node_y.points[-1], 0.0)
    def test_lazy(self):
        self.lon = AuxCoord.from_coord(self.lon)
        self.lon = self.lon.copy(self.lon.lazy_points(),
                                 self.lon.lazy_bounds())
        self.lat = self.lat.copy(self.lat.lazy_points(),
                                 self.lat.lazy_bounds())

        mesh = self.create()
        for coord in list(mesh.all_coords):
            if coord is not None:
                self.assertTrue(coord.has_lazy_points())
        for conn in list(mesh.all_connectivities):
            if conn is not None:
                self.assertTrue(conn.has_lazy_indices())
Beispiel #12
0
    def _resample_coord(self, sample_points, coord, coord_dims):
        """
        Interpolate the given coordinate at the provided sample points.

        """
        # NB. This section is ripe for improvement:
        # - Internally self._points() expands coord.points to the same
        #   N-dimensional shape as the cube's data, but it doesn't
        #   collapse it again before returning so we have to do that
        #   here.
        # - By expanding to N dimensions self._points() is doing
        #   unnecessary work.
        data = self._points(sample_points, coord.points, coord_dims)
        index = tuple(0 if dim not in coord_dims else slice(None)
                      for dim in range(self._src_cube.ndim))
        new_points = data[index]
        # Watch out for DimCoord instances that are no longer monotonic
        # after the resampling.
        try:
            new_coord = coord.copy(new_points)
        except ValueError:
            aux_coord = AuxCoord.from_coord(coord)
            new_coord = aux_coord.copy(new_points)
        return new_coord
Beispiel #13
0
    def _resample_coord(self, sample_points, coord, coord_dims):
        """
        Interpolate the given coordinate at the provided sample points.

        """
        # NB. This section is ripe for improvement:
        # - Internally self._points() expands coord.points to the same
        #   N-dimensional shape as the cube's data, but it doesn't
        #   collapse it again before returning so we have to do that
        #   here.
        # - By expanding to N dimensions self._points() is doing
        #   unnecessary work.
        data = self._points(sample_points, coord.points, coord_dims)
        index = tuple(0 if dim not in coord_dims else slice(None)
                      for dim in range(self._src_cube.ndim))
        new_points = data[index]
        # Watch out for DimCoord instances that are no longer monotonic
        # after the resampling.
        try:
            new_coord = coord.copy(new_points)
        except ValueError:
            aux_coord = AuxCoord.from_coord(coord)
            new_coord = aux_coord.copy(new_points)
        return new_coord