コード例 #1
0
ファイル: tools.py プロジェクト: zimmerst/CRLikelihood
def addTargetSetToCatalog(catalog,config):
    # returns a catalog which includes the target set
    from uw.like.roi_catalogs import SourceCatalog
    from skymaps import SkyDir
    from dsphs.base.target import load_targets_from_config

    if not isinstance(catalog,SourceCatalog):
        raise Exception("before merging, catalog must be source catalog")
    if config['randomize']['profile'] is None: 
        config['randomize']['profile']='point'
        print RuntimeWarning("no randomize.profile chosen, falling back to point")
    if config['randomize']['vetoyaml'] is None:
        # do nothing. 
        return catalog
    cfg = copy.deepcopy(config)
    del config
    # work entirely on 2nd config.
    cfg['targetfile'] = cfg['randomize']['vetoyaml'] 
    target_set = load_targets_from_config(cfg) # this one load what's in vetoyaml
    target_set.set_profile(cfg['randomize']['profile'])
    print 'loaded %i sources with profile %s'%(len(target_set),cfg['randomize']['profile'])
    tlist = [t.get_source_model(profile=cfg['randomize']['profile']) for t in target_set]
    ps, ds = [], []
    if cfg['randomize']['profile']=="point": ps = tlist
    else: ds = tlist
    #print ps, ds
    print 'merging %i sources with catalog containing %i sources'%(len(target_set),
                                                                 len(catalog.get_sources(SkyDir(0,0,SkyDir.GALACTIC),radius=180.)))
    cnew = catalog.merge_lists(SkyDir(0,0,SkyDir.GALACTIC),radius=180.,user_point_list=ps,user_diffuse_list=ds)
    catalog.sources = cnew[0]+cnew[1] # joint catalogs
    del cfg # cleanup
    print 'size after merger %i'%len(catalog.sources)
    return catalog
コード例 #2
0
ファイル: Spectrum.py プロジェクト: zimmerst/CRLikelihood
# logLike3 -- likelihood with user-defined SED input file

sedfiles = [sedfile]
suffixes = ['logLike2']
decay = False
if config['decay']:
    print '*DECAY mode requested*'
    decay = True
if opts.seddir is not None:
    sedfiles += [join(opts.seddir,"analysis/%s/pwl/%s/%s_sed.yaml"%
                      (opts.target,sed_index,opts.target))]
    suffixes += ['logLike3']
    
for sedfile, suffix in zip(sedfiles,suffixes):

    TARGETS = load_targets_from_config(config)
    jnominal = TARGETS[opts.target].get_safe_jvalue(profile)
    target = TARGETS[opts.target]

    workdir=join(basedir,"analysis/%s/%s/"%(target,opts.spectrum))
    
    # Form of the likelihood function
    fntypes = ['lgauss','lgauss_like','lgauss']

    # Methods
    methods = ['profile','profile','marginalize']

    # Apply correction to J factor
    rescale = [True, False, False]
    
    # Create an array of target sets with randomized J values