Skip to content

Commit

Permalink
Merge pull request #51 from LSSTDESC/issue/50/cli_rail_pipe
Browse files Browse the repository at this point in the history
moved cli to src/rail/cli/rail_pipe
  • Loading branch information
eacharles authored Dec 6, 2024
2 parents da7ac15 + e48a304 commit 4be9b57
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dev = [
]

[project.scripts]
rail_pipe = "rail.cli.pipe_commands:pipe_cli"
rail_pipe = "rail.cli.rail_pipe.pipe_commands:pipe_cli"

[build-system]
requires = [
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions src/rail/cli/rail_pipe/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file must exist with these contents
from .pipe_commands import pipe_cli

if __name__ == "__main__":
pipe_cli()
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from rail.core import __version__

from rail.utils.project import RailProject
from rail.cli import pipe_options, pipe_scripts
from rail.cli.reduce_roman_rubin_data import reduce_roman_rubin_data
from rail.cli.rail_pipe import pipe_options, pipe_scripts
from rail.cli.rail_pipe.reduce_roman_rubin_data import reduce_roman_rubin_data


@click.group()
Expand Down Expand Up @@ -37,41 +37,46 @@ def build_command(config_file: str, **kwargs: Any) -> int:
return ok


@pipe_cli.command(name="reduce")
@pipe_cli.command(name="subsample")
@pipe_options.config_file()
@pipe_options.input_tag()
@pipe_options.input_selection()
@pipe_options.selection()
@pipe_options.flavor()
@pipe_options.label()
@pipe_options.run_mode()
def reduce_command(config_file: str, **kwargs: Any) -> int:
"""Reduce the roman rubin simulations for PZ analysis"""
def subsample_command(config_file: str, **kwargs: Any) -> int:
"""Make a training or test data set by randomly selecting objects"""
"""Make a training data set by randomly selecting objects"""
project = RailProject.load_config(config_file)
flavors = project.get_flavor_args(kwargs.pop('flavor'))
selections = project.get_selection_args(kwargs.pop('selection'))
input_selections = kwargs.pop('input_selection')
iter_kwargs = project.generate_kwargs_iterable(selection=selections, input_selection=input_selections)
input_tag = kwargs.pop('input_tag', 'truth')
iter_kwargs = project.generate_kwargs_iterable(flavor=flavors, selection=selections)
ok = 0
for kw in iter_kwargs:
ok |= reduce_roman_rubin_data(project, input_tag, **kw, **kwargs)
ok |= pipe_scripts.subsample_data(project, **kw, **kwargs)
return ok


@pipe_cli.command(name="subsample")
@pipe_cli.group(name="reduce")
def reduce_group() -> None:
"""Reduce input data for PZ analysis"""


@reduce_group.command(name="roman_rubin")
@pipe_options.config_file()
@pipe_options.input_tag()
@pipe_options.input_selection()
@pipe_options.selection()
@pipe_options.flavor()
@pipe_options.label()
@pipe_options.run_mode()
def subsample_command(config_file: str, **kwargs: Any) -> int:
"""Make a training or test data set by randomly selecting objects"""
"""Make a training data set by randomly selecting objects"""
def reduce_roman_rubin(config_file: str, **kwargs: Any) -> int:
"""Reduce the roman rubin simulations for PZ analysis"""
project = RailProject.load_config(config_file)
flavors = project.get_flavor_args(kwargs.pop('flavor'))
selections = project.get_selection_args(kwargs.pop('selection'))
iter_kwargs = project.generate_kwargs_iterable(flavor=flavors, selection=selections)
input_selections = kwargs.pop('input_selection')
iter_kwargs = project.generate_kwargs_iterable(selection=selections, input_selection=input_selections)
input_tag = kwargs.pop('input_tag', 'truth')
ok = 0
for kw in iter_kwargs:
ok |= pipe_scripts.subsample_data(project, **kw, **kwargs)
ok |= reduce_roman_rubin_data(project, input_tag, **kw, **kwargs)
return ok


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import click

from rail.cli.options import (
from rail.cli.rail.options import (
EnumChoice,
PartialOption,
PartialArgument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rail.utils import catalog_utils
from rail.core.stage import RailPipeline
from rail.utils.project import RailProject
from rail.cli.pipe_options import RunMode
from rail.cli.rail_pipe.pipe_options import RunMode


def handle_command(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pyarrow.parquet as pq
from pyarrow import acero

from rail.cli.pipe_options import RunMode
from rail.cli.rail_pipe.pipe_options import RunMode
from rail.utils.project import RailProject


Expand Down

0 comments on commit 4be9b57

Please sign in to comment.