Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #24

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
31 changes: 9 additions & 22 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Nox Test Sessions."""

from __future__ import annotations

import argparse
Expand All @@ -8,14 +10,12 @@

DIR = Path(__file__).parent.resolve()

nox.options.sessions = ["lint", "tests"] # "pylint",
nox.options.sessions = ["lint", "pylint", "tests"]


@nox.session
def lint(session: nox.Session) -> None:
"""
Run the linter.
"""
"""Run the linter."""
session.install("pre-commit")
session.run(
"pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs
Expand All @@ -25,9 +25,7 @@ def lint(session: nox.Session) -> None:
# TODO: turn this on eventually
@nox.session
def pylint(session: nox.Session) -> None:
"""
Run PyLint.
"""
"""Run PyLint."""
# This needs to be installed into the package environment, and is slower
# than a pre-commit check
session.install(".", "pylint")
Expand All @@ -36,19 +34,14 @@ def pylint(session: nox.Session) -> None:

@nox.session
def tests(session: nox.Session) -> None:
"""
Run the unit and regular tests.
"""
"""Run the unit and regular tests."""
session.install(".[test]")
session.run("pytest", *session.posargs)


@nox.session(reuse_venv=True)
def docs(session: nox.Session) -> None:
"""
Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links.
"""

"""Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links."""
parser = argparse.ArgumentParser()
parser.add_argument("--serve", action="store_true", help="Serve after building")
parser.add_argument(
Expand Down Expand Up @@ -87,10 +80,7 @@ def docs(session: nox.Session) -> None:

@nox.session
def build_api_docs(session: nox.Session) -> None:
"""
Build (regenerate) API docs.
"""

"""Build (regenerate) API docs."""
session.install("sphinx")
session.chdir("docs")
session.run(
Expand All @@ -106,10 +96,7 @@ def build_api_docs(session: nox.Session) -> None:

@nox.session
def build(session: nox.Session) -> None:
"""
Build an SDist and wheel.
"""

"""Build an SDist and wheel."""
build_path = DIR.joinpath("build")
if build_path.exists():
shutil.rmtree(build_path)
Expand Down
69 changes: 32 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ classifiers = [
]
dynamic = ["version"]
dependencies = [
"numpy",
"scipy>1.10",
"asdf",
"dustmaps",
"astropy",
"matplotlib",
"astroquery",
"gala",
"galstreams",
"matplotlib",
"numba",
"numpy",
"pyia",
"astroquery",
"dustmaps",
"asdf",
"scipy>1.10",
"ugali",
]

Expand Down Expand Up @@ -81,6 +82,7 @@ addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
filterwarnings = [
"error",
"ignore:numpy.ndarray size changed",
]
log_cli_level = "INFO"
testpaths = [
Expand Down Expand Up @@ -123,41 +125,27 @@ disallow_incomplete_defs = true
src = ["src"]

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
extend-select = ["ALL"]
ignore = [
"ANN101", # Missing type annotation for self in method
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
"BLE001", # Using bare `except`
"COM812", # Missing trailing comma
"D107", # Missing docstring in `__init__`
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"ERA001", # Commented-out code
"FIX002", # Line contains TODO
"N8", # Naming conventions
"N999", # Invalid module name
"PD", # Pandas
"PLR", # Design related pylint codes
"TD002", # Missing author in TODO
"TD003", # Missing issue link on the line following this TODO
# TODO: fix these and remove
"ARG001", # Unused function argument `X`
"ARG003", # Unused method argument `X`
"E711", # Comparison to `None` should be `cond is None`
"E731", # Do not assign a `lambda` expression, use a `def`
"EM101", # Exception must not use a string literal, assign to variable first
"F821", # Undefined name `X`
"PT018", # Assertion should be broken down into multiple parts
"RET504", # Unnecessary assignment `return` statement
"RET505", # Unnecessary `else` after `return`
"SIM118", # Use `key in dict` instead of `key in dict.keys()`
"T201", # `print` found
Expand All @@ -167,8 +155,11 @@ isort.required-imports = ["from __future__ import annotations"]
# typing-modules = ["cats._compat.typing"]

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20"]
"docs/conf.py" = ["A001", "D100", "INP001"]
"scripts/**" = ["INP001"]
"tests/**" = ["ANN", "D1", "INP", "S101", "T20"]
"noxfile.py" = ["T20"]
"__init__.py" = ["F403"]
# TODO: fix these and remove
"src/cats/pawprint/tests/mwe.py" = ["F821"]

Expand All @@ -181,7 +172,11 @@ similarities.ignore-imports = "yes"
messages_control.disable = [
"design",
"fixme",
"line-too-long",
"missing-module-docstring",
"wrong-import-position",
# TODO: fix these and remove
"attribute-defined-outside-init",
"duplicate-code",
"invalid-name",
"no-member",
"unused-variable",
]
67 changes: 23 additions & 44 deletions src/cats/combine_pm_cmd.py → scripts/combine_pm_cmd.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
"""Combine PM and CMD cuts."""

from __future__ import annotations

from typing import Any

import astropy.table as at
import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd

from cats.cmd.CMD import Isochrone
from cats.pawprint.pawprint import Footprint2D, Pawprint

plt = mpl.pyplot

plt.rc(
"xtick",
top=True,
direction="in",
labelsize=15,
)
plt.rc(
"ytick",
right=True,
direction="in",
labelsize=15,
)
plt.rc(
"font",
family="Arial",
)
from cats.cmd import Isochrone
from cats.pawprint import Footprint2D, Pawprint

plt.rc("xtick", top=True, direction="in", labelsize=15)
plt.rc("ytick", right=True, direction="in", labelsize=15)
plt.rc("font", family="Arial")


def generate_isochrone_vertices(
cat,
sky_poly,
pm_poly,
config,
):
"""
cat: Any, sky_poly: Any, pm_poly: Any, config: Any
) -> Any:
"""Generate Isochrone Vertices.

Use the generated class to make a new polygon for the given catalog in CMD
space given a sky and PM polygon.
"""
Expand Down Expand Up @@ -63,26 +50,17 @@ def generate_isochrone_vertices(
return o.simpleSln(0.1, 15, mass_thresh=0.83)[0]


def generate_pm_vertices(
cat,
sky_poly,
cmd_poly,
config,
):
"""
def generate_pm_vertices() -> list[list[float]]:
"""Generate Proper Motion Vertices.

Use the generated class to make a new polygon for the given catalog in PM
space given a sky and CMD polygon.
"""
pm_poly = [
[-7.0, 0.0],
[-5.0, 0.0],
[-5.0, 1.6],
[-7.0, -1.6],
]
return pm_poly
return [[-7.0, 0.0], [-5.0, 0.0], [-5.0, 1.6], [-7.0, -1.6]]


def load_sky_region(fn):
def load_sky_region(fn: Any) -> tuple[list[float], list[float]]:
"""Load Sky Region."""
sky_print = [
[-5, -2],
[+5, -2],
Expand All @@ -94,12 +72,13 @@ def load_sky_region(fn):


def main() -> int:
"""Run Script."""
# load in config file, catalog from filename
config = pd.read_json("config.json")
cat = at.Table.read(config.streaminfo.cat_fn)

# load in file with the sky footprint.
sky_poly, bg_poly = load_sky_region(config.streaminfo.sky_print)
sky_poly, _ = load_sky_region(config.streaminfo.sky_print)

# have an initial selection for the PM region that is very wide
# this could also be stored in a footprint
Expand Down
14 changes: 9 additions & 5 deletions src/cats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""
Copyright (c) 2023 CATS. All rights reserved.
"""Copyright (c) 2023 CATS. All rights reserved.

cats: Community Atlas of Tidal Streams
"""


from __future__ import annotations

from ._version import version as __version__
__all__ = [
# Constants
"__version__",
# Modules
"data",
"frames",
]

__all__ = ["__version__"]
from ._version import version as __version__
2 changes: 0 additions & 2 deletions src/cats/_version.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
from __future__ import annotations

version: str
version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str]
Loading