Skip to content

Commit

Permalink
Merge branch 'feature/ui_rework' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
schmelly committed Mar 12, 2024
2 parents 3c94e9e + aecb6d0 commit f0eac1b
Show file tree
Hide file tree
Showing 19 changed files with 1,067 additions and 132 deletions.
34 changes: 30 additions & 4 deletions graxpert/application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from graxpert.astroimage import AstroImage
from graxpert.background_extraction import extract_background
from graxpert.commands import INIT_HANDLER, RESET_POINTS_HANDLER, RM_POINT_HANDLER, SEL_POINTS_HANDLER, Command
from graxpert.denoising import denoise
from graxpert.localization import _
from graxpert.mp_logging import logfile_name
from graxpert.preferences import fitsheader_2_app_state, load_preferences, prefs_2_app_state
from graxpert.stretch import stretch_all, StretchParameters
from graxpert.stretch import StretchParameters, stretch_all
from graxpert.ui.loadingframe import DynamicProgressThread


Expand Down Expand Up @@ -63,6 +64,8 @@ def initialize(self):
eventbus.add_listener(AppEvents.INTERPOL_TYPE_CHANGED, self.on_interpol_type_changed)
eventbus.add_listener(AppEvents.SMOTTHING_CHANGED, self.on_smoothing_changed)
eventbus.add_listener(AppEvents.CALCULATE_REQUEST, self.on_calculate_request)
# denoising
eventbus.add_listener(AppEvents.DENOISE_REQUEST, self.on_denoise_request)
# saving
eventbus.add_listener(AppEvents.SAVE_AS_CHANGED, self.on_save_as_changed)
eventbus.add_listener(AppEvents.SAVE_REQUEST, self.on_save_request)
Expand Down Expand Up @@ -305,6 +308,30 @@ def on_save_as_changed(self, event):
def on_smoothing_changed(self, event):
self.prefs.smoothing_option = event["smoothing_option"]

def on_denoise_request(self, event):
if self.images["Original"] is None:
messagebox.showerror("Error", _("Please load your picture first."))
return

eventbus.emit(AppEvents.CALCULATE_BEGIN)

progress = DynamicProgressThread(callback=lambda p: eventbus.emit(AppEvents.CALCULATE_PROGRESS, {"progress": p}))

try:
imarray = np.copy(self.images["Original"].img_array)

denoise(imarray, ai_model_path_from_version(self.prefs.ai_version), progress=progress)

eventbus.emit(AppEvents.UPDATE_DISPLAY_TYPE_REEQUEST, {"display_type": "Processed"})

except Exception as e:
logging.exception(e)
eventbus.emit(AppEvents.DENOISE_ERROR)
messagebox.showerror("Error", _("An error occured during denoising. Please see the log at {}.".format(logfile_name)))
finally:
progress.done_progress()
eventbus.emit(AppEvents.DENOISE_END)

def on_save_request(self, event):
if self.prefs.saveas_option == "16 bit Tiff" or self.prefs.saveas_option == "32 bit Tiff":
dir = tk.filedialog.asksaveasfilename(initialfile=self.filename + "_GraXpert.tiff", filetypes=[("Tiff", ".tiff")], defaultextension=".tiff", initialdir=self.prefs.working_dir)
Expand Down Expand Up @@ -383,11 +410,10 @@ 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):
Expand All @@ -409,7 +435,7 @@ def do_stretch(self):
logging.exception(e)

eventbus.emit(AppEvents.STRETCH_IMAGE_END)

def remove_pt(self, event):
if len(self.cmd.app_state.background_points) == 0 or not self.prefs.display_pts:
return False
Expand Down
6 changes: 6 additions & 0 deletions graxpert/application/app_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class AppEvents(Enum):
CALCULATE_PROGRESS = auto()
CALCULATE_END = auto()
CALCULATE_ERROR = auto()
# denoising
DENOISE_REQUEST = auto()
DENOISE_BEGIN = auto()
DENOISE_PROGRESS = auto()
DENOISE_END = auto()
DENOISE_ERROR = auto()
# saving
SAVE_AS_CHANGED = auto()
SAVE_REQUEST = auto()
Expand Down
2 changes: 2 additions & 0 deletions graxpert/denoising.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def denoise(image, AI_dir, window_size=256, stride=128, strength=1.0, progress=None):
raise NotImplementedError("Denoising has not been implemented yet")
Loading

0 comments on commit f0eac1b

Please sign in to comment.