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
6 changes: 2 additions & 4 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ jobs:
pip install ruff
- name: Lint
run: |
ruff check --statistics *.py
ruff check --statistics apps/
ruff check --statistics .
- name: Format
run: |
ruff format --check *.py
ruff format --check apps/
ruff format --check .
85 changes: 85 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

# Same as Black.
line-length = 88
indent-width = 4

# Assume Python 3.11
target-version = "py311"

[lint]
# Rules can be found at https://docs.astral.sh/ruff/rules
select = ["E4", "E7", "E9", "F", "E1", "E2", "W", "N", "D", "B", "C4", "PD", "PERF"]
ignore = [
"C408", "C420", "C901", "C416",
"D400", "D401", "D100", "D102", "D103", "D104", "D415", "D419", "D101",
"E731", "D205",
"N812", "N806", "N803",
"PLR0913",
"D420"
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"

[lint.pydocstyle]
convention = "numpy"
25 changes: 12 additions & 13 deletions app_lsst.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from flask import Flask, Blueprint

from flask import Blueprint, Flask
from flask_restx import Api
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics
from config_prometheus import child_exit, pre_fork, post_fork
from prometheus_client import values
from prometheus_client.values import MultiProcessValue
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics

from apps import __version__

from apps.utils.utils import extract_configuration

from apps.routes.v1.lsst.sources.api import ns as ns_sources
from apps.routes.v1.lsst.objects.api import ns as ns_objects
from apps.routes.v1.lsst.fp.api import ns as ns_fp
from apps.routes.v1.lsst.blocks.api import ns as ns_blocks
from apps.routes.v1.lsst.conesearch.api import ns as ns_conesearch
from apps.routes.v1.lsst.cutouts.api import ns as ns_cutouts
from apps.routes.v1.lsst.schema.api import ns as ns_schema
from apps.routes.v1.lsst.sso.api import ns as ns_sso
from apps.routes.v1.lsst.fp.api import ns as ns_fp
from apps.routes.v1.lsst.objects.api import ns as ns_objects
from apps.routes.v1.lsst.resolver.api import ns as ns_resolver
from apps.routes.v1.lsst.schema.api import ns as ns_schema
from apps.routes.v1.lsst.skymap.api import ns as ns_skymap
from apps.routes.v1.lsst.sources.api import ns as ns_sources
from apps.routes.v1.lsst.sso.api import ns as ns_sso
from apps.routes.v1.lsst.statistics.api import ns as ns_stats
from apps.routes.v1.lsst.tags.api import ns as ns_tags
from apps.routes.v1.lsst.blocks.api import ns as ns_blocks
from apps.utils.utils import extract_configuration
from config_prometheus import child_exit, post_fork, pre_fork

config = extract_configuration("config.yml")


def get_worker_id():
"""return stable id for worker"""
"""Return stable id for worker"""
return os.environ.get("GUNICORN_WORKER_ID", str(os.getpid()))


Expand Down
31 changes: 15 additions & 16 deletions app_ztf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,38 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from flask import Flask, Blueprint

from flask import Blueprint, Flask
from flask_restx import Api
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics
from config_prometheus import child_exit, pre_fork, post_fork
from prometheus_client import values
from prometheus_client.values import MultiProcessValue
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics

from apps import __version__

from apps.utils.utils import extract_configuration

from apps.routes.v1.ztf.objects.api import ns as ns_objects
from apps.routes.v1.ztf.cutouts.api import ns as ns_cutouts
from apps.routes.v1.ztf.latests.api import ns as ns_latests
from apps.routes.v1.ztf.anomaly.api import ns as ns_anomaly
from apps.routes.v1.ztf.classes.api import ns as ns_classes
from apps.routes.v1.ztf.conesearch.api import ns as ns_conesearch
from apps.routes.v1.ztf.sso.api import ns as ns_sso
from apps.routes.v1.ztf.cutouts.api import ns as ns_cutouts
from apps.routes.v1.ztf.latests.api import ns as ns_latests
from apps.routes.v1.ztf.metadata.api import ns as ns_metadata
from apps.routes.v1.ztf.objects.api import ns as ns_objects
from apps.routes.v1.ztf.resolver.api import ns as ns_resolver
from apps.routes.v1.ztf.tracklet.api import ns as ns_tracklet
from apps.routes.v1.ztf.schema.api import ns as ns_schema
from apps.routes.v1.ztf.skymap.api import ns as ns_skymap
from apps.routes.v1.ztf.statistics.api import ns as ns_statistics
from apps.routes.v1.ztf.sso.api import ns as ns_sso
from apps.routes.v1.ztf.ssobulk.api import ns as ns_ssobulk
from apps.routes.v1.ztf.ssocand.api import ns as ns_ssocand
from apps.routes.v1.ztf.anomaly.api import ns as ns_anomaly
from apps.routes.v1.ztf.ssoft.api import ns as ns_ssoft
from apps.routes.v1.ztf.metadata.api import ns as ns_metadata
from apps.routes.v1.ztf.ssobulk.api import ns as ns_ssobulk
from apps.routes.v1.ztf.statistics.api import ns as ns_statistics
from apps.routes.v1.ztf.tracklet.api import ns as ns_tracklet
from apps.utils.utils import extract_configuration
from config_prometheus import child_exit, post_fork, pre_fork

config = extract_configuration("config.yml")


def get_worker_id():
"""return stable id for worker"""
"""Return stable id for worker"""
return os.environ.get("GUNICORN_WORKER_ID", str(os.getpid()))


Expand Down
2 changes: 1 addition & 1 deletion apps/routes/v1/lsst/blocks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ class Blocks(Resource):
def get(self):
"""Retrieve block definition"""
tags, descriptions = extract_blocks(True)
out = {k: v for k, v in zip(tags, descriptions)}
out = {k: v for k, v in zip(tags, descriptions, strict=True)}
return jsonify(out)
3 changes: 2 additions & 1 deletion apps/routes/v1/lsst/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import fink_filters.rubin.blocks as fblocks
import importlib

import fink_filters.rubin.blocks as fblocks


def extract_blocks(with_description=False):
"""Extract user-defined blocks
Expand Down
4 changes: 1 addition & 3 deletions apps/routes/v1/lsst/conesearch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
from flask import Response, request
from flask_restx import Namespace, Resource, fields

from apps.utils.utils import check_args
from apps.utils.utils import send_tabular_data

from apps.routes.v1.lsst.conesearch.utils import run_conesearch
from apps.utils.utils import check_args, send_tabular_data

ns = Namespace("api/v1/conesearch", "Get Rubin alerts data based on coordinates")

Expand Down
25 changes: 12 additions & 13 deletions apps/routes/v1/lsst/conesearch/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import requests
import pandas as pd
import numpy as np
import io
import sys

import numpy as np
import pandas as pd
import requests
from astropy.coordinates import SkyCoord
from astropy.io import votable

import io
import sys

APIURL = sys.argv[1]

RA0 = 53.2514
Expand Down Expand Up @@ -50,7 +49,7 @@ def conesearch(
if columns is not None:
payload.update({"columns": columns})

r = requests.post("{}/api/v1/conesearch".format(APIURL), json=payload)
r = requests.post(f"{APIURL}/api/v1/conesearch", json=payload)

assert r.status_code == 200, r.content

Expand Down Expand Up @@ -145,7 +144,7 @@ def test_bad_radius_conesearch() -> None:
"output_format": "json",
}

r = requests.post("{}/api/v1/conesearch".format(APIURL), json=payload)
r = requests.post(f"{APIURL}/api/v1/conesearch", json=payload)

msg = {
"status": "error",
Expand All @@ -167,7 +166,7 @@ def test_conesearch_with_cols() -> None:
assert not pdf.empty, pdf

# specified fields, plus mandatory i:ra,i:dec, plus computed v:separation
assert len(pdf.columns) == 4, "I count {} columns".format(len(pdf.columns))
assert len(pdf.columns) == 4, f"I count {len(pdf.columns)} columns"


def test_bad_dates() -> None:
Expand All @@ -185,7 +184,7 @@ def test_bad_dates() -> None:
"output_format": "json",
}

r = requests.post("{}/api/v1/conesearch".format(APIURL), json=payload)
r = requests.post(f"{APIURL}/api/v1/conesearch", json=payload)

msg = {
"status": "error",
Expand Down Expand Up @@ -218,7 +217,7 @@ def test_coordinates() -> None:
]
pdf0 = conesearch(ra=RA0, dec=DEC0, columns="r:diaObjectId")
for ra, dec in coords:
pdf = conesearch(ra=RA0, dec=DEC0, columns="r:diaObjectId")
pdf = conesearch(ra=ra, dec=dec, columns="r:diaObjectId")
assert pdf.equals(pdf0)


Expand All @@ -230,7 +229,7 @@ def test_bad_request() -> None:
"""
payload = {"ra": "kfdlkj", "dec": "lkfdjf", "radius": 5, "output_format": "json"}

r = requests.post("{}/api/v1/conesearch".format(APIURL), json=payload)
r = requests.post(f"{APIURL}/api/v1/conesearch", json=payload)

msg = {
"status": "error",
Expand Down Expand Up @@ -262,7 +261,7 @@ def test_various_outputs() -> None:

if __name__ == "__main__":
""" Execute the test suite """
import sys
import doctest
import sys

sys.exit(doctest.testmod()[0])
16 changes: 6 additions & 10 deletions apps/routes/v1/lsst/conesearch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,19 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from flask import Response

import pandas as pd

from numpy import pi as nppi
from healpy import query_disc, ang2vec

import astropy.units as u
from astropy.time import Time
import pandas as pd
from astropy.coordinates import SkyCoord
from astropy.time import Time
from flask import Response
from healpy import ang2vec, query_disc
from line_profiler import profile
from numpy import pi as nppi

from apps.utils.client import connect_to_hbase_table
from apps.utils.decoding import format_lsst_hbase_output
from apps.utils.utils import isoify_time

from line_profiler import profile


@profile
def run_conesearch(payload: dict) -> pd.DataFrame:
Expand Down
3 changes: 1 addition & 2 deletions apps/routes/v1/lsst/cutouts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
from flask import Response, request
from flask_restx import Namespace, Resource, fields

from apps.utils.utils import check_args

from apps.routes.v1.lsst.cutouts.utils import format_and_send_cutout
from apps.utils.utils import check_args

ns = Namespace("api/v1/cutouts", "Get cutout alert data based on Rubin diaSourceId")

Expand Down
3 changes: 2 additions & 1 deletion apps/routes/v1/lsst/cutouts/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# limitations under the License.
"""Call format_and_send_cutout"""

from apps.routes.v1.lsst.cutouts.utils import format_and_send_cutout
from flask import Flask

from apps.routes.v1.lsst.cutouts.utils import format_and_send_cutout

app = Flask("Profile cutouts")

payload = {
Expand Down
Loading
Loading