Skip to content

Commit 9e209ba

Browse files
authored
Merge pull request #613 from xylar/transects-general-vertical-coord
Several updates to ocean transects
2 parents 6bd9592 + 397b4d4 commit 9e209ba

File tree

14 files changed

+2832
-1657
lines changed

14 files changed

+2832
-1657
lines changed

conda_package/docs/api.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,24 @@ Ocean Tools
252252
inject_preserve_floodplain
253253

254254

255-
.. currentmodule:: mpas_tools.ocean.transects
255+
.. currentmodule:: mpas_tools.ocean.viz.transect
256256

257257
.. autosummary::
258258
:toctree: generated/
259259

260+
compute_transect
260261
find_transect_levels_and_weights
261-
interp_mpas_to_transect_triangles
262-
interp_mpas_to_transect_triangle_nodes
263-
interp_transect_grid_to_transect_triangle_nodes
264-
get_outline_segments
262+
interp_mpas_to_transect_cells
263+
interp_mpas_to_transect_nodes
264+
interp_transect_grid_to_transect_nodes
265+
plot_feature_transects
266+
plot_transect
265267

266268
.. currentmodule:: mpas_tools.ocean.viz
267269

268270
.. autosummary::
269271
:toctree: generated/
270272

271-
plot_ocean_transects
272273
add_inset
273274

274275
Sea-ice Tools
@@ -374,14 +375,16 @@ Visualization
374375

375376
mesh_to_triangles
376377

377-
.. currentmodule:: mpas_tools.viz.transects
378+
.. currentmodule:: mpas_tools.viz.transect
378379

379380
.. autosummary::
380381
:toctree: generated/
381382

382-
make_triangle_tree
383-
find_transect_cells_and_weights
384383
find_planar_transect_cells_and_weights
384+
find_spherical_transect_cells_and_weights
385+
interp_mpas_horiz_to_transect_nodes
386+
make_triangle_tree
387+
mesh_to_triangles
385388

386389
.. currentmodule:: mpas_tools.viz.colormaps
387390

conda_package/docs/ocean/visualization.rst

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ Plotting Ocean Transects
1313
:width: 500 px
1414
:align: center
1515

16-
The function :py:func:`mpas_tools.ocean.viz.plot_ocean_transects()` and the
17-
associated ``plot_ocean_transects`` command-line tool can be used to plot
18-
transects of various MPAS-Ocean variables. The arguments to the command-line
19-
tool are:
16+
The function :py:func:`mpas_tools.ocean.viz.transect.plot_transect()` is
17+
used to plot transects of various MPAS-Ocean variables. This function provide
18+
high-level plotting capabilities for visualizing transects of MPAS-Ocean
19+
data. It can create transect plots useful for visualizing test cases or
20+
analyzing global simulation output and comparing with observations.
21+
22+
The function :py:func:`mpas_tools.ocean.viz.transect.plot_feature_transects()`
23+
and the associated ``plot_ocean_transects`` command-line tool can be used to
24+
plot transects of various MPAS-Ocean variables. The arguments to the
25+
command-line tool are:
2026

