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
147 changes: 73 additions & 74 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,66 @@ name: CI Tests

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
linting:
name: Lint with Flake8, Black
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: true
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 black
- name: Lint with Flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --extend-ignore=F821 --exclude .git,.idea,.mypy_cache,Notebooks/
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics --extend-ignore=F821 --exclude .git,.idea,.mypy_cache,Notebooks/
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Enforce Black codestyle.
uses: psf/black@stable
with:
options: "--check --verbose"
src: "./flows_get_brightest"
version: "22.10.0"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: true
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 black
- name: Lint with Flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --extend-ignore=F821 --exclude .git,.idea,.mypy_cache,Notebooks/
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics --extend-ignore=F821 --exclude .git,.idea,.mypy_cache,Notebooks/
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Enforce Black codestyle.
uses: psf/black@stable
with:
options: "--check --verbose"
src: "./flows_finder"
version: "22.10.0"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
mypy:
name: mypy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: true
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install '.[test]'
python -m pip install mypy types-requests
- name: Run MyPy
id: runmypy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mypy flows_get_brightest/ typings/tendrils/ --config-file=pyproject.toml --check-untyped-defs
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: true
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install '.[test]'
python -m pip install mypy types-requests
- name: Run MyPy
id: runmypy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mypy flows_finder/ typings/tendrils/ --config-file=pyproject.toml --check-untyped-defs

build:
strategy:
Expand All @@ -76,28 +76,27 @@ jobs:
name: Pytest on ${{ matrix.os }}, python 3.10

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install '.[test]'
- name: Test with pytest
env:
FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }}
run: |
pytest -v --cov-report "xml:coverage.xml" --cov
- name: Pytest coverage report
uses: MishaKav/pytest-coverage-comment@main
if: startsWith(${{matrix.os}},'ubuntu')
with:
pytest-xml-coverage-path: ./coverage.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
title: Coverage Report
badge-title: Tests Coverage
hide-badge: false
hide-report: false

- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install '.[test]'
- name: Test with pytest
env:
FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }}
run: |
pytest -v --cov-report "xml:coverage.xml" --cov
- name: Pytest coverage report
uses: MishaKav/pytest-coverage-comment@main
if: startsWith(${{matrix.os}},'ubuntu')
with:
pytest-xml-coverage-path: ./coverage.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
title: Coverage Report
badge-title: Tests Coverage
hide-badge: false
hide-report: false
File renamed without changes.
5 changes: 4 additions & 1 deletion flows_get_brightest/__init__.py → flows_finder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
tendrils API. Extensible for other instruments and projects.
Can optionally make a finding chart using NASA SkyView.
"""
from . import make_fc as make_fc # noqa: F401
from . import run_get_brightest as get_brightest # noqa: F401

# from .run_get_brightest import main as main # noqa: F401
from .version import __version__ as __version__ # noqa: F401
from .run_get_brightest import main as main # noqa: F401
3 changes: 3 additions & 0 deletions flows_finder/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from flows_finder.make_fc import main as main

main()
176 changes: 176 additions & 0 deletions flows_finder/argparser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import argparse
from typing import Any

import astropy.units as u

from .catalogs import SkyViewSurveys
from .instruments import FixedSizeInstrument, Hawki, Instrument
from .utils import StrEnum


class Parsers(StrEnum):
get_brightest = "get_brightest"
make_fc = "make_fc"


def get_defaults(use_parser: Parsers) -> argparse.ArgumentParser:
"""Get default arguments for a given parser"""

if use_parser == Parsers.get_brightest:
parser = argparse.ArgumentParser(description="Calculate Brightest Star & Optionally plot Finder Chart")
parser.add_argument(
"-t", "--target", help="calculate for this targetname or targetid", type=str, default="None", action="store"
)
parser.add_argument("-r", "--rotate", help="rotation angle in degrees", type=float, default=0.0, action="store")
parser.add_argument("-a", "--shifta", help="shift alpha in arcsec", type=float, default=0.0, action="store")
parser.add_argument("-d", "--shiftd", help="shift delta in arcsec", type=float, default=0.0, action="store")
parser.add_argument("-p", "--plot", help="whether to query images and plot", action="store_true")
parser.add_argument(
"-i",
"--instrument",
help="instrument name",
choices=["Hawki", "FixedSize"],
type=str,
default="Hawki",
action="store",
)
parser.add_argument(
"--size",
help=(
"Instrument FoV in arcmin (if using FixedSize instrument), finder chart will be roughly twice the size."
),
type=float,
default=7.5,
action="store",
)
return parser
elif use_parser == Parsers.make_fc:
parser = argparse.ArgumentParser(description="Make Finder chart")
group = parser.add_argument_group()
group.add_argument(
"image",
help="OPTIONAL: image to use for plot if not querying",
nargs="?",
type=str,
action="store",
default=None,
)
group.add_argument(
"-s",
"--survey",
help=(
f"survey to query for image {[e.value for e in SkyViewSurveys]}, else pass path to fits image with WCS."
),
action="store",
type=str,
default="DSS",
)
parser.add_argument(
"-t", "--target", help="FLOWS Targetname or targetid", type=str, default="None", action="store"
)

parser.add_argument(
"-i",
"--instrument",
help="instrument name",
choices=["Hawki", "FixedSize"],
type=str,
default="FixedSize",
action="store",
)
parser.add_argument(
"--size",
"--fov",
help="Instrument FoV in arcmin (if using FixedSize instrument), finder chart will be slightly bigger.",
type=float,
default=7.5,
action="store",
)
parser.add_argument(
"--cmap", help="matplotlib colormap to use for image", type=str, default="gist_yarg", action="store"
)

group1 = parser.add_argument_group("Plot Scaling:")
group1.add_argument("--scale", help="How to scale image", type=str, default="linear", action="store")
group1.add_argument("--sigma", help="Sigma for Z-scaling", type=float, default=2.5, action="store")
group1.add_argument("--contrast", help="Contrast [0,1] for Z-scaling", type=float, default=0.25, action="store")

group2 = parser.add_argument_group("Rotation & Shifts:")
group2.add_argument("-r", "--rotate", help="rotation angle in degrees", type=float, default=0.0, action="store")
group2.add_argument("-a", "--shifta", help="shift alpha in arcsec", type=float, default=0.0, action="store")
group2.add_argument("-d", "--shiftd", help="shift delta in arcsec", type=float, default=0.0, action="store")
return parser

raise ValueError(f"Parser {use_parser} not supported")


def get_instrument(args: argparse.Namespace) -> type[Instrument]:
if args.instrument not in ["Hawki", "FixedSize"]:
raise ValueError(f"Instrument {args.instrument} not supported, use Hawki or FixedSize")
instrument: type[Instrument] = Hawki
if args.instrument == "FixedSize":
instrument = FixedSizeInstrument
instrument.field_hw = args.size << u.arcmin
return instrument


def check_flows_target(args: argparse.Namespace, parser: argparse.ArgumentParser) -> int | str:
target = args.target.strip()
if target == "None":
parser.error("target id or name not provided, use -t <targetid> or <targetname>")
elif target.isnumeric():
args.target = int(args.target)
return args.target


def parse_brightest() -> tuple[float, int | str, float, float, bool, type[Instrument]]:
parser = get_defaults(Parsers.get_brightest)
args = parser.parse_args()

args.target = check_flows_target(args, parser)

instrument = get_instrument(args)

return args.rotate, args.target, args.shifta, args.shiftd, args.plot, instrument


def parse_fc() -> (
tuple[float, int | str, float, float, type[Instrument], str | None, str | None, str, str, float, float]
):
parser = get_defaults(Parsers.make_fc)
args = parser.parse_args()

args.target = check_flows_target(args, parser)
instrument = get_instrument(args)

if args.survey not in [e.value for e in SkyViewSurveys]:
raise ValueError(f"Survey {args.survey} not supported, use {[e.value for e in SkyViewSurveys]}")

if args.image is not None:
args.survey = None

if not (0 < args.contrast <= 1):
raise ValueError(f"Contrast must be between 0 and 1, got {args.contrast}")

return (
args.rotate,
args.target,
args.shifta,
args.shiftd,
instrument,
args.image,
args.survey,
args.cmap,
args.scale,
args.sigma,
args.contrast,
)


def parse(use_parser: Parsers = Parsers.get_brightest) -> Any:
"""Parse command line input to get target, position angle (rotate), alpha and delta offsets (shifta, shiftd)"""
match use_parser:
case Parsers.get_brightest:
return parse_brightest()
case Parsers.make_fc:
return parse_fc()
File renamed without changes.
Loading