def addPSPLSuperExpCutoff(lib, name, ra, dec, ebl=None, 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=-10.0, index1_max=-0., cutoff_free=1, cutoff_value=1e4, cutoff_min=20, cutoff_max=3e5, index2_free=0, index2_value=1.0, index2_min=0.0, index2_max=10.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') try: spec.setAttribute('type', 'EblAtten::PLSuperExpCutoff') addParameter(spec, 'tau_norm', ebl['free_tau_norm'], ebl['tau_norm'], 1.0, 0, 2.5) addParameter(spec, 'redshift', ebl['free_redshift'], ebl['redshift'], 1.0, 0, 5) addParameter(spec, 'ebl_model', 0, ebl['model'], 1.0, 0, 20) except TypeError,NameError: spec.setAttribute('type', 'PLSuperExpCutoff')
def ChangeModel(comp, 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""" # if approximated Gamma is outside of bounds set it to limit Gamma_min = -5 Gamma_max = 0.5 Gamma = min(max(Gamma_min, Gamma), Gamma_max) Eav = utils.GetE0(E1, E2) spectrum = comp.logLike.getSource(name).getSrcFuncs()['Spectrum'] spectrum.getParam('Prefactor').setBounds(1e-5, 1e5) spectrum.getParam('Prefactor').setScale(utils.fluxScale(Pref)) spectrum.getParam('Prefactor').setValue(utils.fluxNorm(Pref)) spectrum.getParam('Index').setBounds(Gamma_min, Gamma_max) spectrum.getParam('Index').setValue(Gamma) spectrum.getParam('Index').setFree(0) spectrum.getParam('Scale').setValue(Eav) spectrum.getParam('Scale').setBounds(20, 3e6) return comp
def addPSPowerLaw2(lib, name, ra, dec, ebl=None, 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,extendedName=""): """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) if extendedName=="": src.setAttribute('type', 'PointSource') else: src.setAttribute('type', 'DiffuseSource') spec = doc.createElement('spectrum') try: spec.setAttribute('type', 'EblAtten::PowerLaw2') addParameter(spec, 'tau_norm', ebl['free_tau_norm'], ebl['tau_norm'], 1.0, 0, 2.5) addParameter(spec, 'redshift', ebl['free_redshift'], ebl['redshift'], 1.0, 0, 5) addParameter(spec, 'ebl_model', 0, ebl['model'], 1.0, 0, 20) except TypeError,NameError: spec.setAttribute('type', 'PowerLaw2')
def ChangeModel(comp, 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""" # if approximated Gamma is outside of bounds set it to limit Gamma_min=-5 Gamma_max=0.5 Gamma = min(max(Gamma_min,Gamma),Gamma_max) Eav = utils.GetE0(E1, E2) spectrum = comp.logLike.getSource(name).getSrcFuncs()['Spectrum'] spectrum.getParam('Prefactor').setBounds(1e-5,1e5) spectrum.getParam('Prefactor').setScale(utils.fluxScale(Pref)) spectrum.getParam('Prefactor').setValue(utils.fluxNorm(Pref)) spectrum.getParam('Index').setBounds(Gamma_min,Gamma_max) spectrum.getParam('Index').setValue(Gamma) spectrum.getParam('Index').setFree(False) spectrum.getParam('Scale').setValue(Eav) spectrum.getParam('Scale').setBounds(20,3e6) return comp
def addPSLogparabola(lib, name, ra, dec, ebl=None, 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, beta_max=5.0,extendedName=""): """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) if extendedName=="": src.setAttribute('type', 'PointSource') else: src.setAttribute('type', 'DiffuseSource') spec = doc.createElement('spectrum') try: spec.setAttribute('type', 'EblAtten::LogParabola') addParameter(spec, 'tau_norm', ebl['free_tau_norm'], ebl['tau_norm'], 1.0, 0, 2.5) addParameter(spec, 'redshift', ebl['free_redshift'], ebl['redshift'], 1.0, 0, 5) addParameter(spec, 'ebl_model', 0, ebl['model'], 1.0, 0, 20) except TypeError,NameError: spec.setAttribute('type', 'LogParabola')
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,extendedName=""): """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) if extendedName=="": src.setAttribute('type', 'PointSource') else: src.setAttribute('type', 'DiffuseSource') 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 = AddSpatial(doc,ra,dec,extendedName) 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., 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.0005, beta_max=5.0, extendedName=""): """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) if extendedName == "": src.setAttribute('type', 'PointSource') else: src.setAttribute('type', 'DiffuseSource') 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 = AddSpatial(doc, ra, dec, extendedName) src.appendChild(spatial) lib.appendChild(src)
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, extendedName=""): """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) if extendedName == "": src.setAttribute('type', 'PointSource') else: src.setAttribute('type', 'DiffuseSource') 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 = AddSpatial(doc, ra, dec, extendedName) 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 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)) Gamma_min = -5 Gamma_max = 0 # if approximated Gamma is outside of bounds set it to limit if Gamma < Gamma_min: Gamma = Gamma_min elif Gamma > Gamma_max: Gamma = Gamma_max Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam( 'Index').setBounds(Gamma_min, Gamma_max) 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
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=-10.0, index1_max=-0., 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=10.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.0005, beta_max=5.0,extendedName=""): """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) if extendedName=="": src.setAttribute('type', 'PointSource') else: src.setAttribute('type', 'DiffuseSource') 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 = AddSpatial(doc,ra,dec,extendedName) 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)) Gamma_min=-5 Gamma_max=0 # if approximated Gamma is outside of bounds set it to limit if Gamma < Gamma_min: Gamma = Gamma_min elif Gamma > Gamma_max: Gamma = Gamma_max Fit.logLike.getSource(name).getSrcFuncs()['Spectrum'].getParam('Index').setBounds(Gamma_min,Gamma_max) 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