|
1 | 1 | #!/usr/bin/env python |
| 2 | +import numpy as np |
2 | 3 | import xarray as xr |
3 | 4 |
|
4 | 5 | from mpas_tools.cime.constants import constants |
5 | 6 | from mpas_tools.mesh.conversion import convert, cull |
6 | 7 | from mpas_tools.planar_hex import make_planar_hex_mesh |
7 | 8 | from mpas_tools.translate import center |
8 | 9 | from mpas_tools.viz.mesh_to_triangles import mesh_to_triangles |
| 10 | +from mpas_tools.viz.transect.horiz import _fix_periodic_tris |
9 | 11 | from mpas_tools.viz.transect import ( |
10 | 12 | find_planar_transect_cells_and_weights, |
11 | 13 | find_spherical_transect_cells_and_weights, |
@@ -130,6 +132,24 @@ def test_find_planar_transect_cells_and_weights(): |
130 | 132 | assert var in ds_transect.data_vars |
131 | 133 |
|
132 | 134 |
|
| 135 | +def test_fix_periodic_tris_dataset_copy(): |
| 136 | + ds_tris = xr.Dataset( |
| 137 | + data_vars={ |
| 138 | + 'xNode': ( |
| 139 | + ('nTriangles', 'nNodes'), |
| 140 | + np.array([[0.0, 8.0, -8.0]]), |
| 141 | + ), |
| 142 | + } |
| 143 | + ) |
| 144 | + |
| 145 | + ds_new = _fix_periodic_tris(ds_tris, 'xNode', period=10.0) |
| 146 | + |
| 147 | + assert ds_new.sizes['nTriangles'] == 3 |
| 148 | + assert np.allclose(ds_new.xNode.values[0, :], [0.0, -2.0, 2.0]) |
| 149 | + assert np.allclose(ds_new.xNode.values[1, :], [10.0, 8.0, 12.0]) |
| 150 | + assert np.allclose(ds_new.xNode.values[2, :], [-10.0, -12.0, -8.0]) |
| 151 | + |
| 152 | + |
133 | 153 | def _get_triangles(): |
134 | 154 | ds_mesh = xr.open_dataset(get_test_data_file('mesh.QU.1920km.151026.nc')) |
135 | 155 | earth_radius = constants['SHR_CONST_REARTH'] |
|
0 commit comments