Skip to content

Commit

Permalink
Merge pull request #46 from lsst/tickets/DM-35347
Browse files Browse the repository at this point in the history
DM-35347: Switch to pyproject.toml
  • Loading branch information
mwittgen committed Jul 15, 2022
2 parents a1cf026 + 563d466 commit 0e49bb9
Show file tree
Hide file tree
Showing 35 changed files with 468 additions and 472 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Reformat code with isort/black
4b97dad9311110ee7a3d30332af50242053bd543
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Checklist

- [ ] ran Jenkins
- [ ] added a release note for user-visible changes to `doc/changes`
22 changes: 10 additions & 12 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
jobs:
build_and_test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
with:
Expand All @@ -20,7 +24,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "setup.cfg"

Expand All @@ -47,8 +51,6 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: 3.8
cache: "pip"
cache-dependency-path: "setup.cfg"

- name: Install dependencies
run: |
Expand Down Expand Up @@ -78,25 +80,21 @@ jobs:

steps:
# uncomment when building aarch64
#- name: Set up QEMU
# uses: docker/setup-qemu-action@v2
# if: runner.os == 'Linux'
# with:
# platforms: arm64
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
# if: runner.os == 'Linux'
# with:
# platforms: arm64

- uses: actions/checkout@v3
with:
# Need to clone everything to embed the versiona
fetch-depth: 0
cache: "pip"
cache-dependency-path: "setup.cfg"

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
cache: "pip"
cache-dependency-path: "setup.cfg"

- name: Install dependencies
run: |
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/docstyle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Run docstyle

on:
push:
branches:
- main
pull_request:

jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/docstyle.yaml@main
with:
args: "python/lsst/sphgeom/"
11 changes: 11 additions & 0 deletions .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Check Python formatting

on:
push:
branches:
- main
pull_request:

jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/formatting.yaml@main
11 changes: 11 additions & 0 deletions .github/workflows/yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Lint YAML Files

on:
push:
branches:
- main
pull_request:

jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/yamllint.yaml@main
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
args:
- "--unsafe"
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
16 changes: 16 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends: default

rules:
document-start: {present: false}
line-length:
max: 132
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
ignore: |
/.github/workflows/lint.yaml
truthy:
# "on" as a key in workflows confuses things
ignore: |
/.github/workflows/
indentation:
indent-sequences: consistent
75 changes: 72 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,81 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools >= 46.6.0",
"setuptools",
"lsst-versions >= 1.3.0",
"wheel",
"pybind11 >= 2.5.0",
"numpy >= 1.18",
"lsst-versions",
]
build-backend = "setuptools.build_meta"

[project]
name = "lsst-sphgeom"
description = "A spherical geometry library."
license = {text = "GPLv3+ License"}
readme = "README.md"
authors = [
{name="Rubin Observatory Data Management", email="dm-admin@lists.lsst.org"},
]
classifiers = [
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering :: Astronomy",
]
keywords = ["lsst"]
dependencies = [
"numpy >=1.18",
"healpy"
]
dynamic = ["version"]

[project.urls]
"Homepage" = "https://github.com/lsst/sphgeom"

[project.optional-dependencies]
test = [
"pytest >= 3.2",
"flake8 >= 3.7.5",
"pytest-flake8 >= 1.0.4",
]
yaml = ["pyyaml >= 5.1"]

[tool.setuptools.packages.find]
where = ["python"]

[tool.setuptools]
zip-safe = false
license-files = ["LICENSE"]

[tool.setuptools.dynamic]
version = { attr = "lsst_versions.get_lsst_version" }

[tool.black]
line-length = 110
target-version = ["py38"]

[tool.isort]
profile = "black"
line_length = 110

[tool.lsst_versions]
write_to = "python/lsst/sphgeom/version.py"

[tool.pytest.ini_options]
addopts = "--flake8"
flake8-ignore = ["E133", "E226", "E228", "N802", "N803", "N806", "N812", "N815", "N816", "W503"]

