Skip to content

Commit

Permalink
Added manual selection of AI directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffenhir committed Sep 30, 2023
1 parent e1142e1 commit aaf3ebc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
8 changes: 1 addition & 7 deletions graxpert/background_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


def extract_background(in_imarray, background_points, interpolation_type, smoothing,
downscale_factor, sample_size, RBF_kernel, spline_order, corr_type):
downscale_factor, sample_size, RBF_kernel, spline_order, corr_type, AI_dir):

shm_imarray = shared_memory.SharedMemory(create=True, size=in_imarray.nbytes)
shm_background = shared_memory.SharedMemory(create=True, size=in_imarray.nbytes)
Expand Down Expand Up @@ -53,12 +53,6 @@ def extract_background(in_imarray, background_points, interpolation_type, smooth
if num_colors == 1:
imarray_shrink = np.array([imarray_shrink[:,:,0],imarray_shrink[:,:,0],imarray_shrink[:,:,0]])
imarray_shrink = np.moveaxis(imarray_shrink, 0, -1)

AI_dir = ""
if getattr(sys, 'frozen', False):
AI_dir = os.path.join(os.path.dirname(sys.executable), 'bg_model')
else:
AI_dir = os.path.join(os.path.dirname(__file__), '../bg_model')

model = tf.keras.models.load_model(AI_dir)

Expand Down
2 changes: 1 addition & 1 deletion graxpert/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def calculate(self):
self.interpol_type.get(),self.smoothing.get(),
downscale_factor, self.sample_size.get(),
self.RBF_kernel.get(),self.spline_order.get(),
self.corr_type.get()
self.corr_type.get(), self.prefs["AI_directory"]
))

self.images["Processed"] = AstroImage(self.stretch_option_current, self.saturation)
Expand Down
29 changes: 23 additions & 6 deletions graxpert/help_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,25 @@ def __init__(self, master, canvas, app):
self.spline_order_menu.grid(column=0, row=10, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews")



def AI_directory_clicked():
AI_directory = tk.filedialog.askdirectory(
initialdir = self.app.prefs["AI_directory"]
)

if AI_directory != "":
self.app.prefs["AI_directory"] = AI_directory

self.AI_directory_button = ttk.Button(self.advanced_panel_window,
text=_("Select AI directory"),
command=AI_directory_clicked)

self.AI_directory_button.grid(column=0, row=11, pady=(30*scaling,5*scaling), padx=(40,30), sticky="ews")



text = tk.Message(self.advanced_panel_window, text=_("Correction"), width=240 * scaling, font=heading_font2, anchor="center")
text.grid(column=0, row=11, padx=(10*scaling,10*scaling), pady=(20*scaling,10*scaling), sticky="ew")
text.grid(column=0, row=12, padx=(10*scaling,10*scaling), pady=(20*scaling,10*scaling), sticky="ew")


self.app.corr_types = ["Subtraction", "Division"]
Expand All @@ -283,14 +300,14 @@ def __init__(self, master, canvas, app):
self.app.corr_type.set(self.app.prefs["corr_type"])

self.corr_menu = ttk.OptionMenu(self.advanced_panel_window, self.app.corr_type, self.app.corr_type.get(), *self.app.corr_types)
self.corr_menu.grid(column=0, row=12, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews")
self.corr_menu.grid(column=0, row=13, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews")


text = tk.Message(self.advanced_panel_window, text=_("Interface"), width=240 * scaling, font=heading_font2, anchor="center")
text.grid(column=0, row=13, padx=(40,30), pady=(20*scaling,10*scaling), sticky="ew")
text.grid(column=0, row=14, padx=(40,30), pady=(20*scaling,10*scaling), sticky="ew")

text = tk.Message(self.advanced_panel_window, text=_("Language"), width=240*scaling, anchor="center")
text.grid(column=0, row=14, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews")
text.grid(column=0, row=15, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews")

def lang_change(lang):
messagebox.showerror("", _("Please restart the program to change the language."))
Expand All @@ -304,7 +321,7 @@ def lang_change(lang):
self.app.lang.set("English")

self.lang_menu = ttk.OptionMenu(self.advanced_panel_window, self.app.lang, self.app.lang.get(), *self.app.langs, command=lang_change)
self.lang_menu.grid(column=0, row=15, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews")
self.lang_menu.grid(column=0, row=16, pady=(5*scaling,5*scaling), padx=(40,30), sticky="ews")


def scaling_change():
Expand All @@ -317,7 +334,7 @@ def scaling_change():


self.scaling_slider = Slider(self.advanced_panel_window, self.app.scaling, "Scaling", 0.5, 2, 1, scaling, scaling_change)
self.scaling_slider.grid(column=0, row=16, pady=(10*scaling,10*scaling), padx=(40,30), sticky="ew")
self.scaling_slider.grid(column=0, row=17, pady=(10*scaling,10*scaling), padx=(40,30), sticky="ew")



Expand Down
7 changes: 6 additions & 1 deletion graxpert/preferences.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import os
import sys
import shutil
from datetime import datetime
from typing import AnyStr, List, TypedDict
Expand Down Expand Up @@ -29,6 +30,7 @@ class Prefs(TypedDict):
lang: AnyStr
corr_type: AnyStr
scaling: float
AI_directory: AnyStr

DEFAULT_PREFS: Prefs = {
"working_dir": os.getcwd(),
Expand All @@ -49,7 +51,8 @@ class Prefs(TypedDict):
"spline_order": 3,
"lang": None,
"corr_type": "Subtraction",
"scaling": 1.0
"scaling": 1.0,
"AI_directory": os.path.join(os.path.dirname(sys.executable), 'bg_model')
}


Expand Down Expand Up @@ -119,6 +122,8 @@ def merge_json(prefs: Prefs, json) -> Prefs:
prefs["corr_type"] = json["corr_type"]
if "scaling" in json:
prefs["scaling"] = json["scaling"]
if "AI_dir" in json:
prefs["AI_directory"] = json["AI_directory"]
return prefs


Expand Down
Binary file modified locales/de_DE/LC_MESSAGES/base.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions locales/de_DE/LC_MESSAGES/base.po
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,6 @@ msgstr "Skalierung"

msgid "Please restart the program to apply the changes to UI scaling."
msgstr "Bitte das Programm neu starten, um die Änderungen an der Nutzeroberflächenskalierung anzuwenden."

msgid "Select AI directory"
msgstr "AI Verzeichnis auswählen"

0 comments on commit aaf3ebc

Please sign in to comment.