Skip to content

Commit

Permalink
Merge pull request #241 from discos/fix_recent_numpy
Browse files Browse the repository at this point in the history
Fix issues with recent versions of Python and dependencies
  • Loading branch information
matteobachetti authored Jul 17, 2024
2 parents 0b6de86 + ea36964 commit 9cfc78a
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 94 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ jobs:
toxenv: black
experimental: false

- name: Python 3.10 with all optional dependencies and coverage checking
- name: Python 3.11 with all optional dependencies and coverage checking
os: ubuntu-latest
python: '3.10'
toxenv: py310-test-alldeps-cov
python: '3.11'
toxenv: py311-test-alldeps-cov
experimental: false

- name: OS X - Python 3.8 with all optional dependencies
- name: OS X - Python 3.8 with all optional dependencies at their 3.8-compatible versions
os: macos-latest
python: '3.8'
toxenv: py38-test-alldeps
Expand All @@ -121,10 +121,10 @@ jobs:
toxenv: py310-test-alldeps
experimental: false

- name: Python 3.11 with latest dev versions of key dependencies
- name: Python 3.12 with latest dev versions of key dependencies
os: ubuntu-latest
python: '3.11'
toxenv: py311-test-devdeps
python: '3.12'
toxenv: py312-test-devdeps
experimental: true

steps:
Expand Down
1 change: 1 addition & 0 deletions docs/changes/241.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update dependencies
3 changes: 0 additions & 3 deletions srttools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ def warning_on_one_line(message, category, filename, lineno, line=None):

warnings.formatwarning = warning_on_one_line

# warnings.filterwarnings("error", category=np.VisibleDeprecationWarning)
# warnings.filterwarnings("error", ".*")
warnings.filterwarnings("once", category=UserWarning)
warnings.filterwarnings("once", category=DeprecationWarning)
warnings.filterwarnings("once", category=np.VisibleDeprecationWarning)
warnings.filterwarnings("ignore", "table path was not set via the path= ")

__all__ = []
Expand Down
10 changes: 3 additions & 7 deletions srttools/converters/classfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"""


from astropy.io import fits
from astropy.table import Table, vstack
from astropy.time import Time
Expand Down Expand Up @@ -338,21 +337,18 @@ def find_cycles(table, list_of_keys):
>>> list_of_keys = ['A', 'B']
>>> new_table = find_cycles(table, list_of_keys) # doctest:+ELLIPSIS
-etc-
>>> np.all(new_table['CYCLE'] == [0, 0, 0, 0, 1, 1, 1, 1])
True
>>> assert np.all(new_table['CYCLE'] == [0, 0, 0, 0, 1, 1, 1, 1])
>>> table = Table(data=[[0, 0, 1, 1, 0, 0, 1, 1],
... [0, 1, 0, 1, 0, 1, 0, 1]], names=['A', 'B'])
>>> list_of_keys = ['A', 'B']
>>> new_table = find_cycles(table, list_of_keys) # doctest:+ELLIPSIS
-etc-
>>> np.all(new_table['CYCLE'] == [0, 0, 0, 0, 1, 1, 1, 1])
True
>>> assert np.all(new_table['CYCLE'] == [0, 0, 0, 0, 1, 1, 1, 1])
>>> table = Table(data=[[0, 1, 0, 1], [1, 0, 1, 0]], names=['A', 'B'])
>>> list_of_keys = ['A', 'B']
>>> new_table = find_cycles(table, list_of_keys) # doctest:+ELLIPSIS
-etc-
>>> np.all(new_table['CYCLE'] == [0, 0, 1, 1])
True
>>> assert np.all(new_table['CYCLE'] == [0, 0, 1, 1])
"""
binary_values = 10 ** np.arange(len(list_of_keys), dtype=int)
table["BINARY_COL"] = np.zeros(len(table), dtype=int)
Expand Down
6 changes: 2 additions & 4 deletions srttools/converters/sdfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,8 @@ def _get_empty_array(length, dim):
"""
Examples
--------
>>> np.all(_get_empty_array(10, "0")[1].flatten() == np.zeros(10))
True
>>> np.all(_get_empty_array(10, "(2,2)")[1].flatten() == np.zeros(40))
True
>>> assert np.all(_get_empty_array(10, "0")[1].flatten() == np.zeros(10))
>>> assert np.all(_get_empty_array(10, "(2,2)")[1].flatten() == np.zeros(40))
"""