[tool.pydocstyle]
convention = "numpy"
# Our coding style does not require docstrings for magic methods (D105)
# Our docstyle documents __init__ at the class level (D107)
# We allow methods to inherit docstrings and this is not compatible with D102.
# Docstring at the very first line is not required
# D200, D205 and D400 all complain if the first sentence of the docstring does
# not fit on one line.
add-ignore = ["D107", "D105", "D102", "D100", "D200", "D205", "D400"]
1 change: 1 addition & 0 deletions python/lsst/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
4 changes: 2 additions & 2 deletions python/lsst/sphgeom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"""lsst.sphgeom
"""

from ._healpixPixelization import *
from ._sphgeom import *
from ._sphgeom import Pixelization
from .version import *
from ._yaml import *
from .pixelization_abc import *
from ._healpixPixelization import *
from .version import *

PixelizationABC.register(Pixelization)
36 changes: 15 additions & 21 deletions python/lsst/sphgeom/_healpixPixelization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

import numpy as np

from ._sphgeom import RangeSet, Region, UnitVector3d
from ._sphgeom import Box, Circle, ConvexPolygon, Ellipse
from ._sphgeom import Box, Circle, ConvexPolygon, Ellipse, RangeSet, Region, UnitVector3d
from .pixelization_abc import PixelizationABC


Expand All @@ -35,6 +34,7 @@ class HealpixPixelization(PixelizationABC):
level : `int`
Pixelization level. HEALPix nside = 2**level
"""

MAX_LEVEL = 17

def __init__(self, level: int):
Expand All @@ -50,7 +50,7 @@ def __init__(self, level: int):

# Values used to do pixel/region intersections
self._bit_shift = 8
self._nside_highres = self._nside*(2**(self._bit_shift//2))
self._nside_highres = self._nside * (2 ** (self._bit_shift // 2))

@property
def nside(self):
Expand All @@ -74,6 +74,7 @@ def pixel(self, i) -> Region:

def index(self, v: UnitVector3d) -> int:
import healpy as hp

return hp.vec2pix(self._nside, v.x(), v.y(), v.z(), nest=True)

def toString(self, i: int) -> str:
Expand All @@ -89,9 +90,7 @@ def envelope(self, region: Region, maxRanges: int = 0):

# Dilate the high resolution pixels by one to ensure that the full
# region is completely covered at high resolution.
neighbors = hp.get_all_neighbours(self._nside_highres,
pixels_highres,
nest=True)
neighbors = hp.get_all_neighbours(self._nside_highres, pixels_highres, nest=True)
# Shift back to the original resolution and uniquify
pixels = np.unique(np.right_shift(neighbors, self._bit_shift))

Expand All @@ -112,10 +111,10 @@ def interior(self, region: Region, maxRanges: int = 0):
# the center index points to x, y, z.
corners = hp.boundaries(self._nside, pixels, step=1, nest=True)

corners_int = region.contains(corners[:, 0, :].ravel(),
corners[:, 1, :].ravel(),
corners[:, 2, :].ravel()).reshape((len(pixels), 4))
interior = (np.sum(corners_int, axis=1) == 4)
corners_int = region.contains(
corners[:, 0, :].ravel(), corners[:, 1, :].ravel(), corners[:, 2, :].ravel()
).reshape((len(pixels), 4))
interior = np.sum(corners_int, axis=1) == 4
pixels = pixels[interior]

return RangeSet(pixels)
Expand Down Expand Up @@ -152,26 +151,21 @@ def _interior_pixels_from_region(self, nside: int, region: Region):
if _circle is not None:
center = _circle.getCenter()
vec = np.array([center.x(), center.y(), center.z()]).T
pixels = hp.query_disc(nside,
vec,
_circle.getOpeningAngle().asRadians(),
inclusive=False,
nest=True)
pixels = hp.query_disc(
nside, vec, _circle.getOpeningAngle().asRadians(), inclusive=False, nest=True
)
else:
vertices = np.array([[v.x(), v.y(), v.z()] for v in _poly.getVertices()])
pixels = hp.query_polygon(nside,
vertices,
inclusive=False,
nest=True)
pixels = hp.query_polygon(nside, vertices, inclusive=False, nest=True)

return pixels

def __eq__(self, other):
if isinstance(other, HealpixPixelization):
return (self._level == other._level)
return self._level == other._level

def __repr__(self):
return f"HealpixPixelization({self._level})"

def __reduce__(self):
return (self.__class__, (self._level, ))
return (self.__class__, (self._level,))

0 comments on commit 0e49bb9

Please sign in to comment.