@@ -63,7 +63,7 @@ def setup_hist(lon_data, lat_data, alt_data, time_data,
6363
6464def plot_points (bk_plot , lon_data , lat_data , alt_data , time_data ,
6565 plot_cmap = None , plot_s = None , plot_vmin = None , plot_vmax = None , plot_c = None , edge_color = 'face' ,
66- edge_width = 0 , add_to_histogram = True , ** kwargs ):
66+ edge_width = 0 , add_to_histogram = True , marker = 'o' , ** kwargs ):
6767 """
6868 Plot scatter points on an existing bk_plot object given x,y,z,t for each
6969 and defined plotting colormaps and ranges
@@ -88,16 +88,16 @@ def plot_points(bk_plot, lon_data, lat_data, alt_data, time_data,
8888
8989 art_plan = bk_plot .ax_plan .scatter (lon_data , lat_data ,
9090 c = plot_c ,vmin = plot_vmin , vmax = plot_vmax , cmap = plot_cmap ,
91- s = plot_s ,marker = 'o' , linewidths = edge_width , edgecolors = edge_color , ** kwargs )
91+ s = plot_s , marker = marker , linewidths = edge_width , edgecolors = edge_color , ** kwargs )
9292 art_th = bk_plot .ax_th .scatter (time_data , alt_data ,
9393 c = plot_c ,vmin = plot_vmin , vmax = plot_vmax , cmap = plot_cmap ,
94- s = plot_s ,marker = 'o' , linewidths = edge_width , edgecolors = edge_color , ** kwargs )
94+ s = plot_s , marker = marker , linewidths = edge_width , edgecolors = edge_color , ** kwargs )
9595 art_lon = bk_plot .ax_lon .scatter (lon_data , alt_data ,
9696 c = plot_c ,vmin = plot_vmin , vmax = plot_vmax , cmap = plot_cmap ,
97- s = plot_s ,marker = 'o' , linewidths = edge_width , edgecolors = edge_color , ** kwargs )
97+ s = plot_s , marker = marker , linewidths = edge_width , edgecolors = edge_color , ** kwargs )
9898 art_lat = bk_plot .ax_lat .scatter (alt_data , lat_data ,
9999 c = plot_c ,vmin = plot_vmin , vmax = plot_vmax , cmap = plot_cmap ,
100- s = plot_s ,marker = 'o' , linewidths = edge_width , edgecolors = edge_color , ** kwargs )
100+ s = plot_s , marker = marker , linewidths = edge_width , edgecolors = edge_color , ** kwargs )
101101 art_out = [art_plan , art_th , art_lon , art_lat ]
102102
103103 if add_to_histogram :
@@ -111,6 +111,84 @@ def plot_points(bk_plot, lon_data, lat_data, alt_data, time_data,
111111 art_out .append (art_hist )
112112 return art_out
113113
114+
115+ def plot_2d_network_points (bk_plot , netw_data , actual_height = None , fake_ic_height = 18 , fake_cg_height = 1 ,
116+ color_by = 'time' , pos_color = 'red' , neg_color = 'blue' , ** kwargs ):
117+ """
118+ Plot points from a 2D lightning mapping neworks (ie, NLDN, ENTLN, etc)
119+
120+ Parameters
121+ ----------
122+ bk_plot : `pyxlma.plot.xlma_base_plot.BlankPlot`
123+ A BlankPlot object to plot the data on
124+ netw_data : `pandas.DataFrame` or `xarray.Dataset`
125+ data object with columns/variables 'longitude', 'latitude', 'type' (CG/IC), and 'datetime'
126+ actual_height : `numpy.ndarray` or `pandas.Series` or `xarray.DataArray`
127+ the hieghts of the events to be plotted (default None, fake_ic_height and fake_cg_height used)
128+ fake_ic_height : float
129+ the altitude to plot IC points (default 18 km)
130+ fake_cg_height : float
131+ the altitude to plot CG points (default 1 km)
132+ color_by : ['time', 'polarity']
133+ Whether to color the points by time or polarity. Default 'time'. Ignored if **kwargs contains 'c'.
134+ pos_color : str
135+ color for positive points (default 'red') if color_by='polarity'
136+ neg_color : str
137+ color for negative points (default 'blue') if color_by='polarity'
138+ **kwargs
139+ additional keyword arguments to pass to plt.scatter
140+
141+ Returns
142+ -------
143+ art_out : list
144+ nested lists of artists created by plot_points (first list CG, second list IC)
145+
146+ """
147+
148+ plot_c = kwargs .pop ('c' , None )
149+ vmin = kwargs .pop ('vmin' , None )
150+ vmax = kwargs .pop ('vmax' , None )
151+ marker = kwargs .pop ('marker' , '^' )
152+ if actual_height is not None :
153+ netw_data ['height' ] = actual_height
154+
155+ if plot_c is not None :
156+ netw_data ['plot_c' ] = plot_c
157+ elif color_by == 'time' :
158+ netw_data ['plot_c' ] = color_by_time (netw_data .datetime , bk_plot .tlim )[2 ]
159+ elif color_by == 'polarity' :
160+ pass
161+ else :
162+ raise ValueError ("color_by must be 'time' or 'polarity'" )
163+
164+ cgs = netw_data [netw_data ['type' ]== 'CG' ]
165+ ics = netw_data [netw_data ['type' ]== 'IC' ]
166+
167+ if actual_height is None :
168+ cgs ['height' ] = np .full_like (cgs .longitude , fake_cg_height )
169+ ics ['height' ] = np .full_like (ics .longitude , fake_ic_height )
170+ art_out = []
171+ if color_by == 'polarity' :
172+ cgpos = cgs [cgs .peak_current_kA > 0 ]
173+ cgneg = cgs [cgs .peak_current_kA < 0 ]
174+ icpos = ics [ics .peak_current_kA > 0 ]
175+ icneg = ics [ics .peak_current_kA < 0 ]
176+ art_out .append (plot_points (bk_plot , cgneg .longitude , cgneg .latitude , cgneg .height ,
177+ cgneg .datetime , c = neg_color , marker = marker , add_to_histogram = False , ** kwargs ))
178+ art_out .append (plot_points (bk_plot , cgpos .longitude , cgpos .latitude , cgpos .height ,
179+ cgpos .datetime , c = pos_color , marker = marker , add_to_histogram = False , ** kwargs ))
180+ art_out .append (plot_points (bk_plot , icneg .longitude , icneg .latitude , icneg .height ,
181+ icneg .datetime , c = neg_color , marker = marker , add_to_histogram = False , ** kwargs ))
182+ art_out .append (plot_points (bk_plot , icpos .longitude , icpos .latitude , icpos .height ,
183+ icpos .datetime , c = pos_color , marker = marker , add_to_histogram = False , ** kwargs ))
184+ else :
185+ art_out .append (plot_points (bk_plot , cgs .longitude , cgs .latitude , cgs .height ,
186+ cgs .datetime , c = cgs .plot_c , vmin = vmin , vmax = vmax , marker = marker , add_to_histogram = False , ** kwargs ))
187+ art_out .append (plot_points (bk_plot , ics .longitude , ics .latitude , ics .height ,
188+ ics .datetime , c = ics .plot_c , vmin = vmin , vmax = vmax , marker = marker , add_to_histogram = False , ** kwargs ))
189+ return art_out
190+
191+
114192def plot_3d_grid (bk_plot , xedges , yedges , zedges , tedges ,
115193 alt_lon , alt_lat , alt_time , lat_lon ,
116194 alt_data , plot_cmap = None , ** kwargs ):
0 commit comments