Example #1
0
def prepare_observed(observed):
    """
    Preparing an observed spectrum

    Parameters
    ----------
    observed: Spectrum1D object

    """

    wavelength, flux = observed.wavelength, observed.flux

    if getattr(observed, 'uncertainty', None) is None:
        uncertainty = np.ones_like(flux)
    else:
        uncertainty = getattr(observed.uncertainty, 'array',
                                       observed.uncertainty).value

    wavelength_order = np.argsort(wavelength)

    spec = Spectrum1D.from_array(wavelength[wavelength_order],
                                 flux[wavelength_order])
    spec.uncertainty = uncertainty[wavelength_order]

    return spec
Example #2
0
 def spectrum_1d_getitem(observed, part):
     observed_part = Spectrum1D.from_array(
         observed.wavelength[part],
         observed.flux[part])
     if getattr(observed, 'uncertainty', None) is not None:
         observed_part.uncertainty = getattr(observed.uncertainty, 'array',
                                             observed.uncertainty)[part]
     return observed_part
Example #3
0
    def __call__(self, model):
        fit = np.zeros_like(model.wavelength.value)
        for part, normalizer in zip(self.parts, self.normalizers):
            fit[part] = normalizer(self.spectrum_1d_getitem(model, part)).flux

        return Spectrum1D.from_array(
            model.wavelength.value,
            fit, unit=self.normalizers[0].flux_unit,
            dispersion_unit=model.wavelength.unit)
Example #4
0
    def evaluate_slow(self, wavelength, flux):

        spec = Spectrum1D.from_array(wavelength * u.angstrom,
                                     flux * u.erg/u.s/u.cm**2/u.angstrom)
        return np.array(u.Quantity(self.calculate_magnitudes(spec)).value)