Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Doc and CI updates #251

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/tox-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ jobs:
linux: py310-test-oldestdeps
toxargs: -v

- name: Python 3.10 on Windows with minimal dependencies
windows: py310-test
- name: Python 3.11 on Windows with minimal dependencies
windows: py311-test
toxargs: -v

- name: Python 3.10 on OSX with minimal dependencies
macos: py310-test
- name: Python 3.11 on OSX with minimal dependencies
macos: py311-test
toxargs: -v

- name: Python 3.11 on Linux with all dependencies, remote data, and coverage
linux: py311-test-alldeps-cov
- name: Python 3.12 on Linux with all dependencies, remote data, and coverage
linux: py312-test-alldeps-cov
coverage: codecov
toxargs: -v
posargs: --remote-data=any

- name: (Allowed Failure) Python 3.12 on Linux with dev dependencies
linux: py312-test-devdeps
- name: (Allowed Failure) Python 3.13 on Linux with dev dependencies
linux: py313-test-devdeps
toxargs: -v
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build:
apt_packages:
- graphviz
tools:
python: "3.11"
python: "3.13"

sphinx:
builder: html
Expand Down
107 changes: 106 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
"""Need to repeat the astropy header config here for tox."""
# This file is used to configure the behavior of pytest

import numpy as np
import pytest
from astropy import units as u
from astropy.io import fits
from astropy.nddata import CCDData, NDData, VarianceUncertainty
from astropy.utils.data import get_pkg_data_filename
from specutils import Spectrum1D, SpectralAxis

try:
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
Expand All @@ -7,6 +15,103 @@
ASTROPY_HEADER = False


# Test image is comprised of 30 rows with 10 columns each. Row content
# is row index itself. This makes it easy to predict what should be the
# value extracted from a region centered at any arbitrary Y position.
def _mk_test_data(imgtype, nrows=30, ncols=10):
image_ones = np.ones(shape=(nrows, ncols))
image = image_ones.copy()
for j in range(nrows):
image[j, ::] *= j
if imgtype == "raw":
pass # no extra processing
elif imgtype == "ccddata":
image = CCDData(image, unit=u.Jy)
else: # spectrum
flux = image * u.DN
uncert = VarianceUncertainty(image_ones)
if imgtype == "spec_no_axis":
image = Spectrum1D(flux, uncertainty=uncert)
else: # "spec"
image = Spectrum1D(flux, spectral_axis=np.arange(ncols) * u.um, uncertainty=uncert)
return image


@pytest.fixture
def mk_test_img_raw():
return _mk_test_data("raw")


@pytest.fixture
def mk_test_img():
return _mk_test_data("ccddata")


@pytest.fixture
def mk_test_spec_no_spectral_axis():
return _mk_test_data("spec_no_axis")


@pytest.fixture
def mk_test_spec_with_spectral_axis():
return _mk_test_data("spec")


# Test data file already transposed like this:
# fn = download_file('https://stsci.box.com/shared/static/exnkul627fcuhy5akf2gswytud5tazmw.fits', cache=True) # noqa: E501
# img = fits.getdata(fn).T
@pytest.fixture
def all_images():
np.random.seed(7)

filename = get_pkg_data_filename(
"data/transposed_det_image_seq5_MIRIMAGE_P750Lexp1_s2d.fits", package="specreduce.tests")
img = fits.getdata(filename)
flux = img * (u.MJy / u.sr)
sax = SpectralAxis(np.linspace(14.377, 3.677, flux.shape[-1]) * u.um)
unc = VarianceUncertainty(np.random.rand(*flux.shape))

all_images = {}
all_images['arr'] = img
all_images['s1d'] = Spectrum1D(flux, spectral_axis=sax, uncertainty=unc)
all_images['s1d_pix'] = Spectrum1D(flux, uncertainty=unc)
all_images['ccd'] = CCDData(img, uncertainty=unc, unit=flux.unit)
all_images['ndd'] = NDData(img, uncertainty=unc, unit=flux.unit)
all_images['qnt'] = img * flux.unit
return all_images


@pytest.fixture
def spec1d():
np.random.seed(7)
flux = np.random.random(50)*u.Jy
sa = np.arange(0, 50)*u.pix
spec = Spectrum1D(flux, spectral_axis=sa)
return spec


@pytest.fixture
def spec1d_with_emission_line():
np.random.seed(7)
sa = np.arange(0, 200)*u.pix
flux = (np.random.randn(200) +
10*np.exp(-0.01*((sa.value-130)**2)) +
sa.value/100) * u.Jy
spec = Spectrum1D(flux, spectral_axis=sa)
return spec


