From bec73111642921325d4ac8853ad7b92bd6c02ede Mon Sep 17 00:00:00 2001 From: Bee Lamsma Date: Sun, 12 Jan 2025 13:20:27 -0600 Subject: [PATCH 1/4] added leader speed ploT --- pyxlma/plot/leader_speed.py | 102 ++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 pyxlma/plot/leader_speed.py diff --git a/pyxlma/plot/leader_speed.py b/pyxlma/plot/leader_speed.py new file mode 100644 index 0000000..2e62486 --- /dev/null +++ b/pyxlma/plot/leader_speed.py @@ -0,0 +1,102 @@ +def haversine(lat0, lon0, lat, lon): + + R = 6378.137e3 # this is in meters. For Earth radius in kilometers use 6372.8 km + + dLat = radians(lat - lat) + dLon = radians(lon - lon) + lat1 = radians(lat) + lat2 = radians(lat) + + a = sin(dLat/2)**2 + cos(lat1)*cos(lat2)*sin(dLon/2)**2 + c = 2*asin(sqrt(a)) + + return R * c + +# Usage\n", +lon1 = interactive_lma.bounds['x'][1] +lat1 = interactive_lma.bounds['y'][1] +lon2 = interactive_lma.bounds['x'][0] +lat2 = interactive_lma.bounds['x'][0] + +print(haversine(lat1, lon1, lat2, lon2)) +print('meters') + + +def get_time_distance(lat, lon, time, lat0, lon0, time0): + + lat0=lat0*np.ones_like + + distance_from_origin = (haversine(lat0,lon0,lat,lon)) + time_from_origin = ((time-time0).astype('timedelta64[ns]').astype(float)/1e9) + return distance_from_origin, time_from_origin + + +def time_distance_plot_interactive(interactive_lma, ax): + + + +def time_distance_plot(ax, time, distance, **kwargs): + fig = plt.figure(figsize=(10, 10)) + + + while (m < 10): + x = np.linspace(0, (float(interactive_lma.this_lma_time[interactive_lma.this_lma_time.index[first]].strftime('%S.%f'))-float(interactive_lma.this_lma_time[interactive_lma.this_lma_time.index[last]].strftime('%S.%f')))*-1+10, 100) + y = x * 2 * 10**4 + plt.plot(x+(m/10), y, color = 'b') + yy = x * 10**5 + plt.plot(x+(m/10), yy, color = 'r') + yyy = x * 10**6 + plt.plot(x+(m/10), yyy, color = 'g') + m+=1 + + + x = np.linspace(0, (float(interactive_lma.this_lma_time[interactive_lma.this_lma_time.index[first]].strftime('%S.%f'))-float(interactive_lma.this_lma_time[interactive_lma.this_lma_time.index[last]].strftime('%S.%f')))*-1+10, 100) + y = x * 2 * 10**4 + plt.plot(x, y, color = 'b', label = 'Positive Leader') + yy = x * 10**5 + plt.plot(x, yy, color = 'r', label = 'Negative Leader') + yyy = x * 10**6 + plt.plot(x, yyy, color = 'g', label = 'Dart Leader') + + plt.ylim(0, max(distance_from_origin)+1000) + plt.xlim(-0.05, max(time_from_origin)+0.1) + + sc = plt.scatter(time_from_origin, distance_from_origin, zorder=10, c=altitude, cmap="cool", vmin=0, vmax=6) + plt.colorbar(sc, label='Altitude (km)', spacing='proportional', ticks=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + plt.legend(title = "Leader Type Key", loc = 2, fontsize=12, title_fontsize=16, framealpha=1) + plt.title("Lightning Leader Speed", size=24) + plt.xlabel("Time from Origin (s)", size=12) + plt.ylabel("Distance from Origin (m)", size=12) + + plt.show() + + + + + if (len(flash_events['alt'])==0): + print(" ") + else: + m = 0 + while (m < 20): + x = np.linspace(0, (float((pd.to_datetime(pd.Timestamp(flash_events['time'].values[0]))).strftime('%S.%f'))-float((pd.to_datetime(pd.Timestamp(flash_events['time'].values[-1]))).strftime('%S.%f')))*-1+10, 100) + #print(x) + y = x * 2 * 10**4 + bk_plot.ax_vel.plot(x+(m/10), y, color = 'b') + yy = x * 10**5 + bk_plot.ax_vel.plot(x+(m/10), yy, color = 'r') + yyy = x * 10**6 + bk_plot.ax_vel.plot(x+(m/10), yyy, color = 'g') + m+=1 + #print(m) + + x = np.linspace(0, (float((pd.to_datetime(pd.Timestamp(flash_events['time'].values[0]))).strftime('%S.%f'))-float((pd.to_datetime(pd.Timestamp(flash_events['time'].values[-1]))).strftime('%S.%f')))*-1+10, 100) + #print(x) + y = x * 2 * 10**4 + bk_plot.ax_vel.plot(x, y, color = 'b', label = 'Positive Leader') + yy = x * 10**5 + bk_plot.ax_vel.plot(x, yy, color = 'r', label = 'Negative Leader') + yyy = x * 10**6 + bk_plot.ax_vel.plot(x, yyy, color = 'g', label = 'Dart Leader') + + bk_plot.ax_vel.set_ylim(0, max(dist_data)+1000) + bk_plot.ax_vel.set_xlim(-0.05, max(time2_data)+0.1) \ No newline at end of file From 279d87132486003f49d1f2a472a4680823ffcc7c Mon Sep 17 00:00:00 2001 From: Bee Lamsma Date: Sun, 12 Jan 2025 14:13:14 -0600 Subject: [PATCH 2/4] final draft of leader speed plot functions --- pyxlma/plot/leader_speed.py | 117 +++++++++++++++--------------------- 1 file changed, 49 insertions(+), 68 deletions(-) diff --git a/pyxlma/plot/leader_speed.py b/pyxlma/plot/leader_speed.py index 2e62486..3171c7f 100644 --- a/pyxlma/plot/leader_speed.py +++ b/pyxlma/plot/leader_speed.py @@ -1,3 +1,7 @@ +import numpy as np +from numpy import radians, cos, sin, asin, sqrt +import matplotlib.pyplot as plt + def haversine(lat0, lon0, lat, lon): R = 6378.137e3 # this is in meters. For Earth radius in kilometers use 6372.8 km @@ -12,18 +16,8 @@ def haversine(lat0, lon0, lat, lon): return R * c -# Usage\n", -lon1 = interactive_lma.bounds['x'][1] -lat1 = interactive_lma.bounds['y'][1] -lon2 = interactive_lma.bounds['x'][0] -lat2 = interactive_lma.bounds['x'][0] - -print(haversine(lat1, lon1, lat2, lon2)) -print('meters') - def get_time_distance(lat, lon, time, lat0, lon0, time0): - lat0=lat0*np.ones_like distance_from_origin = (haversine(lat0,lon0,lat,lon)) @@ -32,71 +26,58 @@ def get_time_distance(lat, lon, time, lat0, lon0, time0): def time_distance_plot_interactive(interactive_lma, ax): + lat = interactive_lma.this_lma_lat + lon = interactive_lma.this_lma_lon + alt = interactive_lma.this_lma_alt + time = interactive_lma.this_lma_time + first = np.nanargmin(time) + + distance_from_origin, time_from_origin = get_time_distance(lat, lon, time, + lat[first], lon[first], time[first]) - - -def time_distance_plot(ax, time, distance, **kwargs): - fig = plt.figure(figsize=(10, 10)) - + art_out = time_distance_plot(ax, time_from_origin, distance_from_origin) - while (m < 10): - x = np.linspace(0, (float(interactive_lma.this_lma_time[interactive_lma.this_lma_time.index[first]].strftime('%S.%f'))-float(interactive_lma.this_lma_time[interactive_lma.this_lma_time.index[last]].strftime('%S.%f')))*-1+10, 100) - y = x * 2 * 10**4 - plt.plot(x+(m/10), y, color = 'b') - yy = x * 10**5 - plt.plot(x+(m/10), yy, color = 'r') - yyy = x * 10**6 - plt.plot(x+(m/10), yyy, color = 'g') - m+=1 + return art_out - - x = np.linspace(0, (float(interactive_lma.this_lma_time[interactive_lma.this_lma_time.index[first]].strftime('%S.%f'))-float(interactive_lma.this_lma_time[interactive_lma.this_lma_time.index[last]].strftime('%S.%f')))*-1+10, 100) + +def time_distance_plot(ax, time, distance, m_reference_lines = 10, **kwargs): + m = -m_reference_lines + x = np.linspace(0, time*-1+m_reference_lines, 100) y = x * 2 * 10**4 - plt.plot(x, y, color = 'b', label = 'Positive Leader') yy = x * 10**5 - plt.plot(x, yy, color = 'r', label = 'Negative Leader') yyy = x * 10**6 - plt.plot(x, yyy, color = 'g', label = 'Dart Leader') + + art_out = [] + + while (m < m_reference_lines): + art = ax.plot(x+(m/m_reference_lines), y, color = 'b') + art_out.extend(art) + art = ax.plot(x+(m/m_reference_lines), yy, color = 'r') + art_out.extend(art) + art = ax.plot(x+(m/m_reference_lines), yyy, color = 'g') + art_out.extend(art) + m+=1 + + art = ax.plot(x, y, color = 'b', label = 'Positive Leader') + art_out.extend(art) + art = ax.plot(x, yy, color = 'r', label = 'Negative Leader') + art_out.extend(art) + art = ax.plot(x, yyy, color = 'g', label = 'Dart Leader') + art_out.extend(art) - plt.ylim(0, max(distance_from_origin)+1000) - plt.xlim(-0.05, max(time_from_origin)+0.1) + ax.set_ylim(0, max(distance)+1000) + ax.set_xlim(-0.05, max(time)+0.1) + + sc = ax.scatter(time, distance, zorder=10, c=altitude, cmap="cool", vmin=0, vmax=6) + art_out.append(sc) + #art = ax.legend(title = "Leader Type Key", loc = 2, fontsize=12, title_fontsize=16, framealpha=1) + #art_out.extend(art) + ax.set_title("Lightning Leader Speed", size=24) + ax.set_xlabel("Time from Origin (s)", size=12) + ax.set_ylabel("Distance from Origin (m)", size=12) + + return art_out - sc = plt.scatter(time_from_origin, distance_from_origin, zorder=10, c=altitude, cmap="cool", vmin=0, vmax=6) - plt.colorbar(sc, label='Altitude (km)', spacing='proportional', ticks=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - plt.legend(title = "Leader Type Key", loc = 2, fontsize=12, title_fontsize=16, framealpha=1) - plt.title("Lightning Leader Speed", size=24) - plt.xlabel("Time from Origin (s)", size=12) - plt.ylabel("Distance from Origin (m)", size=12) - plt.show() - - - - - if (len(flash_events['alt'])==0): - print(" ") - else: - m = 0 - while (m < 20): - x = np.linspace(0, (float((pd.to_datetime(pd.Timestamp(flash_events['time'].values[0]))).strftime('%S.%f'))-float((pd.to_datetime(pd.Timestamp(flash_events['time'].values[-1]))).strftime('%S.%f')))*-1+10, 100) - #print(x) - y = x * 2 * 10**4 - bk_plot.ax_vel.plot(x+(m/10), y, color = 'b') - yy = x * 10**5 - bk_plot.ax_vel.plot(x+(m/10), yy, color = 'r') - yyy = x * 10**6 - bk_plot.ax_vel.plot(x+(m/10), yyy, color = 'g') - m+=1 - #print(m) - - x = np.linspace(0, (float((pd.to_datetime(pd.Timestamp(flash_events['time'].values[0]))).strftime('%S.%f'))-float((pd.to_datetime(pd.Timestamp(flash_events['time'].values[-1]))).strftime('%S.%f')))*-1+10, 100) - #print(x) - y = x * 2 * 10**4 - bk_plot.ax_vel.plot(x, y, color = 'b', label = 'Positive Leader') - yy = x * 10**5 - bk_plot.ax_vel.plot(x, yy, color = 'r', label = 'Negative Leader') - yyy = x * 10**6 - bk_plot.ax_vel.plot(x, yyy, color = 'g', label = 'Dart Leader') - bk_plot.ax_vel.set_ylim(0, max(dist_data)+1000) - bk_plot.ax_vel.set_xlim(-0.05, max(time2_data)+0.1) \ No newline at end of file + \ No newline at end of file From 7aa80210dc5a295656487a96ca7e15871124c6ef Mon Sep 17 00:00:00 2001 From: Bee Lamsma Date: Sun, 12 Jan 2025 14:39:34 -0600 Subject: [PATCH 3/4] another leader speed update --- pyxlma/plot/leader_speed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyxlma/plot/leader_speed.py b/pyxlma/plot/leader_speed.py index 3171c7f..83dcc5d 100644 --- a/pyxlma/plot/leader_speed.py +++ b/pyxlma/plot/leader_speed.py @@ -68,7 +68,7 @@ def time_distance_plot(ax, time, distance, m_reference_lines = 10, **kwargs): ax.set_ylim(0, max(distance)+1000) ax.set_xlim(-0.05, max(time)+0.1) - sc = ax.scatter(time, distance, zorder=10, c=altitude, cmap="cool", vmin=0, vmax=6) + sc = ax.scatter(time, distance, **kwargs) art_out.append(sc) #art = ax.legend(title = "Leader Type Key", loc = 2, fontsize=12, title_fontsize=16, framealpha=1) #art_out.extend(art) From e861f3c1aa1408435e0700292227394bc6fb5786 Mon Sep 17 00:00:00 2001 From: Bee Lamsma Date: Sun, 12 Jan 2025 16:41:03 -0600 Subject: [PATCH 4/4] one last leader speed update for the day --- pyxlma/plot/leader_speed.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pyxlma/plot/leader_speed.py b/pyxlma/plot/leader_speed.py index 83dcc5d..8bc853d 100644 --- a/pyxlma/plot/leader_speed.py +++ b/pyxlma/plot/leader_speed.py @@ -1,27 +1,33 @@ import numpy as np -from numpy import radians, cos, sin, asin, sqrt +from numpy import radians, cos, sin, arcsin, sqrt import matplotlib.pyplot as plt +import pandas as pd def haversine(lat0, lon0, lat, lon): R = 6378.137e3 # this is in meters. For Earth radius in kilometers use 6372.8 km - dLat = radians(lat - lat) - dLon = radians(lon - lon) - lat1 = radians(lat) + dLat = radians(lat - lat0) + dLon = radians(lon - lon0) + lat1 = radians(lat0) lat2 = radians(lat) a = sin(dLat/2)**2 + cos(lat1)*cos(lat2)*sin(dLon/2)**2 - c = 2*asin(sqrt(a)) + c = 2*arcsin(sqrt(a)) return R * c def get_time_distance(lat, lon, time, lat0, lon0, time0): - lat0=lat0*np.ones_like - + lat0=lat0*np.ones_like(lat) + lon0=lon0*np.ones_like(lon) + dt = time-time0 + distance_from_origin = (haversine(lat0,lon0,lat,lon)) - time_from_origin = ((time-time0).astype('timedelta64[ns]').astype(float)/1e9) + if(type(dt) == pd.core.series.Series): + dt = dt.to_numpy() + + time_from_origin = ((dt).astype('timedelta64[ns]').astype(float)/1e9) return distance_from_origin, time_from_origin @@ -40,9 +46,11 @@ def time_distance_plot_interactive(interactive_lma, ax): return art_out -def time_distance_plot(ax, time, distance, m_reference_lines = 10, **kwargs): +def time_distance_plot(ax, time, distance, pad_sec = 10, **kwargs): + m_reference_lines = 10 m = -m_reference_lines - x = np.linspace(0, time*-1+m_reference_lines, 100) + dt = time[-1]-time[0] + x = np.linspace(0, dt + pad_sec, 100) y = x * 2 * 10**4 yy = x * 10**5 yyy = x * 10**6