Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vstarstack/library/loaders/yuv.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def readyuv(fname: str, width: int, height: int):
dataframe = vstarstack.library.data.DataFrame(params, tags)
exptime = 1

dataframe.add_channel(yuv, "raw", encoded=True)
dataframe.add_channel(yuv, "raw", encoded=True, signal=True)
dataframe.add_parameter("yuv422", "format")
dataframe.add_parameter(exptime, "weight")
yield dataframe
Expand Down
1 change: 1 addition & 0 deletions src/vstarstack/library/projection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum

class ProjectionType(Enum):
NoneProjection = 0
Perspective = 1
Orthographic = 2
Equirectangular = 3
16 changes: 13 additions & 3 deletions src/vstarstack/library/projection/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

def add_description(dataframe : vstarstack.library.data.DataFrame, projection : ProjectionType, **argv):
"""Add projection description to dataframe"""
if projection == ProjectionType.Perspective:
if projection == ProjectionType.NoneProjection:
name = "none"
elif projection == ProjectionType.Perspective:
F = argv["F"]
kw = argv["kw"]
kh = argv["kh"]
Expand Down Expand Up @@ -51,7 +53,9 @@ def extract_description(dataframe : vstarstack.library.data.DataFrame) -> typing
"""Extract projection description from dataframe"""
projection = dataframe.get_parameter("projection")
if projection is None:
return None
return None, {}
elif projection == "none":
return ProjectionType.NoneProjection, {}
elif projection == "perspective":
return ProjectionType.Perspective, {
"F" : dataframe.get_parameter("projection_perspective_F"),
Expand All @@ -75,7 +79,10 @@ def build_projection(projection: ProjectionType, desc : dict, shape : tuple):
w = shape[1]
h = shape[0]

if projection == ProjectionType.Perspective:
if projection == ProjectionType.NoneProjection:
raise Exception("Trying to build \"NoneProjection\"")

elif projection == ProjectionType.Perspective:
F = desc["F"]
kw = desc["kw"]
kh = desc["kh"]
Expand All @@ -91,6 +98,9 @@ def build_projection(projection: ProjectionType, desc : dict, shape : tuple):
rot = desc["rot"]
return OrthographicProjection(w, h, a, b, angle, rot)

else:
raise Exception("Trying to build some unknown projection")

def get_projection(dataframe : vstarstack.library.data.DataFrame):
"""Get projection from dataframe"""
projection, desc = extract_description(dataframe)
Expand Down
86 changes: 54 additions & 32 deletions src/vstarstack/tool/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import vstarstack.library.calibration.dark
import vstarstack.library.calibration.flat

# applying flats
def _process_file_flatten(input_fname : str,
flat : vstarstack.library.data.DataFrame,
output_fname : str):
Expand All @@ -31,17 +32,6 @@ def _process_file_flatten(input_fname : str,
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)
if result is None:
print(f"Can not remove dark from {input_fname}")
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):
Expand All @@ -51,14 +41,6 @@ def _process_dir_flatten(input_path : str,
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]
Expand All @@ -70,6 +52,26 @@ def _process_flatten(_project : vstarstack.tool.cfg.Project,
else:
_process_file_flatten(input_path, flat, output_path)

# applying darks
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)
if result is None:
print(f"Can not remove dark from {input_fname}")
vstarstack.tool.common.check_dir_exists(output_fname)
result.store(output_fname)

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_remove_dark(_project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
Expand All @@ -81,31 +83,46 @@ def _process_remove_dark(_project : vstarstack.tool.cfg.Project,
else:
_process_file_remove_dark(input_path, dark, output_path)

def _process_build_dark(_project : vstarstack.tool.cfg.Project,
# building darks
def _process_build_dark(project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
dark_fname = argv[1]
if len(argv) >= 2:
input_path = argv[0]
dark_fname = argv[1]
else:
input_path = project.config.paths.dark.npy
dark_fname = project.config.paths.dark.result
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,
# building flats
def _process_build_flat_simple(project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
flat_fname = argv[1]
if len(argv) >= 2:
input_path = argv[0]
flat_fname = argv[1]
else:
input_path = project.config.paths.flat.npy
flat_fname = project.config.paths.flat.result
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,
def _process_build_flat_sky(project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_path = argv[0]
flat_fname = argv[1]
if len(argv) >= 2:
input_path = argv[0]
flat_fname = argv[1]
else:
input_path = project.config.paths.flat.npy
flat_fname = project.config.paths.flat.result

smooth = vstarstack.tool.cfg.get_param("smooth", int, 31)
if smooth % 2 == 0:
smooth += 1
Expand All @@ -116,13 +133,18 @@ def _process_build_flat_sky(_project : vstarstack.tool.cfg.Project,
vstarstack.tool.common.check_dir_exists(flat_fname)
flat.store(flat_fname)

def _process_approximate_flat(_project : vstarstack.tool.cfg.Project,
def _process_approximate_flat(project : vstarstack.tool.cfg.Project,
argv : list[str]):
input_fname = argv[0]
output_fname = argv[1]
if len(argv) >= 2:
input_fname = argv[0]
flat_fname = argv[1]
else:
input_fname = project.config.paths.flat.result
flat_fname = project.config.paths.flat.result

df = vstarstack.library.data.DataFrame.load(input_fname)
df = vstarstack.library.calibration.flat.approximate_flat_image(df)
df.store(output_fname)
df.store(flat_fname)

commands = {
"flatten": (_process_flatten,
Expand Down
5 changes: 2 additions & 3 deletions src/vstarstack/tool/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import vstarstack.tool.cfg

def run(project: vstarstack.tool.cfg.Project, _argv: list):
orig = project.config.paths.npy_orig
fixed = project.config.paths.npy_fixed
orig = project.config.paths.light.npy
shifted = project.config.paths.aligned

for path in [orig, fixed, shifted]:
for path in [orig, shifted]:
files = vstarstack.tool.common.listfiles(path, ".zip")
for _, filename in files:
print(filename)
Expand Down
19 changes: 15 additions & 4 deletions src/vstarstack/tool/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@
"projection" : (str, "COPY"),
},
"paths": {
"original": (str, "orig", {"directory" : True}),
"npy_orig": (str, "npy_orig", {"directory" : True}),
"npy_fixed": (str, "npy", {"directory" : True}),
"light" : {
"original": (str, "orig/light", {"directory" : True}),
"npy": (str, "npy/light", {"directory" : True}),
"result" : (str, "light.zip"),
},
"flat" : {
"original": (str, "orig/flat", {"directory" : True}),
"npy": (str, "npy/flat", {"directory" : True}),
"result" : (str, "flat.zip"),
},
"dark" : {
"original": (str, "orig/dark", {"directory" : True}),
"npy": (str, "npy/dark", {"directory" : True}),
"result" : (str, "dark.zip"),
},
"aligned": (str, "aligned", {"directory" : True}),
"output": (str, "sum.zip"),
"descs" : (str, "descs", {"directory" : True}),
"relative_shifts": (str, "shifts.json"),
"absolute_shifts": (str, "shift.json"),
Expand Down
4 changes: 2 additions & 2 deletions src/vstarstack/tool/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ def run(project: vstarstack.tool.cfg.Project, argv: list):
_process_file(input_path, default_format, input_path, output_path)
else:
_process_path(default_format,
project.config.paths.npy_orig,
project.config.paths.npy_fixed)
project.config.paths.light.npy,
project.config.paths.light.npy)
2 changes: 1 addition & 1 deletion src/vstarstack/tool/fine_shift/align_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def apply(project: vstarstack.tool.cfg.Project, argv: list):
else:
subpixels = 1
else:
npys = project.config.paths.npy_fixed
npys = project.config.paths.light.npy
aligns = project.config.fine_shift.aligns
subpixels = project.config.fine_shift.subpixels
outputs = project.config.paths.aligned
Expand Down
2 changes: 1 addition & 1 deletion src/vstarstack/tool/fine_shift/align_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def align(project: vstarstack.tool.cfg.Project, argv: list):
cluster_f = argv[1]
aligns = argv[2]
else:
npys = project.config.paths.npy_fixed
npys = project.config.paths.light.npy
cluster_f = project.config.cluster.path
aligns = project.config.fine_shift.aligns

Expand Down
2 changes: 1 addition & 1 deletion src/vstarstack/tool/fine_shift/align_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def align(project: vstarstack.tool.cfg.Project, argv: list):
else:
pre_aligns = None
else:
npys = project.config.paths.npy_fixed
npys = project.config.paths.light.npy
aligns = project.config.fine_shift.aligns
pre_aligns = project.config.fine_shift.aligns

Expand Down
4 changes: 2 additions & 2 deletions src/vstarstack/tool/image_processing/blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ def run(project: vstarstack.tool.cfg.Project, argv: list):
else:
process_file(argv)
else:
process_dir([project.config.paths.npy_fixed,
project.config.paths.npy_fixed])
process_dir([project.config.paths.light.npy,
project.config.paths.light.npy])
4 changes: 2 additions & 2 deletions src/vstarstack/tool/image_processing/deconvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def run(project : vstarstack.tool.cfg.Project, argv : list[str]):
strength = int(argv[1])
outputs = argv[2]
else:
inputs = project.config.paths.npy_fixed
outputs = project.config.paths.npy_fixed
inputs = project.config.paths.light.npy
outputs = project.config.paths.light.npy
strength = int(argv[0])

if os.path.isdir(inputs):
Expand Down
4 changes: 2 additions & 2 deletions src/vstarstack/tool/image_processing/distorsion.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ def run(project: vstarstack.tool.cfg.Project, argv: list):
else:
_process_file(distorsion, argv)
else:
_process_dir(distorsion, [project.config.paths.npy_fixed,
project.config.paths.npy_fixed])
_process_dir(distorsion, [project.config.paths.light.npy,
project.config.paths.light.npy])
4 changes: 2 additions & 2 deletions src/vstarstack/tool/image_processing/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def copy(project: vstarstack.tool.cfg.Project, argv: list):
orig = argv[0]
fixed = argv[1]
else:
orig = project.config.paths.npy_orig
fixed = project.config.paths.npy_fixed
orig = project.config.paths.light.npy
fixed = project.config.paths.light.npy
files = vstarstack.tool.common.listfiles(orig, ".zip")
for name, fname in files:
print("Copying ", name)
Expand Down
4 changes: 2 additions & 2 deletions src/vstarstack/tool/image_processing/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def _process(project: vstarstack.tool.cfg.Project, argv: list):
else:
_process_file(argv)
else:
_process_dir([project.config.paths.npy_fixed,
project.config.paths.npy_fixed])
_process_dir([project.config.paths.light.npy,
project.config.paths.light.npy])

def run(project: vstarstack.tool.cfg.Project, argv: list):
_process(project, argv)
4 changes: 2 additions & 2 deletions src/vstarstack/tool/image_processing/remove_sky.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def process(project: vstarstack.tool.cfg.Project, argv: list, model_name : str):
else:
process_file(argv, model_name)
else:
process_dir([project.config.paths.npy_fixed,
project.config.paths.npy_fixed], model_name)
process_dir([project.config.paths.light.npy,
project.config.paths.light.npy], model_name)

commands = {
"isoline": (lambda project, argv: process(project, argv, "isoline"),
Expand Down
4 changes: 2 additions & 2 deletions src/vstarstack/tool/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def simple_add(project: vstarstack.tool.cfg.Project, argv: list):
out = argv[1]
else:
path_images = project.config.paths.aligned
out = project.config.paths.output
out = project.config.paths.light.result

imgs = vstarstack.tool.common.listfiles(path_images, ".zip")
filenames = [img[1] for img in imgs]
Expand All @@ -50,7 +50,7 @@ def sigma_clip(project: vstarstack.tool.cfg.Project, argv: list):
sigma_steps = 1
else:
path_images = project.config.paths.aligned
out = project.config.paths.output
out = project.config.paths.light.result
kappa1 = project.config.merge.sigma_clip_coefficient_begin
kappa2 = project.config.merge.sigma_clip_coefficient_end
sigma_steps = project.config.merge.sigma_clip_steps
Expand Down
4 changes: 2 additions & 2 deletions src/vstarstack/tool/objects/cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

def run(project: vstarstack.tool.cfg.Project, argv: list[str]):
if len(argv) < 3:
npypath = project.config.paths.npy_fixed
npypath = project.config.paths.light.npy
jsonpath = project.config.paths.descs
cutpath = project.config.paths.npy_fixed
cutpath = project.config.paths.light.npy
else:
npypath = argv[0]
jsonpath = argv[1]
Expand Down
2 changes: 1 addition & 1 deletion src/vstarstack/tool/objects/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _process(project, detector, argv):
_process_file(project, input_path, output_path, detector)
else:
_process_path(project,
project.config.paths.npy_fixed,
project.config.paths.light.npy,
project.config.paths.descs,
detector)

Expand Down
Loading