2127
.. code-block:: none
2228
@@ -38,6 +44,9 @@ tool are:
3844
-c COLORMAP, --colormap COLORMAP
3945
A colormap to use for the plots, default depends on the field name.
4046
--flip Flip the x axis for all transects
47+
--write_netcdf Whether to write a NetCDF file for the transect in addition to the image
48+
--method METHOD The type of interpolation to use in plots. Options are "flat" and "bilinear"
49+
4150
4251
See `transects <https://github.com/MPAS-Dev/geometric_features/tree/main/geometric_data/ocean/transect>`_
4352
from ``geometric_features`` for a examples of what a geojson transect might
@@ -107,3 +116,61 @@ One way of customizing these visualizaitons is to make your own copy of
107116
`transects.py <https://github.com/MPAS-Dev/MPAS-Tools/blob/master/conda_package/mpas_tools/ocean/viz/transects.py>`_
108117
and change ``_plot_transect()`` to suite your needs, (changing figure size, dpi,
109118
colorbar, etc.)
119+
120+
.. _ocean_viz_transects_interp:
121+
122+
Ocean Transect Interpolation
123+
============================
124+
125+
The ``mpas_tools.ocean.viz.transect.vert`` module provides functions for
126+
interpolating MPAS-Ocean data onto a vertical transect. This is useful for
127+
visualizing data along a specific path through the ocean, showing the
128+
vertical structure of ocean properties. These functions allow you to create
129+
cross-sectional plots of temperature, salinity, and other variables.
130+
131+
The following functions are available:
132+
133+
The function :py:func:`mpas_tools.ocean.viz.transect.compute_transect()`
134+
builds a sequence of quads showing the transect intersecting MPAS cells.
135+
This function takes horizontal and vertical mesh information and constructs
136+
a set of quadrilaterals that represent the transect's path through the
137+
MPAS-Ocean mesh. The resulting quads can then be used for plotting or
138+
further analysis.
139+
140+
The remaining functions and those in :ref:`viz_transect_horiz` are lower level
141+
functions that are used by ``compute_transect()`` and are not typically called
142+
directly.
143+
144+
The function
145+
:py:func:`mpas_tools.ocean.viz.transect.find_transect_levels_and_weights()`
146+
constructs a vertical coordinate for a transect and computes interpolation
147+
weights that can be used in ``interp_mpas_to_transect_nodes()`` to performed
148+
linear interpolation.
149+
150+
The function
151+
:py:func:`mpas_tools.ocean.viz.transect.interp_mpas_to_transect_cells()`
152+
interpolates an MPAS-Ocean DataArray to transect cells, keeping constant values
153+
over each MPAS-Ocean cell. This function uses the indices computed by
154+
``find_transect_levels_and_weights()`` to map data from the MPAS-Ocean mesh
155+
onto the transect. The result is an ``xarray.DataArray`` with values
156+
sampled to transect cells.
157+
158+
159+
The function
160+
:py:func:`mpas_tools.ocean.viz.transect.interp_mpas_to_transect_nodes()`
161+
interpolates an MPAS-Ocean DataArray to transect nodes, linearly
162+
interpolating fields between the closest neighboring cells. This function
163+
uses the interpolation weights computed by
164+
``find_transect_levels_and_weights()`` to map data from the MPAS-Ocean mesh
165+
onto the transect. The result is an ``xarray.DataArray`` with values
166+
interpolated to the transect's nodes.
167+
168+
The function
169+
:py:func:`mpas_tools.ocean.viz.transect.interp_transect_grid_to_transect_nodes()`
170+
interpolates a 2D grid of data to transect nodes, linearly interpolating
171+
fields between the closest neighboring cells. This requires that the
172+
``z_transect`` parameter has been passed into function
173+
``find_transect_levels_and_weights()`` (or ``compute_transect()``) uses
174+
weights generated in ``find_transect_levels_and_weights()`` to interpolate data
175+
from the MPAS-Ocean mesh to transect nodes the transect, resulting an
176+
``xarray.DataArray`` with values.

conda_package/docs/visualization.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,57 @@ In this example, we use the ``3Wbgy5`` colormap:
131131
.. image:: images/so60to12_res.png
132132
:width: 500 px
133133
:align: center
134+
135+
.. _viz_transect_horiz:
136+
137+
Horizontal Transect Interpolation
138+
=================================
139+
140+
The ``mpas_tools.viz.transect.horiz`` module provides functions for
141+
interpolating MPAS data onto a horizontal transect. This is useful for
142+
visualizing data along a specific path on the horizontal plane of the
143+
mesh.
144+
145+
The function
146+
:py:func:`mpas_tools.viz.transect.mesh_to_triangles()` converts an MPAS
147+
mesh to a triangle mesh by decomposing each cell into one triangle connecting
148+
the cell center to each edge. The resulting triangle mesh can then be used
149+
for visualization or for other spatial analysis tasks.
150+
151+
The function
152+
:py:func:`mpas_tools.viz.transect.make_triangle_tree()` creates a triangle
153+
tree for efficient point location. This function is used internally to
154+
speed up the process of finding which triangle a given point lies within.
155+
It constructs a data structure that allows for fast spatial queries,
156+
making it more efficient to determine the location of points relative to
157+
the mesh. This is especially useful for high-resolution meshes or when
158+
performing a large number of point location operations.
159+
160+
The function
161+
:py:func:`mpas_tools.viz.transect.find_planar_transect_cells_and_weights()`
162+
finds the cells that intersect a planar transect and the weights for
163+
interpolating data from cell centers to the transect nodes. The function
164+
takes the MPAS mesh as an ``xarray.Dataset`` object and the start and end
165+
points of the transect as Cartesian coordinates. The function
166+
returns the cell indices and weights for interpolating data from cell
167+
centers to the transect nodes, the indices of the cells that intersect
168+
the transect, and the Cartesian coordinates of the transect nodes. This
169+
is a key step in creating transect plots of MPAS data.
170+
171+
The function
172+
:py:func:`mpas_tools.viz.transect.find_spherical_transect_cells_and_weights()`
173+
does the same for a transect on the sphere. It
174+
identifies the cells intersected by a great circle path defined by
175+
longitude and latitude coordinates. Like its planar counterpart, it
176+
returns cell indices, interpolation weights, intersected cell indices,
177+
and transect node coordinates, but all calculations are performed on the
178+
sphere.
179+
180+
The function
181+
:py:func:`mpas_tools.viz.transect.interp_mpas_horiz_to_transect_nodes()`
182+
interpolates MPAS data to transect nodes. This function takes the MPAS
183+
data field and the transect node information (cell indices and weights)
184+
generated by either the planar or spherical transect finding functions.
185+
It then performs a weighted average of the data values at the cell
186+
centers to estimate the data values at the transect nodes. The result is
187+
a 1D array of interpolated data values along the transect.

0 commit comments

Comments
 (0)