Expand Down
21 changes: 7 additions & 14 deletions srttools/destripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ def mask_zeros(image, expo=None, npix_tol=None):
>>> import numpy as np
>>> img = [[0, 1, 1], [0, 1, 1], [1, 1, 1]]
>>> masked_image, mask = mask_zeros(img, expo=img, npix_tol=1)
>>> np.all(masked_image == [[1, 1], [1, 1], [1, 1]])
True
>>> np.all(mask == [[False, True, True], [False, True, True],
>>> assert np.all(masked_image == [[1, 1], [1, 1], [1, 1]])
>>> assert np.all(mask == [[False, True, True], [False, True, True],
... [False, True, True]])
True
>>> masked_image, mask = mask_zeros(img, npix_tol=2)
>>> np.all(masked_image == img)
True
>>> assert np.all(masked_image == img)
>>> img = [[0, 0, 0], [1, 1, 1], [1, 1, 1]]
>>> masked_image, mask = mask_zeros(img, npix_tol=1)
>>> np.all(masked_image == [[1, 1, 1], [1, 1, 1]])
True
>>> assert np.all(masked_image == [[1, 1, 1], [1, 1, 1]])
"""
image = np.asarray(image)
mask = np.ones(image.shape, dtype=bool)
Expand Down Expand Up @@ -78,14 +74,11 @@ def clip_and_smooth(img, clip_sigma=3, smooth_window=10, direction=0):
Examples
--------
>>> img = np.zeros((2,2))
>>> np.all(clip_and_smooth(img, smooth_window=(5, 5)) == img)
True
>>> assert np.all(clip_and_smooth(img, smooth_window=(5, 5)) == img)
>>> img = np.array([[0, 0], [1, 1]])
>>> np.all(clip_and_smooth(img, direction=0) == img)
True
>>> assert np.all(clip_and_smooth(img, direction=0) == img)
>>> img = np.array([[0, 1], [0, 1]])
>>> np.all(clip_and_smooth(img, direction=1) == img)
True
>>> assert np.all(clip_and_smooth(img, direction=1) == img)
>>> img = np.array([[1, 1.], [8., 1]])
>>> np.allclose(clip_and_smooth(img, clip_sigma=1, smooth_window=0),
... [[1, 1], [3.0310889132455352, 1]])
Expand Down
4 changes: 2 additions & 2 deletions srttools/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import traceback
import copy
import functools
from datetime import datetime
from datetime import datetime, timezone
from collections.abc import Iterable

from scipy.stats import binned_statistic_2d
Expand Down Expand Up @@ -1483,7 +1483,7 @@ def save_ds9_images(
warnings.warn("Azimuth is wrapping around 0. Beware.")

header["CREATOR"] = "SDT"
ut = Time(datetime.utcnow(), scale="utc")
ut = Time(datetime.now(timezone.utc), scale="utc")
header["COMMENT"] = f"Made with the SRT Single-Dish Tools on UT {ut.fits}"
hdu = fits.PrimaryHDU(header=header)
hdulist.append(hdu)
Expand Down
11 changes: 5 additions & 6 deletions srttools/io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Input/output functions."""

import astropy.io.fits as fits
from astropy.table import Table
import numpy as np
Expand Down Expand Up @@ -236,9 +237,9 @@ def observing_angle(rest_angle, derot_angle):
Examples
--------
>>> observing_angle(0 * u.rad, TWOPI * u.rad).to(u.rad).value
>>> float(observing_angle(0 * u.rad, TWOPI * u.rad).to(u.rad).value)
0.0
>>> observing_angle(0, TWOPI).to(u.rad).value
>>> float(observing_angle(0, TWOPI).to(u.rad).value)
0.0
"""
if not hasattr(rest_angle, "unit"):
Expand Down Expand Up @@ -375,10 +376,8 @@ def is_close_to_sun(ra, dec, obstime, tolerance=3 * u.deg):
--------
>>> ra, dec = 131.13535699 * u.deg, 18.08202663 * u.deg
>>> obstime = Time("2017-08-01")
>>> is_close_to_sun(ra, dec, obstime, tolerance=3 * u.deg)
True
>>> is_close_to_sun(ra, dec + 4 * u.deg, obstime, tolerance=3 * u.deg)
False
>>> assert is_close_to_sun(ra, dec, obstime, tolerance=3 * u.deg)
>>> assert not is_close_to_sun(ra, dec + 4 * u.deg, obstime, tolerance=3 * u.deg)
"""
coords = SkyCoord(ra=ra, dec=dec, frame=GCRS(obstime=obstime))
sun_position = get_sun(obstime).transform_to(GCRS(obstime=obstime))
Expand Down
22 changes: 8 additions & 14 deletions srttools/scan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Scan class."""

import time
import pickle
import glob
Expand Down Expand Up @@ -76,31 +77,24 @@ def angular_distance(angle0, angle1):
>>> dist = 0.1
>>> a0 = 1.
>>> a1 = 1. + dist
>>> np.isclose(angular_distance(a0, a1), dist)
True
>>> assert np.isclose(angular_distance(a0, a1), dist)
>>> a0 = -0.05
>>> a1 = 0.05
>>> np.isclose(angular_distance(a0, a1), dist)
True
>>> assert np.isclose(angular_distance(a0, a1), dist)
>>> a0 += TWOPI
>>> np.isclose(angular_distance(a0, a1), dist)
True
>>> assert np.isclose(angular_distance(a0, a1), dist)
>>> a1 += 6 * np.pi
>>> np.isclose(angular_distance(a0, a1), dist)
True
>>> assert np.isclose(angular_distance(a0, a1), dist)
>>> a0 = np.pi - 0.5 * dist
>>> a1 = np.pi + 0.5 * dist
>>> np.isclose(angular_distance(a0, a1), dist)
True
>>> assert np.isclose(angular_distance(a0, a1), dist)
>>> a0 = TWOPI - 0.5 * dist
>>> a1 = TWOPI + 0.5 * dist
>>> np.isclose(angular_distance(a0, a1), dist)
True
>>> np.all(np.isclose(
>>> assert np.isclose(angular_distance(a0, a1), dist)
>>> assert np.all(np.isclose(
... angular_distance([0, np.pi, TWOPI],
... np.asarray([0, np.pi, TWOPI]) + dist),
... dist))
True
"""
angle0 = np.fmod(angle0, TWOPI)
angle1 = np.fmod(angle1, TWOPI)
Expand Down
14 changes: 5 additions & 9 deletions srttools/simulate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Functions to simulate scans and maps."""


import numpy as np
import numpy.random as ra
import os
Expand Down Expand Up @@ -161,7 +160,7 @@ def _default_flat_shape(x):
Examples
--------
>>> _default_flat_shape(4314)
>>> float(_default_flat_shape(4314))
100.0
>>> np.allclose(_default_flat_shape(np.arange(3)),
... np.array([100., 100., 100.]))
Expand Down Expand Up @@ -294,7 +293,7 @@ def _default_map_shape(x, y):
Examples
--------
>>> _default_map_shape(4314, 234)
>>> int(_default_map_shape(4314, 234))
100
>>> res = np.array([[ 100., 100., 100., 100.],
... [ 100., 100., 100., 100.],
Expand Down Expand Up @@ -620,12 +619,9 @@ def _single_value_as_tuple(value, nvals=2):
Examples
--------
>>> np.all(_single_value_as_tuple(1) == (1, 1))
True
>>> np.all(_single_value_as_tuple((1, 1, 1)) == (1, 1, 1))
True
>>> np.all(_single_value_as_tuple(1, nvals=3) == (1, 1, 1))
True
>>> assert np.all(_single_value_as_tuple(1) == (1, 1))
>>> assert np.all(_single_value_as_tuple((1, 1, 1)) == (1, 1, 1))
>>> assert np.all(_single_value_as_tuple(1, nvals=3) == (1, 1, 1))
"""
if isinstance(value, Iterable):
return value
Expand Down
42 changes: 14 additions & 28 deletions srttools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ def get_circular_statistics(array):
--------
>>> array = np.array([6.1, 6.2, 0.16, 0.26])
>>> res = get_circular_statistics(array)
>>> np.isclose(res['min'], 6.1 - 2*np.pi)
True
>>> res['max'] == 0.26
True
>>> assert np.isclose(res['min'], 6.1 - 2*np.pi)
>>> assert res['max'] == 0.26
"""
array = np.asarray(array) % TWOPI
mean_ = circmean(array)
Expand Down Expand Up @@ -284,8 +282,7 @@ def compare_strings(s1, s2):
True
>>> import numpy as np
>>> res = np.array([ True, False], dtype=bool)
>>> np.all(compare_strings(np.array(['a', 'b'], dtype='S'), u'a') == res)
True
>>> assert np.all(compare_strings(np.array(['a', 'b'], dtype='S'), u'a') == res)
"""

s1 = standard_string(s1)
Expand Down Expand Up @@ -362,12 +359,10 @@ def interpolate_invalid_points_image(array, zeros_are_invalid=False):
--------
>>> img = np.ones((3, 3))
>>> img[1, 1] = np.nan
>>> np.all(interpolate_invalid_points_image(img) == np.ones((3, 3)))
True
>>> assert np.all(interpolate_invalid_points_image(img) == np.ones((3, 3)))
>>> img = np.ones((3, 3))
>>> img[1, 1] = 0
>>> np.all(interpolate_invalid_points_image(img, True) == np.ones((3, 3)))
True
>>> assert np.all(interpolate_invalid_points_image(img, True) == np.ones((3, 3)))
"""
from scipy import interpolate

Expand Down Expand Up @@ -429,23 +424,19 @@ def get_center_of_mass(im, radius=1, approx=None):
... [0,1,1,0],
... [0,1,1,0]))
>>> cm = get_center_of_mass(image)
>>> np.all(cm == np.array([2.0, 1.5]))
True
>>> assert np.all(cm == np.array([2.0, 1.5]))
>>> image = np.array(([0, 0,0,0,0, 0],
... [0, 0,0,0,0, 0],
... [0, 0,1,1,0, 0],
... [0, 0,1,1,0, 0],
... [0, 0,1,1,0, 0],
... [0, 0,0,0,0, 0]))
>>> cm = get_center_of_mass(image, radius=0.4)
>>> np.all(cm == np.array([2.5, 2.5]))
False
>>> assert not np.all(cm == np.array([2.5, 2.5]))
>>> cm = get_center_of_mass(image, radius=0.4, approx='max')
>>> np.all(cm == np.array([2.5, 2.5]))
True
>>> assert np.all(cm == np.array([2.5, 2.5]))
>>> cm = get_center_of_mass(image)
>>> np.all(cm == np.array([3., 2.5]))
True
>>> assert np.all(cm == np.array([3., 2.5]))
"""
import scipy.ndimage

Expand Down Expand Up @@ -750,8 +741,7 @@ def calculate_moments(y, imax=None, window_length=5):
--------
>>> y = np.exp(-np.linspace(-10, 10, 1101)**2/2)
>>> mo = calculate_moments(y)
>>> np.all(np.isclose(mo['skewness'], 0))
True
>>> assert np.all(np.isclose(mo['skewness'], 0))
"""
from scipy.signal import savgol_filter

Expand Down Expand Up @@ -798,8 +788,7 @@ def scantype(ra, dec, az=None, el=None):
>>> els = np.linspace(0.5, 0.7, 100)
>>> azs = np.linspace(0.5, 0.7, 100)
>>> st = scantype(ras, decs, azs, els)
>>> np.all(st[0] == ras)
True
>>> assert np.all(st[0] == ras)
>>> st[1] == 'RA>'
True
>>> # Opposite direction
Expand All @@ -818,8 +807,7 @@ def scantype(ra, dec, az=None, el=None):
>>> els = list(zip(np.linspace(0.5, 0.7, 100), np.linspace(0.5, 0.7, 100)))
>>> azs = list(zip(np.linspace(0.5, 0.7, 100), np.linspace(0.5, 0.7, 100)))
>>> st = scantype(ras, decs, azs, els)
>>> np.all(st[0] == ras)
True
>>> assert np.all(st[0] == ras)
>>> st[1] == 'RA>'
True
"""
Expand Down Expand Up @@ -853,10 +841,8 @@ def median_diff(array, sorting=False):
Examples
--------
>>> median_diff([1, 2, 0, 4, -1, -2])
-1.0
>>> median_diff([1, 2, 0, 4, -1, -2], sorting=True)
1.0
>>> assert median_diff([1, 2, 0, 4, -1, -2]) == -1.0
>>> assert median_diff([1, 2, 0, 4, -1, -2], sorting=True) == 1.0
"""
if len(array) == 0:
return 0
Expand Down

0 comments on commit 9cfc78a

Please sign in to comment.