Skip to content

Instantly share code, notes, and snippets.

@myociss
Created August 15, 2025 18:01
Show Gist options
  • Select an option

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

Select an option

Save myociss/cb1e76b6e5dc1e9f346ccfe1dd1f1c6b to your computer and use it in GitHub Desktop.
Lightning Flash Clustering: convert (lat, lon, alt) to (x, y, z)
def to_ecef(spatial_data: array_type) -> array_type:
rad_lat = spatial_data[:,0] * np.pi / 180
rad_lon = spatial_data[:,1] * np.pi / 180
altitudes = spatial_data[:,2]
a=6378137.0
b=6356752.314245
e2=1 - b**2/a**2
cot = 1 / np.tan(rad_lat)
n_phi = a / np.sqrt(1 - (e2/ (1+ np.square(cot))))
transformed_data = np.zeros(spatial_data.shape)
transformed_data[:,0] = (n_phi + altitudes) * np.cos(rad_lat) * np.cos(rad_lon)
transformed_data[:,1] = (n_phi + altitudes) * np.cos(rad_lat) * np.sin(rad_lon)
transformed_data[:,2] = ((1-e2)*n_phi + altitudes) * np.sin(rad_lat)
return transformed_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment