Skip to content

Commit

Permalink
Restructure a bit to make this work
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fish committed Sep 6, 2024
1 parent b4180bd commit 6dfced0
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 262 deletions.
10 changes: 8 additions & 2 deletions src/sim_recon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from .main import sim_reconstruct, sim_psf_to_otf
from .info import __version__

__all__ = ("__version__", "sim_reconstruct", "sim_psf_to_otf")
__all__ = [
__version__,
]

if __name__ == "__main__":
from .main import sim_reconstruct, sim_psf_to_otf

__all__.append(sim_reconstruct, sim_psf_to_otf)
4 changes: 2 additions & 2 deletions src/sim_recon/cli/otf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging

from ..main import sim_psf_to_otf
from .parsing import parse_otf_args
from .parsing.otf import parse_args
from ..progress import set_use_tqdm


def main() -> None:
namespace, otf_kwargs = parse_otf_args()
namespace, otf_kwargs = parse_args()

set_use_tqdm(namespace.use_tqdm)

Expand Down
4 changes: 2 additions & 2 deletions src/sim_recon/cli/otf_view.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging

from ..otf_view import plot_otfs
from .parsing import parse_otf_view_args
from .parsing.otf_view import parse_args
from ..progress import set_use_tqdm


def main():
namespace = parse_otf_view_args()
namespace = parse_args()

set_use_tqdm(namespace.use_tqdm)

Expand Down
254 changes: 0 additions & 254 deletions src/sim_recon/cli/parsing.py

This file was deleted.

Empty file.
95 changes: 95 additions & 0 deletions src/sim_recon/cli/parsing/otf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from __future__ import annotations
import argparse
from typing import TYPE_CHECKING

from ...settings.formatting import OTF_FORMATTERS
from .shared import (
add_general_args,
add_override_args_from_formatters,
add_help,
handle_required,
)

if TYPE_CHECKING:
from typing import Any
from collections.abc import Sequence

__all__ = ("parse_args",)


def parse_args(
args: Sequence[str] | None = None,
) -> tuple[argparse.Namespace, dict[str, Any]]:
parser = argparse.ArgumentParser(
prog="sim-otf",
description="SIM PSFs to OTFs",
add_help=False,
)
parser.add_argument(
"-c",
"--config-path",
dest="config_path",
help="Path to the root config that specifies the paths to the OTFs and the other configs",
)
parser.add_argument(
"-p",
"--psf",
dest="psf_paths",
nargs="+",
help="Paths to PSF files to be reconstructed (multiple paths can be given)",
)
parser.add_argument(
"-o",
"--output-directory",
default=None,
help="If specified, the output directory that the OTFs will be saved in, otherwise each OTF will be saved in the same directory as its PSF",
)
parser.add_argument(
"--overwrite",
action="store_true",
help="If specified, files will be overwritten if they already exist (unique filenames will be used otherwise)",
)
parser.add_argument(
"--no-cleanup",
dest="cleanup",
action="store_false",
help="If specified, files created during the OTF creation process will not be cleaned up",
)
parser.add_argument(
"--shape",
dest="xy_shape",
default=None,
nargs=2,
type=int,
help="Takes 2 integers (X Y), specifying the shape to crop PSFs to before converting (powers of 2 are fastest)",
)

add_general_args(parser)

namespace, unknown = parser.parse_known_args(args)

add_override_args_from_formatters(parser, OTF_FORMATTERS)

add_help(parser)

override_namespace = parser.parse_args(unknown)

handle_required(
parser,
namespace,
("-c/--config-path", "config_path"),
("-p/--psf", "psf_paths"),
)

non_override_dests = vars(namespace).keys()
otf_kwargs = {
k: v
for k, v in vars(override_namespace).items()
if v is not None and k not in non_override_dests
}

return namespace, otf_kwargs


if __name__ == "__main__":
parse_args()
Loading

0 comments on commit 6dfced0

Please sign in to comment.