Skip to content

Commit

Permalink
Merge pull request #92 from desihub/updates-for-kibo
Browse files Browse the repository at this point in the history
Updates in preparation for next release
  • Loading branch information
weaverba137 authored Aug 5, 2024
2 parents 3d5ddee + 529946d commit 9b17e49
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 106 deletions.
85 changes: 63 additions & 22 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,23 @@ jobs:
python -m pip install 'matplotlib${{ matrix.matplotlib-version }}'
python -m pip install 'astropy${{ matrix.astropy-version }}'
python -m pip install 'numpy${{ matrix.numpy-version }}'
- name: Run the test
run: pytest

#
# Temporarily use coverage to test more recent versions.
# Note that Astropy>=5.1 introduces an ordering change in unit display, which
# causes doctest failures.
#
coverage:
name: Test coverage
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: ['3.10']

steps:
- name: Checkout code
Expand All @@ -72,7 +78,7 @@ jobs:
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install pytest pytest-astropy pyyaml coveralls
python -m pip install Pillow\<10.4 numpy\<1.21 scipy\<1.6 matplotlib\<3.4 astropy\<5.0
python -m pip install numpy\<1.23 scipy\<1.9 matplotlib\<3.9 astropy\<5.1
- name: Run the test with coverage
run: pytest --cov
Expand All @@ -87,38 +93,38 @@ jobs:
name: Doc test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.8']
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.10']

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

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip wheel setuptools Sphinx\<8
python -m pip install -e .[docs]
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip wheel setuptools Sphinx\<8
python -m pip install -e .[docs]
- name: Test the documentation
run: sphinx-build -W --keep-going -b html docs docs/_build/html
- name: Test the documentation
run: sphinx-build -W --keep-going -b html docs docs/_build/html

style:
name: Style test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
os: [ubuntu-latest]
python-version: ['3.10']

steps:
- name: Checkout code
Expand All @@ -139,3 +145,38 @@ jobs:
# If allowed failures are needed, uncomment continue-on-error.
# continue-on-error: true
run: flake8 speclite --count --max-line-length=100

#
# Temporary test to make sure the package can at least be installed
# for more recent Python versions.
#
install:
name: Installation test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
python-version: ['3.10', '3.11', '3.12']

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

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install numpy\<2.0 scipy matplotlib astropy pyyaml
- name: Test installing from the checkout
run: python -m pip install .

- name: Run a script that should have been installed
run: speclite_benchmark --all
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "astropy_helpers"]
path = astropy_helpers
url = https://github.com/astropy/astropy-helpers.git
url = https://github.com/bsipocz/astropy-helpers.git
2 changes: 1 addition & 1 deletion astropy_helpers
52 changes: 0 additions & 52 deletions conftest.py

This file was deleted.

6 changes: 5 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ speclite Change Log
-----------------

- Fix ``scipy.integrate`` name changes; pin Pillow version so unit tests work (PR `#91`_).
- *Planned*: fix several remaining issues.
- Fix issues related to :meth:`~specutils.filters.FilterSequence.pad_spectrum` and
:meth:`~specutils.filters.FilterResponse.get_ab_maggies`; allow ``pip install``
on more recent Python versions;
replace deprecated ``matplotlib`` colormap function (PR `#92`_).

.. _`#91`: https://github.com/desihub/speclite/pull/91
.. _`#92`: https://github.com/desihub/speclite/pull/92

0.19 (2024-04-30)
-----------------
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@
if eval(setup_cfg.get('edit_on_github')):
extensions += ['sphinx_astropy.ext.edit_on_github']

versionmod = __import__(setup_cfg['package_name'] + '.version')
versionmod = import_module(setup_cfg['package_name'] + '.version')
edit_on_github_project = setup_cfg['github_project']
if versionmod.version.release:
edit_on_github_branch = "v" + versionmod.version.version
if versionmod.release:
edit_on_github_branch = "v" + versionmod.version
else:
edit_on_github_branch = "master"
edit_on_github_branch = "main"

edit_on_github_source_root = ""
edit_on_github_doc_root = "docs"
Expand Down
20 changes: 15 additions & 5 deletions speclite/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import astropy.units as u
import argparse

import speclite
import speclite.filters


def magnitude_calculation(results, num_repeats):
Expand Down Expand Up @@ -85,18 +85,25 @@ def magnitude_calculation(results, num_repeats):


