Skip to content

Commit

Permalink
Added checkbox for linked channels stretch option
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffenhir committed Jan 21, 2024
1 parent 0c59443 commit 94f5204
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
23 changes: 15 additions & 8 deletions graxpert/application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def initialize(self):
# stretch options
eventbus.add_listener(AppEvents.STRETCH_OPTION_CHANGED, self.on_stretch_option_changed)
eventbus.add_listener(AppEvents.CHANGE_SATURATION_REQUEST, self.on_change_saturation_request)
eventbus.add_listener(AppEvents.CHANNELS_LINKED_CHANGED, self.on_channels_linked_option_changed)
# sample selection
eventbus.add_listener(AppEvents.DISPLAY_PTS_CHANGED, self.on_display_pts_changed)
eventbus.add_listener(AppEvents.BG_FLOOD_SELECTION_CHANGED, self.on_bg_floot_selection_changed)
Expand Down Expand Up @@ -155,7 +156,7 @@ def on_calculate_request(self, event=None):
self.images["Background"].copy_metadata(self.images["Original"])

all_images = [self.images["Original"].img_array, self.images["Processed"].img_array, self.images["Background"].img_array]
stretches = stretch_all(all_images, StretchParameters(self.prefs.stretch_option))
stretches = stretch_all(all_images, StretchParameters(self.prefs.stretch_option, self.prefs.channels_linked_option))
self.images["Original"].update_display_from_array(stretches[0], self.prefs.saturation)
self.images["Processed"].update_display_from_array(stretches[1], self.prefs.saturation)
self.images["Background"].update_display_from_array(stretches[2], self.prefs.saturation)
Expand Down Expand Up @@ -220,7 +221,7 @@ def on_load_image(self, event):

try:
image = AstroImage()
image.set_from_file(filename, StretchParameters(self.prefs.stretch_option), self.prefs.saturation)
image.set_from_file(filename, StretchParameters(self.prefs.stretch_option, self.prefs.channels_linked_option), self.prefs.saturation)

except Exception as e:
eventbus.emit(AppEvents.LOAD_IMAGE_ERROR)
Expand Down Expand Up @@ -363,9 +364,9 @@ def on_save_stretched_request(self, event):

try:
if self.images["Processed"] is None:
self.images["Original"].save_stretched(dir, self.prefs.saveas_option, StretchParameters(self.prefs.stretch_option))
self.images["Original"].save_stretched(dir, self.prefs.saveas_option, StretchParameters(self.prefs.stretch_option, self.prefs.channels_linked_option))
else:
self.images["Processed"].save_stretched(dir, self.prefs.saveas_option, StretchParameters(self.prefs.stretch_option))
self.images["Processed"].save_stretched(dir, self.prefs.saveas_option, StretchParameters(self.prefs.stretch_option, self.prefs.channels_linked_option))
except Exception as e:
eventbus.emit(AppEvents.SAVE_ERROR)
logging.exception(e)
Expand All @@ -381,7 +382,15 @@ def on_spline_order_changed(self, event):

def on_stretch_option_changed(self, event):
self.prefs.stretch_option = event["stretch_option"]
self.do_stretch()

def on_channels_linked_option_changed(self, event):
self.prefs.channels_linked_option = event["channels_linked"]
self.do_stretch()


# application logic
def do_stretch(self):
eventbus.emit(AppEvents.STRETCH_IMAGE_BEGIN)

try:
Expand All @@ -391,7 +400,7 @@ def on_stretch_option_changed(self, event):
if img is not None:
all_images.append(img.img_array)
if len(all_images) > 0:
stretches = stretch_all(all_images, StretchParameters(self.prefs.stretch_option))
stretches = stretch_all(all_images, StretchParameters(self.prefs.stretch_option, self.prefs.channels_linked_option))
for idx, img in enumerate(self.images.values()):
if img is not None:
img.update_display_from_array(stretches[idx], self.prefs.saturation)
Expand All @@ -400,8 +409,7 @@ def on_stretch_option_changed(self, event):
logging.exception(e)

eventbus.emit(AppEvents.STRETCH_IMAGE_END)

# application logic

def remove_pt(self, event):
if len(self.cmd.app_state.background_points) == 0 or not self.prefs.display_pts:
return False
Expand Down Expand Up @@ -436,7 +444,6 @@ def remove_pt(self, event):
else:
return False

# application logic
def reset_backgroundpts(self):
if len(self.cmd.app_state.background_points) > 0:
self.cmd = Command(RESET_POINTS_HANDLER, self.cmd)
Expand Down
1 change: 1 addition & 0 deletions graxpert/application/app_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AppEvents(Enum):
REDRAW_POINTS_REQUEST = auto()
# stretch options
STRETCH_OPTION_CHANGED = auto()
CHANNELS_LINKED_CHANGED = auto()
# sample selection
DISPLAY_PTS_CHANGED = auto()
BG_FLOOD_SELECTION_CHANGED = auto()
Expand Down
1 change: 1 addition & 0 deletions graxpert/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Prefs:
bg_pts_option: int = 15
stretch_option: AnyStr = "No Stretch"
saturation: float = 1.0
channels_linked_option: bool = False
display_pts: bool = True
bg_tol_option: float = 1.0
interpol_type_option: AnyStr = "RBF"
Expand Down
40 changes: 23 additions & 17 deletions graxpert/ui/left_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def __init__(self, parent, **kwargs):
self.saturation = tk.DoubleVar()
self.saturation.set(graxpert.prefs.saturation)
self.saturation.trace_add("write", lambda a, b, c: eventbus.emit(AppEvents.CHANGE_SATURATION_REQUEST, {"saturation": self.saturation.get()}))

