Ejemplo n.º 1
0
    def link(self, par):
        datasets = self.filter_datasets()
        name, parname = par.split('.')

        fullparname0 = '{0}.{1}'.format(datasets[0]['model_comps'][name]['model_name'], parname)
        for dataset in datasets[1:]:
            fullparname = '{0}.{1}'.format(dataset['model_comps'][name]['model_name'], parname)
            if fullparname != fullparname0:
                logger.info('Linking {0} => {1}'.format(fullparname, fullparname0))
                ui.link(fullparname, fullparname0)
Ejemplo n.º 2
0
    def link(self, par):
        datasets = self.filter_datasets()
        name, parname = par.split('.')

        fullparname0 = '{0}.{1}'.format(datasets[0]['model_comps'][name]['model_name'], parname)
        for dataset in datasets[1:]:
            fullparname = '{0}.{1}'.format(dataset['model_comps'][name]['model_name'], parname)
            if fullparname != fullparname0:
                logger.info('Linking {0} => {1}'.format(fullparname, fullparname0))
                ui.link(fullparname, fullparname0)
Ejemplo n.º 3
0
    def tie_par(self, par, base, *others):
        """Tie parameters in one or more shells to the base shell.

        This is a limited form of the Sherpa ability to link parameters,
        since it sets the parameter in the other shells to the same
        value as the parameter in the base shell. More complex
        situations will require direct calls to `sherpa.astro.ui.link`.

        Parameters
        ----------
        par : str
            The parameter specifier, as <model_type>.<par_name>.
        base : int
            The base shell number.
        *others : scalar
            The shell, or shells to link to the base shell.

        See Also
        --------
        set_par, untie_par

        Examples
        --------

        Tie the temperature and abundance parameters in shell 9 to that
        in shell 8, so that any fits will set the shell 9 values to those
        used in shell 8 (so reducing the number of free parameters in the
        fit).

        >>> dep.tie_par('xsapec.kt', 8, 9)
        Tying xsapec_9.kT to xsapec_8.kT
        >>> dep.tie_par('xsapec.abundanc', 8, 9)
        Tying xsapec_9.Abundanc to xsapec_8.Abundanc

        Tie three annuli together:

        >>> dep.tie_par('xsapec.kt', 12, 13, 14)
        Tying xsapec_13.kT to xsapec_12.kT
        Tying xsapec_14.kT to xsapec_12.kT

        """

        bpar = self._find_shell_par(par, base)

        for other in others:
            opar = self._find_shell_par(par, other)
            print('Tying {} to {}'.format(opar.fullname, bpar.fullname))
            ui.link(opar, bpar)
Ejemplo n.º 4
0
def fixBkgModel(id=1, freeNorm=True):
    """
    Fix the background model
    Paramaters:
    freeNorm = True
        If freeNorm is True, leave the overall background normalization free.
    """
    bk = ui.get_bkg_model(id=id)
    if freeNorm:
        pars = bk.pars
        c0 = pars[0]
        for p in pars[1:]:
            if p.val != 0 and p.fullname.startswith('pca'):
                ui.link(p, p.val / c0.val * c0)
            else:
                ui.freeze(p)
    else:
        ui.freeze(bk)
Ejemplo n.º 5
0
def fit_lines(linelist, id = None, delta_lam = .2, plot = False, outfile = None):
    mymodel = filili.multilinemanager.GaussLines('const1d', id = id, baseline = baseline)
    linelist['fililiname'] = [''] * len(linelist['linename'])
    for i in range(len(linelist['linename'])):
        lname = linelist['linename'][i]
        lwave = linelist['wave'][i]
        previouslines = set(mymodel.line_name_list())
        mymodel.add_line(linename = filter(lambda x: x.isalnum(), lname), pos = lwave)
        linenamelist = mymodel.line_name_list()
        newline = (set(linenamelist) - previouslines).pop()
        linelist['fililiname'][i] = newline
        if i ==0:
            firstline = linenamelist[0]
            ui.get_model_component(firstline).pos.max = lwave + delta_lam/10.
            ui.get_model_component(firstline).pos.min = lwave - delta_lam/10.
        else:
            dl = lwave - linelist['wave'][0]
            ui.link(ui.get_model_component(newline).pos, ui.get_model_component(firstline).pos + dl)
    
    #ui.set_analysis("wave")
    ui.ignore(None, None) #ignores all data
    ui.notice(min(linelist['wave'])-delta_lam, max(linelist['wave']) + delta_lam)
    ui.fit(id)
    if plot:
        ui.plot_fit(id)
        if has_chips:
            pychips.set_curve("crv1",["err.*","true"])
            pychips.set_plot_title(linelist['name'])
            if outfile is not None:
                pychips.print_window(outfile, ['clobber','true'])
        elif has_mpl:
            plt.title(linelist['name'])
            if outfile is not None:
                plt.savefig(outfile)
        else:
            raise NoPlottingSystemError("Neither pychips nor matplotlib are found.")
