def voigtfunc_and_jac(vwave, vpars, convolve_jac=True): ### Check to see if cfg variables are set if isinstance(cfg.fitidx, int) | isinstance(cfg.wave, int): cfg.fitidx = fitpix(vwave, vpars) cfg.wave = vwave if len(cfg.lsfs) == 0: makevoigt.get_lsfs() g, dg_dcol, dg_dv, dg_db = makevoigt.voigt_and_jac(vwave[cfg.fitidx], vpars[0], vpars[1], vpars[2], vpars[3], vpars[4]) g_full = np.ones(len(vwave)) g_full[cfg.fitidx] = g convfactor = makevoigt.convolvecos(vwave, g_full, vpars[0], vpars[3]) jac = np.vstack([dg_dcol, dg_db, dg_dv]) jac_full = np.zeros([jac.shape[0], len(vwave)]) jac_full[:, cfg.fitidx] = jac # might be better to wait to do the convolution until after things are agglomerated if convolve_jac: for e, row in enumerate(jac_full): # minus 1 plus 1 because convolvecos pads with 1s jac_full[e] = makevoigt.convolvecos(vwave, 1 + row, vpars[0], vpars[3]) - 1 return convfactor, jac_full
def stevevoigterrfunc_w_jac(x, xall0, notfixed, indices, wavelength, flux, sig): xall = xall0.copy() xall[notfixed] = x[indices] folded_xall = np.asarray(foldpars(xall)) model, jac = voigtfunc_and_jac(wavelength, folded_xall, convolve_jac=False) status = 0 residuals = (flux[cfg.fitidx] - model[cfg.fitidx]) / sig[cfg.fitidx] jac = jac[:, cfg.fitidx].reshape([3, -1, len(residuals)]) jac_x = np.zeros([len(x), jac.shape[2]]) line_inds, var_inds = np.unravel_index(notfixed, folded_xall.T.shape) var_ind_mapping_dict = {1: 0, 2: 1, 4: 2} for x_ind, line_ind, var_ind in zip(indices, line_inds, var_inds): jac_x[x_ind] += jac[var_ind_mapping_dict[var_ind], line_ind] jac_full = np.zeros([len(x), len(wavelength)]) jac_full[:, cfg.fitidx] = jac_x for row_e, row in enumerate(jac_full): jac_full[row_e] = makevoigt.convolvecos(wavelength, row + 1, None, None) - 1 jac_x = jac_full[:, cfg.fitidx] jac_x /= sig[cfg.fitidx] jac_x *= -1 try: residuals = residuals.value except AttributeError: pass return residuals, jac_x
def voigtfunc(vwave,vpars): ### Check to see if cfg variables are set if isinstance(cfg.fitidx, int)|isinstance(cfg.wave, int): cfg.fitidx = fitpix(vwave, vpars) cfg.wave = vwave if len(cfg.lsfs) == 0: makevoigt.get_lsfs() vflux=np.zeros(len(vwave))+1. factor=makevoigt.voigt(vwave,vpars[0],vpars[1],vpars[2],vpars[3],vpars[4]) convfactor=makevoigt.convolvecos(vwave,factor,vpars[0],vpars[3]) vflux*=convfactor return vflux