Skip to content

Commit

Permalink
rename sdss-astra to astra; update docs; put astra to bin/
Browse files Browse the repository at this point in the history
  • Loading branch information
andycasey committed Apr 15, 2019
1 parent f1b3c50 commit 21c30ab
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 132 deletions.
94 changes: 62 additions & 32 deletions bin/astra
Original file line number Diff line number Diff line change
@@ -1,47 +1,77 @@
#!/usr/bin/env python
# encoding: utf-8
#
# @Author: José Sánchez-Gallego
# @Date: Dec 1, 2017
# @Filename: astra
# @License: BSD 3-Clause
# @Copyright: José Sánchez-Gallego

import click
import os
from shutil import rmtree
from astra import log
from logging import DEBUG, INFO
from astra.db.connection import Base, engine
from sqlalchemy_utils import database_exists, create_database

from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals
from astra.tools.sdss_astra import (data, subset, component, execute,
query_execute, schedule)

import argparse
import os
import sys
# Common options.
@click.group()
@click.option("-v", "verbose", default=False, is_flag=True,
help="verbose mode")
@click.pass_context
def cli(context, verbose):
context.ensure_object(dict)
context.obj["verbose"] = verbose

# TODO: This isn't correctly followed for sqlalchemy output.
# It defaults to verbose!
log.set_level(DEBUG if verbose else INFO)


@cli.command()
@click.option("-y", "confirm", default=False, is_flag=True,
help="drop the database if it already exists")
@click.pass_context
def setup(context, confirm):
r""" Setup databases using the current configuration. """

log.debug("Running setup")

if not database_exists(engine.url):
log.info(f"Creating database {engine.url}")
create_database(engine.url)

elif not confirm \
and click.confirm("Database already exists. This will wipe the database, including all "\
"downloaded components, and start again. Are you sure?", abort=True):
None

log.debug("Dropping all tables")
Base.metadata.drop_all(engine)

from astra.main import math
log.debug("Creating all tables")
Base.metadata.create_all(engine)

log.debug("Removing old components")
component_dir = os.getenv("ASTRA_COMPONENT_DIR", None)
if component_dir is not None:
if os.path.exists(component_dir):
rmtree(component_dir)
os.makedirs(component_dir, exist_ok=True)

if __name__ == '__main__':

# An example of how to write a command line parser that works with the
# main.math function. For more details on how to use argparse, start with
# this tutorial: https://kapeli.com/dash_share?docset_file=Python%203&docset_name=Python%203&path=doc/howto/argparse.html%23id1&platform=python&repo=Main&version=3.6.3
log.info("Astra is ready.")
return None

parser = argparse.ArgumentParser(
prog=os.path.basename(sys.argv[0]),
description='Performs an arithmetic operation.')

parser.add_argument('VALUE1', type=float, help='The first operand')
parser.add_argument('OPERATOR', type=str, help='The operator [+, -, *, /]')
parser.add_argument('VALUE2', type=float, help='The second operand')
# Add various commands
cli.add_command(data.data)
cli.add_command(subset.subset)
cli.add_command(component.component)
cli.add_command(execute.execute)
cli.add_command(query_execute.query_execute)
cli.add_command(schedule.schedule)

parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='sets verbose mode')

args = parser.parse_args()

result = math(args.VALUE1, args.VALUE2, arith_operator=args.OPERATOR)

