def addPSPowerLaw2(lib, name, ra, dec, emin=200, emax=3e5, flux_free=1, flux_value=1.6e-8, flux_scale=0, flux_max=1000.0, flux_min=1e-5, index_free=1, index_value=-2.0, index_min=-5.0, index_max=-0.5): """Add a source with a POWERLAW2 model""" elim_min = 30 elim_max = 300000 if emin < elim_min: elim_min = emin if emax > elim_max: elim_max = emax if flux_scale == 0: flux_scale = utils.fluxScale(flux_value) flux_value /= flux_scale doc = lib.ownerDocument src = doc.createElement('source') src.setAttribute('name', name) src.setAttribute('type', 'PointSource') spec = doc.createElement('spectrum') spec.setAttribute('type', 'PowerLaw2') addParameter(spec, 'Integral', flux_free, flux_value, flux_scale, flux_min, flux_max) addParameter(spec, 'Index', index_free, index_value, 1.0, index_min, index_max) addParameter(spec, 'LowerLimit', 0, emin, 1.0, elim_min, elim_max) addParameter(spec, 'UpperLimit', 0, emax, 1.0, elim_min, elim_max) src.appendChild(spec) spatial = doc.createElement('spatialModel') spatial.setAttribute('type', 'SkyDirFunction') addParameter(spatial, 'RA', 0, ra, 1.0, -360.0, 360.0) addParameter(spatial, 'DEC', 0, dec, 1.0, -90.0, 90.0) src.appendChild(spatial) lib.appendChild(src)
def addPSPowerLaw1(lib, name, ra, dec, eflux=0, flux_free=1, flux_value=1e-9, flux_scale=0, flux_max=1000.0, flux_min=1e-5, index_free=1, index_value=-2.0, index_min=-5.0, index_max=-0.5,extendedName=""): """Add a source with a POWERLAW1 model""" elim_min = 30 elim_max = 300000 if flux_scale == 0: flux_scale = utils.fluxScale(flux_value) flux_value /= flux_scale doc = lib.ownerDocument src = doc.createElement('source') src.setAttribute('name', name) if extendedName=="": src.setAttribute('type', 'PointSource') else: src.setAttribute('type', 'DiffuseSource') spec = doc.createElement('spectrum') spec.setAttribute('type', 'PowerLaw') addParameter(spec, 'Prefactor', flux_free, flux_value, flux_scale, flux_min, flux_max) addParameter(spec, 'Index', index_free, index_value, 1.0, index_min, index_max) addParameter(spec, 'Scale', 0, eflux, 1.0, elim_min, elim_max) src.appendChild(spec) spatial = AddSpatial(doc,ra,dec,extendedName) src.appendChild(spatial) lib.appendChild(src)
def addPSPLSuperExpCutoff(lib, name, ra, dec, eflux=0, flux_free=1, flux_value=1e-9, flux_scale=0, flux_max=1000.0, flux_min=1e-5, index1_free=1, index1_value=-2.0, index1_min=-5.0, index1_max=-0.5, cutoff_free=1, cutoff_value=1e4, cutoff_min=200, cutoff_max=3e5, index2_free=0, index2_value=-1.0, index2_min=-5.0, index2_max=-0.5): """Add a source with a SUPEREXPCUTOFF model""" elim_min = 30 elim_max = 300000 if flux_scale == 0: flux_scale = utils.fluxScale(flux_value) flux_value /= flux_scale doc = lib.ownerDocument src = doc.createElement('source') src.setAttribute('name', name) src.setAttribute('type', 'PointSource') spec = doc.createElement('spectrum') spec.setAttribute('type', 'PLSuperExpCutoff') addParameter(spec, 'Prefactor', flux_free, flux_value, flux_scale, flux_min, flux_max) addParameter(spec, 'Index1', index1_free, index1_value, 1.0, index1_min, index1_max) addParameter(spec, 'Scale', 0, eflux, 1.0, elim_min, elim_max) addParameter(spec, 'Cutoff', cutoff_free, cutoff_value, 1.0, cutoff_min, cutoff_max) addParameter(spec, 'Index2', index2_free, index2_value, 1.0, index2_min, index2_max) src.appendChild(spec) spatial = doc.createElement('spatialModel') spatial.setAttribute('type', 'SkyDirFunction') addParameter(spatial, 'RA', 0, ra, 1.0, -360.0, 360.0) addParameter(spatial, 'DEC', 0, dec, 1.0, -90.0, 90.0) src.appendChild(spatial) lib.appendChild(src)
def addPSPLSuperExpCutoff(lib, name, ra, dec, eflux=0, flux_free=1, flux_value=1e-9, flux_scale=0, flux_max=1000.0, flux_min=1e-5, index1_free=1, index1_value=-2.0, index1_min=-5.0, index1_max=-0.5, cutoff_free=1, cutoff_value=1e4, cutoff_min=200, cutoff_max=3e5, index2_free=0, index2_value=1.0, index2_min=0.0, index2_max=5.0,extendedName=""): """Add a source with a SUPEREXPCUTOFF model""" elim_min = 30 elim_max = 300000 if flux_scale == 0: flux_scale = utils.fluxScale(flux_value) flux_value /= flux_scale doc = lib.ownerDocument src = doc.createElement('source') src.setAttribute('name', name) if extendedName=="": src.setAttribute('type', 'PointSource') else: src.setAttribute('type', 'DiffuseSource') spec = doc.createElement('spectrum') spec.setAttribute('type', 'PLSuperExpCutoff') addParameter(spec, 'Prefactor', flux_free, flux_value, flux_scale, flux_min, flux_max) addParameter(spec, 'Index1', index1_free, index1_value, 1.0, index1_min, index1_max) addParameter(spec, 'Scale', 0, eflux, 1.0, elim_min, elim_max) addParameter(spec, 'Cutoff', cutoff_free, cutoff_value, 1.0, cutoff_min, cutoff_max) addParameter(spec, 'Index2', index2_free, index2_value, 1.0, index2_min, index2_max) src.appendChild(spec) spatial = AddSpatial(doc,ra,dec,extendedName) src.appendChild(spatial) lib.appendChild(src)
def addPSLogparabola(lib, name, ra, dec, enorm=300, norm_free=1, norm_value=1e-9, norm_scale=0, norm_max=1000.0, norm_min=1e-5, alpha_free=1, alpha_value=1.0, alpha_min=.5, alpha_max=5., beta_free=1, beta_value=1.0, beta_min=0.05, beta_max=5.0): """Add a source with a LOGPARABOLA model""" elim_min = 30 elim_max = 300000 if enorm == 0: enorm = 2e5 # meanEnergy(emin,emax,index_value) norm_value *= (enorm / 100.0) ** alpha_value if norm_scale == 0: norm_scale = utils.fluxScale(norm_value) norm_value /= norm_scale doc = lib.ownerDocument src = doc.createElement('source') src.setAttribute('name', name) src.setAttribute('type', 'PointSource') spec = doc.createElement('spectrum') spec.setAttribute('type', 'LogParabola') addParameter(spec, 'norm', norm_free, norm_value, norm_scale, norm_min, norm_max) addParameter(spec, 'alpha', alpha_free, alpha_value, 1.0, alpha_min, alpha_max) addParameter(spec, 'Eb', 0, enorm, 1.0, elim_min, elim_max) addParameter(spec, 'beta', beta_free, beta_value, 1.0, beta_min, beta_max) src.appendChild(spec) spatial = doc.createElement('spatialModel') spatial.setAttribute('type', 'SkyDirFunction') addParameter(spatial, 'RA', 0, ra, 1.0, -360.0, 360.0) addParameter(spatial, 'DEC', 0, dec, 1.0, -90.0, 90.0) src.appendChild(spatial) lib.appendChild(src)
def ChangeModel(Fit, E1, E2, name, Pref, Gamma): """Change the spectral model of a source called name to allow a fit between E1 and E2 If the spectral model is PowerLaw, the prefactor is updated if not the model is change to PowerLaw. The index is frozen in all cases""" Eav = utils.GetE0(E1, E2) # Set Parameters Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Prefactor').setBounds(1e-5,1e5) Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Prefactor').setScale(utils.fluxScale(Pref)) Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Prefactor').setValue(utils.fluxNorm(Pref)) Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Index').setBounds(-5,0) Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Index').setValue(Gamma) Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Index').setFree(0) Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Scale').setValue(Eav) Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Scale').setBounds(20,3e6) return Fit