Skip to content

Commit

Permalink
add warning to line_matching.py if the matched set is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tepickering committed May 17, 2024
1 parent 8994bb9 commit f226188
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions specreduce/line_matching.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Sequence
import warnings

import numpy as np

Expand Down Expand Up @@ -47,9 +48,13 @@ def find_arc_lines(
QTable
A table of detected arc lines and their properties: centroid, fwhm, and amplitude.
"""
# Asssume FWHM is given in pixels if unit is not specified
# If fwhm is a float, convert it to a Quantity with the same unit as the spectral axis
# of the input spectrum.
if not isinstance(fwhm, u.Quantity):
fwhm *= u.pix
fwhm *= spectrum.spectral_axis.unit

Check warning on line 54 in specreduce/line_matching.py

View check run for this annotation

Codecov / codecov/patch

specreduce/line_matching.py#L53-L54

Added lines #L53 - L54 were not covered by tests

if fwhm.unit != spectrum.spectral_axis.unit:
raise ValueError("fwhm must have the same units as the spectral axis of the input spectrum.")

Check warning on line 57 in specreduce/line_matching.py

View check run for this annotation

Codecov / codecov/patch

specreduce/line_matching.py#L56-L57

Added lines #L56 - L57 were not covered by tests

detected_lines = find_lines_threshold(spectrum, noise_factor=noise_factor)
detected_lines = detected_lines[detected_lines['line_type'] == 'emission']

Check warning on line 60 in specreduce/line_matching.py

View check run for this annotation

Codecov / codecov/patch

specreduce/line_matching.py#L59-L60

Added lines #L59 - L60 were not covered by tests
Expand Down Expand Up @@ -102,9 +107,9 @@ def match_lines_wcs(
"""

# This routine uses numpy broadcasting which doesn't always behave with Quantity objects.
# Convert to u.pix and pull out the np.ndarray values.
# Pull out the np.ndarray values to avoid those issues.
if isinstance(pixel_positions, u.Quantity):
pixel_positions = pixel_positions.to(u.pix).value
pixel_positions = pixel_positions.value

Check warning on line 112 in specreduce/line_matching.py

View check run for this annotation

Codecov / codecov/patch

specreduce/line_matching.py#L111-L112

Added lines #L111 - L112 were not covered by tests

# Extra sanity handling to make sure the input Sequence can be converted to an np.array
try:
Expand All @@ -118,4 +123,8 @@ def match_lines_wcs(
matched_table = QTable()
matched_table["pixel_center"] = pixel_positions[matched_loc[0]] * u.pix
matched_table["wavelength"] = catalog_wavelengths[matched_loc[1]]

Check warning on line 125 in specreduce/line_matching.py

View check run for this annotation

Codecov / codecov/patch

specreduce/line_matching.py#L120-L125

Added lines #L120 - L125 were not covered by tests

if len(matched_table) == 0:
warnings.warn("No lines matched within the given tolerance.")

Check warning on line 128 in specreduce/line_matching.py

View check run for this annotation

Codecov / codecov/patch

specreduce/line_matching.py#L127-L128

Added lines #L127 - L128 were not covered by tests

return matched_table

Check warning on line 130 in specreduce/line_matching.py

View check run for this annotation

Codecov / codecov/patch

specreduce/line_matching.py#L130

Added line #L130 was not covered by tests

0 comments on commit f226188

Please sign in to comment.