Exemple #1
0
    def __init__(self, freq_dict):
        """
        Initialize the various parameters defining the redshiftedgroup transitions

        freq_dict - frequencies of the indvidual transitions indexed by name
        """
        self.freq_dict = freq_dict

        self.fitter = model.SpectralModel(
            self,
            3,
            parnames=['amp', 'center', 'width'],
            parlimited=[(False, False), (False, False), (True, False)],
            parlimits=[(0, 0), (0, 0), (0, 0)],
            shortvarnames=(
                "A", "v",
                "\\sigma"),  # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.vheight_fitter = model.SpectralModel(
            fitter.vheightmodel(self),
            4,
            parnames=['height', 'amp', 'center', 'width'],
            parlimited=[(False, False), (False, False), (True, False),
                        (False, False), (True, False)],
            parlimits=[(0, 0), (0, 0), (0, 0), (0, 0)],
            shortvarnames=(
                "H", "A", "v",
                "\\sigma"),  # specify the parameter names (TeX is OK)
            fitunits='Hz')
Exemple #2
0
def lorentzian_fitter():
    """
    Generator for lorentzian fitter class
    """

    myclass =  model.SpectralModel(lorentzian, 3,
            parnames=['amplitude','shift','width'], 
            parlimited=[(False,False),(False,False),(True,False)], 
            parlimits=[(0,0), (0,0), (0,0)],
            shortvarnames=('A',r'\Delta x',r'\sigma'),
            )
    myclass.__name__ = "lorentzian"
    
    return myclass
Exemple #3
0
def powerlaw_fitter(order=1):
    """
    Generator for powerlaw fitter class
    """

    myclass = model.SpectralModel(powerlaw,
                                  2,
                                  parnames=['scale', 'power'],
                                  parlimited=[(False, False), (False, False)],
                                  parlimits=[(0, 0), (0, 0)],
                                  shortvarnames=('S', 'P'))
    myclass.__name__ = "powerlaw"

    return myclass
Exemple #4
0
def poly_fitter(order=1):
    """
    Generator for polynomial fitter class
    """

    myclass = model.SpectralModel(
        polymodel,
        order + 1,
        parnames=['coeff%i' % ii for ii in xrange(order + 1)],
        parlimited=[(False, False) for ii in xrange(order + 1)],
        parlimits=[(0, 0) for ii in xrange(order + 1)],
        shortvarnames=['C%i' % ii for ii in xrange(order + 1)])
    myclass.__name__ = "polymodel"

    return myclass
def gaussian_vheight_fitter():
    """
    Generator for Gaussian fitter class
    """

    vhg = fitter.vheightmodel(gaussian)
    myclass =  model.SpectralModel(vhg, 4,
            parnames=['height','amplitude','shift','width'], 
            parlimited=[(False,False),(False,False),(False,False),(True,False)], 
            parlimits=[(0,0),(0,0), (0,0), (0,0)],
            shortvarnames=('B','A',r'\Delta x',r'\sigma'),
            centroid_par='shift',
            fwhm_func=gaussian_fwhm,
            fwhm_pars=['width'],
            )
    myclass.__name__ = "vheightgaussian"
    
    return myclass
def gaussian_fitter():
    """
    Generator for Gaussian fitter class
    """

    myclass =  model.SpectralModel(gaussian, 3,
            parnames=['amplitude','shift','width'], 
            parlimited=[(False,False),(False,False),(True,False)], 
            parlimits=[(0,0), (0,0), (0,0)],
            shortvarnames=('A',r'\Delta x',r'\sigma'),
            centroid_par='shift',
            fwhm_func=gaussian_fwhm,
            fwhm_pars=['width'],
            integral_func=_integral_modelpars,
            )
    myclass.__name__ = "gaussian"
    
    return myclass
def voigt_fitter():
    """
    Generator for voigt fitter class
    """

    myclass =  model.SpectralModel(voigt, 4,
            parnames=['amplitude','shift','gwidth','lwidth'], 
            parlimited=[(False,False),(False,False),(True,False),(True,False)], 
            parlimits=[(0,0), (0,0), (0,0), (0,0)],
            shortvarnames=('A',r'\Delta x',r'\sigma_G',r'\sigma_L'),
            centroid_par='shift',
            fwhm_func=voigt_fwhm,
            fwhm_pars=['gwidth','lwidth'],
            )
    myclass.__name__ = "voigt"
    myclass.moments = types.MethodType(voigt_moments, myclass,
                                       myclass.__class__)
    
    return myclass
