Skip to content

Commit

Permalink
Merge pull request #2 from IdahoLabResearch/CDAT_In_Progress
Browse files Browse the repository at this point in the history
Bringing main branch up to v1.0
  • Loading branch information
GeorgeEvans0 authored Dec 23, 2022
2 parents 67c8bc4 + 8bc589e commit 396a7e4
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 299 deletions.
2 changes: 1 addition & 1 deletion CDB-AP_1.0/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.application import Application
from source_code.application import Application

app = Application()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tkinter as tk
from tkinter import ttk
from . import PlotModule as p
from . import plot_module as p


class SWParameterForm(p.PlotWindow): #, tk.Frame):
Expand Down Expand Up @@ -42,42 +42,43 @@ def subframe1_buttons(self, parent):
self.inputs["ShiftButton"].grid(row=0, column=4, sticky="nsew") # slide this button over

# new buttons
logscale_checkbox = ttk.Checkbutton(parent, text="Check to turn off log scale",
logscale_checkbox = ttk.Checkbutton(parent, text="Linear Scale",
variable=self.data_container.inputs["LogscaleState"])
logscale_checkbox.grid(row=0, column=5, sticky='nsew')

def create_sw_parameter_inputs(self):
subframe2 = tk.LabelFrame(self, text="S-W Parameter Definitions", background='gray93')
subframe2 = tk.LabelFrame(self, text="S and W parameter regions of interest (ROI) limits (keV)",
background='gray93')

subframe2.rowconfigure(0, weight=1) # single row frame
for n in range(6):
subframe2.columnconfigure(n, weight=1)

ttk.Label(subframe2, text="S max").grid(row=0, column=0, sticky="nse")
self.inputs["Smax"] = ttk.Spinbox(subframe2, from_=460, to=560, increment=0.01)
self.inputs["Smax"].insert(tk.END, self.params["Smax"])
self.inputs["Smax"].bind("<Return>", self.refresh)
self.inputs["Smax"].grid(row=0, column=1, sticky="nsew")
ttk.Label(subframe2, text="S-ROI max:").grid(row=0, column=0, sticky="nse")
self.inputs["S-ROI Max (keV)"] = ttk.Spinbox(subframe2, from_=461, to=561, increment=0.01)
self.inputs["S-ROI Max (keV)"].insert(tk.END, self.params["S-ROI Max (keV)"])
self.inputs["S-ROI Max (keV)"].bind("<Return>", self.refresh)
self.inputs["S-ROI Max (keV)"].grid(row=0, column=1, sticky="nsew")

ttk.Label(subframe2, text="W min").grid(row=0, column=2, sticky="nse")
self.inputs["Wmin"] = ttk.Spinbox(subframe2, from_=460, to=560, increment=0.01) # cast to string before using
self.inputs["Wmin"].insert(tk.END, self.params["Wmin"])
self.inputs["Wmin"].bind("<Return>", self.refresh)
self.inputs["Wmin"].grid(row=0, column=3, sticky="nsew")
ttk.Label(subframe2, text="Right W-ROI min:").grid(row=0, column=2, sticky="nse")
self.inputs["Right W-ROI Min (keV)"] = ttk.Spinbox(subframe2, from_=461, to=561, increment=0.01) # cast to string before using
self.inputs["Right W-ROI Min (keV)"].insert(tk.END, self.params["Right W-ROI Min (keV)"])
self.inputs["Right W-ROI Min (keV)"].bind("<Return>", self.refresh)
self.inputs["Right W-ROI Min (keV)"].grid(row=0, column=3, sticky="nsew")

ttk.Label(subframe2, text="W max").grid(row=0, column=4, sticky="nse")
self.inputs["Wmax"] = ttk.Spinbox(subframe2, from_=460, to=560, increment=0.01)
self.inputs["Wmax"].insert(tk.END, self.params["Wmax"])
self.inputs["Wmax"].bind("<Return>", self.refresh)
self.inputs["Wmax"].grid(row=0, column=5, sticky="nsew")
ttk.Label(subframe2, text="Right W-ROI max:").grid(row=0, column=4, sticky="nse")
self.inputs["Right W-ROI Max (keV)"] = ttk.Spinbox(subframe2, from_=461, to=561, increment=0.01)
self.inputs["Right W-ROI Max (keV)"].insert(tk.END, self.params["Right W-ROI Max (keV)"])
self.inputs["Right W-ROI Max (keV)"].bind("<Return>", self.refresh)
self.inputs["Right W-ROI Max (keV)"].grid(row=0, column=5, sticky="nsew")

# calculate the companions in the data container
subframe2.grid(row=2, sticky="nsew")

def refresh(self, *args):
try:
# set new params
for key in ("Smax", "Wmax", "Wmin"):
for key in ("S-ROI Max (keV)", "Right W-ROI Max (keV)", "Right W-ROI Min (keV)"):
self.data_container.set(name="parameter", key=key, value=float(self.inputs[key].get()))
self.inputs[key].delete(0, tk.END)
self.inputs[key].insert(tk.END, self.params[key])
Expand All @@ -90,6 +91,12 @@ def refresh(self, *args):
self.showed_no_data_warning = True
tk.messagebox.showerror("Error", "Please load data first")

# store the parameters that were used for this instance.
self.data_container.check_boxes["fold"] = self.data_container.inputs["FoldingState"].get()
self.data_container.check_boxes["shift"] = self.data_container.inputs["ShiftingState"].get()
self.data_container.check_boxes["smoothing_window_size"] = self.data_container.inputs["Smoothing"].get()
self.data_container.check_boxes["gaussian_smoothing"] = self.data_container.inputs["GaussianSmoothingState"].get()

def plot(self, *args):
""" event occurs when Return is pressed, but only is passed in some of the times this function will be called"""
self.ax.clear()
Expand Down Expand Up @@ -128,9 +135,9 @@ def plot(self, *args):
# draw the lines for the sw parameters here
[self.ax.vlines(val, self.ymin, self.ymax, linewidth=p.LINE_WIDTH) for val in self.params.values()]
# alpha controls the transparency
self.ax.axvspan(self.params["SmaxL"], self.params["Smax"], alpha=0.5, color='red')
self.ax.axvspan(self.params["WmaxL"], self.params["WminL"], alpha=0.5, color='blue')
self.ax.axvspan(self.params["Wmin"], self.params["Wmax"], alpha=0.5, color='blue')
self.ax.axvspan(self.params["S-ROI Min (keV)"], self.params["S-ROI Max (keV)"], alpha=0.5, color='red')
self.ax.axvspan(self.params["Left W-ROI Max (keV)"], self.params["Left W-ROI Min (keV)"], alpha=0.5, color='blue')
self.ax.axvspan(self.params["Right W-ROI Min (keV)"], self.params["Right W-ROI Max (keV)"], alpha=0.5, color='blue')

# set the legend so it is outside the main box
self.ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), prop={'size': p.LEGEND_FONT_SIZE})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tkinter as tk
from tkinter import ttk
from . import PlotModule as p
from . import plot_module as p
import mplcursors


