Skip to content

Instantly share code, notes, and snippets.

@myociss
Created August 15, 2025 19:42
Show Gist options
  • Select an option

  • Save myociss/70a7decaf96f93a88810d4af48a549aa to your computer and use it in GitHub Desktop.

Select an option

Save myociss/70a7decaf96f93a88810d4af48a549aa to your computer and use it in GitHub Desktop.
Lightning Flash Clustering: load and format data
from clustering_algorithm.cluster_flashes import load_dat, to_ecef
import numpy as np
center_geo = np.array([40.4463980, -104.6368130, 1000.00]) # COLMA center
lma_center = to_ecef(np.expand_dims(center_geo, axis=0))
n_grid_points, grid_spacing = 18, 0.2559
grid_start_lat = center_geo[0] - (n_grid_points / 2) * grid_spacing
grid_start_lon = center_geo[1] - (n_grid_points / 2) * grid_spacing
data, start_time = load_dat(os.path.join(data_dir, fname), min_stations=min_stations, max_chi_squared=max_chi_squared, max_altitude=max_altitude)
data_grid_lat = np.floor( (data[:,1] - grid_start_lat) / grid_spacing )
data_grid_lon = np.floor( (data[:,2] - grid_start_lon) / grid_spacing )
spatial_data = to_ecef(data[:,1:4]) - center
sources = np.zeros((data.shape[0], 10))
sources[:,0] = data[:,0]
sources[:,1:4] = spatial_data
sources[:,4] = data[:,5]
sources[:,5] = data_grid_lat
sources[:,6] = data_grid_lon
sources[:,7:] = data[:,1:4] # retain initial geodetic coordinates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment