Skip to content

Commit

Permalink
Merge pull request #85 from saimn/numpy-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog authored Apr 22, 2024
2 parents 4ebfd89 + 96e4c55 commit cbdec83
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 223 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# macos-13 is an intel runner, macos-14 is apple silicon
os: [ubuntu-latest, windows-latest, macos-13, macos-14]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.12'

- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
uses: pypa/cibuildwheel@v2.17.0

- uses: actions/upload-artifact@v4
with:
Expand All @@ -38,7 +34,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.12'
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.2.0.dev (unreleased)
----------------------

- Drop support for Python 3.6.
- The minimum supported version of Python is now 3.9.
- Change to normalization for convolution fine structure method to instead use a matched filter.

1.1.0 (2021-11-19)
Expand Down
7 changes: 1 addition & 6 deletions astroscrappy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,8 @@
scipy.
"""

# Affiliated packages may add whatever they like to this file, but
# should keep this content at the top.
# ----------------------------------------------------------------------------
from ._astropy_init import * # noqa
# ----------------------------------------------------------------------------

from .astroscrappy import * # noqa
from .utils import * # noqa
from .version import version as __version__ # noqa

__all__ = ['detect_cosmics'] # noqa
25 changes: 0 additions & 25 deletions astroscrappy/_astropy_init.py

This file was deleted.

17 changes: 17 additions & 0 deletions astroscrappy/setup_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

from numpy import get_include
from setuptools import Extension

ROOT = os.path.relpath(os.path.dirname(__file__))


def get_extensions():
sources = [os.path.join(ROOT, "astroscrappy.pyx")]
ext = Extension(
name="astroscrappy.astroscrappy",
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
include_dirs=[get_include()],
sources=sources,
)
return [ext]
25 changes: 18 additions & 7 deletions astroscrappy/tests/test_cleaning.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from ..astroscrappy import detect_cosmics

import pytest

from . import fake_data
from ..astroscrappy import detect_cosmics


# Get fake data to work on
imdata, crmask = fake_data.make_fake_data()
@pytest.fixture
def testdata():
# Get fake data to work on
imdata, crmask = fake_data.make_fake_data()
return imdata, crmask


def test_median_clean():
@pytest.mark.xfail
def test_median_clean(testdata):
imdata, crmask = testdata
# Because our image only contains single cosmics, turn off
# neighbor detection. Also, our cosmic rays are high enough
# contrast that we can turn our detection threshold up.
Expand All @@ -22,7 +30,8 @@ def test_median_clean():
assert _mask2.sum() == 0


def test_medmask_clean():
def test_medmask_clean(testdata):
imdata, crmask = testdata
# Because our image only contains single cosmics, turn off
# neighbor detection. Also, our cosmic rays are high enough
# contrast that we can turn our detection threshold up.
Expand All @@ -37,7 +46,8 @@ def test_medmask_clean():
assert _mask2.sum() == 0


def test_meanmask_clean():
def test_meanmask_clean(testdata):
imdata, crmask = testdata
# Because our image only contains single cosmics, turn off
# neighbor detection. Also, our cosmic rays are high enough
# contrast that we can turn our detection threshold up.
Expand All @@ -52,7 +62,8 @@ def test_meanmask_clean():
assert _mask2.sum() == 0


def test_idw_clean():
def test_idw_clean(testdata):
imdata, crmask = testdata
# Because our image only contains single cosmics, turn off
# neighbor detection. Also, our cosmic rays are high enough
# contrast that we can turn our detection threshold up.
Expand Down
2 changes: 1 addition & 1 deletion astroscrappy/utils/median_utils.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ without requiring the GIL.
Calculate the median on the first n elements of C float array
without requiring the GIL.
"""
cdef float cymedian(float* aptr, int n) nogil
cdef float cymedian(float* aptr, int n) noexcept nogil
2 changes: 1 addition & 1 deletion astroscrappy/utils/median_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def median(np.ndarray[np.float32_t, mode='c', cast=True] a, int n):
med = PyMedian(aptr, n)
return med