Expand All @@ -11,7 +11,7 @@ def __init__(self, name, data_container, *args, **kwargs):

self.rowconfigure(1, weight=1) # let the plot resize

self.label = tk.Label(self, text="Welcome to the S vs W plotting section")
self.label = tk.Label(self, text="Welcome to the S vs. W plotting section")
self.label.grid(row=0, column=0, padx=10, pady=10)
self.name = name
# load the data
Expand Down Expand Up @@ -47,11 +47,17 @@ def refresh(self, *args):
# to pop up multiple times each click
if not self.showed_no_data_warning:
self.showed_no_data_warning = True
tk.messagebox.showerror("Error", "Please set/check SW parameters first")
tk.messagebox.showerror("Error", 'Please load the "S and W Parameters" tab before loading this tab')

# store the parameters that were used for this instance.
self.data_container.check_boxes["fold"] = self.data_container.inputs["FoldingState"].get()
self.data_container.check_boxes["shift"] = self.data_container.inputs["ShiftingState"].get()
self.data_container.check_boxes["smoothing_window_size"] = self.data_container.inputs["Smoothing"].get()
self.data_container.check_boxes["gaussian_smoothing"] = self.data_container.inputs["GaussianSmoothingState"].get()

def plot(self):
# we have to extract the data here because it can change any time we change the sw param tab
SW, SW_err = self.data_container.calculate_S(self.data, ref=self.ref) # . added sw)err
# we have to extract the data here because it can change any time we change the S and W parameters tab
SW, SW_err = self.data_container.calculate_S(self.data, ref=self.ref)
self.ax.clear()

if not self.data_container.inputs["FlippingState"].get():
Expand All @@ -61,24 +67,12 @@ def plot(self):
xlabel = "S"
ylabel = "W"

# s = [SW[key][xlabel] for key in SW] # . todo delete commented out code
# w = [SW[key][ylabel] for key in SW]
# hover_labels = ["S = " + str(SW[key][xlabel]) + " +/- " + str(SW_err[key]["dS"]) +
# "\nW = " + str(SW[key][ylabel]) + " +/- " + str(SW_err[key]["dW"]) for key in SW]
# print(hover_labels, "hv")
# left click or hover to view, right click to hide.
# cursor = mplcursors.cursor(self.ax.plot(s, w, ','), hover=True, multiple=True) # . added multiple = true
# cursor.connect("add", lambda sel: sel.annotation.set_text(hover_labels[sel.index()]))

