-
Notifications
You must be signed in to change notification settings - Fork 300
Add summary of ugrid to cube print out #3688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8cefdf4
bbecf2f
495f8e4
d8274ae
3f4e76e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,16 @@ | |
|
|
||
|
|
||
| class CubeUgrid( | ||
| namedtuple("CubeUgrid", ["cube_dim", "grid", "mesh_location"]) | ||
| namedtuple( | ||
| "CubeUgrid", | ||
| [ | ||
| "cube_dim", | ||
| "grid", | ||
| "mesh_location", | ||
| "topology_dimension", | ||
| "node_coordinates", | ||
| ], | ||
| ) | ||
| ): | ||
| """ | ||
| Object recording the unstructured grid dimension of a cube. | ||
|
|
@@ -64,13 +73,25 @@ class CubeUgrid( | |
| Which element of the mesh the cube is mapped to. | ||
| Can be 'face', 'edge' or 'node'. A 'volume' is not supported. | ||
|
|
||
| * topology_dimension (int): | ||
| The highest dimensionality of the geometric elements in the mesh. | ||
|
|
||
| * node_coordinates (set): | ||
| A set of the names of the spatial coordinates, used to geolocate the nodes. | ||
|
|
||
| """ | ||
|
|
||
| def __str__(self): | ||
| result = "Cube unstructured-grid dimension:" | ||
| result += "\n cube dimension = {}".format(self.cube_dim) | ||
| result += '\n mesh_location = "{}"'.format(self.mesh_location) | ||
| result += '\n mesh "{}" :\n'.format(self.grid.mesh_name) | ||
| result += '\n mesh "{}" :'.format(self.grid.mesh_name) | ||
| result += '\n topology_dimension "{}" :'.format( | ||
| self.topology_dimension | ||
| ) | ||
| result += '\n node_coordinates "{}" :\n'.format( | ||
| " ".join(self.node_coordinates) | ||
| ) | ||
| try: | ||
| mesh_str = str(self.grid.info) | ||
| except TypeError: | ||
|
|
@@ -79,6 +100,9 @@ def __str__(self): | |
| result += "\n" | ||
| return result | ||
|
|
||
| def name(self): | ||
| return ".".join([self.grid.mesh_name, self.mesh_location]) | ||
|
|
||
|
|
||
| class UGridCFReader: | ||
| """ | ||
|
|
@@ -188,8 +212,23 @@ def complete_ugrid_cube(self, cube): | |
| raise ValueError(msg.format(meshes_info)) | ||
| if meshes_info: | ||
| i_dim, (mesh, mesh_location) = meshes_info[0] | ||
| mesh_var = self.dataset.variables[mesh.mesh_name] | ||
|
|
||
| topology_dimension = mesh_var.getncattr("topology_dimension") | ||
| node_coordinates = [] | ||
| for node_var_name in mesh_var.getncattr("node_coordinates").split( | ||
| " " | ||
| ): | ||
| node_var = self.dataset.variables[node_var_name] | ||
| node_coordinates.append(node_var.getncattr("standard_name")) | ||
|
||
| node_coordinates = set(node_coordinates) | ||
|
|
||
| cube.ugrid = CubeUgrid( | ||
| cube_dim=i_dim, grid=mesh, mesh_location=mesh_location | ||
| cube_dim=i_dim, | ||
| grid=mesh, | ||
| mesh_location=mesh_location, | ||
| topology_dimension=topology_dimension, | ||
| node_coordinates=node_coordinates, | ||
| ) | ||
| else: | ||
| # Add an empty 'cube.ugrid' to all cubes otherwise. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Copyright Iris contributors | ||
| # | ||
| # This file is part of Iris and is released under the LGPL license. | ||
| # See COPYING and COPYING.LESSER in the root of the repository for full | ||
| # licensing details. | ||
| """ | ||
| Integration tests for the print strings of a UGRID-based cube. | ||
|
|
||
| """ | ||
|
|
||
| # Import iris.tests first so that some things can be initialised before | ||
| # importing anything else. | ||
| import iris.tests as tests | ||
|
|
||
| from iris.cube import CubeList | ||
| from iris import Constraint | ||
| from iris.fileformats.netcdf import load_cubes | ||
|
|
||
|
|
||
| @tests.skip_data | ||
| class TestUgrid(tests.IrisTest): | ||
| def setUp(self): | ||
| file_path = tests.get_data_path( | ||
| ("NetCDF", "unstructured_grid", "theta_nodal_xios.nc") | ||
| ) | ||
|
|
||
| # cube = iris.load_cube(file_path, "theta") | ||
| # Note: cannot use iris.load, as merge does not yet preserve | ||
| # the cube 'ugrid' properties. | ||
|
|
||
| # Here's a thing that at least works. | ||
| loaded_cubes = CubeList(load_cubes(file_path, temp_xios_fix=True)) | ||
| (self.cube,) = loaded_cubes.extract(Constraint("theta")) | ||
|
|
||
| def test_str__short(self): | ||
| text = self.cube.summary(shorten=True) | ||
| expect = "Potential Temperature / (K) (time: 1; levels: 6; *-- : 866)" | ||
| self.assertEqual(text, expect) | ||
|
|
||
| def test_str__long(self): | ||
| self.cube.attributes.clear() # Just remove some uninteresting content. | ||
| text = str(self.cube) | ||
| expect = """\ | ||
| Potential Temperature / (K) (time: 1; levels: 6; *-- : 866) | ||
| Dimension coordinates: | ||
| time x - - | ||
| levels - x - | ||
| Auxiliary coordinates: | ||
| time x - - | ||
| ugrid information: | ||
| Mesh0.node - - x | ||
| topology_dimension: 2 | ||
| node_coordinates: latitude longitude | ||
| Cell methods: | ||
| point: time\ | ||
| """ | ||
| self.assertEqual(text, expect) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| tests.main() |
Uh oh!
There was an error while loading. Please reload this page.