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
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
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)
def __call__(self, spectrum): wavelength, flux = spectrum.wavelength.value, spectrum.flux interpolated_flux = np.interp(self.observed.wavelength.value, wavelength, flux) return Spectrum1D.from_array( self.observed.wavelength, interpolated_flux, dispersion_unit=self.observed.wavelength.unit, unit=self.observed.unit)
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)
def __call__(self, spectrum): from specutils import extinction extinction_factor = 10**(-0.4*extinction.extinction_ccm89( spectrum.wavelength, a_v=self.a_v, r_v=self.r_v)) return Spectrum1D.from_array( spectrum.wavelength.value, extinction_factor * spectrum.flux, dispersion_unit=spectrum.wavelength.unit, unit=spectrum.unit)
def __call__(self, spectrum): from specutils import extinction extinction_factor = 10**(-0.4 * extinction.extinction_ccm89( spectrum.wavelength, a_v=self.a_v, r_v=self.r_v)) return Spectrum1D.from_array(spectrum.wavelength.value, extinction_factor * spectrum.flux, dispersion_unit=spectrum.wavelength.unit, unit=spectrum.unit)
def __call__(self, spectrum): from specutils import extinction extinction_factor = np.ones_like(spectrum.wavelength.value) valid_wavelength = ((spectrum.wavelength > 910 * u.angstrom) & (spectrum.wavelength < 33333 * u.angstrom)) extinction_factor[valid_wavelength] = 10 ** (-0.4 * extinction.extinction_ccm89( spectrum.wavelength[valid_wavelength], a_v=self.a_v, r_v=self.r_v).to(u.angstrom).value) return Spectrum1D.from_array(spectrum.wavelength, extinction_factor * spectrum.flux)
def __call__(self, spectrum): from specutils import extinction extinction_factor = np.ones_like(spectrum.wavelength.value) valid_wavelength = ((spectrum.wavelength > 910 * u.angstrom) & (spectrum.wavelength < 33333 * u.angstrom)) extinction_factor[valid_wavelength] = 10**( -0.4 * extinction.extinction_ccm89(spectrum.wavelength[valid_wavelength], a_v=self.a_v, r_v=self.r_v).to(u.angstrom).value) return Spectrum1D.from_array(spectrum.wavelength, extinction_factor * spectrum.flux)
def __call__(self, spectrum): wavelength, flux = spectrum.wavelength.value, spectrum.flux log_grid_log_wavelength = np.arange(np.log(wavelength.min()), np.log(wavelength.max()), self.resolution.to(1).value) log_grid_wavelength = np.exp(log_grid_log_wavelength) log_grid_flux = np.interp(log_grid_wavelength, wavelength, flux) profile = self.rotational_profile() log_grid_convolved = nd.convolve1d(log_grid_flux, profile) convolved_flux = np.interp(wavelength, log_grid_wavelength, log_grid_convolved) return Spectrum1D.from_array(spectrum.wavelength, convolved_flux, dispersion_unit=spectrum.wavelength.unit, unit=spectrum.unit)
def __call__(self, spectrum): wavelength, flux = spectrum.wavelength.value, spectrum.flux log_grid_log_wavelength = np.arange( np.log(wavelength.min()), np.log(wavelength.max()), 1 / (self.sampling * self.R.to(1).value)) log_grid_wavelength = np.exp(log_grid_log_wavelength) log_grid_flux = np.interp(log_grid_wavelength, wavelength, flux) sigma = self.sampling / (2 * np.sqrt(2 * np.log(2))) log_grid_convolved = nd.gaussian_filter1d(log_grid_flux, sigma) convolved_flux = np.interp(wavelength, log_grid_wavelength, log_grid_convolved) return Spectrum1D.from_array(spectrum.wavelength, convolved_flux, dispersion_unit=spectrum.wavelength.unit, unit=spectrum.unit)
def __call__(self, spectrum): wavelength, flux = spectrum.wavelength.value, spectrum.flux log_grid_log_wavelength = np.arange(np.log(wavelength.min()), np.log(wavelength.max()), 1 / (self.sampling * self.R.to(1).value)) log_grid_wavelength = np.exp(log_grid_log_wavelength) log_grid_flux = np.interp(log_grid_wavelength, wavelength, flux) sigma = self.sampling / (2 * np.sqrt(2 * np.log(2))) log_grid_convolved = nd.gaussian_filter1d(log_grid_flux, sigma) convolved_flux = np.interp(wavelength, log_grid_wavelength, log_grid_convolved) return Spectrum1D.from_array(spectrum.wavelength, convolved_flux, dispersion_unit=spectrum.wavelength.unit, unit=spectrum.unit)
def __call__(self, spectrum): R = self.resolution Lambda = self.central_wavelength.value wavelength = spectrum.dispersion.value conversionfactor = 2 * np.sqrt(2 * np.log(2)) deltax = np.mean(wavelength[1:] - wavelength[0:-1]) FWHM = Lambda / R sigma = (FWHM / deltax) / conversionfactor flux = spectrum.flux convolved_flux = gaussian_filter1d(flux, sigma, axis=0, order=0) return Spectrum1D.from_array(spectrum.dispersion, convolved_flux, dispersion_unit=spectrum.dispersion.unit, unit=spectrum.unit)
def __call__(self,spectrum): R = self.resolution Lambda = self.central_wavelength.value wavelength = spectrum.dispersion.value conversionfactor = 2 * np.sqrt(2 * np.log(2)) deltax = np.mean(wavelength[1:] - wavelength[0:-1]) FWHM = Lambda/R sigma = (FWHM/deltax)/conversionfactor flux = spectrum.flux convolved_flux = gaussian_filter1d(flux, sigma, axis=0, order=0) return Spectrum1D.from_array( spectrum.dispersion, convolved_flux, dispersion_unit=spectrum.dispersion.unit, unit=spectrum.unit)
def eval(self, teff, logg, feh): """ Interpolating on the grid to the necessary parameters Parameters ---------- teff: float effective temperature logg: float base ten logarithm of surface gravity in cgs feh: float [Fe/H] """ flux = self.interpolate_grid(teff, logg, feh) return Spectrum1D.from_array(self.wavelength, flux, dispersion_unit=u.angstrom, unit=u.Unit('erg/ (cm2 s Angstrom)'))
def eval(self, *args): """ Interpolating on the grid to the necessary parameters Parameters ---------- teff: float effective temperature logg: float base ten logarithm of surface gravity in cgs feh: float [Fe/H] """ flux = self.interpolate_grid(*args) return Spectrum1D.from_array(self.wavelength.value, flux, dispersion_unit=self.wavelength.unit, unit=self.flux_unit)
def __call__(self, model): # V[:,0]=mfi/e, Vp[:,1]=mfi/e*w, .., Vp[:,npol]=mfi/e*w**npol V = self._Vp * (model.flux / self.uncertainty)[:, np.newaxis] # normalizes different powers scl = np.sqrt((V * V).sum(0)) if np.isfinite(scl[0].value): # check for validity before evaluating sol, resids, rank, s = np.linalg.lstsq(V / scl, self.signal_to_noise, self._rcond) sol = (sol.T / scl).T if rank != self._Vp.shape[-1] - 1: msg = "The fit may be poorly conditioned" warnings.warn(msg) fit = np.dot(V, sol) * self.uncertainty # keep coefficients in case the outside wants to look at it self.polynomial = Polynomial(sol, domain=self.domain.value, window=self.window.value) return Spectrum1D.from_array(model.wavelength.value, fit) else: return model
def __call__(self, model): # V[:,0]=mfi/e, Vp[:,1]=mfi/e*w, .., Vp[:,npol]=mfi/e*w**npol V = self._Vp * (model.flux / self.uncertainty)[:, np.newaxis] # normalizes different powers scl = np.sqrt((V*V).sum(0)) if np.isfinite(scl[0].value): # check for validity before evaluating sol, resids, rank, s = np.linalg.lstsq(V/scl, self.signal_to_noise, self._rcond) sol = (sol.T / scl).T if rank != self._Vp.shape[-1] - 1: msg = "The fit may be poorly conditioned" warnings.warn(msg) fit = np.dot(V, sol) * self.uncertainty # keep coefficients in case the outside wants to look at it self.polynomial = Polynomial(sol, domain=self.domain.value, window=self.window.value) return Spectrum1D.from_array( model.wavelength.value, fit) else: return model
def __call__(self, spectrum): doppler_factor = 1. + (self.vrad / const.c) return Spectrum1D.from_array(spectrum.wavelength * doppler_factor, spectrum.flux)
def __call__(self, spectrum): doppler_factor = 1. + self.vrad / const.c return Spectrum1D.from_array(spectrum.wavelength * doppler_factor, spectrum.flux, dispersion_unit=spectrum.wavelength.unit)
def __call__(self): return Spectrum1D.from_array(self.wavelength, self._interpolate_flux())