Ejemplo n.º 6
0
    def link(self, par):
        """Link the parameter across the data stacks.

        Link all occurences of the model parameter to the value in the
        first dataset in the stack.

        Parameters
        ----------
        par : string
           Parameter name, in the format "<model_type>.<par_name>".
        """
        datasets = self.filter_datasets()
        name, parname = par.split('.')

        def _name(dset):
            return dset['model_comps'][name]['model_name']

        fullparname0 = '{0}.{1}'.format(_name(datasets[0]), parname)
        for dataset in datasets[1:]:
            fullparname = '{0}.{1}'.format(_name(dataset), parname)
            if fullparname != fullparname0:
                logger.info('Linking {0} => {1}'.format(fullparname,
                                                        fullparname0))
                ui.link(fullparname, fullparname0)
Ejemplo n.º 7
0
    def link(self, par):
        """Link the parameter across the data stacks.

        Link all occurences of the model parameter to the value in the
        first dataset in the stack.

        Parameters
        ----------
        par : string
           Parameter name, in the format "<model_type>.<par_name>".
        """
        datasets = self.filter_datasets()
        name, parname = par.split('.')

        def _name(dset):
            return dset['model_comps'][name]['model_name']

        fullparname0 = '{0}.{1}'.format(_name(datasets[0]), parname)
        for dataset in datasets[1:]:
            fullparname = '{0}.{1}'.format(_name(dataset), parname)
            if fullparname != fullparname0:
                logger.info('Linking {0} => {1}'.format(fullparname,
                                                        fullparname0))
                ui.link(fullparname, fullparname0)
Ejemplo n.º 8
0
    from astropy.io import fits
except:
    import pyfits as fits

filename = 'skymap_ex.fits'
nomposstr = '05h34m31.94s 22d00m52.2s'
header = fits.getheader(filename)
proj = wcs.Projection(header)
xc, yc = float(header['NAXIS1']) / 2., float(header['NAXIS2']) / 2.
ui.load_image(filename)
ui.notice2d('circle({0}, {1}, {2})'.format(xc, yc, float(header['NAXIS2']) / 4.))
ui.set_source(ui.gauss2d.g1 + ui.gauss2d.g2)
g1.xpos = xc
g1.ypos = yc
g2.fwhm = g1.fwhm = 3.
ui.link(g2.xpos, g1.xpos)
ui.link(g2.ypos, g1.ypos)
g2.ampl = 50.
g1.ampl = 50.
ui.guess()
ui.fit()
ui.image_fit()
ui.covar()
conf = ui.get_covar_results()
conf_dict = dict([(n,(v, l, h)) for n,v,l,h in
                   zip(conf.parnames, conf.parvals, conf.parmins, conf.parmaxes)])
x, y = proj.toworld((conf_dict['g1.xpos'][0], conf_dict['g1.ypos'][0]))
xmin, ymin = proj.toworld((conf_dict['g1.xpos'][0] + conf_dict['g1.xpos'][1],
                           conf_dict['g1.ypos'][0] + conf_dict['g1.ypos'][1]))
xmax, ymax = proj.toworld((conf_dict['g1.xpos'][0] + conf_dict['g1.xpos'][2],
                           conf_dict['g1.ypos'][0] + conf_dict['g1.ypos'][2]))
Ejemplo n.º 9
0
except:
    import pyfits as fits

filename = 'skymap_ex.fits'
nomposstr = '05h34m31.94s 22d00m52.2s'
header = fits.getheader(filename)
proj = wcs.Projection(header)
xc, yc = float(header['NAXIS1']) / 2., float(header['NAXIS2']) / 2.
ui.load_image(filename)
ui.notice2d('circle({0}, {1}, {2})'.format(xc, yc,
                                           float(header['NAXIS2']) / 4.))
ui.set_source(ui.gauss2d.g1 + ui.gauss2d.g2)
g1.xpos = xc
g1.ypos = yc
g2.fwhm = g1.fwhm = 3.
ui.link(g2.xpos, g1.xpos)
ui.link(g2.ypos, g1.ypos)
g2.ampl = 50.
g1.ampl = 50.
ui.guess()
ui.fit()
ui.image_fit()
ui.covar()
conf = ui.get_covar_results()
conf_dict = dict([(n, (v, l, h)) for n, v, l, h in zip(
    conf.parnames, conf.parvals, conf.parmins, conf.parmaxes)])
x, y = proj.toworld((conf_dict['g1.xpos'][0], conf_dict['g1.ypos'][0]))
xmin, ymin = proj.toworld((conf_dict['g1.xpos'][0] + conf_dict['g1.xpos'][1],
                           conf_dict['g1.ypos'][0] + conf_dict['g1.ypos'][1]))
xmax, ymax = proj.toworld((conf_dict['g1.xpos'][0] + conf_dict['g1.xpos'][2],
                           conf_dict['g1.ypos'][0] + conf_dict['g1.ypos'][2]))