-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalign_apply.py
More file actions
85 lines (71 loc) · 2.68 KB
/
align_apply.py
File metadata and controls
85 lines (71 loc) · 2.68 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
#
# 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 json
import multiprocessing as mp
from vstarstack.library.fine_movement.aligner import Aligner
import vstarstack.tool.usage
import vstarstack.tool.cfg
import vstarstack.tool.configuration
import vstarstack.library.data
import vstarstack.library.common
import vstarstack.tool.common
ncpu = vstarstack.tool.cfg.nthreads
def align_file(project : vstarstack.tool.cfg.Project,
name : str,
input_image_f : str,
desc_f : str,
output_image_f : str,
subpixels : int):
"""Apply alignment to each file"""
print(f"{name}: {input_image_f} : {desc_f} -> {output_image_f} [{subpixels}]")
if not os.path.exists(input_image_f):
return
if not os.path.exists(desc_f):
return
with open(desc_f, encoding='utf8') as f:
aligner = Aligner.deserialize(json.load(f))
df = vstarstack.library.data.DataFrame.load(input_image_f)
# apply alignment to file
df = aligner.apply_alignment(df, subpixels)
print(f"{name} - aligned")
vstarstack.tool.common.check_dir_exists(output_image_f)
df.store(output_image_f)
def _align_file_wrapper(arg):
align_file(*arg)
def apply(project: vstarstack.tool.cfg.Project, argv: list):
if len(argv) >= 3:
npys = argv[0]
aligns = argv[1]
outputs = argv[2]
if len(argv) >= 4:
subpixels = int(argv[3])
else:
subpixels = 1
else:
npys = project.config.paths.light.npy
aligns = project.config.fine_shift.aligns
subpixels = project.config.fine_shift.subpixels
outputs = project.config.paths.aligned
files = vstarstack.tool.common.listfiles(npys, ".zip")
with mp.Pool(ncpu) as pool:
args = [(project,
name,
input_image_f,
os.path.join(aligns, name + ".json"),
os.path.join(outputs, name + ".zip"),
subpixels)
for name, input_image_f in files]
for _ in pool.imap_unordered(_align_file_wrapper, args):
pass