if args.verbose:
print('{} {} {} = {}'.format(args.VALUE1, args.OPERATOR, args.VALUE2, result))
else:
print(result)
if __name__ == "__main__":
cli(obj=dict())
14 changes: 7 additions & 7 deletions docs/sphinx/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ now you will need to supply the relevant information in a `YAML-formatted
owner_email_address: andrew.casey@monash.edu


To add this component to Astra, use the ``sdss-astra`` shell utility::
To add this component to Astra, use the ``astra`` shell utility::

sdss-astra component create --from-path my-component.yml
astra component create --from-path my-component.yml

Most keywords in the above example are self-explanatory. The most important
terms are the ``github_repo_slug`` and the ``component_cli``, which should
Expand Down Expand Up @@ -189,9 +189,9 @@ Updating components
===================

All attributes relating to a component can be updated **except** the
``github_repo_slug``. Attribuets can be updated using the ``sdss-astra`` tool::
``github_repo_slug``. Attribuets can be updated using the ``astra`` tool::

sdss-astra component update {github_repo_slug} --active true
astra component update {github_repo_slug} --active true

[TBD: more examples of things to alter]

Expand All @@ -206,17 +206,17 @@ You will rarely need to delete components because you can just mark them as
inactive and they will no longer be run on any observations. If you do need
to delete a component you can do so using::

sdss-astra component delete {github_repo_slug}
astra component delete {github_repo_slug}

It will ask you if you are sure. You can use the ``-y`` flag to indicate yes and
skip this question.

Executing components
====================

You can directly execute a component using the ``sdss-astra`` utility. For example::
You can directly execute a component using the ``astra`` utility. For example::

sdss-astra execute the-cannon -i training-paths.txt -o tmp/ --train --data-release 16
astra execute the-cannon -i training-paths.txt -o tmp/ --train --data-release 16

will train a Cannon model using the data files listed in the text file
(``training-paths.txt``) and use Data Release 16 labels for those
Expand Down
16 changes: 8 additions & 8 deletions docs/sphinx/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ a database that records the data files present in each directory in order to
identify new or updated files. When new or updated data are detected, Astra will
schedule all *active* components to be executed. Once new observations have been
processed by all active components, they will only be re-processed once a new
component is added. To watch a folder you can use the ``sdss-astra`` shell
component is added. To watch a folder you can use the ``astra`` shell
utility::

sdss-astra data watch -r /path/to/SDSS/data --interval 3600
astra data watch -r /path/to/SDSS/data --interval 3600

[TBD: link to full docs for ``sdss-astra`` CLI]
[TBD: link to full docs for ``astra`` CLI]

Unwatching folders
==================

You can use the ``sdss-astra`` shell utility to stop watching a folder::
You can use the ``astra`` shell utility to stop watching a folder::

sdss-astra data unwatch /path/to/SDSS/data
astra data unwatch /path/to/SDSS/data


Force refresh
Expand All @@ -44,7 +44,7 @@ Force refresh
If you want to forcibly refresh all watched folders instead of waiting until
the next interval, you can do so with::

sdss-astra data refresh
astra data refresh


Subsets
Expand All @@ -56,9 +56,9 @@ allow for multiple components to run on something like 'calibration sets'
(or 'science verification set', etc). Named subsets are available to any
component through the functions in ``astra.utils``.

Use the ``sdss-astra`` utility to create a named subset::
Use the ``astra`` utility to create a named subset::

sdss-astra subset create dr20.science-verification -i paths.txt
astra subset create dr20.science-verification -i paths.txt

Data products can be part of many subsets (data products have a many-to-many
relationship with subsets), and subsets can be created to automatically add
Expand Down
10 changes: 8 additions & 2 deletions docs/sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ then you can simply enter the following command in a terminal window::

sdss_install -G astra


Development version
^^^^^^^^^^^^^^^^^^^

Expand All @@ -64,9 +63,16 @@ The configuration for Astra is currently specified in the ``python/astra/etc/ast
file. Once those configuration settings are updated, you can set Astra up by
running the following command from the terminal::

sdss-astra setup
astra setup


Using modules on the Utah system
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TBD some docs::

sdss_install -G astra
module load astra



Expand Down
6 changes: 3 additions & 3 deletions docs/sphinx/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
.. rubric:: :header_no_toc:`Tools`


``sdss-astra``
``astra``
========

The ``sdss-astra`` command line tool provides most of the functionality needed
The ``astra`` command line tool provides most of the functionality needed
to manage data flows, analysis components, scheduling and monitoring of analysis
tasks, and bookkeeping the outputs from those analysis tasks.

This documentation page will be automatically generated using the help strings
of each function, but for now you can see a list of commands that are expected
to be available in the ``sdss-astra`` tool (e.g., ``sdss-astra data watch``):
to be available in the ``astra`` tool (e.g., ``astra data watch``):

===================== =============
Command Description
Expand Down
80 changes: 0 additions & 80 deletions python/astra/tools/sdss_astra/cli.py

This file was deleted.

0 comments on commit 21c30ab

Please sign in to comment.