-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfence_add_radar.py
More file actions
93 lines (80 loc) · 4.29 KB
/
fence_add_radar.py
File metadata and controls
93 lines (80 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pyvista as pv
import numpy as np
################## NDH Tools self imports
###########################################################
from .find_nearest import find_nearest
###########################################################
def fence_add_radar(plotter,radar_data,depth_data,depth_cutoff_val=500,depth_ds=2,horiz_ds=5,opacity=1,vmin=0,vmax=0,lighting=[0.4,0.8,0],nan_surface=1):
"""
% (C) Nick Holschuh - Amherst College - 2026 ([email protected])
% This function uses PyVista to add radar profiles to an interactive fence diagram
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The inputs are:
%
% plotter - The Pyvista plotter object generated by "fence_initiate"
% radar_data - Radar data object generated by radar_load
% depth_data - Depth data object generated by radar_load
% depth_cutoff_val - z value below which will be cut off from the figure
% depth_ds - Integer used to downsample the radar image in the depth dimension
% horiz_ds - Integer used to downsample the radar image in the horizontal dimension
% opacity - Value between 0 and 1 indicating fence opacity. Large values are better
% vmin - value for minimum on the colormap. 0 will use default range
% vmax - value for maximum on the colormap. 0 will use default range
% lighting - three value array describing the ambient, diffuse, and specular light (0-1)
% nan_surface - flag, 1, to remove all samples above the radar surface
%
%%%%%%%%%%%%%%%
% The output is a dictionary containing:
%
% plotter - The plotter object which can be passed into later functions
% mesh - The way PyVista works requires that the mesh still be in memory. So
% preserving independent mesh objects is required to generate the final html file
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
"""
depth_cutoff = find_nearest(depth_data['depth_axis'],depth_cutoff_val)
rxgrid = np.tile(radar_data['x'][::horiz_ds],(len(depth_data['depth_axis'][:depth_cutoff['index'][0]:depth_ds]),1))
rygrid = np.tile(radar_data['y'][::horiz_ds],(len(depth_data['depth_axis'][:depth_cutoff['index'][0]:depth_ds]),1))
rzgrid = np.tile(depth_data['depth_axis'][:depth_cutoff['index'][0]:depth_ds],(len(radar_data['x'][::horiz_ds]),1)).T
intensity_grid = depth_data['new_data'][:depth_cutoff['index'][0]:depth_ds,::horiz_ds]
if nan_surface == 1:
for ind in np.arange(len(depth_data['surface_elev'][::horiz_ds])):
blank_ind = find_nearest(depth_data['depth_axis'],depth_data['surface_elev'][ind*horiz_ds])
intensity_grid[0:int(blank_ind['index'][0]/depth_ds),ind] = np.NaN
# 1. Create your mesh just like before
mesh = pv.StructuredGrid(rxgrid, rygrid, rzgrid)
# 2. Flatten your 2D intensity array.
# CRITICAL: Use order='F' so the values match VTK's coordinate system!
intensities_flat = intensity_grid.flatten(order='F')
# 3. Attach the data to the mesh points
mesh.point_data['My_Intensities'] = intensities_flat
noclims = 0
if vmin == 0:
if vmax == 0:
noclims = 1
if noclims == 1:
plotter.add_mesh(
mesh,
scalars='My_Intensities',
cmap='gray_r', # Pick any standard matplotlib colormap (plasma, inferno, coolwarm, etc.)
show_scalar_bar=False, # Draws a nice legend bar on the screen
opacity=opacity,
ambient=lighting[0], # Boost this to brighten the raw RGB colors
diffuse=lighting[1], # Standard matte scattering
specular=lighting[2], # No shiny glare
nan_opacity=0.0
)
else:
plotter.add_mesh(
mesh,
scalars='My_Intensities',
cmap='gray_r', # Pick any standard matplotlib colormap (plasma, inferno, coolwarm, etc.)
clim=[vmin,vmax],
show_scalar_bar=False, # Draws a nice legend bar on the screen
opacity=opacity,
ambient=lighting[0], # Boost this to brighten the raw RGB colors
diffuse=lighting[1], # Standard matte scattering
specular=lighting[2], # No shiny glare
nan_opacity=0.0
)
return plotter, mesh