Skip to content
Snippets Groups Projects

Make GPS Lk/Unlk and GPS Clock Power to plot in the same channel

Merged Lan Dam requested to merge i162_show_GPS_clock_0_when_no_data into master
4 files
+ 30
22
Compare changes
  • Side-by-side
  • Inline
Files
4
# class with all plotting functions
from typing import Dict, Optional
from typing import Dict
import numpy as np
from matplotlib.axes import Axes
@@ -50,31 +50,24 @@ class Plotting:
return ax
def plot_multi_color_dots_base(
self, c_data: Dict, chan_db_info: Dict, ax: Optional[Axes],
linked_ax: Optional[Axes], equal_upper: bool = True):
self, c_data: Dict, chan_db_info: Dict, equal_upper: bool = True):
"""
plot dots in center with colors defined by valueColors in database:
Color codes are defined in colorSettings and limitted in 'valColRE'
in dbSettings.py
:param c_data: data of the channel which includes down-sampled
data in keys 'times' and 'data'.
(if needed) data in keys 'times' and 'data'.
:param chan_db_info: info of channel from DB
:param ax: axes to plot channel
:param linked_ax: axes of another channel
linked to this channel => both channels' will be plotted on the
same axes
:param equal_upper:
if True, plot_from_value_color_equal_on_upper_bound will be used
otherwise, plot_from_value_color_equal_on_lower_bound will be use
:return: ax in which the channel is plotted
"""
if linked_ax is not None:
ax = linked_ax
if ax is None:
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h,
has_min_max_lines=False)
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h,
has_min_max_lines=False)
if equal_upper:
points_list, colors = \
get_categorized_data_from_value_color_equal_on_upper_bound(
@@ -101,14 +94,32 @@ class Plotting:
ax, sample_no_list=[None, total_samples, None],
sample_no_colors=sample_no_colors,
sample_no_pos=[None, 0.5, None],
chan_db_info=chan_db_info, linked_ax=linked_ax)
chan_db_info=chan_db_info)
ax.x_center = c_data['times'][0]
ax.chan_db_info = chan_db_info
return ax
def plot_tri_colors(self, c_data, chan_db_info, chan_id,
ax, linked_ax):
def plot_multi_color_dots_equal_on_upper_bound(
self, c_data: Dict, chan_db_info: Dict, chan_id: str) -> Axes:
"""
Use plot_multi_color_dots_base() to plot channel in which colors are
identified by plot_from_value_color_equal_on_upper_bound
"""
return self.plot_multi_color_dots_base(
c_data, chan_db_info, equal_upper=True)
def plot_multi_color_dots_equal_on_lower_bound(
self, c_data: Dict, chan_db_info: Dict, chan_id: str) -> Axes:
"""
Use plot_multi_color_dots_base() to plot channel in which colors are
identified by plot_from_value_color_equal_on_lower_bound
"""
return self.plot_multi_color_dots_base(
c_data, chan_db_info, equal_upper=False)
def plot_tri_colors(
self, c_data: Dict, chan_db_info: Dict, chan_id: str) -> Axes:
"""
Plot 3 different values in 3 lines with 3 different colors according
to valueColors:
@@ -116,27 +127,19 @@ class Plotting:
value = -1 => plot on line y=-1 with M color
value = 0 => plot on line y=0 with R color
value = 1 => plot on line y=1 with Y color
Color codes are defined in colorSettings and limitted in 'valColRE'
Color codes are defined in colorSettings and limited in 'valColRE'
in dbSettings.py
:param c_data: data of the channel which includes down-sampled
data in keys 'times' and 'data'. Refer to DataTypeModel.__init__.
soh_data[key][chan_id]
:param chan_db_info: dict - info of channel from DB
(if needed) data in keys 'times' and 'data'.
:param chan_db_info: info of channel from DB
:param chan_id: name of channel
:param ax: axes to draw plot of channel
:param linked_ax: axes of another channel
linked to this channel => both channels' will be plotted on the
same axes
:return ax: axes of the channel
"""
if linked_ax is not None:
ax = linked_ax
if ax is None:
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h,
has_min_max_lines=False)
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h,
has_min_max_lines=False)
value_colors = chan_db_info['valueColors'].split('|')
@@ -173,56 +176,31 @@ class Plotting:
ax, sample_no_list=total_sample_list,
sample_no_colors=sample_no_colors,
sample_no_pos=[0.05, 0.5, 0.95],
chan_db_info=chan_db_info, linked_ax=linked_ax)
chan_db_info=chan_db_info)
ax.chan_db_info = chan_db_info
return ax
def plot_multi_color_dots_equal_on_upper_bound(
self, c_data, chan_db_info, chan_id, ax, linked_ax):
"""
Use plot_multi_color_dots_base() to plot channel in which colors are
identified by plot_from_value_color_equal_on_upper_bound
"""
return self.plot_multi_color_dots_base(
c_data, chan_db_info, ax, linked_ax, equal_upper=True)
def plot_multi_color_dots_equal_on_lower_bound(
self, c_data, chan_db_info, chan_id, ax, linked_ax):
"""
Use plot_multi_color_dots_base() to plot channel in which colors are
identified by plot_from_value_color_equal_on_lower_bound
"""
return self.plot_multi_color_dots_base(
c_data, chan_db_info, ax, linked_ax, equal_upper=False)
def plot_up_down_dots(self, c_data, chan_db_info, chan_id, ax, linked_ax):
def plot_up_down_dots(
self, c_data: Dict, chan_db_info: Dict, chan_id: str) -> Axes:
"""
Plot channel with 2 different values, one above, one under center line.
Each value has corresponding color defined in valueColors in database.
Ex: 1:Y|0:R means
value == 1 => plot above center line with Y color
value == 0 => plot under center line with R color
Color codes are defined in colorSettings
Color codes are defined in colorSettings.
:param c_data: dict - data of the channel which includes down-sampled
data in keys 'times' and 'data'. Refer to DataTypeModel.__init__.
soh_data[key][chan_id]
:param chan_db_info: dict - info of channel from DB
:param chan_id: str - name of channel
:param ax: matplotlib.axes.Axes - axes to draw plot of channel
:param linked_ax: matplotlib.axes.Axes/None - axes of another channel
linked to this channel => both channels' will be plotted on the
same axes
:return ax: matplotlib.axes.Axes - axes of the channel
:param c_data: data of the channel which includes down-sampled
(if needed) data in keys 'times' and 'data'.
:param chan_db_info: info of channel from DB
:param chan_id: name of channel
:return ax: axes of the channel
"""
if linked_ax is not None:
ax = linked_ax
if ax is None:
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h,
has_min_max_lines=False)
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h,
has_min_max_lines=False)
val_cols = chan_db_info['valueColors'].split('|')
# up/down has 2 values: 0, 1 which match with index of points_list
@@ -254,7 +232,7 @@ class Plotting:
sample_no_list=[len(points_list[0]), None, len(points_list[1])],
sample_no_colors=[clr[colors[0]], None, clr[colors[1]]],
sample_no_pos=[0.25, None, 0.75],
chan_db_info=chan_db_info, linked_ax=linked_ax)
chan_db_info=chan_db_info)
# x_bottom, x_top are the times of data points to be displayed at
# bottom or top of the plot
@@ -264,27 +242,23 @@ class Plotting:
ax.chan_db_info = chan_db_info
return ax
def plot_time_dots(self, c_data, chan_db_info, chan_id, ax, linked_ax):
def plot_time_dots(
self, c_data: Dict, chan_db_info: Dict, chan_id: str) -> Axes:
"""
Plot times only
:param c_data: dict - data of the channel which includes down-sampled
data in keys 'times' and 'data'. Refer to DataTypeModel.__init__.
soh_data[key][chan_id]
:param chan_db_info: dict - info of channel from DB
:param chan_id: str - name of channel
:param ax: matplotlib.axes.Axes - axes to draw plot of channel
:param linked_ax: matplotlib.axes.Axes/None - axes of another channel
linked to this channel => both channels' will be plotted on the
same axes
:return ax: matplotlib.axes.Axes - axes of the channel
:param c_data: data of the channel which includes down-sampled
(if needed) data in keys 'times' and 'data'.
:param chan_db_info: info of channel from DB
:param chan_id: name of channel
:return ax: axes of the channel
"""
if linked_ax is not None:
ax = linked_ax
if ax is None:
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h)
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h)
color = 'W'
if chan_db_info['valueColors'] not in [None, 'None', '']:
@@ -295,7 +269,7 @@ class Plotting:
ax, sample_no_list=[None, total_x, None],
sample_no_colors=[None, clr[color], None],
sample_no_pos=[None, 0.5, None],
chan_db_info=chan_db_info, linked_ax=linked_ax)
chan_db_info=chan_db_info)
for x in x_list:
ax.plot(x, [0] * len(x), marker='s', markersize=1.5,
@@ -306,38 +280,31 @@ class Plotting:
ax.chan_db_info = chan_db_info
return ax
def plot_lines_dots(self, c_data, chan_db_info, chan_id,
ax, linked_ax, info=''):
def plot_lines_dots(
self, c_data: Dict, chan_db_info: Dict, chan_id: str, info: str = ''
) -> Axes:
"""
Plot lines with dots at the data points. Colors of dot and lines are
defined in valueColors in database.
Ex: L:G|D:W means
Ex: L:G|D:W|Z:C means
Lines are plotted with color G
Dots are plotted with color W
Additional dot with value Zero in color C (for channel GPS Lk/Unlk)
If D is not defined, dots won't be displayed.
If L is not defined, lines will be plotted with color G
Color codes are defined in colorSettings
:param c_data: dict - data of the channel which includes down-sampled
data in keys 'times' and 'data'. Refer to DataTypeModel.__init__.
soh_data[key][chan_id] or DataTypeModel.__init__.
waveform_data[key]['read_data'][chan_id] for waveform data
:param chan_db_info: dict - info of channel from DB
:param chan_id: str - name of channel
:param ax: matplotlib.axes.Axes - axes to draw plot of channel
:param linked_ax: matplotlib.axes.Axes/None - axes of another channel
linked to this channel => both channels' will be plotted on the
same axes
:param info: str - additional info to be displayed on sub-title under
:param c_data: data of the channel which includes down-sampled
(if needed) data in keys 'times' and 'data'.
:param chan_db_info: info of channel from DB
:param chan_id: name of channel
:param info: additional info to be displayed on sub-title under
main-title
:return ax: matplotlib.axes.Axes - axes of the channel
:return ax: axes of the channel
"""
if linked_ax is not None:
ax = linked_ax
if ax is None:
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h)
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h)
x_list, y_list = c_data['times'], c_data['data']
@@ -358,24 +325,44 @@ class Plotting:
d_color = l_color
if chan_id == 'GPS Lk/Unlk':
z_color = colors['Z']
sample_no_list = []
ax.x_bottom = x_list[0][np.where(y_list[0] == -1)[0]]
sample_no_list.append(ax.x_bottom.size)
sample_no_list.append(None)
ax.x_center = x_list[0][np.where(y_list[0] == 0)[0]]
sample_no_list.append(ax.x_center.size)
ax.x_top = x_list[0][np.where(y_list[0] == 1)[0]]
sample_no_list.append(ax.x_top.size)
sample_no_colors = [clr[d_color], None, clr[d_color]]
sample_no_pos = [0.05, None, 0.95]
sample_no_colors = [clr[d_color], clr[z_color], clr[d_color]]
sample_no_pos = [0.05, 0.5, 0.95]
top_bottom_index = np.where(y_list[0] != 0)[0]
# for plotting top & bottom
x_list = [x_list[0][top_bottom_index]]
y_list = [y_list[0][top_bottom_index]]
ax.myPlot = ax.plot(ax.x_center, [0] * ax.x_center.size,
marker='s',
markersize=1.5,
linestyle='',
zorder=constants.Z_ORDER['DOT'],
mfc=clr[z_color],
mec=clr[z_color],
picker=True, pickradius=3)
info = "GPS Clock Power"
else:
sample_no_list = [None, sum([len(x) for x in x_list]), None]
sample_no_colors = [None, clr[d_color], None]
sample_no_pos = [None, 0.5, None]
ax.x_center = x_list[0]
ax.y_list = y_list[0]
self.plotting_axes.set_axes_info(
ax, sample_no_list=sample_no_list,
sample_no_colors=sample_no_colors,
sample_no_pos=sample_no_pos,
chan_db_info=chan_db_info,
info=info, y_list=y_list, linked_ax=linked_ax)
info=info, y_list=y_list)
for x, y in zip(x_list, y_list):
if not has_dot and sample_no_list[1] > 1:
@@ -397,53 +384,39 @@ class Plotting:
mec=clr[d_color],
picker=True, pickradius=3)
if chan_id != 'GPS Lk/Unlk':
ax.x_center = x_list[0]
ax.y_list = y_list[0]
ax.chan_db_info = chan_db_info
return ax
def plot_lines_s_rate(self, c_data, chan_db_info, chan_id, ax, linked_ax):
def plot_lines_s_rate(
self, c_data: Dict, chan_db_info: Dict, chan_id: str) -> Axes:
"""
Plot line only for waveform data channel (seismic data). Sample rate
unit will be displayed
:param c_data: dict - data of the channel which includes down-sampled
data in keys 'times' and 'data'. Refer to DataTypeModel.__init__.
waveform_data[key]['read_data'][chan_id]
:param chan_db_info: dict - info of channel from DB
:param chan_id: str - name of channel
:param ax: matplotlib.axes.Axes - axes to draw plot of channel
:param linked_ax: matplotlib.axes.Axes/None - axes of another channel
linked to this channel => both channels' will be plotted on the
same axes
:return ax: matplotlib.axes.Axes - axes of the channel
:param c_data: data of the channel which includes down-sampled
(if needed) data in keys 'times' and 'data'.
:param chan_db_info: info of channel from DB
:param chan_id: name of channel
:return ax: axes of the channel
"""
if c_data['samplerate'] >= 1.0:
info = "%dsps" % c_data['samplerate']
else:
info = "%gsps" % c_data['samplerate']
return self.plot_lines_dots(c_data, chan_db_info, chan_id,
ax, linked_ax, info=info)
return self.plot_lines_dots(c_data, chan_db_info, chan_id, info=info)
def plot_lines_mass_pos(self, c_data, chan_db_info, chan_id,
ax, linked_ax):
def plot_lines_mass_pos(
self, c_data: Dict, chan_db_info: Dict, chan_id: str) -> Axes:
"""
Plot multi-color dots with grey line for mass position channel.
Use get_masspos_value_colors() to get value_colors map based on
Menu - MP Coloring selected from Main Window.
:param c_data: dict - data of the channel which includes down-sampled
data in keys 'times' and 'data'. Refer to DataTypeModel.__init__.
mass_pos_data[key][chan_id]
:param chan_db_info: dict - info of channel from DB
:param chan_id: str - name of channel
:param ax: matplotlib.axes.Axes - axes to draw plot of channel
:param linked_ax: matplotlib.axes.Axes/None - axes of another channel
linked to this channel => both channels' will be plotted on the
same axes
:return ax: matplotlib.axes.Axes - axes of the channel
:param c_data: data of the channel which includes down-sampled
(if needed) data in keys 'times' and 'data'.
:param chan_db_info: info of channel from DB
:param chan_id: name of channel
:return ax: axes of the channel
"""
value_colors = get_masspos_value_colors(
self.main_window.mass_pos_volt_range_opt, chan_id,
@@ -452,14 +425,12 @@ class Plotting:
if value_colors is None:
return
if ax is None:
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h)
plot_h = self.plotting_axes.get_height(chan_db_info['height'])
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h)
x_list, y_list = c_data['times'], c_data['data']
total_x = sum([len(x) for x in x_list])
self.plotting_axes.set_axes_info(
ax, sample_no_list=[None, total_x, None],
sample_no_colors=[None, clr['W'], None],
Loading