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
17 changes: 15 additions & 2 deletions bin/vstarstack
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ import sys

import vstarstack.tool.process
import vstarstack.tool.cfg
import vstarstack.tool.usage

program_project = vstarstack.tool.cfg.get_project()
program_argv = [item for item in sys.argv[1:] if item[:2] != "--"]

vstarstack.tool.process.run(program_project, program_argv, 'vstarstack')
if vstarstack.tool.cfg.get_param("autocomplete", bool, False):
#with open("complete", "w") as f:
# print(sys.argv, file=f)
program_argv = [item for item in sys.argv[2:] if item[:2] != "--"]
variants = vstarstack.tool.usage.autocompletion(vstarstack.tool.process.commands,
program_argv)
for variant in variants:
print(variant)
else:
program_argv = [item for item in sys.argv[1:] if item[:2] != "--"]
vstarstack.tool.usage.run(program_project,
program_argv,
"",
vstarstack.tool.process.commands)
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

from setuptools import setup, Extension, find_packages

import os
from setuptools import setup, Extension

perspective = Extension(name="vstarstack.library.projection.perspective",
sources=["src/vstarstack/library/projection/perspective.c"])
Expand All @@ -29,7 +28,8 @@
sources=["src/vstarstack/library/fine_shift/image_wave.c"])

root = os.path.join(os.path.abspath(os.path.dirname(__file__)), "src")
result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(root) for f in filenames if os.path.splitext(f)[1] == '.py']
result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(root)
for f in filenames if os.path.splitext(f)[1] == '.py']
result = list(set([os.path.dirname(item[len(root)+1:]) for item in result]))
result = [item.replace("/",".") for item in result if "tests" not in item]

Expand Down
3 changes: 0 additions & 3 deletions src/vstarstack/tool/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,3 @@ def _process_build_flat_sky(_project : vstarstack.tool.cfg.Project,
"Create flat image - use sky images",
"flats/ flat.zip")
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "calibration", commands, autohelp=True)
2 changes: 1 addition & 1 deletion src/vstarstack/tool/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def get_param(name, type_of_var, default):
"""Get cmdline parameter --name=value"""
for arg in sys.argv[2:]:
for arg in sys.argv[1:]:
if arg[:2] != "--":
continue
arg = arg[2:]
Expand Down
3 changes: 0 additions & 3 deletions src/vstarstack/tool/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,3 @@ def find_shift(project: vstarstack.tool.cfg.Project, argv: list):
"Find shifts from cluster file",
"cluster.json shifts.json"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "cluster", commands, autohelp=True)
4 changes: 0 additions & 4 deletions src/vstarstack/tool/fine_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,3 @@ def apply_alignment(project: vstarstack.tool.cfg.Project, argv: list):
"align-features": (find_alignment, "find alignment of images", "clusters.json alignments/"),
"apply-aligns": (apply_alignment, "apply alignments to images", "npys/ alignments/ output/"),
}


def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "fine-shift", commands, autohelp=True)
4 changes: 0 additions & 4 deletions src/vstarstack/tool/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,3 @@ def _exposures(_project, argv):
"rename-channel": (_rename_channel, "filename.zip original_name target_name - rename channel"),
"exposure": (_exposures, "display image exposures per channel", "file.zip"),
}


def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "image", commands, autohelp=True)
6 changes: 1 addition & 5 deletions src/vstarstack/tool/image_processing/blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def process_dir(argv):
with mp.Pool(vstarstack.tool.cfg.nthreads) as pool:
pool.starmap(blur, args)

def process(project: vstarstack.tool.cfg.Project, argv: list):
def run(project: vstarstack.tool.cfg.Project, argv: list):
if len(argv) > 0:
if os.path.isdir(argv[0]):
process_dir(argv)
Expand All @@ -53,7 +53,3 @@ def process(project: vstarstack.tool.cfg.Project, argv: list):
else:
process_dir([project.config.paths.npy_fixed,
project.config.paths.npy_fixed])


