radarx.retrieve.lightning.cluster_flashes#

radarx.retrieve.lightning.cluster_flashes(obj, *, distance=3000.0, time=0.15, min_points=1, max_duration=None, noise='flash', n_threads=None, engine='auto')[source]#

Group LMA VHF sources into flashes by their space-time separation.

Parameters:
  • obj (xarray.Dataset) – LMA sources, e.g. from radarx.io.read_lma() (filter them by chi-square and number of stations first, e.g. max_chi2=1, min_stations=6).

  • distance (float, optional) – Distance scale \(d\) in metres. Default 3000 m: Fuchs et al. (2016) [1] (p. 8628) took 3 km for the sensitive Colorado network and 6 km for the less sensitive Alabama and D.C. networks, “in accordance with values from other algorithms” there.

  • time (float, optional) – Time scale \(\tau\) in seconds. Default 0.15 s, the 150 ms of Fuchs et al. (2016) [1] (p. 8628).

  • min_points (int, optional) – Minimum number of sources \(N_{min}\) (the source itself counted) within the normalized distance of one for a source to start or extend a flash, as the min_samples of DBSCAN [2]. Default 1 (single linkage, which is also the result for 2). Fuchs et al. [1] used 2 (Alabama, D.C.) and 10 (Colorado). A source that is not core but near a core source joins the flash of the nearest-in-index core source.

  • max_duration (float, optional) – Longest flash in s. A longer flash is cut into consecutive flashes, the next starting at the first source later than max_duration after the start of the current one. Fuchs et al. [1] impose 3 s (“by default”); their cut is a consequence of clustering buffers of twice that length, radarx’s cut in time order is its own (so the result differs from theirs for flashes that reach the buffer boundary). Default None (no limit).

  • noise ({"flash", "drop"}, optional) – Sources that belong to no cluster (min_points above 2): "flash" (default) makes each a flash of one source, "drop" gives them event_parent_flash_id -1, no flash, as DBSCAN’s noise label.

  • n_threads (int, optional) – Threads for the compiled kernel. Default: all cores.

  • engine ({"auto", "compiled", "numpy"}, optional) – Implementation to use. "auto" (default) prefers the compiled kernel and falls back to NumPy.

Returns:

xarray.Dataset – The sources sorted by time with event_parent_flash_id and the flashes on number_of_flashes (flash_id, flash_time_start, flash_time_end, flash_duration, flash_event_count, flash_init_latitude/longitude/altitude, flash_center_latitude/longitude/altitude, flash_area), numbered in the order of their first source. Existing flash variables are replaced.

Notes

Two sources are linked when \((|\Delta \mathbf{x}| / d)^2 + (\Delta t / \tau)^2 \le 1\), with \(\Delta \mathbf{x}\) the straight-line (Earth-centred Cartesian, WGS84) separation; flashes are the connected groups of linked sources (single linkage).

Relation to Fuchs et al. (2016). Single linkage is the clustering of DBSCAN [2] with \(\epsilon = 1\) on these normalized coordinates and a minimum number of points \(N_{min}\) (scikit-learn min_samples, the source itself counted) of 1 or 2. Fuchs et al. [1] (sections 2.1 and 2.2, pp. 8628-8629) used \(N_{min} = 2\) for Alabama and D.C. and \(N_{min} = 10\) for Colorado. With min_points \(= N_{min}\) above 2 a flash grows only from core sources, those with at least \(N_{min}\) sources within \(\epsilon\); core sources within \(\epsilon\) of each other are in one flash, a source that is not core joins the flash of the core source within \(\epsilon\) that comes first in time (DBSCAN leaves the choice among several to the order of the search, which is irrelevant for sources that are near one flash only), and the rest is noise. On 150 synthetic random-walk flashes (issue 278) this reproduces a brute-force DBSCAN (adjusted Rand index 1.0) for \(N_{min}\) from 1 to 10. Issue 278 reports that on a synthetic set of 150 flashes the Colorado setting gives 162 flashes where single linkage gave 150. Whether the paper removes the noise sources or keeps them as flashes has not been checked against the paper, so both are offered (noise).

Maximum duration. Fuchs et al. [1] (p. 8629) impose “by default an arbitrary 3 s maximum duration” on flashes, because they cluster a buffer of twice that duration in a stream. With max_duration a flash longer than that is cut in time order into consecutive flashes, each starting at the first source later than max_duration after the start of the previous one. This is radarx’s own cut and agrees with the paper only in that long flashes are split; the buffer boundaries of the paper are not reproduced. A 5 s flash with max_duration=3 becomes two. No limit is imposed by default.

The flash centroid is the mean of the source latitudes, longitudes and altitudes and the plan area is the convex hull of the sources in an azimuthal equidistant projection about their mean position (both radarx definitions; Fuchs et al. [1], p. 8626, describe the plan area as a rubber band around the flash seen from above, after Bruning and MacGorman [3], not checked against the paper). Fuchs et al. measure the normalization from the LMA coordinate centre; here the first source is subtracted, which does not change any separation. The normalization of the space and time axes is the weighted Euclidean distance of Mach et al. [4] as used by Fuchs et al. [1] (p. 8628; the paper of Mach et al. is not checked). The plan-area hull is computed with Qhull (Barber et al. [6]) in the NumPy path and with Andrew’s monotone chain [5] in the compiled kernel; both give the area of the same convex polygon.

Dask. This function computes the dask array: the flashes are found from all sources. The input is loaded into memory and the result is held in memory.

References