Skip to content

Commit 2a6a162

Browse files
committed
Add 2D network subsetting
1 parent 2d85171 commit 2a6a162

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

pyxlma/plot/interactive.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,54 @@ def get_glm_plot_subset(interactive_plot, glm):
409409
glm_sub = glm.reduce_to_entities('group_id', glm_sub.event_parent_group_id.data)
410410

411411
return glm_sub
412+
413+
414+
def get_2d_network_subset(interactive_plot, netw_data, adjust_alt=True, pad_factor=0.01):
415+
"""
416+
Subset 2D network point data to the current view of an interactive plot.
417+
418+
Parameters
419+
----------
420+
interactive_plot : `pyxlma.plot.interactive.InteractiveLMAPlot`
421+
The XLMA plot from which the bounds of the current view are extracted
422+
netw_data : `pandas.DataFrame`
423+
2d network point location data of the type expected by
424+
`pyxlma.plot.xlma_plot_feature.plot_2d_network_points`
425+
adjust_alt : bool
426+
if True, adjust the `icheight` column of netw_sub to fit within the plot range
427+
if False, reject any points whose `icheight` is outside the plot range.
428+
pad_factor : float
429+
if adjust_alt==True, factor of the plot's total altitude height range to use
430+
as padding on the minimum and maximum altitude.
431+
432+
Returns
433+
-------
434+
netw_sub : `pandas.DataFrame`
435+
subset netw_data to match the current plot
436+
"""
437+
xlim = interactive_plot.bounds['x']
438+
ylim = interactive_plot.bounds['y']
439+
zlim = [z*1000.0 for z in interactive_plot.bounds['z']]
440+
tlim = interactive_plot.bounds['t']
441+
start, end = np.datetime64(tlim[0]), np.datetime64(tlim[1])
442+
z_span = zlim[1] - zlim[0]
443+
444+
in_lat = (netw_data['latitude'] >= ylim[0]) & (netw_data['latitude'] < ylim[1])
445+
in_lon = (netw_data['longitude'] >= xlim[0]) & (netw_data['longitude'] < xlim[1])
446+
in_time = (netw_data['datetime'] >= start) & (netw_data['datetime'] < end)
447+
448+
# Must copy, or it gives a view of the original dataframe/
449+
netw_sub = netw_data[in_lat & in_lon & in_time].copy()
450+
451+
# if altitude greater or less than top or bottom of plot, move to top or bottom.
452+
if adjust_alt:
453+
min_z = zlim[0]+pad_factor*z_span
454+
max_z = zlim[1]-pad_factor*z_span
455+
below = (netw_sub['icheight'] < min_z)
456+
above = (netw_sub['icheight'] >= max_z)
457+
netw_sub['icheight'] = np.where(below, min_z, netw_sub['icheight'])
458+
netw_sub['icheight'] = np.where(above, max_z, netw_sub['icheight'])
459+
else:
460+
in_alt = (netw_sub['icheight'] >= zlim[0]) & (netw_sub['icheight'] < zlim[1])
461+
netw_sub = netw_sub[in_alt]
462+
return netw_sub

0 commit comments

Comments
 (0)