From 6c7f44f42a8b153525f0561d27cc951d748b6aa7 Mon Sep 17 00:00:00 2001 From: krakenrf <> Date: Fri, 28 Oct 2022 06:49:47 +0100 Subject: graph enhancements --- _UI/_web_interface/kraken_web_interface.py | 198 ++++++++--------------------- 1 file changed, 56 insertions(+), 142 deletions(-) diff --git a/_UI/_web_interface/kraken_web_interface.py b/_UI/_web_interface/kraken_web_interface.py index dfbc89d..ba85079 100755 --- a/_UI/_web_interface/kraken_web_interface.py +++ b/_UI/_web_interface/kraken_web_interface.py @@ -42,6 +42,8 @@ import plotly.graph_objects as go import plotly.express as px import plotly.io as pio import io +from io import BytesIO + import numpy as np from configparser import ConfigParser @@ -495,9 +497,11 @@ pr_fig.add_trace(go.Heatmap( [1.0, '#4A0000']])) +youssef_color_map = ['#000020', '#000030', '#000050', '#000091', '#1E90FF', '#FFFFFF', '#FFFF00', '#FE6D16', '#FE6D16', '#FF0000', + '#FF0000', '#C60000', '#9F0000', '#750000', '#4A0000'] - - +color_map = colors.ListedColormap(youssef_color_map) +scalarMap = cm.ScalarMappable(cmap=color_map) #app = dash.Dash(__name__, suppress_callback_exceptions=True, compress=True, update_title="") # cannot use update_title with dash_devices app = dash.Dash(__name__, suppress_callback_exceptions=True, compress=True) @@ -1269,9 +1273,10 @@ def plot_pr(): #CAFMatrix = CAFMatrix / 50 #/ np.amax(CAFMatrix) # Noramlize with the maximum value #CAFMatrix = CAFMatrix / np.amax(CAFMatrix) # Noramlize with the maximum value starttime = time.time() - #CAFMatrix = resize(CAFMatrix,(1024,1024),order=1) - CAFMatrix = CAFMatrix - np.amin(CAFMatrix) / (np.amax(CAFMatrix) - np.amin(CAFMatrix)) + valueMax = np.amax(CAFMatrix) + valueMin = np.amin(CAFMatrix) + CAFMatrix = CAFMatrix - valueMin / (valueMax - valueMin) if webInterface_inst.CAFMatrixPersist is None or webInterface_inst.CAFMatrixPersist.shape != CAFMatrix.shape or not webInterface_inst.en_persist: webInterface_inst.CAFMatrixPersist = CAFMatrix @@ -1285,147 +1290,54 @@ def plot_pr(): CAFDynRange = webInterface_inst.pr_dynamic_range_max CAFMatrixLog[CAFMatrixLog > CAFDynRange] = CAFDynRange - CAFMatrixLog = resize(CAFMatrixLog,(1024,1024),order=1) - - endtime = time.time() - - print("resize time taken: " + str((endtime-starttime)*1000)) + CAFMatrixLog = resize(CAFMatrixLog,(1024,1024),order=1, anti_aliasing=True) + seg_colors = scalarMap.to_rgba(CAFMatrixLog) + img = Image.fromarray(np.uint8(seg_colors*255)) - y_height = CAFMatrixLog.shape[0] - - bistatic_speed_ms = -webInterface_inst.module_signal_processor.max_doppler * c / webInterface_inst.module_receiver.daq_center_freq - bistatic_speed_kmh = bistatic_speed_ms * 3.6 - - y_range = list(np.linspace(-bistatic_speed_kmh, bistatic_speed_kmh, y_height)) # in Hz - - webInterface_inst.pr_graph_reset_flag = True - #if webInterface_inst.RD_matrix is not None: + #webInterface_inst.pr_graph_reset_flag = True if not webInterface_inst.pr_graph_reset_flag: + #pr_fig.update_layout(hovermode="x", showlegend=False) + pr_fig.update_layout( + images=[go.layout.Image( + source=img)] + ) + app.push_mods({ - 'pr-graph': {'extendData': [dict(z = [CAFMatrixLog]), [0], len(CAFMatrixLog)]} - #'pr-graph': {'extendData': [dict(z = [CAFMatrixLog], y = [y_range]), [0], len(CAFMatrixLog)]} + 'pr-graph': {'figure': pr_fig}, }) + + + # app.push_mods({ + # 'pr-graph': {'extendData': [dict(z = [CAFMatrixLog]), [0], len(CAFMatrixLog)]} + # # 'pr-graph': {'extendData': [dict(z = [CAFMatrixLog], y = [y_range]), [0], len(CAFMatrixLog)]} + # }) else: webInterface_inst.pr_graph_reset_flag = False + y_height = CAFMatrixLog.shape[0] + + bistatic_speed_ms = -webInterface_inst.module_signal_processor.max_doppler * c / webInterface_inst.module_receiver.daq_center_freq + bistatic_speed_kmh = bistatic_speed_ms * 3.6 + + y_range = list(np.linspace(-bistatic_speed_kmh, bistatic_speed_kmh, y_height)) # in Hz + x_length = CAFMatrixLog.shape[1] bistatic_distance = webInterface_inst.module_signal_processor.max_bistatic_range bistatic_resolution = c / (webInterface_inst.module_receiver.iq_header.sampling_freq) bistatic_resolution_km = bistatic_resolution / 1000 - print(str(CAFMatrixLog.shape)) + max_bistatic_distance = bistatic_distance*bistatic_resolution_km - x_range = list(np.linspace(0, bistatic_distance*bistatic_resolution_km, x_length)) - - #matrixMax = np.amax(CAFMatrixLog) - #matrixMin = np.amin(CAFMatrixLog) - #cNorm = Normalize(vmin=webInterface_inst.pr_dynamic_range_min, vmax=webInterface_inst.pr_dynamic_range_max) - - youssef_color_map = ['#000020', '#000030', '#000050', '#000091', '#1E90FF', '#FFFFFF', '#FFFF00', '#FE6D16', '#FE6D16', '#FF0000', - '#FF0000', '#C60000', '#9F0000', '#750000', '#4A0000'] - - color_map = colors.ListedColormap(youssef_color_map) - - #scalarMap = cm.ScalarMappable(cmap='jet') - - scalarMap = cm.ScalarMappable(cmap=color_map) + x_range = list(np.linspace(0, max_bistatic_distance, x_length)) - - #smoothedCAFMatrixLog = gaussian_filter(CAFMatrixLog, sigma=0.5) - - seg_colors = scalarMap.to_rgba(CAFMatrixLog) - img = Image.fromarray(np.uint8(seg_colors*255)) - - - - # img_fig = go.Figure(layout=fig_layout) - # img_fig.add_trace(go.Heatmap( - # z=CAFMatrixLog, - # x=x_range, - # y=y_range, - # zsmooth='best', #False, - # #zsmooth=False, #False, - # showscale=False, - # #hoverinfo='skip', - # colorscale=[[0.0, '#000020'], - # [0.0714, '#000030'], - # [0.1428, '#000050'], - # [0.2142, '#000091'], - # [0.2856, '#1E90FF'], - # [0.357, '#FFFFFF'], - # [0.4284, '#FFFF00'], - # [0.4998, '#FE6D16'], - # [0.5712, '#FE6D16'], - # [0.6426, '#FF0000'], - # [0.714, '#FF0000'], - # [0.7854, '#C60000'], - # [0.8568, '#9F0000'], - # [0.9282, '#750000'], - # [1.0, '#4A0000']])) - - - # img_fig.update_xaxes(title_text="Bistatic Range [km]", - # color='rgba(255,255,255,1)', - # title_font_size=20, - # #tickfont_size=figure_font_size, - # #mirror=True, - # ticks='outside', - # showline=True) - # img_fig.update_yaxes(title_text="Bistatic Speed [km/h]", - # color='rgba(255,255,255,1)', - # title_font_size=20, - # #tickfont_size=figure_font_size, - # #range=[-5, 5], - # #mirror=True, - # ticks='outside', - # showline=True) - - # img_bytes = pio.to_image(img_fig, format = 'png') - # img = Image.open(io.BytesIO(img_bytes)) - -################## - # pr_fig = go.Figure(layout=fig_layout) - # pr_fig.add_trace(go.Image(z=img)) - -################## - - xmin = x_range[0] - xmax = x_range[len(x_range)-1] - ymin = y_range[0] - ymax = y_range[len(y_range)-1] + xmin = 0 + xmax = max_bistatic_distance #x_range[len(x_range)-1] + ymin = -bistatic_speed_kmh #y_range[0] + ymax = bistatic_speed_kmh #y_range[len(y_range)-1] pr_fig = go.Figure(layout=fig_layout) - # CAFMatrixDummy = np.empty((32,256)) #resize(CAFMatrix,(64,64),order=1) - - # y_height = CAFMatrixDummy.shape[0] - - # bistatic_speed_ms = -webInterface_inst.module_signal_processor.max_doppler * c / webInterface_inst.module_receiver.daq_center_freq - # bistatic_speed_kmh = bistatic_speed_ms * 3.6 - - # y_range = list(np.linspace(-bistatic_speed_kmh, bistatic_speed_kmh, y_height)) # in Hz - - # x_length = CAFMatrixDummy.shape[1] - # bistatic_distance = webInterface_inst.module_signal_processor.max_bistatic_range - # bistatic_resolution = c / (webInterface_inst.module_receiver.iq_header.sampling_freq) - # bistatic_resolution_km = bistatic_resolution / 1000 - - # x_range = list(np.linspace(0, bistatic_distance*bistatic_resolution_km, x_length)) - - - # # pr_fig.add_trace(go.Heatmap( - # # z=CAFMatrixDummy, - # # x=x_range, - # # y=y_range, - # zsmooth='best', #False, - # zsmooth=False, #False, - # # showscale=False, - # # opacity=0, - # # hoverinfo='skip' - # # )) - - pr_fig.add_trace(go.Scatter( x=x_range, y=[0] * len(x_range), @@ -1440,7 +1352,7 @@ def plot_pr(): pr_fig.update_xaxes(title_text="Bistatic Range [km]", color='rgba(255,255,255,1)', title_font_size=20, - fixedrange = True, + #fixedrange = True, # tickfont_size=figure_font_size, # mirror=True, ticks='outside', @@ -1448,15 +1360,25 @@ def plot_pr(): pr_fig.update_yaxes(title_text="Bistatic Speed [km/h]", color='rgba(255,255,255,1)', title_font_size=20, - fixedrange = True, + #fixedrange = True, # tickfont_size=figure_font_size, # range=[-5, 5], # mirror=True, ticks='outside', showline=True) - pr_fig.update_layout(hovermode="x", showlegend=False) + # Constants + img_width = 900 + img_height = 800 + + #pr_fig.update_layout(hovermode="x", showlegend=False) pr_fig.update_layout( + hovermode="x", + showlegend=False, + xaxis=dict(showgrid=False, zeroline=False, range=[xmin, xmax]), + yaxis=dict(showgrid=False, zeroline=False, range=[ymin, ymax]), + width=img_width, + height=img_height, images=[go.layout.Image( x=xmin, sizex=xmax-xmin, @@ -1469,19 +1391,7 @@ def plot_pr(): sizing="stretch", source=img)] ) - - - # Constants - img_width = 900 - img_height = 800 - # Configure other layout - pr_fig.update_layout( - xaxis=dict(showgrid=False, zeroline=False, range=[xmin, xmax]), - yaxis=dict(showgrid=False, zeroline=False, range=[ymin, ymax]), - width=img_width, - height=img_height, - ) ###################### @@ -1543,6 +1453,10 @@ def plot_pr(): 'pr-graph': {'figure': pr_fig}, }) + endtime = time.time() + print("full plot time taken: " + str((endtime-starttime)*1000)) + + def plot_spectrum(): global spectrum_fig global waterfall_fig -- cgit v1.2.3