def main(argv=None):
"""Entry-point for :command:`speclite_benchmark`.
Returns
-------
:class:`int`
An integer suitable for passing to :func:`sys.exit`.
"""
# parse command-line arguments
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-n', '--num-repeats', type=int, default=1000,
help = 'number of times to repeat timing loops')
parser.add_argument('--all', action='store_true',
parser.add_argument('-a', '--all', action='store_true',
help = 'run all benchmark suites')
parser.add_argument('--magnitude', action='store_true',
parser.add_argument('-m', '--magnitude', action='store_true',
help = 'benchmark magnitude calculations')
parser.add_argument('--save', type=str, default=None,
parser.add_argument('-s', '--save', type=str, default=None,
help='Name of file to save results to (or print if not set)')
parser.add_argument('--format', type=str,
parser.add_argument('-f', '--format', type=str,
default='ascii.fixed_width_two_line',
help='format to use for results')
args = parser.parse_args(argv)
Expand All @@ -106,6 +113,9 @@ def main(argv=None):
dtype=('S8', 'S40', float))
if args.magnitude or args.all:
results = magnitude_calculation(results, args.num_repeats)
else:
print('ERROR: No test suite specified (--magnitude or --all)!')
return 1

results.write(args.save, format=args.format,
delimiter_pad=' ', position_char='=',
Expand Down
2 changes: 1 addition & 1 deletion speclite/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# variables that are used for configuration.
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS

from astropy.tests.helper import enable_deprecations_as_exceptions
# from astropy.tests.helper import enable_deprecations_as_exceptions

## Uncomment the following line to treat all DeprecationWarnings as
## exceptions
Expand Down
11 changes: 5 additions & 6 deletions speclite/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@
default_flux_unit : :class:`astropy.units.Unit`
The default units for spectral flux density per unit wavelength.
"""
from __future__ import print_function, division # pragma: no cover

import os
import os.path
import glob
Expand Down Expand Up @@ -1312,7 +1310,9 @@ def __init__(self, response, wavelength,
self._response = load_filter(response)
else:
self._response = response
self._wavelength = validate_wavelength_array(wavelength, min_length=2)
# Work with a copy of the wavelength array,
# see https://github.com/desihub/speclite/issues/34
self._wavelength = validate_wavelength_array(wavelength, min_length=2).copy()
self.num_wavelength = len(self._wavelength)

# Check if extrapolation would be required.
Expand Down Expand Up @@ -1769,7 +1769,7 @@ def pad_spectrum(self, spectrum, wavelength, axis=-1, method='median'):
padded_wavelength = np.asanyarray(wavelength)
for response in sorted_responses:
padded_spectrum, padded_wavelength = response.pad_spectrum(
padded_spectrum, padded_wavelength)
padded_spectrum, padded_wavelength, axis=axis, method=method)
return padded_spectrum, padded_wavelength


Expand Down Expand Up @@ -1991,9 +1991,8 @@ def plot_filters(responses, wavelength_unit=None,
min_wlen, max_wlen = min(effective_wavelengths), max(effective_wavelengths)

import matplotlib.pyplot as plt
import matplotlib.cm as cm

cmap = cm.get_cmap(cmap)
cmap = plt.get_cmap(cmap)
fig, ax = plt.subplots()
plt.xscale(wavelength_scale)
if wavelength_limits is not None:
Expand Down
17 changes: 4 additions & 13 deletions speclite/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
"""
import numpy as np
import numpy.ma as ma
import numpy.lib.recfunctions as rfn
import scipy.interpolate
from packaging import version

if version.parse(np.__version__) >= version.parse('1.16'):
import numpy.lib.recfunctions as rfn

def resample(data_in, x_in, x_out, y, data_out=None, kind='linear'):
"""Resample the data of one spectrum using interpolation.
Expand Down Expand Up @@ -166,16 +164,9 @@ def resample(data_in, x_in, x_out, y, data_out=None, kind='linear'):
for i,y in enumerate(y_names):
y_in[:,i] = data_in[y].filled(np.nan)
else:
if version.parse(np.__version__) >= version.parse('1.16'):
# The slicing does not work in numpy 1.16 and above
# we use structured_to_unstructured to get the slice that we care about
y_in = rfn.structured_to_unstructured(
data_in[y_names]).reshape(data_in.shape + y_shape)
else:
y_in = data_in[y_names]
# View the structured 1D array as a 2D unstructured array (without
# copying any memory).
y_in = y_in.view(y_type).reshape(data_in.shape + y_shape)
# The slicing does not work in numpy 1.16 and above
# we use structured_to_unstructured to get the slice that we care about
y_in = rfn.structured_to_unstructured(data_in[y_names]).reshape(data_in.shape + y_shape)

# interp1d will only propagate NaNs correctly for certain values of `kind`.
# With numpy = 1.6 or 1.7, only 'nearest' and 'linear' work.
Expand Down
Loading

0 comments on commit 9b17e49

Please sign in to comment.