def run(project: vstarstack.tool.cfg.Project, argv: list):
process(project, argv)
11 changes: 1 addition & 10 deletions src/vstarstack/tool/image_processing/border.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def process_dir(argv):
brd_left, brd_top, brd_right, brd_bottom) for name, fname in files])


def process(project: vstarstack.tool.cfg.Project, argv: list):
def run(project: vstarstack.tool.cfg.Project, argv: list):
if len(argv) > 0:
if os.path.isdir(argv[0]):
process_dir(argv)
Expand All @@ -80,12 +80,3 @@ def process(project: vstarstack.tool.cfg.Project, argv: list):
else:
process_dir([project.config.paths.npy_fixed,
project.config.paths.npy_fixed])


commands = {
"*": (process, "remove border", "(input.zip output.zip | [input/ output/])"),
}


def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "image-process border", commands)
9 changes: 1 addition & 8 deletions src/vstarstack/tool/image_processing/distorsion.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _process_dir(distorsion : vstarstack.library.image_process.distorsion.Distor
pool.starmap(dedistorsion, [(distorsion, name, fname, os.path.join(
outpath, name + ".zip")) for name, fname in files])

def _process(project: vstarstack.tool.cfg.Project, argv: list):
def run(project: vstarstack.tool.cfg.Project, argv: list):
a = project.distorsion["a"]
b = project.distorsion["b"]
c = project.distorsion["c"]
Expand All @@ -62,10 +62,3 @@ def _process(project: vstarstack.tool.cfg.Project, argv: list):
else:
_process_dir(distorsion, [project.config.paths.npy_fixed,
project.config.paths.npy_fixed])

commands = {
"*": (_process, "Remove distrosion", "(input.file output.file | [input/ output/])"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "image-process distorsion", commands)
6 changes: 1 addition & 5 deletions src/vstarstack/tool/image_processing/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ def copy(project: vstarstack.tool.cfg.Project, argv: list):
commands = {
"copy": (copy, "just copy images from original to pipeline dir"),
"distorsion": (vstarstack.tool.image_processing.distorsion.run, "fix distorsion"),
"remove-sky": (vstarstack.tool.image_processing.remove_sky.run, "remove sky"),
"remove-sky": (vstarstack.tool.image_processing.remove_sky.commands, "remove sky"),
"border": (vstarstack.tool.image_processing.border.run, "remove border"),
"normalize": (vstarstack.tool.image_processing.normalize.run, "normalize to weight"),
"blur": (vstarstack.tool.image_processing.blur.run, "gaussian blur"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
"""Run image fix methods"""
vstarstack.tool.usage.run(project, argv, "image-process", commands, autohelp=True)
5 changes: 0 additions & 5 deletions src/vstarstack/tool/image_processing/remove_sky.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,3 @@ def process(project: vstarstack.tool.cfg.Project, argv: list, model_name : str):
"quadratic": (lambda project, argv: process(project, argv, "quadratic"),
"use quadratic gradient model"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
"""Run removing of sky"""
vstarstack.tool.usage.run(
project, argv, "image-process remove-sky", commands, autohelp=True)
3 changes: 0 additions & 3 deletions src/vstarstack/tool/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,3 @@ def sigma_clip(project: vstarstack.tool.cfg.Project, argv: list):
"simple": (simple_add, "simple add images"),
"sigma-clip": (sigma_clip, "add images with sigma clipping"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "merge", commands, autohelp=True)
7 changes: 0 additions & 7 deletions src/vstarstack/tool/objects/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,3 @@ def _process_disc(project, argv):
"detect compact objects with disc detector",
"npy/ descs/"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project,
argv,
"objects detect",
commands,
autohelp=True)
5 changes: 1 addition & 4 deletions src/vstarstack/tool/objects/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def _enable_objects(project : vstarstack.tool.cfg.Project, _argv: list[str]):

commands = {
"config": (_enable_objects, "configure compact_objects pipeline"),
"detect": (vstarstack.tool.objects.detect.run, "detect compact objects"),
"detect": (vstarstack.tool.objects.detect.commands, "detect compact objects"),
"cut": (vstarstack.tool.objects.cut.run, "cut compact objects"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list[str]):
vstarstack.tool.usage.run(project, argv, "objects", commands, autohelp=True)
11 changes: 2 additions & 9 deletions src/vstarstack/tool/planets/buildmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def _process_path(project : vstarstack.tool.cfg.Project,
out = os.path.join(maps_path, name + ".zip")
_process_file(project, filename, out)

def _process(project : vstarstack.tool.cfg.Project,
argv : list[str]):
def run(project : vstarstack.tool.cfg.Project,
argv : list[str]):
if len(argv) > 0:
input_path = argv[0]
output_path = argv[1]
Expand All @@ -47,10 +47,3 @@ def _process(project : vstarstack.tool.cfg.Project,
_process_path(project,
project.config.paths.aligned,
project.config.planets.paths.maps)

commands = {
"*": (_process, "build surface map from image", "aligned/ maps/"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list[str]):
vstarstack.tool.usage.run(project, argv, "planets buildmap", commands)
3 changes: 0 additions & 3 deletions src/vstarstack/tool/planets/planets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ def _enable_planets(project : vstarstack.tool.cfg.Project, _argv: list[str]):
"configure": (_enable_planets, "configure planets in project"),
"buildmap": (vstarstack.tool.planets.buildmap.run, "build planet surface map"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "planets", commands, autohelp=True)
38 changes: 12 additions & 26 deletions src/vstarstack/tool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#


import sys

import vstarstack.tool.cfg
import vstarstack.tool.usage
import vstarstack.tool.manage_project
Expand All @@ -34,45 +32,33 @@
import vstarstack.tool.calibration

commands = {
"readimage": (vstarstack.tool.readimage.run,
"readimage": (vstarstack.tool.readimage.commands,
"read source images to npz"),
"debayer": (vstarstack.tool.debayer.run,
"debayer RAW images"),
"image-process": (vstarstack.tool.image_processing.fixes.run,
"image-process": (vstarstack.tool.image_processing.fixes.commands,
"image-process - make optical fixes and other image fixes"),
"calibration": (vstarstack.tool.calibration.run,
"calibration": (vstarstack.tool.calibration.commands,
"calibration - flats, darks"),
"objects": (vstarstack.tool.objects.objects.run,
"commands for processing images with compact objects (planets, diffractions, etc)"),
"stars": (vstarstack.tool.stars.stars.run,
"objects": (vstarstack.tool.objects.objects.commands,
"commands for processing images with compact objects " +
"(planets, diffractions, etc)"),
"stars": (vstarstack.tool.stars.stars.commands,
"commands for processing stars images"),
"cluster": (vstarstack.tool.cluster.run,
"cluster": (vstarstack.tool.cluster.commands,
"command for cluster processing"),
"shift": (vstarstack.tool.shift.run,
"shift": (vstarstack.tool.shift.commands,
"move and rotate images to match them"),
"merge": (vstarstack.tool.merge.run,
"merge": (vstarstack.tool.merge.commands,
"merge images", "input_dir/ output.npz"),
"project": (vstarstack.tool.manage_project.run,
"configurate project"),
# "planets": (vstarstack.targets.planets.planets.run,
# "commands for processing planets"),
"image": (vstarstack.tool.image.run,
"image": (vstarstack.tool.image.commands,
"image processing (show, convert, etc)"),
"clean": (vstarstack.tool.clean.run,
"remove temporary files"),
"fine-shift": (vstarstack.tool.fine_shift.run,
"fine-shift": (vstarstack.tool.fine_shift.commands,
"fine shift images"),
}


def run(project: vstarstack.tool.cfg.Project, argv: list, progname=None):
"""Run program"""
if progname is not None:
vstarstack.tool.usage.setprogname(progname)
vstarstack.tool.usage.run(project, argv, "", commands, autohelp=True)


if __name__ == "__main__":
program_project = vstarstack.tool.cfg.get_project()
program_argv = [item for item in sys.argv[2:] if item[:2] != "--"]
run(program_project, program_argv, sys.argv[1])
4 changes: 0 additions & 4 deletions src/vstarstack/tool/readimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,3 @@ def _read_video(project: vstarstack.tool.cfg.Project, argv: list):
"fits": (_read_fits, "read FITS images"),
"video": (_read_video, "read VIDEO images"),
}

def run(project: vstarstack.tool.cfg.Project, argv: list):
"""Run reading image files"""
vstarstack.tool.usage.run(project, argv, "readimage", commands, autohelp=True)
7 changes: 2 additions & 5 deletions src/vstarstack/tool/stars/stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ def _enable_stars(project : vstarstack.tool.cfg.Project, _argv: list[str]):
"detect": (vstarstack.tool.stars.detect.run, "detect stars"),
"describe": (vstarstack.tool.stars.describe.run, "find descriptions for each image"),
"match": (vstarstack.tool.stars.match.run, "match stars between images"),
"cluster": (vstarstack.tool.stars.build_clusters.run, "find matching stars clusters between images"),
"cluster": (vstarstack.tool.stars.build_clusters.run,
"find matching stars clusters between images"),
}


def run(project: vstarstack.tool.cfg.Project, argv: list):
vstarstack.tool.usage.run(project, argv, "stars", commands, autohelp=True)
50 changes: 38 additions & 12 deletions src/vstarstack/tool/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,34 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import sys
import vstarstack.tool.cfg
_PRGNAME = "vstarstack"

def setprogname(name : str):
"""Setup program name"""
global _PRGNAME
_PRGNAME = name

def autocompletion(commands : dict, argv : list):
"""Autocompletion"""
if len(argv) == 0:
current_input = ""
else:
current_input = argv[0]
for cmd in commands:
if cmd == current_input:
submodule = commands[cmd][0]
if isinstance(submodule, dict):
return autocompletion(submodule, argv[1:])
return []

variants = []
for cmd in commands:
if cmd.startswith(current_input):
variants.append(cmd)
return variants

def usage(base : str, commands : dict, message : str):
"""Display usage"""
print(f"Usage: {_PRGNAME} {base} command ...")
Expand All @@ -34,31 +55,36 @@ def usage(base : str, commands : dict, message : str):
extra = commands[cmd][2]
print(f"{cmd} - {desc}\n\t{_PRGNAME} {base} {cmd} {extra}\n")
else:
print(f"{cmd} - {desc}\n\t{_PRGNAME} {base} {cmd}...\n")
print(f"{cmd} - {desc}\n\t{_PRGNAME} {base} {cmd} ...\n")
else:
if len(commands[cmd]) >= 3:
extra = commands[cmd][2]
print(f"(default) - {desc}\n\t{_PRGNAME} {base} {extra}\n")
else:
print(f"(default) - {desc}\n\t{_PRGNAME} {base}...\n")
print(f"(default) - {desc}\n\t{_PRGNAME} {base} ...\n")

print("help - print usage")
print(f"\t{_PRGNAME} {base} [help]\n")


def run(project, argv, base, commands, message=None, autohelp=False):
def run(project, argv, base, commands, message=None):
"""Run usage"""
if (autohelp and len(argv) == 0) or (len(argv) > 0 and argv[0] == "help"):
if (len(argv) == 0) or (len(argv) > 0 and argv[0] == "help"):
usage(base, commands, message)
return

if len(argv) > 0:
cmd = argv[0]
cmd = argv[0]
if cmd not in commands:
print(f"Command {cmd} not found!")
usage(base, commands, message)
return

if cmd not in commands:
print(f"Command {cmd} not found!")
usage(base, commands, message)
return
commands[cmd][0](project, argv[1:])
submodule = commands[cmd][0]
if isinstance(submodule, dict):
if len(base) > 0:
new_base = base + " " + cmd
else:
new_base = cmd
run(project, argv[1:], new_base, submodule, message)
else:
commands["*"][0](project, argv)
submodule(project, argv[1:])
Loading