-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalibration.py
More file actions
133 lines (122 loc) · 5.65 KB
/
calibration.py
File metadata and controls
133 lines (122 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
# Copyright (c) 2023 Vladislav Tsendrovskii
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
import os
import multiprocessing as mp
import vstarstack.tool.common
import vstarstack.tool.cfg
import vstarstack.tool.usage
import vstarstack.library.common
import vstarstack.library.data
import vstarstack.library.calibration.dark
import vstarstack.library.calibration.flat
def _process_file_flatten(input_fname : str,
flat : vstarstack.library.data.DataFrame,
output_fname : str):
print(f"Processing {input_fname}")
dataframe = vstarstack.library.data.DataFrame.load(input_fname)
result = vstarstack.library.calibration.flat.flatten(dataframe, flat)
vstarstack.tool.common.check_dir_exists(output_fname)
result.store(output_fname)
def _process_file_remove_dark(input_fname : str,
dark : vstarstack.library.data.DataFrame,
output_fname : str):
print(f"Processing {input_fname}")
dataframe = vstarstack.library.data.DataFrame.load(input_fname)
result = vstarstack.library.calibration.dark.remove_dark(dataframe, dark)
vstarstack.tool.common.check_dir_exists(output_fname)
result.store(output_fname)
def _process_dir_flatten(input_path : str,
flat : vstarstack.library.data.DataFrame,
output_path : str):
files = vstarstack.tool.common.listfiles(input_path, ".zip")
files = vstarstack.tool.common.listfiles(input_path, ".zip")
with mp.Pool(vstarstack.tool.cfg.nthreads) as pool:
args = [(filename, flat, os.path.join(output_path, name + ".zip")) for name, filename in files]
pool.starmap(_process_file_flatten, args)
def _process_dir_remove_dark(input_path : str,
dark : vstarstack.library.data.DataFrame,
output_path : str):
files = vstarstack.tool.common.listfiles(input_path, ".zip")
with mp.Pool(vstarstack.tool.cfg.nthreads) as pool:
args = [(filename, dark, os.path.join(output_path, name + ".zip")) for name, filename in files]
pool.starmap(_process_file_remove_dark, args)
def _process_flatten(_project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
flat_fname = argv[1]
output_path = argv[2]
flat = vstarstack.library.data.DataFrame.load(flat_fname)
if os.path.isdir(input_path):
_process_dir_flatten(input_path, flat, output_path)
else:
_process_file_flatten(input_path, flat, output_path)
def _process_remove_dark(_project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
dark_fname = argv[1]
output_path = argv[2]
dark = vstarstack.library.data.DataFrame.load(dark_fname)
if os.path.isdir(input_path):
_process_dir_remove_dark(input_path, dark, output_path)
else:
_process_file_remove_dark(input_path, dark, output_path)
def _process_build_dark(_project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
dark_fname = argv[1]
files = vstarstack.tool.common.listfiles(input_path, ".zip")
darks = [item[1] for item in files]
src = vstarstack.library.common.FilesImageSource(darks)
dark = vstarstack.library.calibration.dark.prepare_darks(src)
dark.store(dark_fname)
def _process_build_flat_simple(_project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
flat_fname = argv[1]
smooth = vstarstack.tool.cfg.get_param("smooth", int, 31)
files = vstarstack.tool.common.listfiles(input_path, ".zip")
flats = [item[1] for item in files]
src = vstarstack.library.common.FilesImageSource(flats)
flat = vstarstack.library.calibration.flat.prepare_flat_simple(src, smooth)
flat.store(flat_fname)
def _process_build_flat_sky(_project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
flat_fname = argv[1]
smooth = vstarstack.tool.cfg.get_param("smooth", int, 31)
if smooth % 2 == 0:
smooth += 1
files = vstarstack.tool.common.listfiles(input_path, ".zip")
flats = [item[1] for item in files]
src = vstarstack.library.common.FilesImageSource(flats)
flat = vstarstack.library.calibration.flat.prepare_flat_sky(src, smooth)
vstarstack.tool.common.check_dir_exists(flat_fname)
flat.store(flat_fname)
commands = {
"flatten": (_process_flatten,
"Flatten image",
"inputs/ flat.zip outputs/"),
"remove-dark": (_process_remove_dark,
"Substract dark from image",
"inputs/ dark.zip outputs/"),
"build-dark" : (_process_build_dark,
"Create dark image",
"darks/ dark.zip"),
"build-flat-simple" : (_process_build_flat_simple,
"Create flat image - just sum of flats",
"flats/ flat.zip"),
"build-flat-sky" : (_process_build_flat_sky,
"Create flat image - use sky images",
"flats/ flat.zip")
}