Skip to content

Commit e4b848e

Browse files
Add element emission lines data in JSON format
1 parent 0ba877e commit e4b848e

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

pyCCDGUI.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ a = Analysis(
1111
('assets/palette.png', 'assets'),
1212
('assets/save.png', 'assets'),
1313
('assets/lens.png', 'assets'),
14+
('spectrometer/element_emission_lines.json', 'spectrometer'),
1415
],
1516
hiddenimports=[],
1617
hookspath=[],

spectrometer/CCDpanelsetup.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,37 @@ def saveopenfields(self, save_row, CCDplot):
973973
lambda *args: self.CCDplot.update_marker_colors(bool(self.element_match_var.get())),
974974
)
975975

976+
# Tolerance settings for emission line matching
977+
tolerance_frame = ttk.Frame(self)
978+
tolerance_frame.grid(column=0, row=save_row + 6, padx=(45, 5), pady=(10, 5), columnspan=3, sticky="w")
979+
980+
# Green tolerance (exact match)
981+
ttk.Label(tolerance_frame, text="Green:").grid(row=0, column=0, padx=(0, 2), sticky="e")
982+
self.green_tolerance_var = tk.DoubleVar(value=config.green_tolerance_nm)
983+
green_entry = ttk.Entry(tolerance_frame, textvariable=self.green_tolerance_var, width=6)
984+
green_entry.grid(row=0, column=1, padx=2)
985+
ttk.Label(tolerance_frame, text="nm").grid(row=0, column=2, padx=(0, 8), sticky="w")
986+
987+
# Yellow tolerance (close match)
988+
ttk.Label(tolerance_frame, text="Yellow:").grid(row=0, column=3, padx=2, sticky="e")
989+
self.yellow_tolerance_var = tk.DoubleVar(value=config.yellow_tolerance_nm)
990+
yellow_entry = ttk.Entry(tolerance_frame, textvariable=self.yellow_tolerance_var, width=6)
991+
yellow_entry.grid(row=0, column=4, padx=2)
992+
ttk.Label(tolerance_frame, text="nm").grid(row=0, column=5, padx=(0, 8), sticky="w")
993+
994+
# Apply button in same row
995+
ttk.Button(
996+
tolerance_frame,
997+
text="Apply",
998+
command=self.apply_tolerance_settings,
999+
style="Accent.TButton"
1000+
).grid(row=0, column=6, padx=5)
1001+
1002+
# Center the tolerance frame
1003+
self.grid_columnconfigure(0, weight=1)
1004+
self.grid_columnconfigure(1, weight=1)
1005+
self.grid_columnconfigure(2, weight=1)
1006+
9761007
def open_calibration(self):
9771008
"""Open calibration window with proper callback reference"""
9781009
default_calibration.open_calibration_window(
@@ -1099,6 +1130,30 @@ def open_color_picker(self):
10991130
command=lambda: self.close_color_window()
11001131
).pack(pady=15)
11011132

1133+
def apply_tolerance_settings(self):
1134+
"""Apply the tolerance settings and refresh the plot"""
1135+
try:
1136+
green_val = self.green_tolerance_var.get()
1137+
yellow_val = self.yellow_tolerance_var.get()
1138+
1139+
# Validate inputs
1140+
if green_val <= 0 or yellow_val <= 0:
1141+
return
1142+
1143+
if green_val >= yellow_val:
1144+
# Show warning that green should be less than yellow
1145+
return
1146+
1147+
# Update config values
1148+
config.green_tolerance_nm = green_val
1149+
config.yellow_tolerance_nm = yellow_val
1150+
1151+
# Refresh the plot to show updated colors
1152+
if config.spectroscopy_mode:
1153+
self.CCDplot.update_marker_colors(True)
1154+
except ValueError:
1155+
pass # Invalid number, ignore
1156+
11021157
def update_emission_color_controls(self):
11031158
"""Enable or disable emission line color controls based on current mode."""
11041159
button = getattr(self, "emission_color_button", None)
@@ -1545,7 +1600,7 @@ def aboutbutton(self, about_row):
15451600

15461601
self.logo_label = ttk.Label(self, image=logo_photo)
15471602
self.logo_label.image = logo_photo # Keep a reference
1548-
self.logo_label.grid(row=about_row + 1, columnspan=3, pady=(40, 5), padx=(7,0))
1603+
self.logo_label.grid(row=about_row + 1, columnspan=3, pady=(15, 5), padx=(7,0))
15491604
except Exception as e:
15501605
print(f"Could not load logo: {e}")
15511606

spectrometer/CCDplots.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,19 @@ def _get_marker_color_and_elements(self, wavelength):
443443
distance = abs(wavelength - emission_wavelength)
444444

445445
# Calculate match percentage based on distance
446-
# 0 nm = 100%, 3 nm = 70%, >3 nm = <70%
447-
if distance == 0:
448-
match_percentage = 100
449-
elif distance <= 3:
450-
match_percentage = 100 - (distance / 3.0) * 30
446+
# Use configurable thresholds from config
447+
green_threshold = config.green_tolerance_nm
448+
yellow_threshold = config.yellow_tolerance_nm
449+
450+
if distance <= green_threshold:
451+
# Within green tolerance: 90-100% match
452+
match_percentage = 100 - (distance / green_threshold) * 10
453+
elif distance <= yellow_threshold:
454+
# Within yellow tolerance: 80-90% match
455+
match_percentage = 90 - ((distance - green_threshold) / (yellow_threshold - green_threshold)) * 10
451456
else:
452-
match_percentage = max(0, 70 - (distance - 3) * 10)
457+
# Beyond yellow tolerance, skip this element
458+
continue
453459

454460
# Only include matches >= 80%
455461
if match_percentage >= 80:

spectrometer/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
spectroscopy_mode = False # False = regular mode, True = spectroscopy mode
3535
CALIBRATION_COEFF = [0, 1, 0, 0] # fallback linear
3636

37+
# Emission line matching tolerance (in nm)
38+
green_tolerance_nm = 0.3 # Lines within this distance show as green (90-100% match)
39+
yellow_tolerance_nm = 3.0 # Lines within this distance show as yellow (80-89% match)
40+
3741
min_sh = 20
3842
max_sh = 4294967295

0 commit comments

Comments
 (0)