@pytest.fixture
def spec1d_with_absorption_line():
np.random.seed(7)
sa = np.arange(0, 200)*u.pix
flux = (np.random.randn(200) -
10*np.exp(-0.01*((sa.value-130)**2)) +
sa.value/100) * u.Jy
spec = Spectrum1D(flux, spectral_axis=sa)
return spec


def pytest_configure(config):

if ASTROPY_HEADER:
Expand Down
10 changes: 10 additions & 0 deletions docs/conf.py
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Credit goes to AA-Turner in astropy/astropy#17659

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import sys
import datetime

import sphinx

from specreduce import __version__

try:
Expand All @@ -36,6 +38,14 @@
print('ERROR: the documentation requires the sphinx-astropy package to be installed')
sys.exit(1)

# xref: https://github.com/sphinx-doc/sphinx/issues/13232#issuecomment-2608708175
if sys.version_info[:2] >= (3, 13) and sphinx.version_info[:2] < (8, 2):
import pathlib

from sphinx.util.typing import _INVALID_BUILTIN_CLASSES

_INVALID_BUILTIN_CLASSES[pathlib.Path] = "pathlib.Path"

# -- General configuration ----------------------------------------------------

# By default, highlight as Python 3.
Expand Down
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@ filterwarnings = [
"ignore:numpy\\.ufunc size changed:RuntimeWarning",
"ignore:numpy\\.ndarray size changed:RuntimeWarning",
"ignore:Can\\'t import specreduce_data package",
"ignore:.*unclosed <ssl.SSLSocket",
# Python 3.12 warning from dateutil imported by matplotlib
"ignore:.*utcfromtimestamp:DeprecationWarning",
"ignore:.*unclosed <ssl.SSLSocket",
# DeprecationWarning from gwcs 0.18.3 in oldestdeps
"ignore:.*pkg_resources.*:DeprecationWarning",
]

[tool.coverage]

[tool.coverage.run]
omit = [
"specreduce/_astropy_init*",
"specreduce/conftest.py",
"specreduce/tests/*",
"specreduce/version*",
"*/specreduce/_astropy_init*",
"*/specreduce/conftest.py",
"*/specreduce/tests/*",
"*/specreduce/version*",
]
Expand Down
33 changes: 19 additions & 14 deletions specreduce/calibration_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,33 +303,38 @@ class AtmosphericExtinction(Spectrum1D):

Parameters
----------
model : Name of atmospheric extinction model provided by ``specreduce_data``. Valid
model : str
Name of atmospheric extinction model provided by ``specreduce_data``. Valid
options are:

kpno - Kitt Peak National Observatory (default)
ctio - Cerro Tololo International Observatory
apo - Apache Point Observatory
lapalma - Roque de los Muchachos Observatory, La Palma, Canary Islands
mko - Mauna Kea Observatories
mtham - Lick Observatory, Mt. Hamilton station
paranal - European Southern Observatory, Cerro Paranal station
* kpno - Kitt Peak National Observatory (default)
* ctio - Cerro Tololo International Observatory
* apo - Apache Point Observatory
* lapalma - Roque de los Muchachos Observatory, La Palma, Canary Islands
* mko - Mauna Kea Observatories
* mtham - Lick Observatory, Mt. Hamilton station
* paranal - European Southern Observatory, Cerro Paranal station

extinction : Optionally provided extinction data for this spectrum. Used along with
extinction : float, `~astropy.units.Quantity`, or `None`, optional
Provides extinction data for this spectrum. Used along with
spectral_axis to build custom atmospheric extinction model. If no units are provided,
assumed to be given in magnitudes.

spectral_axis : Optional Dispersion information with the same shape as the last (or only)
spectral_axis : `~astropy.coordinates.SpectralCoord`, `~astropy.units.Quantity`, or `None`, optional
Dispersion information with the same shape as the last (or only)
dimension of flux, or one greater than the last dimension of flux
if specifying bin edges. Used along with flux to build custom atmospheric
extinction model.

Properties
Attributes
----------
extinction_mag : Extinction expressed in dimensionless magnitudes
extinction_mag : `~astropy.units.Quantity`
Extinction expressed in dimensionless magnitudes

transmission : Extinction expressed as fractional transmission
transmission : `~astropy.units.Quantity`
Extinction expressed as fractional transmission

"""
""" # noqa: E501
def __init__(
self,
model: str = "kpno",
Expand Down
135 changes: 0 additions & 135 deletions specreduce/conftest.py

This file was deleted.

Loading