def setup_roi(name, snrdata, catalog_dict=dict(), roi_dict=dict()): snr=yaml.load(open(snrdata))[name] skydir=SkyDir(*snr['cel']) size=snr['size'] ds=DataSpecification( ft1files='$FERMILANDE/data/PWNCAT2/nov_30_2011/ft1_PWNCAT2_allsky.fits', ft2files='$FERMILANDE/data/PWNCAT2/nov_30_2011/ft2_PWNCAT2_allsky.fits', ltcube='$FERMILANDE/data/PWNCAT2/nov_30_2011/ltcube_PWNCAT2_allsky.fits', binfile='$FERMILANDE/data/PWNCAT2/nov_30_2011/binned_%s.fits' % 4) sa=SpectralAnalysis(ds, binsperdec = 4, roi_dir = skydir, irf = 'P7SOURCE_V6', maxROI = 10, minROI = 10, event_class = 0) diffuse_sources = diffuse_sources = get_default_diffuse( diffdir=e('$FERMILANDE/diffuse'), gfile='ring_2year_P76_v0.fits', ifile='isotrop_2year_P76_source_v0.txt') catalogs = Catalog2FGL('$FERMILANDE/catalogs/gll_psc_v05.fit', latextdir='$FERMILANDE/extended_archives/gll_psc_v05_templates/', **catalog_dict) roi = sa.roi( catalogs = catalogs, diffuse_sources = diffuse_sources, **roi_dict) return roi
import base64 import getpass import polib import xmlrpc.client as xmlrpclib import os import glob from os.path import expanduser as e # connection information host = '127.0.0.1' port = 8069 # paths to community and enterprise modules BASE_MODULE_PATH = [ e('~/odoo/odoo/openerp/addons/base/i18n'), e('~/odoo/odoo/odoo/addons/base/i18n') ] ADDONS_PATH = e('~/odoo/odoo/addons/') TXPATH = e('~/odoo/odoo/.tx/config') ENT_ADDONS_PATH = e('~/odoo/enterprise/') ENT_TXPATH = e('~/odoo/enterprise/.tx/config') THEME_PATH = e('~/odoo/design-themes/') THEME_TXPATH = e('~/odoo/design-themes/.tx/config') l = glob.glob(os.path.join(ADDONS_PATH, '*/__init__.py')) # without 'web' as is in enterprise and breaks if more than one 'theme_' ADDONS_1 = [ os.path.basename(os.path.dirname(i)) for i in l if ( # 'l10n_' not in i and # 'theme_' not in i and
def setup_pwn(name,pwndata,phase, free_radius=5, tempdir=None, emin=1.0e2, emax=1.0e5,maxroi=10,model=None,**kwargs): """Name of the source pwndata Yaml file returns pointlike ROI. """ sources=yaml.load(open(pwndata)) catalog_name=sources[name]['catalog'] ltcube=sources[name]['ltcube'] pulsar_position=SkyDir(*sources[name]['dir']) ft2=sources[name]['ft2'] ft1=sources[name]['ft1'] # in case no list was passed if len(phase)==2 and isinstance(phase[0],numbers.Real) and \ isinstance(phase[1],numbers.Real): # write in case phase wraps around. if phase[0]>phase[1]: phase=[[phase[0],1.0],[0.0,phase[1]]] else: phase = [phase] phase_factor=get_phase_factor(phase) print "phase" print phase print "phase_factor=%.2f"%phase_factor catalog=FermiCatalog(e("$FERMI/catalogs/gll_psc_v02.fit"),free_radius=free_radius) catalog_source=[i for i in catalog.get_sources(SkyDir(),180) if i.name==catalog_name][0] center=catalog_source.skydir if tempdir is None: tempdir=mkdtemp(prefix='/scratch/') binfile=j(tempdir,'binned_phased.fits') # apply phase cut to ft1 file phased_ft1 = j(tempdir,'ft1_phased.fits') phasetools.phase_cut(ft1,phased_ft1,phaseranges=phase) # create a temporary ltcube scaled by the phase factor # phased_ltcube=j(tempdir,'phased_ltcube.fits') # phase_ltcube(ltcube,phased_ltcube, phase=phase) phased_ltcube=ltcube from uw.like.pointspec import DataSpecification data_specification = DataSpecification( ft1files = phased_ft1, ft2files = ft2, ltcube = phased_ltcube, binfile = binfile) spectral_analysis = SpectralAnalysis(data_specification, binsperdec = 4, emin = 100, emax = 100000, irf = "P6_V3_DIFFUSE", roi_dir = center, maxROI = maxroi, minROI = maxroi) if model == None : roi=spectral_analysis.roi( roi_dir=center, diffuse_sources=get_default_diffuse(diffdir=e("$FERMI/diffuse"), gfile="gll_iem_v02.fit", ifile="isotropic_iem_v02.txt"), catalogs = catalog, phase_factor = 1.0, fit_emin = [emin,emin], fit_emax = [emax,emax], **kwargs) else : roi=spectral_analysis.roi( roi_dir=center, xmlfile = model, phase_factor =1.0, fit_emin = [emin,emin], fit_emax = [emax,emax], **kwargs) print "---------------------Energy range--------------------" print "emin="+str(roi.bands[0].emin)+"\n" print "emax="+str(roi.bands[len(roi.bands)-1].emax)+"\n" # keep overall flux of catalog source, # but change the starting index to 2. roi.modify(which=catalog_name, name=name, index=2, keep_old_flux=True) return roi
import yaml import numpy as np from skymaps import SkyDir from uw.like.pointspec import DataSpecification from uw.like.pointspec_helpers import get_default_diffuse from uw.like.roi_catalogs import Catalog2FGL from lande_cache import SpectralAnalysisCache import snr_contour_loader #name='G34.7-0.4' name='G260.4-3.4' l = lambda f: yaml.load(open(e(f))) snrdata=l('$superfile/snrdata.yaml') templates=l('$superfile/snrtemplates.yaml') snr=snrdata[name] skydir=SkyDir(*snr['cel']) radius=snr['radius'] pwncat2='/nfs/slac/g/ki/ki03/lande/fermi/data/data/PWNCAT2/nov_30_2011/' ds=DataSpecification( ft1files=j(pwncat2,'ft1_PWNCAT2_allsky.fits'), binfile=j(pwncat2,'binned_4.fits'), ft2files=j(pwncat2,'ft2_PWNCAT2_allsky.fits'), ltcube=j(pwncat2,'ltcube_PWNCAT2_allsky.fits'))
def setup_pointlike(name,pwnlist,phasing=True): """Name of the source pwnlist Yaml file phasing=true : apply phase cut phasing=false : don't do it""" sources=yaml.load(open(pwnlist)) catalog_name=sources[name]['catalog'] phase=sources[name]['phase'] ltcube=sources[name]['ltcube'] pulsar_position=SkyDir(*sources[name]['dir']) if phasing==True: phase_factor=phase[1]-phase[0] if phase[1]>phase[0] else (1-phase[0]) + (phase[1]-0) ft1=sources[name]['ft1'] else : phase_factor=1.0 raise Exception("Unable to phase data") catalog=FermiCatalog(e("$FERMI/catalogs/gll_psc_v02.fit"),free_radius=5) catalog_source=[i for i in catalog.get_sources(SkyDir(),180) if i.name==catalog_name][0] center=catalog_source.skydir from uw.like.pointspec import DataSpecification data_specification = DataSpecification( ft1files = ft1, ltcube = ltcube, binfile = "binned_%s.fits" % name) spectral_analysis = SpectralAnalysis(data_specification, binsperdec = 8, emin = 100, emax = 100000, irf = "P6_V3_DIFFUSE", roi_dir = center, maxROI = 10, minROI = 10) roi=LandeROI(spectral_analysis.roi( roi_dir=center, diffuse_sources=get_default_diffuse(diffdir=e("$FERMI/diffuse"), gfile="gll_iem_v02.fit", ifile="isotropic_iem_v02.txt"), catalogs = catalog, fit_emin = 100, fit_emax = 100000, catalog_include_radius = 20, phase_factor = phase_factor) ) roi.del_source(catalog_name) # make residual TS map # add in PWN Candidate source=PointSource( name=name, model=PowerLaw(p=[1,2]), skydir=pulsar_position ) source.model.set_flux(1e-7,emin=100,emax=100000) roi.add_source(source) return roi
import argparse import base64 import getpass import xmlrpc.client as xmlrpclib import os import glob from os.path import expanduser as e # connection information host = '127.0.0.1' port = 8069 # paths to community and enterprise modules BASE_MODULE_PATH = [e('~/odoo/odoo/openerp/addons/base/i18n'), e('~/odoo/odoo/odoo/addons/base/i18n')] ADDONS_PATH = e('~/odoo/odoo/addons/') TXPATH = e('~/odoo/odoo/.tx/config') ENT_ADDONS_PATH = e('~/odoo/enterprise/') ENT_TXPATH = e('~/odoo/enterprise/.tx/config') THEME_PATH = e('~/odoo/design-themes/') THEME_TXPATH = e('~/odoo/design-themes/.tx/config') l = glob.glob(os.path.join(ADDONS_PATH, '*/__init__.py')) # without 'web' as is in enterprise and breaks if more than one 'theme_' ADDONS_1 = [os.path.basename(os.path.dirname(i)) for i in l if ( # 'l10n_' not in i and 'theme_' not in i and 'hw_' not in i )] + ['base'] ADDONS_2 = [os.path.basename(os.path.dirname(i)) for i in l if (
def setup_region(name,pwndata,phase, free_radius=5, tempdir=None, maxroi=10, xml=None, **kwargs): """Name of the source pwndata Yaml file returns pointlike ROI. """ phase = PhaseRange(phase) sources=yaml.load(open(pwndata)) catalog_name=sources[name]['catalog']['2fgl'] ltcube=sources[name]['ltcube'] pulsar_position=SkyDir(*sources[name]['dir']) ft2=sources[name]['ft2'] ft1=sources[name]['ft1'] catalog=FermiCatalog(e("$FERMI/catalogs/gll_psc_v02.fit")) catalog=Catalog2FGL('$FERMI/catalogs/gll_psc_v05.fit', latextdir='$FERMI/extended_archives/gll_psc_v05_templates', free_radius=free_radius) catalog_source=catalog.get_source(catalog_name) center=catalog_source.skydir if tempdir is None: tempdir=mkdtemp(prefix='/scratch/') binfile=j(tempdir,'binned_phased.fits') if np.allclose(phase.phase_fraction,1): phased_ltcube = ltcube phased_ft1 = ft1 else: # create a temporary ltcube scaled by the phase factor phased_ltcube=j(tempdir,'phased_ltcube.fits') phase_ltcube(ltcube,phased_ltcube, phase=phase) # apply phase cut to ft1 file phased_ft1 = j(tempdir,'ft1_phased.fits') phasetools.phase_cut(ft1,phased_ft1,phaseranges=phase.tolist(dense=False)) from uw.like.pointspec import DataSpecification ds = DataSpecification( ft1files = phased_ft1, ft2files = ft2, ltcube = phased_ltcube, binfile = binfile) sa = SpectralAnalysis(ds, binsperdec = 8, emin = 100, emax = 100000, irf = "P6_V11_DIFFUSE", roi_dir = center, maxROI = maxroi, minROI = maxroi) if xml is None: roi=sa.roi( diffuse_sources=get_default_diffuse(diffdir="/afs/slac/g/glast/groups/diffuse/mapcubes", gfile="gll_iem_v02.fit", ifile="isotropic_iem_v02.txt"), catalogs = catalog, phase_factor =1, **kwargs) else: roi=sa.roi_from_xml( roi_dir=center, xmlfile = xml, phase_factor =1, **kwargs) print 'bins ',roi.bin_edges roi.del_source(catalog_name) return roi
import xmlrpclib import os import glob from os.path import expanduser as e # connection information host = 'localhost' port = 8069 db = '9e' username = '******' password = '******' # paths to community and enterprise modules BASE_MODULE_PATH = e('~/odoo/odoo/openerp/addons/base/i18n') ADDONS_PATH = e('~/odoo/odoo/addons/') TXPATH = e('~/odoo/odoo/.tx/config') ENT_ADDONS_PATH = e('~/odoo/enterprise/') ENT_TXPATH = e('~/odoo/enterprise/.tx/config') l = glob.glob(os.path.join(ADDONS_PATH, '*/__init__.py')) # without 'web' as is in enterprise and breaks if more than one 'theme_' ADDONS_1 = [ os.path.basename(os.path.dirname(i)) for i in l if ('l10n_' not in i and 'theme_' not in i and os.path.basename(os.path.dirname(i)) != 'web') ] + ['base'] ADDONS_2 = [ os.path.basename(os.path.dirname(i)) for i in l if ('l10n_' in i and 'l10n_be' not in i and 'l10n_ch' not in i
def setup_pwn(name,pwndata,phase, free_radius=5, tempdir=None, **kwargs): """Name of the source pwndata Yaml file returns pointlike ROI. """ sources=yaml.load(open(pwndata)) catalog_name=sources[name]['catalog'] ltcube=sources[name]['ltcube'] pulsar_position=SkyDir(*sources[name]['dir']) ft2=sources[name]['ft2'] ft1=sources[name]['ft1'] # in case no list was passed if len(phase)==2 and isinstance(phase[0],numbers.Real) and \ isinstance(phase[1],numbers.Real): # write in case phase wraps around. if phase[0]>phase[1]: phase=[[phase[0],1.0],[0.0,phase[1]]] else: phase = [phase] phase_factor=get_phase_factor(phase) catalog=FermiCatalog(e("$FERMI/catalogs/gll_psc_v02.fit"),free_radius=free_radius) catalog_source=[i for i in catalog.get_sources(SkyDir(),180) if i.name==catalog_name][0] center=catalog_source.skydir if tempdir is None: tempdir=mkdtemp(prefix='/scratch/') binfile=j(tempdir,'binned_phased.fits') # apply phase cut to ft1 file phased_ft1 = j(tempdir,'ft1_phased.fits') phasetools.phase_cut(ft1,phased_ft1,phaseranges=phase) # create a temporary ltcube scaled by the phase factor # phased_ltcube=j(tempdir,'phased_ltcube.fits') # phase_ltcube(ltcube,phased_ltcube, phase=[0.0,1.0]) phased_ltcube=ltcube from uw.like.pointspec import DataSpecification data_specification = DataSpecification( ft1files = phased_ft1, ft2files = ft2, ltcube = phased_ltcube, binfile = binfile) spectral_analysis = SpectralAnalysis(data_specification, binsperdec = 4, emin = 100, emax = 100000, irf = "P6_V3_DIFFUSE", roi_dir = center, maxROI = 10, minROI = 10) roi=spectral_analysis.roi( roi_dir=center, diffuse_sources=get_default_diffuse(diffdir=e("$FERMI/diffuse"), gfile="gll_iem_v02.fit", ifile="isotropic_iem_v02.txt"), catalogs = catalog, phase_factor = phase_factor, **kwargs) # phaseing already done to the ltcube print "phase_factor=%.2f"%phase_factor # keep overall flux of catalog source, # but change the starting index to 2. roi.modify(which=catalog_name, name=name, index=2, keep_old_flux=True) roi.toXML(filename="essai") print roi roi.print_summary() for names in roi.get_names(): try : roi.modify(names,Norm=roi.get_model(names)[0]*roi.phase_factor) except : try : roi.modify(names,Int_flux=roi.get_model(names)[0]*roi.phase_factor) except : print names table=roi.get_names() print roi.modify(which=table[len(table)-2],model=PowerLaw(p=[1.0*phase_factor,0.1]),free=[True,False]) print roi.modify(which=table[len(table)-1],model=PowerLaw(p=[1.0*phase_factor,0.1]),free=[True,False]) # print roi.modify(which='eg_v02',free=[False]) print roi return roi
import xmlrpclib import os import glob from os.path import expanduser as e # connection information host = 'localhost' port = 8069 db = '9e' username = '******' password = '******' # paths to community and enterprise modules BASE_MODULE_PATH = e('~/odoo/odoo/openerp/addons/base/i18n') ADDONS_PATH = e('~/odoo/odoo/addons/') TXPATH = e('~/odoo/odoo/.tx/config') ENT_ADDONS_PATH = e('~/odoo/enterprise/') ENT_TXPATH = e('~/odoo/enterprise/.tx/config') l = glob.glob(os.path.join(ADDONS_PATH, '*/__init__.py')) # without 'web' as is in enterprise and breaks if more than one 'theme_' ADDONS_1 = [os.path.basename(os.path.dirname(i)) for i in l if ('l10n_' not in i and 'theme_' not in i and os.path.basename(os.path.dirname(i)) != 'web')] + ['base'] ADDONS_2 = [os.path.basename(os.path.dirname(i)) for i in l if ('l10n_' in i and 'l10n_be' not in i and 'l10n_ch' not in i and 'l10n_multilang' not in i)] ADDONS_3 = [os.path.basename(os.path.dirname(i)) for i in l if ('l10n_be' in i or 'l10n_ch' in i or 'l10n_sa' in i or 'l10n_multilang' in i)] l = glob.glob(os.path.join(ENT_ADDONS_PATH, '*/__init__.py')) ENT_ADDONS_1 = [os.path.basename(os.path.dirname(i)) for i in l if ( 'l10n_' not in i and 'theme_' not in i and