Skip to content

Commit

Permalink
Ariel
Browse files Browse the repository at this point in the history
  • Loading branch information
schmelly committed Dec 30, 2023
2 parents 07e9bab + 2404922 commit b137803
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
59 changes: 48 additions & 11 deletions graxpert/CommandLineTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import sys
from textwrap import dedent

import numpy as np
from appdirs import user_config_dir
Expand Down Expand Up @@ -30,21 +31,26 @@ def execute(self):

downscale_factor = 1

if self.args.preferences_file:
if self.args.preferences_file is not None:
preferences = Prefs()
preferences.interpol_type_option = "AI"
try:
preferences_file = os.path.abspath(self.args.preferences_file)
if os.path.isfile(preferences_file):
with open(preferences_file, "r") as f:
json_prefs = json.load(f)
preferences.background_points = json_prefs["background_points"]
preferences.sample_size = json_prefs["sample_size"]
preferences.spline_order = json_prefs["spline_order"]
preferences.RBF_kernel = json_prefs["RBF_kernel"]
preferences.interpol_type_option = json_prefs["interpol_type_option"]
preferences.ai_version = json_prefs["ai_version"]

if "background_points" in json_prefs:
preferences.background_points = json_prefs["background_points"]
if "sample_size" in json_prefs:
preferences.sample_size = json_prefs["sample_size"]
if "spline_order" in json_prefs:
preferences.spline_order = json_prefs["spline_order"]
if "RBF_kernel" in json_prefs:
preferences.RBF_kernel = json_prefs["RBF_kernel"]
if "interpol_type_option" in json_prefs:
preferences.interpol_type_option = json_prefs["interpol_type_option"]
if "ai_version" in json_prefs:
preferences.ai_version = json_prefs["ai_version"]
if preferences.interpol_type_option == "Kriging" or preferences.interpol_type_option == "RBF":
downscale_factor = 4

Expand All @@ -53,22 +59,53 @@ def execute(self):
logging.shutdown()
sys.exit(1)
else:
preferences = load_preferences(user_preferences_filename)
preferences = Prefs()
preferences.interpol_type_option = "AI"

if self.args.smoothing:
if self.args.smoothing is not None:
preferences.smoothing_option = self.args.smoothing
logging.info(f"Using user-supplied smoothing value {preferences.smoothing_option}.")
else:
logging.info(f"Using stored smoothing value {preferences.smoothing_option}.")

if self.args.correction:
if self.args.correction is not None:
preferences.corr_type = self.args.correction
logging.info(f"Using user-supplied correction type {preferences.corr_type}.")
else:
logging.info(f"Using stored correction type {preferences.corr_type}.")

if preferences.interpol_type_option == "AI":
ai_model_path = ai_model_path_from_version(self.get_ai_version(preferences))
else:
ai_model_path = None

if preferences.interpol_type_option == "AI":
logging.info(
dedent(
f"""\
Excecuting background extraction with the following parameters:
interpolation type - {preferences.interpol_type_option}
smoothing - {preferences.smoothing_option}
correction type - {preferences.corr_type}
AI model path - {ai_model_path}"""
)
)
else:
logging.info(
dedent(
f"""\
Excecuting background extraction with the following parameters:
interpolation type - {preferences.interpol_type_option}
background points - {preferences.background_points}
sample size - {preferences.sample_size}
kernel - {preferences.RBF_kernel}
spline order - {preferences.spline_order}
smoothing - {preferences.smoothing_option}
orrection type - {preferences.corr_type}
downscale_factor - {downscale_factor}"""
)
)

background_Astro_Image.set_from_array(
extract_background(
astro_Image.img_array,
Expand Down
8 changes: 5 additions & 3 deletions graxpert/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ def main():
type=version_type,
help='Version of the AI model, default: "latest"; available locally: [{}], available remotely: [{}]'.format(", ".join(available_local_versions), ", ".join(available_remote_versions)),
)
parser.add_argument("-correction", "--correction", nargs="?", required=False, default="Subtraction", choices=["Subtraction", "Division"], type=str, help="Subtraction or Division")
parser.add_argument("-smoothing", "--smoothing", nargs="?", required=False, default=0.0, type=float, help="Strength of smoothing between 0 and 1")
parser.add_argument("-correction", "--correction", nargs="?", required=False, default=None, choices=["Subtraction", "Division"], type=str, help="Subtraction or Division")
parser.add_argument("-smoothing", "--smoothing", nargs="?", required=False, default=None, type=float, help="Strength of smoothing between 0 and 1")
parser.add_argument(
"-preferences_file",
"--preferences_file",
nargs="?",
required=False,
default="",
default=None,
type=str,
help="Allows GraXpert commandline to run all extraction methods based on a preferences file that contains background grid points",
)
Expand All @@ -197,10 +197,12 @@ def main():
if args.cli:
from graxpert.CommandLineTool import CommandLineTool

logging.info(f"Starting GraXpert CLI, version: {graxpert_version} release: {graxpert_release}")
clt = CommandLineTool(args)
clt.execute()
logging.shutdown()
else:
logging.info(f"Starting GraXpert UI, version: {graxpert_version} release: {graxpert_release}")
ui_main()

else:
Expand Down

0 comments on commit b137803

Please sign in to comment.