for key in SW:
if self.data_container.hidden_state[key].get() == 'Visible':
# self.ax.plot(SW[key][xlabel], SW[key][ylabel], self.data_container.marker[key].get(),
# label=self.data_container.get('label', key), # . todo delete commented out code
# color=self.data_container.color[key].get())
self.ax.errorbar(SW[key][xlabel], SW[key][ylabel], fmt=self.data_container.marker[key].get(),
yerr=SW_err[key]["dS"], xerr=SW_err[key]["dW"], label=self.data_container.get('label', key),
color=self.data_container.color[key].get()) # . added this error bar stuff
mplcursors.cursor(self.ax, hover=True, multiple=True) # . added here commented out above
color=self.data_container.color[key].get())
mplcursors.cursor(self.ax, hover=True, multiple=True)

self.ax.set_ylabel(ylabel, fontsize=p.LABEL_FONT_SIZE)
self.ax.set_xlabel(xlabel, fontsize=p.LABEL_FONT_SIZE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import tkinter as tk
from . import svswplot as s
from . import S_vs_W_plot as s


class SWRef(s.SvsWPlot, tk.Frame):
class SvsWRefPlot(s.SvsWPlot, tk.Frame):

def __init__(self, name, data_container, *args, **kwargs):
super().__init__(name, data_container, *args, **kwargs)

self.label.destroy()
self.label = tk.Label(self, text="Welcome to the S vs W plotting section with references")
self.label = tk.Label(self, text="Welcome to the S vs. W plotting section with references")
self.label.grid(row=0, column=0, padx=10, pady=10)
self.name = name # todo Check if this variable is needed
self.data_container = data_container
Expand Down Expand Up @@ -36,5 +36,11 @@ def refresh(self, *args):
self.showed_no_data_warning = True
tk.messagebox.showerror("Error", "Please load data first")

# store the parameters that were used for this instance.
self.data_container.check_boxes["fold"] = self.data_container.inputs["FoldingState"].get()
self.data_container.check_boxes["shift"] = self.data_container.inputs["ShiftingState"].get()
self.data_container.check_boxes["smoothing_window_size"] = self.data_container.inputs["Smoothing"].get()
self.data_container.check_boxes["gaussian_smoothing"] = self.data_container.inputs["GaussianSmoothingState"].get()

def plot(self):
super().plot()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

import tkinter as tk
from tkinter import ttk
from . import fileuploadform
from . import ratiocurveplot
from . import swparameterform
from . import svswplot
from . import swref
from . import MathModule as m
from . import file_upload_form
from . import ratio_curves_plot
from . import SW_parameter_form
from . import S_vs_W_plot
from . import SvsW_ref_plot
from . import math_module as m


class Application(tk.Tk):
""" Application root window. Controls all the actions and objectives. """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.title("CDB Plotting Application")
self.title("CDB Analysis Program")
self.resizable(width=None, height=None)
self.minsize(800, 600)

ttk.Label(
self,
text="CDB Plotting Application",
text="CDB Analysis Program",
font=("TkDefaultFont", 16)
).grid(row=0)

Expand All @@ -36,14 +36,14 @@ def __init__(self, *args, **kwargs):

def load_pages(self):
""" store the initial code to load each tab """
load_tab = fileuploadform.FileUploadForm(self.notebook, self.data_container)
SW_info_tab = swparameterform.SWParameterForm(self.notebook, self.data_container)
ratio_curve_tab = ratiocurveplot.RatioCurvePlot(self.notebook, self.data_container)
SvsW_plot_tab = svswplot.SvsWPlot(self.notebook, self.data_container)
SWRef_tab = swref.SWRef(self.notebook, self.data_container)
load_tab = file_upload_form.FileUploadForm(self.notebook, self.data_container)
SW_parameter_tab = SW_parameter_form.SWParameterForm(self.notebook, self.data_container)
ratio_curves_tab = ratio_curves_plot.RatioCurvesPlot(self.notebook, self.data_container)
SvsW_plot_tab = S_vs_W_plot.SvsWPlot(self.notebook, self.data_container)
SvsW_ref_tab = SvsW_ref_plot.SvsWRefPlot(self.notebook, self.data_container)

self.notebook.add(load_tab, text="Load")
self.notebook.add(SW_info_tab, text="SW Params")
self.notebook.add(ratio_curve_tab, text="Ratio Curves")
self.notebook.add(SvsW_plot_tab, text="S vs W")
self.notebook.add(SWRef_tab, text="S/W Ref")
self.notebook.add(SW_parameter_tab, text="S and W Parameters")
self.notebook.add(ratio_curves_tab, text="Ratio Curves")
self.notebook.add(SvsW_plot_tab, text="S vs. W")
self.notebook.add(SvsW_ref_tab, text="S vs. W (Ref.)")
Loading

0 comments on commit 396a7e4

Please sign in to comment.