def voigt_fitter(multisingle='multi'):
    """
    Generator for voigt fitter class
    """

    myclass = model.SpectralModel(
        voigt,
        4,
        parnames=['amplitude', 'shift', 'gwidth', 'lwidth'],
        parlimited=[(False, False), (False, False), (True, False),
                    (True, False)],
        parlimits=[(0, 0), (0, 0), (0, 0), (0, 0)],
        shortvarnames=('A', r'\Delta x', r'\sigma_G', r'\sigma_L'),
        multisingle=multisingle,
        centroid_par='shift',
        fwhm_func=voigt_fwhm,
        fwhm_pars=['gwidth', 'lwidth'],
    )
    myclass.__name__ = "voigt"

    return myclass
Exemple #9
0
def template_fitter(template_spectrum, xshift_units='km/s'):
    """
    Generator for Spectral Template fitter class

    Parameters
    ----------
    template_spectrum : pyspeckit.Spectrum
        A valid spectrum to be scaled and shifted to match the input
    xshift_units : str in pyspeckit.units.unit_type_dict
        The units of the shift to fit.  If you're using a velocity unit, make
        sure there's a reference X-unit for both the template spectrum and the
        input spectrum.

    Examples
    --------
    >>> template = pyspeckit.Spectrum("template_spectrum.fits")
    >>> dataspec = pyspeckit.Spectrum("DataSpectrum.fits")
    >>> template_fitter = pyspeckit.models.template_fitter(template,
    ...                                                    xshift_units='angstroms')
    >>> dataspec.Registry.add_fitter('template',template_fitter, 2)
    >>> dataspec.specfit(fittype='template',guesses=[1,0])
    >>> print dataspec.specfit.parinfo
    """

    modelfunc = spectral_template_generator(template_spectrum,
                                            xshift_units=xshift_units)

    myclass = model.SpectralModel(
        modelfunc,
        2,
        parnames=['scale', 'shift'],
        parlimited=[(True, False), (False, False)],
        parlimits=[(0, 0), (0, 0)],
        shortvarnames=('A', r'\Delta x'),
        centroid_par='shift',
    )
    myclass.__name__ = "spectral_template"

    return myclass
    def __init__(self, line_names, voff_lines_dict, freq_dict,
                 line_strength_dict, relative_strength_total_degeneracy):
        """
        Initialize the various parameters defining the hyperfine transitions

        Parameters
        ----------
        line_names: list
            list of the line names to be used as indices for the dictionaries
        voff_lines_dict: dict
            a linename:v_off dictionary of velocity offsets for the hyperfine
            components.  Technically, this is redundant with freq_dict
        freq_dict: dict
            frequencies of the indvidual transitions
        line_strength_dict: dict
            Relative strengths of the hyperfine components, usually determined
            by their degeneracy and Einstein A coefficients
        """
        self.line_names = line_names
        self.voff_lines_dict = voff_lines_dict
        self.freq_dict = freq_dict
        self.line_strength_dict = line_strength_dict
        self.relative_strength_total_degeneracy = relative_strength_total_degeneracy

        self.fitter = model.SpectralModel(
            self,
            4,
            parnames=['Tex', 'tau', 'center', 'width'],
            parlimited=[(False, False), (True, False), (False, False),
                        (True, False)],
            parlimits=[(0, 0), (0, 0), (0, 0), (0, 0)],
            shortvarnames=(
                "T_{ex}", "\\tau", "v",
                "\\sigma"),  # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.nlines = len(line_names)

        self.varyhf_fitter = model.SpectralModel(
            self.hyperfine_varyhf,
            3 + self.nlines,
            parnames=['Tex', 'center', 'width'] +
            ['tau%s' % k for k in self.line_names],
            parlimited=[(False, False), (False, False), (True, False)] + [
                (True, False),
            ] * self.nlines,
            parlimits=[(0, 0), (0, 0), (0, 0)] + [
                (0, 0),
            ] * self.nlines,
            shortvarnames=("T_{ex}", "v", "\\sigma") + tuple(
                ("\\tau(\\mathrm{%s})" % k for k in self.line_names)),
            # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.varyhf_amp_fitter = model.SpectralModel(
            self.hyperfine_varyhf_amp,
            2 + self.nlines,
            parnames=['center', 'width'] +
            ['amp%s' % k for k in self.line_names],
            parlimited=[(False, False), (True, False)] + [
                (True, False),
            ] * self.nlines,
            parlimits=[(0, 0), (0, 0)] + [
                (0, 0),
            ] * self.nlines,
            shortvarnames=("v", "\\sigma") + tuple(
                ("amp(\\mathrm{%s})" % k for k in self.line_names)),
            # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.varyhf_amp_width_fitter = model.SpectralModel(
            self.hyperfine_varyhf_amp_width,
            1 + self.nlines * 2,
            parnames=['center'] + ['amp%s' % k for k in self.line_names] +
            ['width%s' % k for k in self.line_names],
            parlimited=[(False, False)] + [
                (True, False),
            ] * self.nlines + [(True, False)] * self.nlines,
            parlimits=[(0, 0)] + [
                (0, 0),
            ] * self.nlines * 2,
            shortvarnames=(("v", ) + tuple(
                ("amp(\\mathrm{%s})" % k for k in self.line_names)) + tuple(
                    ("\\sigma(\\mathrm{%s})" % k for k in self.line_names))),
            # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.vheight_fitter = model.SpectralModel(
            fitter.vheightmodel(self),
            5,
            parnames=['height', 'Tex', 'tau', 'center', 'width'],
            parlimited=[(False, False), (False, False), (True, False),
                        (False, False), (True, False)],
            parlimits=[(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)],
            shortvarnames=(
                "H", "T_{ex}", "\\tau", "v",
                "\\sigma"),  # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.background_fitter = model.SpectralModel(
            self.hyperfine_addbackground,
            5,
            parnames=['Tbackground', 'Tex', 'tau', 'center', 'width'],
            parlimited=[(True, False), (False, False), (False, False),
                        (True, False), (False, False), (True, False)],
            parlimits=[(0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)],
            shortvarnames=(
                'T_{BG}', "T_{ex}", "\\tau", "v",
                "\\sigma"),  # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.ampfitter = model.SpectralModel(
            self.hyperfine_amp,
            3,
            parnames=['amp', 'center', 'width'],
            parlimited=[(False, False), (False, False), (True, False)],
            parlimits=[(0, 0), (0, 0), (0, 0)],
            shortvarnames=(
                "amp", "v",
                "\\sigma"),  # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.taufitter = model.SpectralModel(
            self.hyperfine_tau,
            3,
            parnames=['tau', 'center', 'width'],
            parlimited=[(True, False), (False, False), (True, False)],
            parlimits=[(0, 0), (0, 0), (0, 0)],
            shortvarnames=(
                r'\tau', "v",
                "\\sigma"),  # specify the parameter names (TeX is OK)
            fitunits='Hz')

        self.totaltaufitter = model.SpectralModel(
            self.hyperfine_tau_total,
            3,
            parnames=['tau', 'center', 'width'],
            parlimited=[(True, False), (False, False), (True, False)],
            parlimits=[(0, 0), (0, 0), (0, 0)],
            shortvarnames=(
                r'\tau', "v",
                "\\sigma"),  # specify the parameter names (TeX is OK)
            fitunits='Hz')
    return hill_array


def jfunc(t, nu):
    """
    t- kelvin
    nu - Hz?
    """

    H = 6.6260755e-27
    K = 1.380658e-16
    NSIG = 2.0

    # I think this is only necessary for C
    #if(nu<1.0e-6) return t

    to = H * nu / K
    return to / (np.exp(to / t) - 1.0)


hill5_fitter = model.SpectralModel(
    hill5_model,
    5,
    parnames=['tau', 'v_lsr', 'v_infall', 'sigma', 'tpeak'],
    parlimited=[(True, False), (False, False), (True, False), (True, False),
                (True, False)],
    parlimits=[(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)],
    shortvarnames=("\\tau", "v_{lsr}", "v_{infall}", "\\sigma",
                   "T_{peak}"),  # specify the parameter names (TeX is OK)
    fitunits='Hz')