self.channels_linked = tk.BooleanVar()
self.channels_linked.set(graxpert.prefs.channels_linked_option)
self.channels_linked.trace_add("write", lambda a, b, c: eventbus.emit(AppEvents.CHANNELS_LINKED_CHANGED, {"channels_linked": self.channels_linked.get()}))

# sample selection
self.display_pts = tk.BooleanVar()
Expand Down Expand Up @@ -126,6 +130,7 @@ def create_children(self):
max_value=3,
precision=1,
)
self.channels_linked_switch = GraXpertCheckbox(self.sub_frame, width=default_label_width, text=_("Channels linked"), variable=self.channels_linked)

# sample selection
self.sample_selection_title = ExtractionStep(self.sub_frame, 3, _(" Sample Selection"))
Expand Down Expand Up @@ -188,29 +193,30 @@ def place_children(self):
self.stretch_options_title.grid(column=0, row=2, columnspan=2, pady=pady, sticky=tk.EW)
self.stretch_menu.grid(column=1, row=3, pady=pady, sticky=tk.EW)
self.saturation_slider.grid(column=1, row=4, pady=pady, sticky=tk.EW)
self.channels_linked_switch.grid(column=1, row=5, pady=pady, sticky=tk.EW)

# sample selection
self.sample_selection_title.grid(column=0, row=5, columnspan=2, pady=pady, sticky=tk.EW)
self.display_pts_switch.grid(column=1, row=6, pady=pady, sticky=tk.EW)
self.flood_select_pts_switch.grid(column=1, row=7, pady=pady, sticky=tk.EW)
self.bg_pts_slider.grid(column=1, row=8, pady=pady, sticky=tk.EW)
self.bg_tol_slider.grid(column=1, row=9, pady=pady, sticky=tk.EW)
self.bg_selection_button.grid(column=1, row=10, pady=pady, sticky=tk.EW)
self.reset_button.grid(column=1, row=11, pady=pady, sticky=tk.EW)
self.sample_selection_title.grid(column=0, row=6, columnspan=2, pady=pady, sticky=tk.EW)
self.display_pts_switch.grid(column=1, row=7, pady=pady, sticky=tk.EW)
self.flood_select_pts_switch.grid(column=1, row=8, pady=pady, sticky=tk.EW)
self.bg_pts_slider.grid(column=1, row=9, pady=pady, sticky=tk.EW)
self.bg_tol_slider.grid(column=1, row=10, pady=pady, sticky=tk.EW)
self.bg_selection_button.grid(column=1, row=11, pady=pady, sticky=tk.EW)
self.reset_button.grid(column=1, row=12, pady=pady, sticky=tk.EW)

# calculation
self.calculation_title.grid(column=0, row=12, pady=pady, columnspan=2, sticky=tk.EW)
self.intp_type_text.grid(column=1, row=13, pady=pady, sticky=tk.EW)
self.interpol_menu.grid(column=1, row=14, pady=pady, sticky=tk.EW)
self.smoothing_slider.grid(column=1, row=15, pady=pady, sticky=tk.EW)
self.calculate_button.grid(column=1, row=16, pady=pady, sticky=tk.EW)
self.calculation_title.grid(column=0, row=13, pady=pady, columnspan=2, sticky=tk.EW)
self.intp_type_text.grid(column=1, row=14, pady=pady, sticky=tk.EW)
self.interpol_menu.grid(column=1, row=15, pady=pady, sticky=tk.EW)
self.smoothing_slider.grid(column=1, row=16, pady=pady, sticky=tk.EW)
self.calculate_button.grid(column=1, row=17, pady=pady, sticky=tk.EW)

# saving
self.saving_title.grid(column=0, row=17, pady=pady, columnspan=2, sticky=tk.EW)
self.saveas_menu.grid(column=1, row=18, pady=pady, sticky=tk.EW)
self.save_button.grid(column=1, row=19, pady=pady, sticky=tk.EW)
self.save_background_button.grid(column=1, row=20, pady=pady, sticky=tk.EW)
self.save_stretched_button.grid(column=1, row=21, pady=pady, sticky=tk.EW)
self.saving_title.grid(column=0, row=18, pady=pady, columnspan=2, sticky=tk.EW)
self.saveas_menu.grid(column=1, row=19, pady=pady, sticky=tk.EW)
self.save_button.grid(column=1, row=20, pady=pady, sticky=tk.EW)
self.save_background_button.grid(column=1, row=21, pady=pady, sticky=tk.EW)
self.save_stretched_button.grid(column=1, row=22, pady=pady, sticky=tk.EW)

def menu_open_clicked(self, event=None):
eventbus.emit(AppEvents.OPEN_FILE_DIALOG_REQUEST)
Expand Down

0 comments on commit 94f5204

Please sign in to comment.