Skip to content

myociss/lma_flash_clustering

Repository files navigation

LMA Flash Clustering

Simplified implementation of lighting mapping array (LMA) flash clustering algorithm described in "Climatological analyses of LMA data with an open-source lightning flash-clustering algorithm" by Fuchs et al. (2016) (code: https://github.com/deeplycloudy/lmatools).

3D animated scatter plot of lightning flash

Getting Started

Install Python 3.10+.

  1. Run setupvenv.sh to set up a virtual environment and install dependencies, then activate:
./setupvenv.sh
. lma_venv/bin/activate
  1. Create a free account on NASA Earthdata.

  2. Download a lightning mapping array dataset

Clustering Flashes

To create clustered flash .json files from all data files in a directory, run process_lma_data.py. The LMA center for your data can be found by unzipping one of the .dat.gz files and finding the line containing "Coordinate center (lat,lon,alt)".

python process_lma_data.py --lma_center [lma_center_latitude],[lma_center_longitude],[lma_center_altitude] --save_flash_sources 0 --data_dir [earthdata_download_dir] --output [output_dir]

Note: The sources grouped together in each flash will not be saved as an output unless the --save_flash_sources is set to 1. Saving the grouped sources for full datasets will likely take up several GB of disk space. The main utility of saving grouped sources is for plotting individual flashes in 3D.

To process the two example data files in 3d_plots_data/colma_data:

python process_lma_data.py --lma_center 40.4463980,-104.6368130,1000.00 --data_dir ./3d_plots_data/colma_data --save_flash_sources 1 --output ./3d_plots_data/colma_data_flashes

Plotting Flashes in 3D

To plot individual flashes from a .npy file containing grouped sources, run plot_flashes_3d.py after running process_lma_data.py with --save_flash_sources set to 1. This will plot the top_n flashes with the most sources using plotly and save the plots as .html files.

python plot_flashes_3d.py --top_n [top_n] --flashes_file [flashes_file.npy] --plot_dir [plot_dir]

To plot flashes from one of the example files in 3d_plots_data/colma_data_flashes:

python plot_flashes_3d.py --flashes_file ./3d_plots_data/colma_data_flashes/goesr_plt_COLMA_20170508_215000_0600_sources.npy --plot_dir plots_3d --top_n 5

Plotting Flash Statistics

To plot lightning statistics from a full dataset, run plot_lightning_statistics.py after running process_lma_data.py and saving the .json files in [json_dir]. This will generate boxplots of flash duration, sources per flash, flash convex hull area and flash mean power according to flash distance from the LMA center. Gridded plots of flash area, lightning hours and flashes per lightning hour overlaid on a map will also be generated.

python plot_lightning_statistics.py --plot_dir [plot_dir] --json_dir [json_dir]

To add landmarks to the map, use the --landmark_names and --landmark_coordinates options to specify the names and coordinates (lat,long). For example, plotting COLMA data with landmarks:

python plot_lightning_statistics.py --plot_dir [plot_dir] --json_dir [json_dir] --landmark_names Denver Cheyenne --landmark_coordinates "39.742043,-104.991531" "41.1347,-104.8212" --grid_min_y 8

Note: the grid_min_[x|y] and grid_max_[x|y] can be used to exclude a portion of the spatial grid from box plots.

The plots directory contains plots generated from the data collected by COLMA from 03/01/2017-05/31/2017.

About

flash clustering algorithm implementation in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published