|
| 1 | +# Interpolator explanation |
| 2 | +Interpolation is an important functionality of Parcels. On this page we will discuss the way it is |
| 3 | +implemented in **Parcels** and how to write a custom interpolator function. |
| 4 | + |
| 5 | +```{note} |
| 6 | +TODO: expand explanation (similar to Kernel loop explanation) |
| 7 | +``` |
| 8 | + |
| 9 | +When we want to know the state of particles in an environmental field, such as temperature or velocity, |
| 10 | +we _evaluate_ the `parcels.Field` at the particles real position in time and space (`t`, `z`, `lat`, `lon`). |
| 11 | +In Parcels we can do this using square brackets: |
| 12 | +``` |
| 13 | +particles.temperature = fieldset.temperature[particles.time, particles.z, particles.lat, particles.lon] |
| 14 | +``` |
| 15 | +The values of the `temperature` field at the particles' positions are determined using an interpolation |
| 16 | +method. This interpolation method defines how the discretized values of the `parcels.Field` should |
| 17 | +relate to the value at any point within a grid cell. |
| 18 | + |
| 19 | +Each `parcels.Field` is defined on a (structured) `parcels.XGrid` or (unstructured) `parcels.UXGrid`. |
| 20 | +The interpolation function takes information about the particles position relative to this grid (`grid_positions`), |
| 21 | +as well as the `parcels.Field` values of the surrounding grid points in time and space, to calculate |
| 22 | +the requested value at the particles location. |
| 23 | + |
| 24 | +## Interpolator API |
| 25 | +The interpolators included in Parcels are designed for common interpolation schemes in Parcels simulations. |
| 26 | +If we want to add a custom interpolation method, we need to look at the interpolator API: |
| 27 | + |
| 28 | +We can write an interpolator function that takes a `parcels.Field`, a dictionary with the `particle_positions` |
| 29 | +in real space and time, and a dictionary with the `grid_positions`. |
| 30 | + |
| 31 | +The `particle_positions` dictionary contains: |
| 32 | +``` |
| 33 | +particle_positions = {"time", time, "z", z, "lat", lat, "lon", lon} |
| 34 | +``` |
| 35 | + |
| 36 | +For structured (`X`) grids, the `grid_positions` dictionary looks like: |
| 37 | +``` |
| 38 | +grid_positions = { |
| 39 | + "T": {"index": ti, "bcoord": tau}, |
| 40 | + "Z": {"index": zi, "bcoord": zeta}, |
| 41 | + "Y": {"index": yi, "bcoord": eta}, |
| 42 | + "X": {"index": xi, "bcoord", xsi}, |
| 43 | +} |
| 44 | +``` |
| 45 | +where `index` is the grid index in the corresponding dimension, and `bcoord` is the barycentric coordinate in the grid cell. |
| 46 | + |
| 47 | +For unstructured (`UX`) grids, the same dictionary is defined as: |
| 48 | +``` |
| 49 | +grid_positions = { |
| 50 | + "T": {"index": ti, "bcoord": tau}, |
| 51 | + "Z": {"index": zi, "bcoord": zeta}, |
| 52 | + "FACE": {"index": fi, "bcoord": bcoord} |
| 53 | +} |
| 54 | +``` |
0 commit comments