runtraj.particles.ParticlesAccessor.grid_exits#

ParticlesAccessor.grid_exits(bounds)[source]#

Return where each particle first left a longitude/latitude box.

For a backward run these are the points where the air entered the domain, where a field at the domain’s edge is sampled. Unlike endpoints(), which gives where a particle ended, this gives where it first crossed the edge of the box, even if it came back later or stayed in the meteorology domain long after.

A particle is outside when it is beyond an edge of the box, in longitude and latitude. Longitudes are read as contains() reads them: a box across the dateline or past 180 degrees is read modulo 360, and a box 360 degrees wide or more has no west or east edge. Rows are read in order of abs(age), whatever their order in the table, so this works for a backward and a forward run.

The point is on the edge: the exit is the straight line between the particle’s last row inside the box and its first row outside, and lon, lat, zagl, age and time are interpolated along it to where it crosses. If the line crosses two edges at a corner, edge is the first it crosses. A particle whose first row is already outside has no row inside to interpolate from (the meteorology HYSPLIT 5.1.0 writes no row at the release), so it is reported at that row, on the edge it is farthest beyond.

Parameters:

bounds (Bounds) – The box, such as the edge of your study area.

Returns:

One row per particle that left the box, ordered by particle; a particle that stayed inside is not in it. The columns are the table’s release, variant and realization columns, if it has them, then particle, edge ("n", "e", "s" or "w", the side of the box it left by), lon and lat (degrees), zagl (meters), age (minutes since release) and, when the table has a time column, time (UTC). Longitudes are wrapped to -180 to 180 where the interpolation crosses 180.

Return type:

DataFrame

Examples

One particle that leaves a box by its east edge, between two rows:

>>> import pandas as pd
>>> import runtraj
>>> box = runtraj.Bounds(xmin=-112, xmax=-110, ymin=40, ymax=42)
>>> particles = pd.DataFrame(
...     {
...         "particle": [1, 1, 1],
...         "age": [0.0, -60.0, -120.0],
...         "lon": [-111.0, -110.5, -109.5],
...         "lat": [41.0, 41.0, 41.0],
...         "zagl": [10.0, 20.0, 30.0],
...     }
... )
>>> particles.runtraj.grid_exits(box)
   particle edge    lon   lat  zagl   age
0         1    e -110.0  41.0  25.0 -90.0