Skip to content

Commit 2785323

Browse files
committed
Improved uncertainty type handling in WavelengthCalibration1D.
1 parent 786bded commit 2785323

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

specreduce/wavecal1d.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,12 @@ def resample(
502502
raise ValueError("Number of bins must be positive.")
503503

504504
flux = spectrum.flux.value
505-
ucty = spectrum.uncertainty.represent_as(VarianceUncertainty).array
505+
if spectrum.uncertainty is not None:
506+
ucty = spectrum.uncertainty.represent_as(VarianceUncertainty).array
507+
ucty_type = type(spectrum.uncertainty)
508+
else:
509+
ucty = np.zeros_like(flux)
510+
ucty_type = VarianceUncertainty
506511
npix = flux.size
507512
nbins = npix if nbins is None else nbins
508513
if wlbounds is None:
@@ -535,8 +540,7 @@ def resample(
535540
flux_wl[i] = (bin_edges_pix[i + 1] - bin_edges_pix[i]) * flux[i1] * dldx[i1]
536541
ucty_wl[i] = (bin_edges_pix[i + 1] - bin_edges_pix[i]) * ucty[i1] * dldx[i1]
537542
flux_wl = (flux_wl * n) * spectrum.flux.unit
538-
ucty_wl = VarianceUncertainty(ucty_wl * n).represent_as(type(spectrum.uncertainty))
539-
543+
ucty_wl = VarianceUncertainty(ucty_wl * n).represent_as(ucty_type)
540544
return Spectrum(flux_wl, bin_centers_wav * u.angstrom, uncertainty=ucty_wl)
541545

542546
def pix_to_wav(self, pix: MaskedArray | ndarray | float) -> ndarray | float:

0 commit comments

Comments
 (0)