Beispiel #1
0
 def test_different_mesh(self):
     mesh1 = sample_mesh()
     mesh2 = sample_mesh()
     mesh2.long_name = "new_name"
     meshcoord1 = sample_meshcoord(mesh=mesh1)
     meshcoord2 = sample_meshcoord(mesh=mesh2)
     self.assertNotEqual(meshcoord2, meshcoord1)
Beispiel #2
0
 def test_different_identical_mesh(self):
     # For equality, must have the SAME mesh (at present).
     mesh1 = sample_mesh()
     mesh2 = sample_mesh()  # Presumably identical, but not the same
     meshcoord1 = sample_meshcoord(mesh=mesh1)
     meshcoord2 = sample_meshcoord(mesh=mesh2)
     # These should NOT compare, because the Meshes are not identical : at
     # present, Mesh equality is not implemented (i.e. limited to identity)
     self.assertNotEqual(meshcoord2, meshcoord1)
Beispiel #3
0
    def _external(*args, **kwargs):
        from iris.experimental.ugrid import save_mesh
        from iris.tests.stock.mesh import sample_mesh

        save_path_ = kwargs.pop("save_path")
        # Always saving, so laziness is irrelevant. Use lazy to save time.
        kwargs["lazy_values"] = True
        new_mesh = sample_mesh(*args, **kwargs)
        save_mesh(new_mesh, save_path_)
def common_test_setup(self, shape_3d=(0, 2), data_chunks=None):
    # Construct a basic testcase with all-lazy mesh_cube and submesh_cubes
    # full-mesh cube shape is 'shape_3d'
    # data_chunks sets chunking of source cube, (else all-1-chunk)
    n_outer, n_z = shape_3d
    n_mesh = 20
    mesh = sample_mesh(n_nodes=20, n_edges=0, n_faces=n_mesh)
    mesh_cube = sample_mesh_cube(n_z=n_z, mesh=mesh)
    # Fix index-coord name to the expected default for recombine_submeshes.
    mesh_cube.coord("i_mesh_face").rename("i_mesh_index")
    if n_outer:
        # Crudely merge a set of copies to build an outer dimension.
        mesh_cube.add_aux_coord(AuxCoord([0], long_name="outer"))
        meshcubes_2d = []
        for i_outer in range(n_outer):
            cube = mesh_cube.copy()
            cube.coord("outer").points = np.array([i_outer])
            meshcubes_2d.append(cube)
        mesh_cube = CubeList(meshcubes_2d).merge_cube()

    if not data_chunks:
        data_chunks = mesh_cube.shape[:-1] + (-1, )
    mesh_cube.data = da.zeros(mesh_cube.shape, chunks=data_chunks)

    n_regions = 4  # it doesn't divide neatly
    region_len = n_mesh // n_regions
    i_points = np.arange(n_mesh)
    region_inds = [
        np.where((i_points // region_len) == i_region)
        for i_region in range(n_regions)
    ]
    # Disturb slightly to ensure some gaps + some overlaps
    region_inds = [list(indarr[0]) for indarr in region_inds]
    region_inds[2] = region_inds[2][:-2]  # missing points
    region_inds[3] += region_inds[1][:2]  # duplicates
    self.mesh_cube = mesh_cube
    self.region_inds = region_inds
    self.region_cubes = [mesh_cube[..., inds] for inds in region_inds]
    for i_cube, cube in enumerate(self.region_cubes):
        for i_z in range(n_z):
            # Set data='z' ; don't vary over other dimensions.
            cube.data[..., i_z, :] = i_cube + 1000 * i_z + 1
            cube.data = cube.lazy_data()

    # Also construct an array to match the expected result (2d cases only).
    # basic layer showing region allocation (large -ve values for missing)
    expected = np.array([1.0, 1, 1, 1, 1] +
                        [4, 4]  # points in #1 overlapped by #3
                        + [2, 2, 2] + [3, 3, 3] +
                        [-99999, -99999]  # missing points
                        + [4, 4, 4, 4, 4])
    # second layer should be same but +1000.
    # NOTE: only correct if shape_3d=None; no current need to generalise this.
    expected = np.stack([expected, expected + 1000])
    # convert to masked array with missing points.
    expected = np.ma.masked_less(expected, 0)
    self.expected_result = expected
Beispiel #5
0
    def _external(sample_mesh_kwargs_, save_path_):
        from iris.experimental.ugrid import save_mesh
        from iris.tests.stock.mesh import sample_mesh, sample_meshcoord

        if sample_mesh_kwargs_:
            input_mesh = sample_mesh(**sample_mesh_kwargs_)
        else:
            input_mesh = None
        # Don't parse the location or axis arguments - only saving the Mesh at
        #  this stage.
        new_meshcoord = sample_meshcoord(mesh=input_mesh)
        save_mesh(new_meshcoord.mesh, save_path_)
Beispiel #6
0
def generate_cube_like_2d_cubesphere(n_cube: int, with_mesh: bool,
                                     output_path: str):
    """
    Construct and save to file an LFRIc cubesphere-like cube for a given
    cubesphere size, *or* a simpler structured (UM-like) cube of equivalent
    size.

    NOTE: this function is *NEVER* called from within this actual package.
    Instead, it is to be called via benchmarks.remote_data_generation,
    so that it can use up-to-date facilities, independent of the ASV controlled
    environment which contains the "Iris commit under test".
    This means:
      * it must be completely self-contained : i.e. it includes all its
        own imports, and saves results to an output file.

    """
    from iris import save
    from iris.tests.stock.mesh import sample_mesh, sample_mesh_cube

    n_face_nodes = n_cube * n_cube
    n_faces = 6 * n_face_nodes

    # Set n_nodes=n_faces and n_edges=2*n_faces
    # : Not exact, but similar to a 'real' cubesphere.
    n_nodes = n_faces
    n_edges = 2 * n_faces
    if with_mesh:
        mesh = sample_mesh(n_nodes=n_nodes,
                           n_faces=n_faces,
                           n_edges=n_edges,
                           lazy_values=True)
        cube = sample_mesh_cube(mesh=mesh, n_z=1)
    else:
        cube = sample_mesh_cube(nomesh_faces=n_faces, n_z=1)

    # Strip off the 'extra' aux-coord mapping the mesh, which sample-cube adds
    # but which we don't want.
    cube.remove_coord("mesh_face_aux")

    # Save the result to a named file.
    save(cube, output_path)
Beispiel #7
0
 def setUp(self):
     mesh = sample_mesh()
     self.mesh = mesh
     self.meshcoord = sample_meshcoord(mesh=mesh)
Beispiel #8
0
 def setUp(self):
     mesh = sample_mesh()
     self.mesh = mesh
     # Give mesh itself a name: makes a difference between str and repr.
     self.mesh.rename("test_mesh")
     self.meshcoord = sample_meshcoord(mesh=mesh)
Beispiel #9
0
 def test_equal_mesh(self):
     mesh1 = sample_mesh()
     mesh2 = sample_mesh()
     meshcoord1 = sample_meshcoord(mesh=mesh1)
     meshcoord2 = sample_meshcoord(mesh=mesh2)
     self.assertEqual(meshcoord2, meshcoord1)
Beispiel #10
0
 def setUp(self):
     self.mesh = sample_mesh()