graxpert 3.2.0a0.dev4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graxpert/AstroImageRepository.py +114 -0
- graxpert/__init__.py +1 -0
- graxpert/ai_model_handling.py +215 -0
- graxpert/app_state.py +10 -0
- graxpert/application/__init__.py +0 -0
- graxpert/application/app.py +741 -0
- graxpert/application/app_events.py +96 -0
- graxpert/application/eventbus.py +24 -0
- graxpert/astroimage.py +308 -0
- graxpert/background_extraction.py +290 -0
- graxpert/background_flood_selection.py +240 -0
- graxpert/background_grid_selection.py +64 -0
- graxpert/cmdline_tools.py +547 -0
- graxpert/commands.py +200 -0
- graxpert/deconvolution.py +176 -0
- graxpert/denoising.py +178 -0
- graxpert/grid_utils.py +38 -0
- graxpert/img/GraXpert_LOGO_Hauptvariante.png +0 -0
- graxpert/img/Icon.png +0 -0
- graxpert/img/LDN1235_original.jpg +0 -0
- graxpert/img/LDN1235_processed.jpg +0 -0
- graxpert/img/__init__.py +0 -0
- graxpert/img/gfx_numbers.png +0 -0
- graxpert/img/gfx_numbers.svg +737 -0
- graxpert/img/graXpert_Startbadge_Umbriel.png +0 -0
- graxpert/img/hourglass.png +0 -0
- graxpert/locales/__init__.py +0 -0
- graxpert/locales/de_DE/LC_MESSAGES/base.mo +0 -0
- graxpert/localization.py +39 -0
- graxpert/main.py +441 -0
- graxpert/mp_logging.py +97 -0
- graxpert/parallel_processing.py +3 -0
- graxpert/preferences.py +139 -0
- graxpert/radialbasisinterpolation.py +215 -0
- graxpert/resource_utils.py +35 -0
- graxpert/s3_secrets.py +16 -0
- graxpert/skyall.py +152 -0
- graxpert/stretch.py +151 -0
- graxpert/theme/__init__.py +0 -0
- graxpert/theme/graxpert-dark-blue.json +367 -0
- graxpert/ui/__init__.py +1 -0
- graxpert/ui/application_frame.py +115 -0
- graxpert/ui/canvas.py +558 -0
- graxpert/ui/left_menu.py +437 -0
- graxpert/ui/loadingframe.py +142 -0
- graxpert/ui/right_menu.py +315 -0
- graxpert/ui/statusbar.py +102 -0
- graxpert/ui/styling.py +23 -0
- graxpert/ui/tooltip.py +194 -0
- graxpert/ui/ui_events.py +19 -0
- graxpert/ui/widgets.py +297 -0
- graxpert/ui_scaling.py +13 -0
- graxpert/version.py +2 -0
- graxpert-3.2.0a0.dev4.dist-info/METADATA +219 -0
- graxpert-3.2.0a0.dev4.dist-info/RECORD +58 -0
- graxpert-3.2.0a0.dev4.dist-info/WHEEL +5 -0
- graxpert-3.2.0a0.dev4.dist-info/entry_points.txt +2 -0
- graxpert-3.2.0a0.dev4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from textwrap import dedent
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
from appdirs import user_config_dir
|
|
9
|
+
|
|
10
|
+
from graxpert.ai_model_handling import (
|
|
11
|
+
ai_model_path_from_version,
|
|
12
|
+
bge_ai_models_dir,
|
|
13
|
+
denoise_ai_models_dir,
|
|
14
|
+
deconvolution_object_ai_models_dir,
|
|
15
|
+
deconvolution_stars_ai_models_dir,
|
|
16
|
+
download_version,
|
|
17
|
+
latest_version,
|
|
18
|
+
list_local_versions,
|
|
19
|
+
)
|
|
20
|
+
from graxpert.astroimage import AstroImage
|
|
21
|
+
from graxpert.background_extraction import extract_background
|
|
22
|
+
from graxpert.denoising import denoise
|
|
23
|
+
from graxpert.deconvolution import deconvolve
|
|
24
|
+
from graxpert.preferences import Prefs, load_preferences, save_preferences
|
|
25
|
+
from graxpert.s3_secrets import bge_bucket_name, denoise_bucket_name, deconvolution_object_bucket_name, deconvolution_stars_bucket_name
|
|
26
|
+
|
|
27
|
+
user_preferences_filename = os.path.join(user_config_dir(appname="GraXpert"), "preferences.json")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class CmdlineToolBase:
|
|
31
|
+
def __init__(self, args):
|
|
32
|
+
self.args = args
|
|
33
|
+
|
|
34
|
+
def get_output_file_ending(self):
|
|
35
|
+
file_ending = os.path.splitext(self.args.filename)[-1]
|
|
36
|
+
|
|
37
|
+
if file_ending.lower() == ".xisf":
|
|
38
|
+
return ".xisf"
|
|
39
|
+
else:
|
|
40
|
+
return ".fits"
|
|
41
|
+
|
|
42
|
+
def get_output_file_format(self):
|
|
43
|
+
output_file_ending = self.get_output_file_ending()
|
|
44
|
+
if (output_file_ending) == ".xisf":
|
|
45
|
+
return "32 bit XISF"
|
|
46
|
+
else:
|
|
47
|
+
return "32 bit Fits"
|
|
48
|
+
|
|
49
|
+
def get_save_path(self):
|
|
50
|
+
if self.args.output is not None:
|
|
51
|
+
base_path = os.path.dirname(self.args.filename)
|
|
52
|
+
output_file_name = self.args.output + self.get_output_file_ending()
|
|
53
|
+
return os.path.join(base_path, output_file_name)
|
|
54
|
+
else:
|
|
55
|
+
return os.path.splitext(self.args.filename)[0] + "_GraXpert" + self.get_output_file_ending()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class BGECmdlineTool(CmdlineToolBase):
|
|
59
|
+
def __init__(self, args):
|
|
60
|
+
super().__init__(args)
|
|
61
|
+
|
|
62
|
+
def execute(self):
|
|
63
|
+
astro_Image = AstroImage(do_update_display=False)
|
|
64
|
+
astro_Image.set_from_file(self.args.filename, None, None)
|
|
65
|
+
|
|
66
|
+
processed_Astro_Image = AstroImage(do_update_display=False)
|
|
67
|
+
background_Astro_Image = AstroImage(do_update_display=False)
|
|
68
|
+
|
|
69
|
+
processed_Astro_Image.fits_header = astro_Image.fits_header
|
|
70
|
+
background_Astro_Image.fits_header = astro_Image.fits_header
|
|
71
|
+
|
|
72
|
+
downscale_factor = 1
|
|
73
|
+
|
|
74
|
+
if self.args.preferences_file is not None:
|
|
75
|
+
preferences = Prefs()
|
|
76
|
+
preferences.interpol_type_option = "AI"
|
|
77
|
+
try:
|
|
78
|
+
preferences_file = os.path.abspath(self.args.preferences_file)
|
|
79
|
+
if os.path.isfile(preferences_file):
|
|
80
|
+
with open(preferences_file, "r") as f:
|
|
81
|
+
json_prefs = json.load(f)
|
|
82
|
+
if "background_points" in json_prefs:
|
|
83
|
+
preferences.background_points = json_prefs["background_points"]
|
|
84
|
+
if "RBF_kernel" in json_prefs:
|
|
85
|
+
preferences.RBF_kernel = json_prefs["RBF_kernel"]
|
|
86
|
+
if "interpol_type_option" in json_prefs:
|
|
87
|
+
preferences.interpol_type_option = json_prefs["interpol_type_option"]
|
|
88
|
+
if "smoothing_option" in json_prefs:
|
|
89
|
+
preferences.smoothing_option = json_prefs["smoothing_option"]
|
|
90
|
+
if "sample_size" in json_prefs:
|
|
91
|
+
preferences.sample_size = json_prefs["sample_size"]
|
|
92
|
+
if "spline_order" in json_prefs:
|
|
93
|
+
preferences.spline_order = json_prefs["spline_order"]
|
|
94
|
+
if "corr_type" in json_prefs:
|
|
95
|
+
preferences.corr_type = json_prefs["corr_type"]
|
|
96
|
+
if "ai_version" in json_prefs:
|
|
97
|
+
preferences.ai_version = json_prefs["ai_version"]
|
|
98
|
+
if "ai_gpu_acceleration" in json_prefs:
|
|
99
|
+
preferences.ai_gpu_acceleration = json_prefs["ai_gpu_acceleration"]
|
|
100
|
+
|
|
101
|
+
if preferences.interpol_type_option == "Kriging" or preferences.interpol_type_option == "RBF":
|
|
102
|
+
downscale_factor = 4
|
|
103
|
+
|
|
104
|
+
except Exception as e:
|
|
105
|
+
logging.exception(e)
|
|
106
|
+
logging.shutdown()
|
|
107
|
+
sys.exit(1)
|
|
108
|
+
else:
|
|
109
|
+
preferences = Prefs()
|
|
110
|
+
preferences.interpol_type_option = "AI"
|
|
111
|
+
|
|
112
|
+
if self.args.smoothing is not None:
|
|
113
|
+
preferences.smoothing_option = self.args.smoothing
|
|
114
|
+
logging.info(f"Using user-supplied smoothing value {preferences.smoothing_option}.")
|
|
115
|
+
else:
|
|
116
|
+
logging.info(f"Using stored smoothing value {preferences.smoothing_option}.")
|
|
117
|
+
|
|
118
|
+
if self.args.correction is not None:
|
|
119
|
+
preferences.corr_type = self.args.correction
|
|
120
|
+
logging.info(f"Using user-supplied correction type {preferences.corr_type}.")
|
|
121
|
+
else:
|
|
122
|
+
logging.info(f"Using stored correction type {preferences.corr_type}.")
|
|
123
|
+
|
|
124
|
+
if self.args.gpu_acceleration is not None:
|
|
125
|
+
preferences.ai_gpu_acceleration = True if self.args.gpu_acceleration == "true" else False
|
|
126
|
+
logging.info(f"Using user-supplied gpu acceleration setting {preferences.ai_gpu_acceleration}.")
|
|
127
|
+
else:
|
|
128
|
+
logging.info(f"Using stored gpu acceleration setting {preferences.ai_gpu_acceleration}.")
|
|
129
|
+
|
|
130
|
+
if preferences.interpol_type_option == "AI":
|
|
131
|
+
ai_model_path = ai_model_path_from_version(bge_ai_models_dir, self.get_ai_version(preferences))
|
|
132
|
+
else:
|
|
133
|
+
ai_model_path = None
|
|
134
|
+
|
|
135
|
+
if preferences.interpol_type_option == "AI":
|
|
136
|
+
logging.info(
|
|
137
|
+
dedent(
|
|
138
|
+
f"""\
|
|
139
|
+
Excecuting background extraction with the following parameters:
|
|
140
|
+
interpolation type - {preferences.interpol_type_option}
|
|
141
|
+
smoothing - {preferences.smoothing_option}
|
|
142
|
+
correction type - {preferences.corr_type}
|
|
143
|
+
AI model path - {ai_model_path}"""
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
else:
|
|
147
|
+
logging.info(
|
|
148
|
+
dedent(
|
|
149
|
+
f"""\
|
|
150
|
+
Excecuting background extraction with the following parameters:
|
|
151
|
+
interpolation type - {preferences.interpol_type_option}
|
|
152
|
+
background points - {preferences.background_points}
|
|
153
|
+
sample size - {preferences.sample_size}
|
|
154
|
+
kernel - {preferences.RBF_kernel}
|
|
155
|
+
spline order - {preferences.spline_order}
|
|
156
|
+
smoothing - {preferences.smoothing_option}
|
|
157
|
+
orrection type - {preferences.corr_type}
|
|
158
|
+
downscale_factor - {downscale_factor}"""
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
background_Astro_Image.set_from_array(
|
|
163
|
+
extract_background(
|
|
164
|
+
astro_Image.img_array,
|
|
165
|
+
np.array(preferences.background_points),
|
|
166
|
+
preferences.interpol_type_option,
|
|
167
|
+
preferences.smoothing_option,
|
|
168
|
+
downscale_factor,
|
|
169
|
+
preferences.sample_size,
|
|
170
|
+
preferences.RBF_kernel,
|
|
171
|
+
preferences.spline_order,
|
|
172
|
+
preferences.corr_type,
|
|
173
|
+
ai_model_path,
|
|
174
|
+
ai_gpu_acceleration=preferences.ai_gpu_acceleration,
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
processed_Astro_Image.set_from_array(astro_Image.img_array)
|
|
179
|
+
|
|
180
|
+
processed_Astro_Image.save(self.get_save_path(), self.get_output_file_format())
|
|
181
|
+
if self.args.bg:
|
|
182
|
+
background_Astro_Image.save(self.get_background_save_path(), self.get_output_file_format())
|
|
183
|
+
|
|
184
|
+
def get_ai_version(self, prefs):
|
|
185
|
+
user_preferences = load_preferences(user_preferences_filename)
|
|
186
|
+
|
|
187
|
+
ai_version = None
|
|
188
|
+
if self.args.ai_version:
|
|
189
|
+
ai_version = self.args.ai_version
|
|
190
|
+
logging.info(f"Using user-supplied AI version {ai_version}.")
|
|
191
|
+
else:
|
|
192
|
+
ai_version = prefs.bge_ai_version
|
|
193
|
+
|
|
194
|
+
if ai_version is None:
|
|
195
|
+
ai_version = latest_version(bge_ai_models_dir, bge_bucket_name)
|
|
196
|
+
logging.info(f"Using AI version {ai_version}. You can overwrite this by providing the argument '-ai_version'")
|
|
197
|
+
|
|
198
|
+
if not ai_version in [v["version"] for v in list_local_versions(bge_ai_models_dir)]:
|
|
199
|
+
try:
|
|
200
|
+
logging.info(f"AI version {ai_version} not found locally, downloading...")
|
|
201
|
+
download_version(bge_ai_models_dir, bge_bucket_name, ai_version)
|
|
202
|
+
logging.info("download successful")
|
|
203
|
+
except Exception as e:
|
|
204
|
+
logging.exception(e)
|
|
205
|
+
logging.shutdown()
|
|
206
|
+
sys.exit(1)
|
|
207
|
+
|
|
208
|
+
user_preferences.ai_version = ai_version
|
|
209
|
+
save_preferences(user_preferences_filename, user_preferences)
|
|
210
|
+
|
|
211
|
+
return ai_version
|
|
212
|
+
|
|
213
|
+
def get_background_save_path(self):
|
|
214
|
+
save_path = self.get_save_path()
|
|
215
|
+
return os.path.splitext(save_path)[0] + "_background" + self.get_output_file_ending()
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class DenoiseCmdlineTool(CmdlineToolBase):
|
|
219
|
+
def __init__(self, args):
|
|
220
|
+
super().__init__(args)
|
|
221
|
+
self.args = args
|
|
222
|
+
|
|
223
|
+
def execute(self):
|
|
224
|
+
astro_Image = AstroImage(do_update_display=False)
|
|
225
|
+
astro_Image.set_from_file(self.args.filename, None, None)
|
|
226
|
+
|
|
227
|
+
processed_Astro_Image = AstroImage(do_update_display=False)
|
|
228
|
+
|
|
229
|
+
processed_Astro_Image.fits_header = astro_Image.fits_header
|
|
230
|
+
|
|
231
|
+
if self.args.preferences_file is not None:
|
|
232
|
+
preferences = Prefs()
|
|
233
|
+
try:
|
|
234
|
+
preferences_file = os.path.abspath(self.args.preferences_file)
|
|
235
|
+
if os.path.isfile(preferences_file):
|
|
236
|
+
with open(preferences_file, "r") as f:
|
|
237
|
+
json_prefs = json.load(f)
|
|
238
|
+
if "ai_version" in json_prefs:
|
|
239
|
+
preferences.ai_version = json_prefs["ai_version"]
|
|
240
|
+
if "denoise_strength" in json_prefs:
|
|
241
|
+
preferences.denoise_strength = json_prefs["denoise_strength"]
|
|
242
|
+
if "ai_batch_size" in json_prefs:
|
|
243
|
+
preferences.ai_batch_size = json_prefs["ai_batch_size"]
|
|
244
|
+
if "ai_gpu_acceleration" in json_prefs:
|
|
245
|
+
preferences.ai_gpu_acceleration = json_prefs["ai_gpu_acceleration"]
|
|
246
|
+
|
|
247
|
+
except Exception as e:
|
|
248
|
+
logging.exception(e)
|
|
249
|
+
logging.shutdown()
|
|
250
|
+
sys.exit(1)
|
|
251
|
+
else:
|
|
252
|
+
preferences = Prefs()
|
|
253
|
+
|
|
254
|
+
if self.args.denoise_strength is not None:
|
|
255
|
+
preferences.denoise_strength = self.args.denoise_strength
|
|
256
|
+
logging.info(f"Using user-supplied denoise strength value {preferences.denoise_strength}.")
|
|
257
|
+
else:
|
|
258
|
+
logging.info(f"Using stored denoise strength value {preferences.denoise_strength}.")
|
|
259
|
+
|
|
260
|
+
if self.args.ai_batch_size is not None:
|
|
261
|
+
preferences.ai_batch_size = self.args.ai_batch_size
|
|
262
|
+
logging.info(f"Using user-supplied batch size value {preferences.ai_batch_size}.")
|
|
263
|
+
else:
|
|
264
|
+
logging.info(f"Using stored batch size value {preferences.ai_batch_size}.")
|
|
265
|
+
|
|
266
|
+
if self.args.gpu_acceleration is not None:
|
|
267
|
+
preferences.ai_gpu_acceleration = True if self.args.gpu_acceleration == "true" else False
|
|
268
|
+
logging.info(f"Using user-supplied gpu acceleration setting {preferences.ai_gpu_acceleration}.")
|
|
269
|
+
else:
|
|
270
|
+
logging.info(f"Using stored gpu acceleration setting {preferences.ai_gpu_acceleration}.")
|
|
271
|
+
|
|
272
|
+
ai_model_path = ai_model_path_from_version(denoise_ai_models_dir, self.get_ai_version(preferences))
|
|
273
|
+
|
|
274
|
+
logging.info(
|
|
275
|
+
dedent(
|
|
276
|
+
f"""\
|
|
277
|
+
Excecuting denoising with the following parameters:
|
|
278
|
+
AI model path - {ai_model_path}
|
|
279
|
+
denoise strength - {preferences.denoise_strength}"""
|
|
280
|
+
)
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
processed_Astro_Image.set_from_array(
|
|
284
|
+
denoise(astro_Image.img_array, ai_model_path, preferences.denoise_strength, batch_size=preferences.ai_batch_size, ai_gpu_acceleration=preferences.ai_gpu_acceleration)
|
|
285
|
+
)
|
|
286
|
+
processed_Astro_Image.save(self.get_save_path(), self.get_output_file_format())
|
|
287
|
+
|
|
288
|
+
def get_ai_version(self, prefs):
|
|
289
|
+
user_preferences = load_preferences(user_preferences_filename)
|
|
290
|
+
|
|
291
|
+
ai_version = None
|
|
292
|
+
if self.args.ai_version:
|
|
293
|
+
ai_version = self.args.ai_version
|
|
294
|
+
logging.info(f"Using user-supplied AI version {ai_version}.")
|
|
295
|
+
else:
|
|
296
|
+
ai_version = prefs.denoise_ai_version
|
|
297
|
+
|
|
298
|
+
if ai_version is None:
|
|
299
|
+
ai_version = latest_version(denoise_ai_models_dir, denoise_bucket_name)
|
|
300
|
+
logging.info(f"Using AI version {ai_version}. You can overwrite this by providing the argument '-ai_version'")
|
|
301
|
+
|
|
302
|
+
if not ai_version in [v["version"] for v in list_local_versions(denoise_ai_models_dir)]:
|
|
303
|
+
try:
|
|
304
|
+
logging.info(f"AI version {ai_version} not found locally, downloading...")
|
|
305
|
+
download_version(denoise_ai_models_dir, denoise_bucket_name, ai_version)
|
|
306
|
+
logging.info("download successful")
|
|
307
|
+
except Exception as e:
|
|
308
|
+
logging.exception(e)
|
|
309
|
+
logging.shutdown()
|
|
310
|
+
sys.exit(1)
|
|
311
|
+
|
|
312
|
+
user_preferences.ai_version = ai_version
|
|
313
|
+
save_preferences(user_preferences_filename, user_preferences)
|
|
314
|
+
|
|
315
|
+
return ai_version
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
class DeconvObjCmdlineTool(CmdlineToolBase):
|
|
319
|
+
def __init__(self, args):
|
|
320
|
+
super().__init__(args)
|
|
321
|
+
self.args = args
|
|
322
|
+
|
|
323
|
+
def execute(self):
|
|
324
|
+
astro_Image = AstroImage(do_update_display=False)
|
|
325
|
+
astro_Image.set_from_file(self.args.filename, None, None)
|
|
326
|
+
|
|
327
|
+
processed_Astro_Image = AstroImage(do_update_display=False)
|
|
328
|
+
|
|
329
|
+
processed_Astro_Image.fits_header = astro_Image.fits_header
|
|
330
|
+
|
|
331
|
+
if self.args.preferences_file is not None:
|
|
332
|
+
preferences = Prefs()
|
|
333
|
+
try:
|
|
334
|
+
preferences_file = os.path.abspath(self.args.preferences_file)
|
|
335
|
+
if os.path.isfile(preferences_file):
|
|
336
|
+
with open(preferences_file, "r") as f:
|
|
337
|
+
json_prefs = json.load(f)
|
|
338
|
+
if "ai_version" in json_prefs:
|
|
339
|
+
preferences.ai_version = json_prefs["ai_version"]
|
|
340
|
+
if "deconvolution_strength" in json_prefs:
|
|
341
|
+
preferences.deconvolution_strength = json_prefs["deconvolution_strength"]
|
|
342
|
+
if "deconvolution_psfsize" in json_prefs:
|
|
343
|
+
preferences.deconvolution_psfsize = json_prefs["deconvolution_psfsize"]
|
|
344
|
+
if "ai_batch_size" in json_prefs:
|
|
345
|
+
preferences.ai_batch_size = json_prefs["ai_batch_size"]
|
|
346
|
+
if "ai_gpu_acceleration" in json_prefs:
|
|
347
|
+
preferences.ai_gpu_acceleration = json_prefs["ai_gpu_acceleration"]
|
|
348
|
+
|
|
349
|
+
except Exception as e:
|
|
350
|
+
logging.exception(e)
|
|
351
|
+
logging.shutdown()
|
|
352
|
+
sys.exit(1)
|
|
353
|
+
else:
|
|
354
|
+
preferences = Prefs()
|
|
355
|
+
|
|
356
|
+
if self.args.deconvolution_strength is not None:
|
|
357
|
+
preferences.deconvolution_strength = self.args.deconvolution_strength
|
|
358
|
+
logging.info(f"Using user-supplied deconvolution strength value {preferences.deconvolution_strength}.")
|
|
359
|
+
else:
|
|
360
|
+
logging.info(f"Using stored deconvolution strength value {preferences.deconvolution_strength}.")
|
|
361
|
+
|
|
362
|
+
if self.args.deconvolution_psfsize is not None:
|
|
363
|
+
preferences.deconvolution_psfsize = self.args.deconvolution_psfsize
|
|
364
|
+
logging.info(f"Using user-supplied deconvolution psfsize value {preferences.deconvolution_psfsize}.")
|
|
365
|
+
else:
|
|
366
|
+
logging.info(f"Using stored deconvolution psfsize value {preferences.deconvolution_psfsize}.")
|
|
367
|
+
|
|
368
|
+
if self.args.ai_batch_size is not None:
|
|
369
|
+
preferences.ai_batch_size = self.args.ai_batch_size
|
|
370
|
+
logging.info(f"Using user-supplied batch size value {preferences.ai_batch_size}.")
|
|
371
|
+
else:
|
|
372
|
+
logging.info(f"Using stored batch size value {preferences.ai_batch_size}.")
|
|
373
|
+
|
|
374
|
+
if self.args.gpu_acceleration is not None:
|
|
375
|
+
preferences.ai_gpu_acceleration = True if self.args.gpu_acceleration == "true" else False
|
|
376
|
+
logging.info(f"Using user-supplied gpu acceleration setting {preferences.ai_gpu_acceleration}.")
|
|
377
|
+
else:
|
|
378
|
+
logging.info(f"Using stored gpu acceleration setting {preferences.ai_gpu_acceleration}.")
|
|
379
|
+
|
|
380
|
+
ai_model_path = ai_model_path_from_version(deconvolution_object_ai_models_dir, self.get_ai_version(preferences))
|
|
381
|
+
|
|
382
|
+
logging.info(
|
|
383
|
+
dedent(
|
|
384
|
+
f"""\
|
|
385
|
+
Excecuting deconvolution on objects with the following parameters:
|
|
386
|
+
AI model path - {ai_model_path}
|
|
387
|
+
deconvolution strength - {preferences.deconvolution_strength}
|
|
388
|
+
deconvolution psfsize - {preferences.deconvolution_psfsize}"""
|
|
389
|
+
)
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
processed_Astro_Image.set_from_array(
|
|
393
|
+
deconvolve(
|
|
394
|
+
astro_Image.img_array,
|
|
395
|
+
ai_model_path,
|
|
396
|
+
preferences.deconvolution_strength,
|
|
397
|
+
preferences.deconvolution_psfsize,
|
|
398
|
+
batch_size=preferences.ai_batch_size,
|
|
399
|
+
ai_gpu_acceleration=preferences.ai_gpu_acceleration,
|
|
400
|
+
)
|
|
401
|
+
)
|
|
402
|
+
processed_Astro_Image.save(self.get_save_path(), self.get_output_file_format())
|
|
403
|
+
|
|
404
|
+
def get_ai_version(self, prefs):
|
|
405
|
+
user_preferences = load_preferences(user_preferences_filename)
|
|
406
|
+
|
|
407
|
+
ai_version = None
|
|
408
|
+
if self.args.ai_version:
|
|
409
|
+
ai_version = self.args.ai_version
|
|
410
|
+
logging.info(f"Using user-supplied AI version {ai_version}.")
|
|
411
|
+
else:
|
|
412
|
+
ai_version = prefs.deconvolution_object_ai_version
|
|
413
|
+
|
|
414
|
+
if ai_version is None:
|
|
415
|
+
ai_version = latest_version(deconvolution_object_ai_models_dir, deconvolution_object_bucket_name)
|
|
416
|
+
logging.info(f"Using AI version {ai_version}. You can overwrite this by providing the argument '-ai_version'")
|
|
417
|
+
|
|
418
|
+
if not ai_version in [v["version"] for v in list_local_versions(deconvolution_object_ai_models_dir)]:
|
|
419
|
+
try:
|
|
420
|
+
logging.info(f"AI version {ai_version} not found locally, downloading...")
|
|
421
|
+
download_version(deconvolution_object_ai_models_dir, deconvolution_object_bucket_name, ai_version)
|
|
422
|
+
logging.info("download successful")
|
|
423
|
+
except Exception as e:
|
|
424
|
+
logging.exception(e)
|
|
425
|
+
logging.shutdown()
|
|
426
|
+
sys.exit(1)
|
|
427
|
+
|
|
428
|
+
user_preferences.ai_version = ai_version
|
|
429
|
+
save_preferences(user_preferences_filename, user_preferences)
|
|
430
|
+
|
|
431
|
+
return ai_version
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
class DeconvStellarCmdlineTool(CmdlineToolBase):
|
|
435
|
+
def __init__(self, args):
|
|
436
|
+
super().__init__(args)
|
|
437
|
+
self.args = args
|
|
438
|
+
|
|
439
|
+
def execute(self):
|
|
440
|
+
astro_Image = AstroImage(do_update_display=False)
|
|
441
|
+
astro_Image.set_from_file(self.args.filename, None, None)
|
|
442
|
+
|
|
443
|
+
processed_Astro_Image = AstroImage(do_update_display=False)
|
|
444
|
+
|
|
445
|
+
processed_Astro_Image.fits_header = astro_Image.fits_header
|
|
446
|
+
|
|
447
|
+
if self.args.preferences_file is not None:
|
|
448
|
+
preferences = Prefs()
|
|
449
|
+
try:
|
|
450
|
+
preferences_file = os.path.abspath(self.args.preferences_file)
|
|
451
|
+
if os.path.isfile(preferences_file):
|
|
452
|
+
with open(preferences_file, "r") as f:
|
|
453
|
+
json_prefs = json.load(f)
|
|
454
|
+
if "ai_version" in json_prefs:
|
|
455
|
+
preferences.ai_version = json_prefs["ai_version"]
|
|
456
|
+
if "deconvolution_strength" in json_prefs:
|
|
457
|
+
preferences.deconvolution_strength = json_prefs["deconvolution_strength"]
|
|
458
|
+
if "deconvolution_psfsize" in json_prefs:
|
|
459
|
+
preferences.deconvolution_psfsize = json_prefs["deconvolution_psfsize"]
|
|
460
|
+
if "ai_batch_size" in json_prefs:
|
|
461
|
+
preferences.ai_batch_size = json_prefs["ai_batch_size"]
|
|
462
|
+
if "ai_gpu_acceleration" in json_prefs:
|
|
463
|
+
preferences.ai_gpu_acceleration = json_prefs["ai_gpu_acceleration"]
|
|
464
|
+
|
|
465
|
+
except Exception as e:
|
|
466
|
+
logging.exception(e)
|
|
467
|
+
logging.shutdown()
|
|
468
|
+
sys.exit(1)
|
|
469
|
+
else:
|
|
470
|
+
preferences = Prefs()
|
|
471
|
+
|
|
472
|
+
if self.args.deconvolution_strength is not None:
|
|
473
|
+
preferences.deconvolution_strength = self.args.deconvolution_strength
|
|
474
|
+
logging.info(f"Using user-supplied deconvolution strength value {preferences.deconvolution_strength}.")
|
|
475
|
+
else:
|
|
476
|
+
logging.info(f"Using stored deconvolution strength value {preferences.deconvolution_strength}.")
|
|
477
|
+
|
|
478
|
+
if self.args.deconvolution_psfsize is not None:
|
|
479
|
+
preferences.deconvolution_psfsize = self.args.deconvolution_psfsize
|
|
480
|
+
logging.info(f"Using user-supplied deconvolution psfsize value {preferences.deconvolution_psfsize}.")
|
|
481
|
+
else:
|
|
482
|
+
logging.info(f"Using stored deconvolution psfsize value {preferences.deconvolution_psfsize}.")
|
|
483
|
+
|
|
484
|
+
if self.args.ai_batch_size is not None:
|
|
485
|
+
preferences.ai_batch_size = self.args.ai_batch_size
|
|
486
|
+
logging.info(f"Using user-supplied batch size value {preferences.ai_batch_size}.")
|
|
487
|
+
else:
|
|
488
|
+
logging.info(f"Using stored batch size value {preferences.ai_batch_size}.")
|
|
489
|
+
|
|
490
|
+
if self.args.gpu_acceleration is not None:
|
|
491
|
+
preferences.ai_gpu_acceleration = True if self.args.gpu_acceleration == "true" else False
|
|
492
|
+
logging.info(f"Using user-supplied gpu acceleration setting {preferences.ai_gpu_acceleration}.")
|
|
493
|
+
else:
|
|
494
|
+
logging.info(f"Using stored gpu acceleration setting {preferences.ai_gpu_acceleration}.")
|
|
495
|
+
|
|
496
|
+
ai_model_path = ai_model_path_from_version(deconvolution_stars_ai_models_dir, self.get_ai_version(preferences))
|
|
497
|
+
|
|
498
|
+
logging.info(
|
|
499
|
+
dedent(
|
|
500
|
+
f"""\
|
|
501
|
+
Excecuting deconvolution on stellar with the following parameters:
|
|
502
|
+
AI model path - {ai_model_path}
|
|
503
|
+
deconvolution strength - {preferences.deconvolution_strength}
|
|
504
|
+
deconvolution psfsize - {preferences.deconvolution_psfsize}"""
|
|
505
|
+
)
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
processed_Astro_Image.set_from_array(
|
|
509
|
+
deconvolve(
|
|
510
|
+
astro_Image.img_array,
|
|
511
|
+
ai_model_path,
|
|
512
|
+
preferences.deconvolution_strength,
|
|
513
|
+
preferences.deconvolution_psfsize,
|
|
514
|
+
batch_size=preferences.ai_batch_size,
|
|
515
|
+
ai_gpu_acceleration=preferences.ai_gpu_acceleration,
|
|
516
|
+
)
|
|
517
|
+
)
|
|
518
|
+
processed_Astro_Image.save(self.get_save_path(), self.get_output_file_format())
|
|
519
|
+
|
|
520
|
+
def get_ai_version(self, prefs):
|
|
521
|
+
user_preferences = load_preferences(user_preferences_filename)
|
|
522
|
+
|
|
523
|
+
ai_version = None
|
|
524
|
+
if self.args.ai_version:
|
|
525
|
+
ai_version = self.args.ai_version
|
|
526
|
+
logging.info(f"Using user-supplied AI version {ai_version}.")
|
|
527
|
+
else:
|
|
528
|
+
ai_version = prefs.deconvolution_stars_ai_version
|
|
529
|
+
|
|
530
|
+
if ai_version is None:
|
|
531
|
+
ai_version = latest_version(deconvolution_stars_ai_models_dir, deconvolution_stars_bucket_name)
|
|
532
|
+
logging.info(f"Using AI version {ai_version}. You can overwrite this by providing the argument '-ai_version'")
|
|
533
|
+
|
|
534
|
+
if not ai_version in [v["version"] for v in list_local_versions(deconvolution_stars_ai_models_dir)]:
|
|
535
|
+
try:
|
|
536
|
+
logging.info(f"AI version {ai_version} not found locally, downloading...")
|
|
537
|
+
download_version(deconvolution_stars_ai_models_dir, deconvolution_stars_bucket_name, ai_version)
|
|
538
|
+
logging.info("download successful")
|
|
539
|
+
except Exception as e:
|
|
540
|
+
logging.exception(e)
|
|
541
|
+
logging.shutdown()
|
|
542
|
+
sys.exit(1)
|
|
543
|
+
|
|
544
|
+
user_preferences.ai_version = ai_version
|
|
545
|
+
save_preferences(user_preferences_filename, user_preferences)
|
|
546
|
+
|
|
547
|
+
return ai_version
|