Grid explanations user guide - #2779
Conversation
for more information, see https://pre-commit.ci
erikvansebille
left a comment
There was a problem hiding this comment.
Thanks @michaeldenes. See below for some suggestions/questions and comments
|
|
||
| ## Structured grids | ||
|
|
||
| A structured grid is composed of quadrilateral elements, that are indexed using logical 2D or 3D indices, like $(i,j,k)$. In `xarray` terminology, these indices correspond to `dimensions`, for example [...]. In structured grids, grid cell neighbours are easily found by decrementing or incrementing these dimensions. |
There was a problem hiding this comment.
The [...] here needs to be replaced by something? What did you have in mind?
|
|
||
| ## Structured grids | ||
|
|
||
| A structured grid is composed of quadrilateral elements, that are indexed using logical 2D or 3D indices, like $(i,j,k)$. In `xarray` terminology, these indices correspond to `dimensions`, for example [...]. In structured grids, grid cell neighbours are easily found by decrementing or incrementing these dimensions. |
There was a problem hiding this comment.
The sentence "In structured grids, grid cell neighbours are easily found by decrementing or incrementing these dimensions" is true, but not relevant for Parcels v4. We don't search for neighbours anymore. Instead:
- In grids with 1-dimensional coordinates (= rectilinear grids), we do a quick search of the coordinate to find the right value:
Parcels/src/parcels/_core/index_search.py
Lines 47 to 51 in e19411f
- In grids with 2-dimensional coordinates (= curvilinear grids; but could also be rectilinear), we use the hash-table approach that Joe documented extensively in https://docs.oceanparcels.org/en/main/development/unstructured_grid_search.html. Note that there is no fundamental difference between how we treat unstructured grids and structured grids with 2D coordinates. The only implementation difference is the point-in-cell check
- Before going into the hash-table query, I think(?) that we first check if the particle is stil in the old cell (through its element index
ei). But whether this works is to be explored (see Grid search (ei/igrid) not caching between successive grid search calls #2693 and Check that there are unit tests that check for correct particles._ei setting and updating #2669)
So I would rephrase this sentence to better highlight that we don't use neighbour search
|
|
||
| A structured grid is composed of quadrilateral elements, that are indexed using logical 2D or 3D indices, like $(i,j,k)$. In `xarray` terminology, these indices correspond to `dimensions`, for example [...]. In structured grids, grid cell neighbours are easily found by decrementing or incrementing these dimensions. | ||
|
|
||
| There are two styles of structured grids, rectilinear and curvilinear, as shown in Figure 1. Rectilinear grids are nearly always aligned with the coordinate axes (that is, there is a one-to-one mapping between the dimensions and the physical coordinate space), making them simple and computationally efficient to query. However, they're limited by the fact that it is difficult to resolve complex coastlines without high resolution, and they suffer from singularities in the flow fields at the poles where the grid lines converge. Curvilinear grids allow for curved grid lines, which allow for better representation of coastlines. They often move the poles onto land to avoid singularities occuring in the ocean. However, they become trickier to work with, as the spatial positions of their vertices are stored in separate 2D arrays, and moving to an eastward neighbour is not as simple as incrementing the $i$-th coordinate by 1. |
There was a problem hiding this comment.
Why 'nearly' always? In Parcels, I think they have to be always. The index_search works with either 1D coordinates or 2D coordinates
There was a problem hiding this comment.
I think I've seen models with a rotated rectilinear grid (say, along the coast of the Netherlands), which is not aligned East/North, hence the careful choice of wording. Happy to change to "typically" rather than "nearly always".
|
|
||
| A structured grid is composed of quadrilateral elements, that are indexed using logical 2D or 3D indices, like $(i,j,k)$. In `xarray` terminology, these indices correspond to `dimensions`, for example [...]. In structured grids, grid cell neighbours are easily found by decrementing or incrementing these dimensions. | ||
|
|
||
| There are two styles of structured grids, rectilinear and curvilinear, as shown in Figure 1. Rectilinear grids are nearly always aligned with the coordinate axes (that is, there is a one-to-one mapping between the dimensions and the physical coordinate space), making them simple and computationally efficient to query. However, they're limited by the fact that it is difficult to resolve complex coastlines without high resolution, and they suffer from singularities in the flow fields at the poles where the grid lines converge. Curvilinear grids allow for curved grid lines, which allow for better representation of coastlines. They often move the poles onto land to avoid singularities occuring in the ocean. However, they become trickier to work with, as the spatial positions of their vertices are stored in separate 2D arrays, and moving to an eastward neighbour is not as simple as incrementing the $i$-th coordinate by 1. |
There was a problem hiding this comment.
| There are two styles of structured grids, rectilinear and curvilinear, as shown in Figure 1. Rectilinear grids are nearly always aligned with the coordinate axes (that is, there is a one-to-one mapping between the dimensions and the physical coordinate space), making them simple and computationally efficient to query. However, they're limited by the fact that it is difficult to resolve complex coastlines without high resolution, and they suffer from singularities in the flow fields at the poles where the grid lines converge. Curvilinear grids allow for curved grid lines, which allow for better representation of coastlines. They often move the poles onto land to avoid singularities occuring in the ocean. However, they become trickier to work with, as the spatial positions of their vertices are stored in separate 2D arrays, and moving to an eastward neighbour is not as simple as incrementing the $i$-th coordinate by 1. | |
| There are two styles of structured grids, rectilinear and curvilinear, as shown in Figure 1. | |
| 1. Rectilinear grids are nearly always aligned with the coordinate axes (that is, there is a one-to-one mapping between the dimensions and the physical coordinate space), making them simple and computationally efficient to query. However, they're limited by the fact that it is difficult to resolve complex coastlines without high resolution, and they suffer from singularities in the flow fields at the poles where the grid lines converge. | |
| 2. Curvilinear grids allow for curved grid lines, which allow for better representation of coastlines. They often move the poles onto land to avoid singularities occurring in the ocean. However, they become trickier to work with, as the spatial positions of their vertices (their ["coordinates" in xarray-parlance](https://docs.xarray.dev/en/latest/user-guide/terminology.html#term-Coordinate)) are stored in separate 2D coordinate arrays, and moving to an eastward neighbour is not as simple as incrementing the $i$-th dimension by 1. |
|
|
||
| Let's assume we have a simple 2D rectlinear grid. The grid is composed of a number of nodes (or vertices), connected by edges, which together construct grid cells and grid cell faces. In Figure 2, we draw a simple grid cell. Here, your data may be defined on the corners of the grid cell (the nodes/vertices), at the centre of the cell face, or across a cell edge. | ||
|
|
||
|  |
There was a problem hiding this comment.
Why not provide the code to generate this (and following) plot too? That will for sure be useful if someone later wants to adapt the plot - and it also aligns with the rest of the tutorials/documentation by making the file as self-contained as possible. I think you can even collapse/hide the input cell if it's too long and distracting
There was a problem hiding this comment.
This figure is hand drawn. If you'd like, I can turn it into a python script.
|
|
||
|  | ||
|
|
||
| You will need to make several assumptions about your data. Your data may represent a point-wise "sample" of some field. For example, velocity data may be defined at the nodes of your grid, and a fairly safe assumption to make is that you can bi-linearly interpolate these data points to your particle positions. In such an example, your velocity field may look like Figure 3. |
There was a problem hiding this comment.
Why "fairly safe"? I don't understand what you mean. Under what conditions is it fairly safe to make this assumption?
There was a problem hiding this comment.
Again, being safe with word choices. I'll use "a typical assumption to make"
|
|
||
|  | ||
|
|
||
| Alternatively, your data may represent an "average value" across a cell face. For example, your temperature and salinity data may be defined at the cell centre, and represent an average value for the entire grid cell. A fairly safe assumption to make is that you can nearest-neighbour interpolate these data points to your particle positions. In such a case, your temperature field may look like figure 4. |
There was a problem hiding this comment.
Can we be a bit more specific than "may be defined" here? Again, under what conditions would this be typical? How could a user find out?
|
|
||
| Lastly, your data may represent a value across a cell edge. For example, in (2D) Arakawa C-grid datasets, velocities are defined across an edge as they represent a "flux" across that cell edge. [for some reason an accepted assumption is] to perform a 1D linear interpolation of the zonal velocity in the zonal direction, and similarly a 1D linear interpolation of the meridional velocity in the meridional direction. In such a case, your velocity field may look like figure 5. | ||
|
|
||
|  |
There was a problem hiding this comment.
Anything to say about vertical grids? Or even just put a placeholder?
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
Whacky stuff going on with commits. Have decided to redo this in another branch and PR, using an ipynb instead of markdown file. |
Description
This PR includes a grid explanations user guide, to help users understand how their underlying model data is defined and interpreted.
Checklist
mainfor normal development,v3-supportfor v3 support)AI Disclosure