-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #846 from chaquo/astropy
Add packages: astropy, pyerfa, photutils
- Loading branch information
Showing
10 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% if PY_VER == "3.8" %} | ||
{% set numpy_version = "1.19.5" %} | ||
{% else %} | ||
{% set numpy_version = "1.23.3" %} | ||
{% endif %} | ||
|
||
package: | ||
name: astropy | ||
version: 5.1.1 | ||
|
||
build: | ||
number: 1 | ||
|
||
requirements: | ||
build: | ||
- cython 0.29.32 | ||
- extension-helpers 1.0.0 | ||
- setuptools-scm 7.1.0 | ||
host: | ||
- numpy {{ numpy_version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- src-original/setup.py 2022-05-24 19:43:02.000000000 +0000 | ||
+++ src/setup.py 2023-07-24 14:54:26.328796259 +0000 | ||
@@ -4,6 +4,10 @@ | ||
# NOTE: The configuration for the package, including the name, version, and | ||
# other information are set in the setup.cfg file. | ||
|
||
+# Chaquopy | ||
+import builtins | ||
+builtins.__NUMPY_SETUP__ = True # Prevent the compiled parts from being imported. | ||
+ | ||
import sys | ||
|
||
# First provide helpful messages if contributors try and run legacy commands | ||
@@ -65,4 +69,7 @@ | ||
from setuptools import setup # noqa | ||
from extension_helpers import get_extensions # noqa | ||
|
||
-setup(ext_modules=get_extensions()) | ||
+# Chaquopy: added `version`, because setuptools_scm isn't finding it automatically for | ||
+# some reason. | ||
+from setuptools_scm import get_version | ||
+setup(ext_modules=get_extensions(), version=get_version()) | ||
--- src-original/astropy/convolution/convolve.py 2022-10-23 08:14:50.000000000 +0000 | ||
+++ src/astropy/convolution/convolve.py 2023-07-24 22:01:04.533772774 +0000 | ||
@@ -25,7 +25,9 @@ | ||
# numpy.distutils is deprecated since numpy 1.23 | ||
# see https://github.com/astropy/astropy/issues/12865 | ||
warnings.simplefilter('ignore', DeprecationWarning) | ||
- _convolve = load_library("_convolve", LIBRARY_PATH) | ||
+ # Chaquopy: was numpy.ctypeslib.load_library, which requires the file to already | ||
+ # exist (#892). | ||
+ _convolve = ctypes.CDLL(f"{LIBRARY_PATH}/_convolve.so") | ||
except Exception: | ||
raise ImportError("Convolution C extension is missing. Try re-building astropy.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import unittest | ||
|
||
|
||
class TestAstropy(unittest.TestCase): | ||
|
||
# https://docs.astropy.org/en/stable/convolution/index.html#getting-started | ||
def test_convolution(self): | ||
from astropy.convolution import convolve | ||
from numpy.testing import assert_allclose | ||
|
||
assert_allclose(convolve([1, 4, 5, 6, 5, 7, 8], [0.2, 0.6, 0.2]), | ||
[1.4, 3.6, 5.0, 5.6, 5.6, 6.8, 6.2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% if PY_VER == "3.8" %} | ||
{% set numpy_version = "1.19.5" %} | ||
{% else %} | ||
{% set numpy_version = "1.23.3" %} | ||
{% endif %} | ||
|
||
package: | ||
name: photutils | ||
version: 1.1.0 | ||
|
||
requirements: | ||
build: | ||
- cython 0.29.32 | ||
- extension-helpers 1.0.0 | ||
- setuptools-scm 7.1.0 | ||
host: | ||
- numpy {{ numpy_version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- src-original/setup.py 2022-05-24 19:43:02.000000000 +0000 | ||
+++ src/setup.py 2023-04-06 16:08:59.631926941 +0000 | ||
@@ -4,5 +4,9 @@ | ||
# NOTE: The configuration for the package, including the name, version, and | ||
# other information are set in the setup.cfg file. | ||
|
||
+# Chaquopy | ||
+import builtins | ||
+builtins.__NUMPY_SETUP__ = True # Prevent the compiled parts from being imported. | ||
+ | ||
import sys | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import unittest | ||
|
||
|
||
class TestPhotutils(unittest.TestCase): | ||
|
||
# https://photutils.readthedocs.io/en/stable/getting_started.html | ||
def test_basic(self): | ||
from astropy.io import fits | ||
from astropy.stats import mad_std | ||
from io import BytesIO | ||
import numpy as np | ||
from photutils.aperture import aperture_photometry, CircularAperture | ||
from photutils.detection import DAOStarFinder | ||
|
||
# This is equivalent to photutils.datasets.load_star_image. | ||
URL = "http://www.astropy.org/astropy-data/photometry/M6707HH.fits" | ||
hdu = fits.open(BytesIO(read_url(URL)))[0] | ||
|
||
image = hdu.data[500:700, 500:700].astype(float) | ||
image -= np.median(image) | ||
|
||
bkg_sigma = mad_std(image) | ||
daofind = DAOStarFinder(fwhm=4.0, threshold=3.0 * bkg_sigma) | ||
sources = daofind(image) | ||
self.assertEqual(len(sources), 152) | ||
|
||
positions = np.transpose((sources['xcentroid'], sources['ycentroid'])) | ||
apertures = CircularAperture(positions, r=4.0) | ||
phot_table = aperture_photometry(image, apertures) | ||
|
||
phot_table.sort("aperture_sum", reverse=True) | ||
brightest = phot_table[0] | ||
self.assertEqual( | ||
[int(brightest[column].value) for column in ["xcenter", "ycenter"]], | ||
[53, 13]) # See image at the bottom of the above link. | ||
|
||
|
||
# Downloading a URL with "Connection: close", as urllib does, causes an intermittent network | ||
# problem on the emulator (see #5601 and https://issuetracker.google.com/issues/150758736). For | ||
# small files we could just retry until it succeeds, but for large files a failure is much more | ||
# likely, and we might have to keep retrying for several minutes. So use the stdlib's low-level | ||
# HTTP API to make a request with no Connection header. | ||
def read_url(url): | ||
from http.client import HTTPConnection, HTTPSConnection | ||
from urllib.parse import urlparse | ||
|
||
parsed = urlparse(url) | ||
conn_cls = HTTPSConnection if parsed.scheme == "https" else HTTPConnection | ||
conn = conn_cls(parsed.hostname, parsed.port) | ||
full_path = parsed.path | ||
if parsed.query: | ||
full_path += "?" + parsed.query | ||
conn.request("GET", full_path) | ||
data = conn.getresponse().read() | ||
conn.close() | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% if PY_VER == "3.8" %} | ||
{% set numpy_version = "1.19.5" %} | ||
{% else %} | ||
{% set numpy_version = "1.23.3" %} | ||
{% endif %} | ||
|
||
package: | ||
name: pyerfa | ||
version: 2.0.0.3 | ||
|
||
requirements: | ||
build: | ||
- packaging 23.1 | ||
host: | ||
- numpy {{ numpy_version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- src-original/setup.py 2021-11-02 19:17:42.000000000 +0000 | ||
+++ src/setup.py 2023-06-03 11:19:23.806406705 +0000 | ||
@@ -26,6 +26,10 @@ | ||
|
||
@property | ||
def include_dirs(self): | ||
+ # Chaquopy | ||
+ import builtins | ||
+ builtins.__NUMPY_SETUP__ = True # Prevent the compiled parts from being imported. | ||
+ | ||
from numpy import get_include | ||
return self._include_dirs + [get_include()] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import unittest | ||
|
||
|
||
class TestPyerfa(unittest.TestCase): | ||
|
||
# https://pyerfa.readthedocs.io/en/latest/quickstart.html#usage | ||
def test_basic(self): | ||
import erfa | ||
from numpy.testing import assert_allclose | ||
|
||
position, velocity = erfa.plan94(2460000, 0, 1) | ||
assert_allclose(position, [0.090837128 , -0.3904139186, -0.2179738913]) | ||
assert_allclose(velocity, [0.0219234131, 0.0070544853, 0.0014961814]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters