Skip to content

Commit

Permalink
Merge pull request #21 from Lexi-BU/20-add-nominal-values-of-housekee…
Browse files Browse the repository at this point in the history
…ping-data

modifications to the gui
  • Loading branch information
qudsiramiz authored Jan 7, 2025
2 parents a51db87 + 42e9ea5 commit 447907b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 77 deletions.
4 changes: 2 additions & 2 deletions codes/luigi.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ non_lin_corr_status = False
cmap = viridis

[time_options]
start_time = 2023-11-16 10:00:00
end_time = 2024-11-16 16:32:52
start_time = 2025-01-15 00:08:18
end_time = 2025-01-15 00:14:18
time_threshold = 60

102 changes: 54 additions & 48 deletions codes/lxi_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
import tkinter as tk
from tkinter import font, ttk
import tkinter.font as tkFont

import global_variables
import lxi_file_read_funcs as lxrf
Expand Down Expand Up @@ -134,7 +135,7 @@ def ts_plot_inputs(
"fig_width": screen_width / (3 * dpi),
"fig_height": screen_height / (4 * dpi),
"dark_mode": dark_mode_var.get(),
"time_type": time_type.get(),
"hv_status": hv_status.get(),
"display_time_label": display_time_label,
}
llpr.load_ts_plots(**inputs)
Expand Down Expand Up @@ -290,6 +291,17 @@ def refresh_ts_plot():
logger.info("No time series data to plot")


def toggle_hv_status():
# Toggle between "HV-Off" and "HV-On"
if hv_status.get() == "HV-Off":
hv_status.set("HV-On")
hv_status_button.config(text="HV-On", bg="red", fg="white", font=("Helvetica", 12, "bold"))
else:
hv_status.set("HV-Off")
hv_status_button.config(text="HV-Off", bg="green", fg="black", font=("Helvetica", 12, "bold"))
refresh_ts_plot() # Call the plot refresh function


def load_and_copy_files():
"""
This function is called when the "Load Files" button is clicked. It copies the LEXI data files
Expand Down Expand Up @@ -427,6 +439,21 @@ def dark_mode_change():
except Exception:
pass

# Try to change the colors of the toggle buttons
for button in root_item.winfo_children():
try:
if button["text"] == "HV-Off":
button.configure(bg="green", fg="black")
except Exception:
pass
for button in root_item.winfo_children():
try:
if button["text"] == "HV-On":
button.configure(bg="red", fg="white")
except Exception:
pass


# Run the populating entries function to change the color of the entry boxes
# lgeb.populate_entries(root=root, dark_mode=dark_mode)

Expand Down Expand Up @@ -477,8 +504,8 @@ def dark_mode_change():


print(f"The screen width and height are: {screen_width}, {screen_height} for platform: {platform.system()}")
# screen_width = 3600
# screen_height = 1000
screen_width = 3600
screen_height = 1000
print(
"If the GUI size is messed up, uncomment the line 480 and 481 of lxi_gui.py code and set the "
"screen_width and screen_height to your liking."
Expand Down Expand Up @@ -557,23 +584,6 @@ def dark_mode_change():
cursor="hand2",
)
dark_mode_button.grid(row=21, column=0, sticky="nsew", padx=5, pady=5)
# add this button on the housekeeping tab as well
dark_mode_button = tk.Checkbutton(
hk_tab,
text="Dark Mode",
variable=dark_mode_var,
command=dark_mode_change,
bg=bg_color,
fg=fg_color,
font=font_style,
relief="raised",
highlightthickness=5,
highlightcolor=bg_color,
selectcolor="#808080",
cursor="hand2",
)
dark_mode_button.grid(row=12, column=5, columnspan=1, sticky="nsew", padx=5, pady=5)


sci_tab.configure(
bg=bg_color, padx=5, pady=5, relief="raised", borderwidth=5, highlightthickness=5
Expand Down Expand Up @@ -917,7 +927,7 @@ def dark_mode_change():
1, r"C:\Users\Lexi-Admin\Documents\GitHub\Lexi-BU\lxi_gui\data\from_ff"
)
elif platform.system() == "Linux":
folder_path.insert(1, "/home/cephadrius/Desktop/git/Lexi-BU/lxi_gui/data/test/20241010/recovery_files/")
folder_path.insert(1, "/home/cephadrius/Desktop/git/Lexi-BU/lxi_gui/data/from_ff/from_sim/20240925/recovery_files/")
elif platform.system() == "Darwin":
folder_path.insert(1, "/Users/mac/Documents/GitHub/Lexi-BU/lxi_gui/git_data/sample_datasets/")
else:
Expand All @@ -928,7 +938,7 @@ def dark_mode_change():

# Add a textbox to enter the folder path in HK tab as well
folder_path_hk = tk.Entry(hk_tab, justify="center", bg=bg_color, fg="green", borderwidth=2)
folder_path_hk.grid(row=12, column=6, columnspan=1, sticky="nsew")
folder_path_hk.grid(row=12, column=5, columnspan=1, sticky="nsew")

# Set the default folder name in the text box same as the one in the science tab
folder_path_hk.insert(1, folder_path.get())
Expand Down Expand Up @@ -987,7 +997,7 @@ def dark_mode_change():
highlightbackground="green",
highlightcolor="green",
)
folder_load_button_hk.grid(row=12, column=7, columnspan=1, sticky="nsew")
folder_load_button_hk.grid(row=12, column=6, columnspan=1, sticky="nsew")
folder_load_button_hk.config(state="normal")

# Label for plot times
Expand Down Expand Up @@ -1021,11 +1031,11 @@ def dark_mode_change():
start_time_hk = tk.Entry(hk_tab, justify="center", bg=bg_color, fg="green", borderwidth=2)
start_time_hk.insert(0, default_time_dict["start_time"])
start_time_hk.config(insertbackground=insertbackground_color)
start_time_hk.grid(row=12, column=1, columnspan=1, sticky="nsew")
start_time_hk.grid(row=12, column=2, columnspan=1, sticky="nsew")
start_time_label_hk = tk.Label(
hk_tab, text="Start Time", font=font_style, bg=bg_color, fg=fg_color
)
start_time_label_hk.grid(row=13, column=1, columnspan=1, sticky="nsew")
start_time_label_hk.grid(row=13, column=2, columnspan=1, sticky="nsew")

end_time_hk = tk.Entry(hk_tab, justify="center", bg=bg_color, fg="green", borderwidth=2)
end_time_hk.insert(0, default_time_dict["end_time"])
Expand Down Expand Up @@ -1054,30 +1064,26 @@ def dark_mode_change():
)
time_threshold_label.grid(row=18, column=0, columnspan=2)

# Add a dropdown menu for the kind of time to be used, options are "Lexi Time" and "UTC Time" and
# "Local Time"
# Default is "Lexi Time". If the time kind is changed, then run the "refresh_ts_plot" function
# to update the plot.
time_type = tk.StringVar()
time_type.set("LEXI")
time_type_menu = tk.OptionMenu(
# Add a toggle button to turn on/off the HV
hv_status = tk.StringVar()
hv_status.set("HV-Off")

hv_status_button = tk.Button(
hk_tab,
time_type,
"LEXI",
"UTC",
"Local",
command=lambda *_: refresh_ts_plot(),
text="HV-Off",
bg="green",
fg="black",
font=("Helvetica", 12, "bold"),
borderwidth=2,
command=toggle_hv_status
)
# Deactivate the UTC and Local options for now
time_type_menu["menu"].entryconfig(1, state="disabled")
time_type_menu["menu"].entryconfig(2, state="disabled")

time_type_menu.config(bg=bg_color, fg=fg_color, borderwidth=2)
time_type_menu.grid(row=12, column=2, columnspan=1, sticky="nsew")
time_type_label = tk.Label(
hk_tab, text="Time Type", font=font_style, bg=bg_color, fg=fg_color

hv_status_button.grid(row=12, column=1, columnspan=1, sticky="nsew")

hv_status_label = tk.Label(
hk_tab, text="HV Status", font=font_style, bg=bg_color, fg=fg_color
)
time_type_label.grid(row=13, column=2, columnspan=1, sticky="nsew")
hv_status_label.grid(row=13, column=1, columnspan=1, sticky="nsew")

# if any of the ts_options are changed, update the plot
plot_opt_entry_1.trace(
Expand Down Expand Up @@ -1365,7 +1371,7 @@ def apply_default_config(event):
highlightbackground="green",
highlightcolor="green",
)
refresh_ts_hk_button.grid(row=12, column=8, columnspan=1, rowspan=1, sticky="new")
refresh_ts_hk_button.grid(row=12, column=7, columnspan=1, rowspan=1, sticky="new")

quit_button_hk = tk.Button(
hk_tab,
Expand All @@ -1383,6 +1389,6 @@ def apply_default_config(event):
highlightbackground="red",
highlightcolor="red",
)
quit_button_hk.grid(row=12, column=9, columnspan=1, rowspan=1, sticky="new")
quit_button_hk.grid(row=12, column=8, columnspan=1, rowspan=1, sticky="new")

root.mainloop()
85 changes: 60 additions & 25 deletions codes/lxi_gui_plot_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def __init__(
cmap=None,
use_fig_size=None,
dark_mode=None,
time_type=None,
hv_status=None,
display_time_label=None,
):
self.df_slice_hk = df_slice_hk
Expand Down Expand Up @@ -239,7 +239,7 @@ def __init__(
self.cmap = cmap
self.use_fig_size = use_fig_size
self.dark_mode = dark_mode
self.time_type = time_type
self.hv_status = hv_status
self.display_time_label = display_time_label

def ts_plots(self):
Expand Down Expand Up @@ -297,6 +297,32 @@ def ts_plots(self):
"DeltaDroppedCount": "#",
"DeltaLostevntCount": "#",
}
nominal_values_dict_hv_on = {
"PinPullerTemp": "-10 to 50",
"OpticsTemp": "-10 to 50",
"LEXIbaseTemp": "-10 to 50",
"HVsupplyTemp": "-10 to 50",
"+5.2V_Imon": "$68 \pm 0.5$",
"+10V_Imon": "$2.5 \pm 0.4$",
"+3.3V_Imon": "$42.5 \pm 0.5$",
"AnodeVoltMon": "$3.4 \pm 0.6$",
"+28V_Imon": "$57.6 \pm 2.2$",
"DeltaDroppedCount": 0,
"DeltaLostevntCount": 0,
}
nominal_values_dict_hv_off = {
"PinPullerTemp": "-10 to 50",
"OpticsTemp": "-10 to 50",
"LEXIbaseTemp": "-10 to 50",
"HVsupplyTemp": "-10 to 50",
"+5.2V_Imon": "$61.5 \pm 0.5$",
"+10V_Imon": "$0.0033 \pm 0.0$",
"+3.3V_Imon": "$47.7 \pm 0.1$",
"AnodeVoltMon": "$0.0044 \pm 0.0$",
"+28V_Imon": "$44.1 \pm 0.4$",
"DeltaDroppedCount": 0,
"DeltaLostevntCount": 0,
}

alpha = 1
ms = 2
Expand Down Expand Up @@ -339,21 +365,8 @@ def ts_plots(self):
key_50p_val = np.nanpercentile(self.df_slice_hk[self.plot_key], 50)
key_90p_val = np.nanpercentile(self.df_slice_hk[self.plot_key], 90)

# Depending on the time_type, find the x-axis values
if self.time_type == "LEXI":
x_axs_val = self.df_slice_hk.index
elif self.time_type == "UTC":
# Convert self.df_slice_hk.utc_time from string to datetime
self.df_slice_hk.utc_time = pd.to_datetime(
self.df_slice_hk.utc_time, utc=True, format="mixed",
)
x_axs_val = self.df_slice_hk.utc_time
elif self.time_type == "Local":
# Convert self.df_slice_hk.local_time and set the time-zone to the local time-zone
self.df_slice_hk.local_time = pd.to_datetime(
self.df_slice_hk.local_time, format="mixed"
)
x_axs_val = self.df_slice_hk.local_time
x_axs_val = self.df_slice_hk.index

axs1 = plt.subplot(gs[:])
axs1.plot(
x_axs_val,
Expand All @@ -379,6 +392,35 @@ def ts_plots(self):
bbox=dict(facecolor=facecolor, edgecolor=edgecolor, alpha=0.5),
)

# On the plot, display the nominal value of the parameter being plotted at the top left
try:
if self.hv_status == "HV-On":
axs1.text(
0.02,
0.95,
f"Nominal Value={nominal_values_dict_hv_on[self.plot_key]}",
horizontalalignment="left",
verticalalignment="top",
transform=axs1.transAxes,
color=edgecolor,
fontsize=10,
bbox=dict(facecolor=facecolor, edgecolor=edgecolor, alpha=0.5),
)
elif self.hv_status == "HV-Off":
axs1.text(
0.02,
0.95,
f"Nominal Value={nominal_values_dict_hv_off[self.plot_key]}",
horizontalalignment="left",
verticalalignment="top",
transform=axs1.transAxes,
color=edgecolor,
fontsize=10,
bbox=dict(facecolor=facecolor, edgecolor=edgecolor, alpha=0.5),
)
except Exception:
pass

axs1.set_xlim(np.nanmin(x_axs_val), np.nanmax(x_axs_val))
min_x_val_time = np.nanmin(x_axs_val)
max_x_val_time = np.nanmax(x_axs_val)
Expand All @@ -387,14 +429,7 @@ def ts_plots(self):
if self.display_time_label:
# Rotate the x-axis labels by certain degrees and set their fontsize, if required
plt.setp(axs1.get_xticklabels(), rotation=0)
if self.time_type == "LEXI":
axs1.set_xlabel("Time [UTC]")
elif self.time_type == "UTC":
axs1.set_xlabel("Time [UTC]")
elif self.time_type == "Local":
# Get the local time zone of the system
local_timezone = datetime.datetime.now(pytz.timezone('UTC')).astimezone().tzinfo
axs1.set_xlabel(f"Time [{local_timezone}]")
axs1.set_xlabel("Time [UTC]")
# Avoid overlapping of the x-axis labels
fig.autofmt_xdate()
# At the bottom right, display the start and end time of the plot
Expand Down
4 changes: 2 additions & 2 deletions codes/lxi_load_plot_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def load_ts_plots(
fig_width=None,
fig_height=None,
dark_mode=True,
time_type="LEXI",
hv_status="HV-Off",
display_time_label=True,
):
"""
Expand Down Expand Up @@ -81,7 +81,7 @@ def load_ts_plots(
ts_fig_height=fig_height,
ts_fig_width=fig_width,
dark_mode=dark_mode,
time_type=time_type,
hv_status=hv_status,
display_time_label=display_time_label,
).ts_plots()
canvas = FigureCanvasTkAgg(fig_ts, master=frame)
Expand Down

0 comments on commit 447907b

Please sign in to comment.