Skip to content

Commit

Permalink
Updated template_redshift to return final redshifted spectrum and _ch…
Browse files Browse the repository at this point in the history
…i_square_for_templates and _normalize_for_template_matching to accept NaNs
  • Loading branch information
chloe-mt-cheng committed Mar 22, 2022
1 parent db80bd1 commit 264b0c9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions specutils/analysis/template_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def _normalize_for_template_matching(observed_spectrum, template_spectrum, stdde
"""
if stddev is None:
stddev = _uncertainty_to_standard_deviation(observed_spectrum.uncertainty)
num = np.sum((observed_spectrum.flux*template_spectrum.flux) / (stddev**2))
denom = np.sum((template_spectrum.flux / stddev)**2)
num = np.nansum((observed_spectrum.flux*template_spectrum.flux) / (stddev**2))
denom = np.nansum((template_spectrum.flux / stddev)**2)

return num/denom

Expand Down Expand Up @@ -134,7 +134,7 @@ def _chi_square_for_templates(observed_spectrum, template_spectrum, resample_met

# Get chi square
result = (num/denom)**2
chi2 = np.sum(result.value)
chi2 = np.nansum(result.value)

# Create normalized template spectrum, which will be returned with
# corresponding chi2
Expand Down Expand Up @@ -289,5 +289,6 @@ def template_redshift(observed_spectrum, template_spectrum, redshift):
if not np.isnan(chi2) and (chi2_min is None or chi2 < chi2_min):
chi2_min = chi2
final_redshift = rs
final_spectrum = redshifted_spectrum

return redshifted_spectrum, final_redshift, normalized_spectral_template, chi2_min, chi2_list
return final_spectrum, final_redshift, normalized_spectral_template, chi2_min, chi2_list

0 comments on commit 264b0c9

Please sign in to comment.