cdef float cymedian(float* a, int n) nogil:
cdef float cymedian(float* a, int n) noexcept nogil:
"""cymedian(a, n)\n
Cython function to calculate the median without requiring the GIL.
:param a:
Expand Down
21 changes: 9 additions & 12 deletions astroscrappy/utils/setup_package.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
import os
import numpy as np

from distutils.core import Extension
from setuptools import Extension
from extension_helpers import add_openmp_flags_if_available

UTIL_DIR = os.path.relpath(os.path.dirname(__file__))


def get_extensions():

med_sources = [str(os.path.join(UTIL_DIR, "median_utils.pyx")),
str(os.path.join(UTIL_DIR, "medutils.c"))]
med_sources = [os.path.join(UTIL_DIR, "median_utils.pyx"),
os.path.join(UTIL_DIR, "medutils.c")]

im_sources = [str(os.path.join(UTIL_DIR, "image_utils.pyx")),
str(os.path.join(UTIL_DIR, "imutils.c"))]
im_sources = [os.path.join(UTIL_DIR, "image_utils.pyx"),
os.path.join(UTIL_DIR, "imutils.c")]

include_dirs = [np.get_include(), UTIL_DIR]
libraries = []

if 'CFLAGS' in os.environ:
extra_compile_args = os.environ['CFLAGS'].split()
else:
extra_compile_args = ['-g', '-O3', '-funroll-loops', '-ffast-math']

ext_med = Extension(name=str('astroscrappy.utils.median_utils'),
ext_med = Extension(name='astroscrappy.utils.median_utils',
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
sources=med_sources,
include_dirs=include_dirs,
libraries=libraries,
language="c",
extra_compile_args=extra_compile_args)
ext_im = Extension(name=str("astroscrappy.utils.image_utils"),
ext_im = Extension(name="astroscrappy.utils.image_utils",
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
sources=im_sources,
include_dirs=include_dirs,
libraries=libraries,
language="c",
extra_compile_args=extra_compile_args)

add_openmp_flags_if_available(ext_med)
Expand Down
90 changes: 84 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,94 @@
[build-system]
requires = [
"setuptools>=61.2",
"setuptools_scm[toml]>=6.2",
"extension-helpers==1.*",
"numpy>=2.0.0rc1",
"Cython>=3.0,<3.1",
]
build-backend = 'setuptools.build_meta'

requires = ["setuptools",
"setuptools_scm",
"extension-helpers==1.*",
"numpy>=1.25,<2",
"Cython>=3.0,<3.1"]
[project]
name = "astroscrappy"
readme = "README.rst"
authors = [
{ name = "Curtis McCully", email = "[email protected]" },
]
description = "Speedy Cosmic Ray Annihilation Package in Python"
license = { text = "BSD-3-Clause" }
# edit-on-github = "False"
# github-project = "astropy/astroscrappy"
requires-python = ">=3.9"
dependencies = [
"astropy",
"numpy",
]
dynamic = [ "version" ]

build-backend = 'setuptools.build_meta'
[project.urls]
Homepage = "https://github.com/astropy/astroscrappy"

[project.optional-dependencies]
docs = ["sphinx-astropy"]
test = ["Cython", "pytest-astropy", "scipy"]

[tool.setuptools]
license-files = ["licenses/LICENSE.rst"]
include-package-data = true

[tool.setuptools.packages.find]
include = ["astroscrappy*"]

[tool.setuptools.package-data]
"*" = [ "data/*" ]

[tool.setuptools_scm]
write_to = "astroscrappy/version.py"

[tool.pytest.ini_options]
testpaths = ["astroscrappy", "docs"]
astropy_header = true
doctest_plus = "enabled"
text_file_format = "rst"
addopts = "-p no:warnings --doctest-rst"
doctest_norecursedirs = ["*/setup_package.py"]
filterwarnings = [
# action:message:category:module:lineno
# "error",
# "ignore:.*divide by zero encountered in double_scalars.*:RuntimeWarning:arviz",
]

[tool.coverage.run]
source = ["astroscrappy"]
plugins = [ "Cython.Coverage" ]
omit = [
"astroscrappy/conftest.py",
"astroscrappy/*setup_package*",
"astroscrappy/tests/*",
"astroscrappy/*/tests/*",
"astroscrappy/version*",
"*/astroscrappy/conftest.py",
"*/astroscrappy/*setup_package*",
"*/astroscrappy/tests/*",
"*/astroscrappy/*/tests/*",
"*/astroscrappy/version*",
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"except ImportError",
"raise AssertionError",
"raise NotImplementedError",
"def main\\(.*\\):",
"pragma: py{ignore_python_version}",
"def _ipython_key_completions_",
]

[tool.cibuildwheel]
# Skip pypy on mac due to numpy/accelerate issues
skip = ["pp*", "*musllinux*"]
build-verbosity = 1
environment = { PIP_PREFER_BINARY=1 }
test-requires = "pytest scipy"
test-command = "pytest --pyargs astroscrappy"
Expand Down
Loading

0 comments on commit cbdec83

Please sign in to comment.