Exemple #1
0
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
Exemple #2
0
def model_profile(spec,
                  fitpars,
                  instr=None,
                  gratings=None,
                  lsfranges=None,
                  cen_wave=None,
                  lps=None,
                  slits=None):
    '''Produce Voigt profile model from parameters and instrumental setup for
    convolving proper line spread function.  Note

    Parameters
    ----------
    spec : string or XSpectrum1D
        The spectrum to be fitted with the input lines
    fitpars : list of lists
        The joebvp parameter array that includes line measurements
    instr : list of str, optional
        Instruments used to observe the spectral regions defined in lsfranges
    gratings : list of str, optional
        Gratings used for each spectral region defined in lsfranges
    lsfranges : array of size len(instr)x2
        Beginning and ending wavelengths of spectral ranges for each setup
    cen_wave : list of str, optional
        Central wavelength setting for each spectral region defined in lsfranges
    lps : list of str, optional
        Lifetime positions of detector (particularly for COS)
    slits : list of str, optional
        Slit setting for each spectral region defined in lsfranges

    Returns
    -------
    wavelength : Quantity
        Wavelength array from spec
    profile : array
        Voigt profile model

    '''

    ### Setup LSF parameters if provided
    if instr is not None:
        cfg.instr = instr
        cfg.lsfranges = lsfranges
        cfg.gratings = gratings
        cfg.cen_wave = cen_wave
        cfg.lps = lps
        cfg.slits = slits

    ### Deal with alternate input types
    if isinstance(spec, str):
        specobj = readspec(spec)
    else:
        specobj = spec

    makevoigt.get_lsfs()
    #import pdb; pdb.set_trace()
    cfg.wave = specobj.wavelength.value
    cfg.spectrum = specobj
    profile = makevoigt.cosvoigt(cfg.wave, fitpars)
    return specobj.wavelength, profile
Exemple #3
0
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