Agilepy science API tutorial - VELA Region analysis¶

The purpose of this notebook is to show how to use the Agilepy scientific API.

The complete API documentation can be found at this link.¶

Importing the library¶

In [1]:
from agilepy.api.AGAnalysis import AGAnalysis
from tqdm.notebook import tqdm
In [2]:
# Interactive plot
# %matplotlib widget
! root -q
   ------------------------------------------------------------------
  | Welcome to ROOT 6.26/06                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jul 28 2022, 18:08:51                 |
  | From tags/v6-26-06@v6-26-06                                      |
  | With c++ (GCC) 8.5.0 20210514 (Red Hat 8.5.0-13)                 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------


Creating a configuration file¶

In [3]:
confFilePath = "$HOME/agilepy_conf.yaml"
In [4]:
AGAnalysis.getConfiguration(
    evtfile="$AGILE/agilepy-test-data/test_dataset_6.0/EVT/EVT.index",
    logfile="$AGILE/agilepy-test-data/test_dataset_6.0/LOG/LOG.index",
    confFilePath = confFilePath,
    userName = "user-xxx",
    sourceName = "vela-xxx",
    tmin = 433857532,
    tmax = 434289532,
    timetype = "TT",
    glon = 263.55,
    glat = -2.78,
    outputDir = "$HOME/agilepy_analysis",
    verboselvl = 0, 
    userestapi=False
)

Initialization of the class¶

In [5]:
ag = AGAnalysis(confFilePath)

API: configuration file¶

Print all options of the configuration file

In [6]:
ag.printOptions()
{ 'ap': {'radius': 3, 'timeslot': 3600},
  'input': { 'datapath': 'None',
             'evtfile': '//agiletools/agilepy-test-data/test_dataset_6.0/EVT/EVT.index',
             'logfile': '//agiletools/agilepy-test-data/test_dataset_6.0/LOG/LOG.index',
             'userestapi': False},
  'maps': { 'binsize': 0.25,
            'energybins': [[100, 10000]],
            'expstep': 4.0,
            'fovbinnumber': 1,
            'mapsize': 40,
            'offaxisangle': 30,
            'proj': 'ARC',
            'projtype': 'WCS',
            'spectralindex': 2.1,
            'timestep': 160,
            'useEDPmatrixforEXP': False},
  'mle': { 'contourpoints': 40,
           'edpcorrection': 1,
           'expratio_maxthr': 15,
           'expratio_minthr': 0,
           'expratio_size': 10,
           'expratioevaluation': True,
           'fluxcorrection': 0,
           'integratortype': 1,
           'loccl': 5.99147,
           'mindefaulttolerance': 0.01,
           'minimizeralg': 'Migrad',
           'minimizerdefstrategy': 2,
           'minimizertype': 'Minuit',
           'ranal': 10,
           'ulcl': 2},
  'model': { 'emax_sources': 10000,
             'emin_sources': 100,
             'galcoeff': [-1],
             'galmode': 1,
             'galmode2': 0,
             'galmode2fit': 0,
             'isocoeff': [-1],
             'isomode': 1,
             'isomode2': 0,
             'isomode2fit': 0,
             'modelfile': None},
  'output': { 'filenameprefix': 'analysis_product',
              'logfilenameprefix': 'analysis_log',
              'outdir': PosixPath('/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041'),
              'sourcename': 'vela-xxx',
              'username': 'user-xxx',
              'verboselvl': 0},
  'plotting': {'twocolumns': False},
  'selection': { 'albedorad': 80,
                 'bpointing': None,
                 'dq': 0,
                 'emax': 10000,
                 'emin': 100,
                 'filtercode': 5,
                 'fovradmax': 60,
                 'fovradmin': 0,
                 'glat': -2.78,
                 'glon': 263.550001,
                 'lonpole': 180,
                 'lpointing': None,
                 'maplistgen': 'None',
                 'phasecode': 6,
                 'proj': 'ARC',
                 'timelist': 'None',
                 'timetype': 'TT',
                 'tmax': 434289532,
                 'tmin': 433857532}}

Print a single section of the yaml configuration file

In [7]:
ag.printOptions("maps")
{ 'binsize': 0.25,
  'energybins': [[100, 10000]],
  'expstep': 4.0,
  'fovbinnumber': 1,
  'mapsize': 40,
  'offaxisangle': 30,
  'proj': 'ARC',
  'projtype': 'WCS',
  'spectralindex': 2.1,
  'timestep': 160,
  'useEDPmatrixforEXP': False}

Print a single option

In [8]:
ag.getOption("energybins")
Out[8]:
[[100, 10000]]

Set some options

In [9]:
ag.setOptions(energybins=[[100,300], [300, 1000]], mapsize=50, binsize=0.4)
In [10]:
ag.printOptions("maps")
{ 'binsize': 0.4,
  'energybins': [[100, 300], [300, 1000]],
  'expstep': 4.0,
  'fovbinnumber': 1,
  'mapsize': 50,
  'offaxisangle': 30,
  'proj': 'ARC',
  'projtype': 'WCS',
  'spectralindex': 2.1,
  'timestep': 160,
  'useEDPmatrixforEXP': False}

API: interacting with the Sources Library¶

Loading the AGILE's second catalogue of gamma-ray sources¶

In [11]:
sources = ag.loadSourcesFromCatalog("2AGL", rangeDist = (0, 25))
In [12]:
type(sources[0])
Out[12]:
agilepy.core.source.Source.PointSource
In [13]:
for s in sources:
    print(s)
-----------------------------------------------------------
 Source name: 2AGLJ1045-5954 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.8089e-07
	- index : 2.0414
	- Source position (l,b): (287.697, -0.788886)
	- Distance from map center (deg): 24.2159

-----------------------------------------------------------
 Source name: 2AGLJ1048-5836 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.5477e-07
	- index : 2.00039
	- Source position (l,b): (287.422, 0.423015)
	- Distance from map center (deg): 24.0778

-----------------------------------------------------------
 Source name: 2AGLJ1045-5735 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.6495e-07
	- index : 2.25973
	- Source position (l,b): (286.672, 1.23211)
	- Distance from map center (deg): 23.4607

-----------------------------------------------------------
 Source name: 2AGLJ1059-5233 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 3.1410e-07
	- index : 1.77974
	- Source position (l,b): (286.128, 6.61213)
	- Distance from map center (deg): 24.4183

-----------------------------------------------------------
 Source name: 2AGLJ1029-5834 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 2.6485e-07
	- index : 1.91101
	- Source position (l,b): (285.221, -0.689424)
	- Distance from map center (deg): 21.7604

-----------------------------------------------------------
 Source name: 2AGLJ1015-5852 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.9174e-07
	- index : 2.03933
	- Source position (l,b): (283.945, -1.85807)
	- Distance from map center (deg): 20.3987

-----------------------------------------------------------
 Source name: 2AGLJ1020-5752 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 2.7247e-07
	- index : 2.12932
	- Source position (l,b): (283.95, -0.621559)
	- Distance from map center (deg): 20.5036

-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702

-----------------------------------------------------------
 Source name: 2AGLJ1020-5906 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.3879e-07
	- index : 1.78216
	- Source position (l,b): (284.629, -1.89938)
	- Distance from map center (deg): 21.0794

Alternative solution: loading the sources from a custom AGILE .txt file¶

The sources that are already present in the Sources Library will not be loaded twice.

In [14]:
sources_hypotesis = """
969.539e-08 263.585 -2.84083 1.71345 0 2 2AGLJ0835-4514 0.0 2 3913.06 1.34774 0.5 5 20 10000 0 100
10e-08 273.0 -1.1 2.1 1 2 NEWOURCE 0.0 0 0 0 0.5 5 20 10000 0 100
"""
with open("./sources_hyp.txt", "w") as sf:
    sf.write(sources_hypotesis)
In [15]:
#sources = ag.loadSourcesFromFile("./sources_hyp.txt", rangeDist = (0, 25))

Selecting the sources¶

The selection criteria can be expressed using the following Source class’s parameters:

  • name: the unique code identifying the source.
  • dist: the distance of the source from the center of the maps.
  • flux: the flux value.
  • sqrtTS: the radix square of the ts.
In [16]:
selectedSources = ag.selectSources('flux > 0')
In [17]:
len(selectedSources)
Out[17]:
9
In [18]:
selectedSources = ag.selectSources('name == "2AGLJ0835-4514"')
In [19]:
len(selectedSources)
for s in selectedSources:
    print(s)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
In [20]:
selectedSources = ag.selectSources("flux > 0 AND dist <= 2")
In [21]:
len(selectedSources)
for s in selectedSources:
    print(s)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702

Free/Fix source parameters¶

You can fix or free the following parametes:

  • flux
  • index
  • index1
  • index2
  • cutoffEnergy
  • pivotEnergy
  • curvature
  • index2
  • pos for the position of the source
In [22]:
_sources = ag.freeSources('name == "2AGLJ0835-4514"', "flux", True, show=True)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
In [23]:
for s in _sources:
    print(s)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
In [24]:
_sources = ag.freeSources('name == "2AGLJ0835-4514"', "index1", True)
In [25]:
for s in _sources:
    print(s)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux index1
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
In [26]:
_sources = ag.freeSources("flux > 0 AND dist <= 2", "flux", True)
In [27]:
#len is 0 because the flux is already free
len(_sources)
Out[27]:
0
In [28]:
for s in _sources:
    print(s)

Resetting the changes:

In [29]:
_sources = ag.freeSources('name == "2AGLJ0835-4514"', "flux", False)
In [30]:
ag.freeSources('name == "2AGLJ0835-4514"', "index1", False)
Out[30]:
[<agilepy.core.source.Source.PointSource at 0x7fe3ffd76b80>]
In [31]:
ag.freeSources("flux > 0 AND dist <= 2", "flux", False)
Out[31]:
[]

Deleting sources¶

In [32]:
deleted = ag.deleteSources('name == "2AGLJ1048-5836"').pop()
print(deleted)
-----------------------------------------------------------
 Source name: 2AGLJ1048-5836 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.5477e-07
	- index : 2.00039
	- Source position (l,b): (287.422, 0.423015)
	- Distance from map center (deg): 24.0778
In [33]:
len(ag.getSources())
Out[33]:
8

Adding a source¶

Passing a dictionary:

In [34]:
newSourceDict = {
    "glon" : 273.0,
    "glat":  -1.1,
    "spectrumType" : "PowerLaw",
    "flux": 10e-08,
    "index": 2.1
}

if ag.addSource("NEWSOURCE", newSourceDict):
    print("Source loaded")
Source loaded
In [35]:
len(ag.getSources())
Out[35]:
9

Passing a Source object:

In [36]:
type(deleted)
Out[36]:
agilepy.core.source.Source.PointSource
In [37]:
if ag.addSource("NEWSOURCE", deleted):
    print("Source loaded")
else:
    print("Source is already present in the SourcesLibrary")
2022-10-22 16:50:41,931 [WARNING ] [SourcesLibrary] The source NEWSOURCE already exists. The 'sourceObject' will not be added to the SourcesLibrary.
Source is already present in the SourcesLibrary
In [38]:
deletedSources = ag.deleteSources('name == "NEWSOURCE"')
In [39]:
len(ag.getSources())
Out[39]:
8

Update the value of a spectrum parameter of a source¶

In [40]:
sources = ag.selectSources('name == "2AGLJ0835-4514"')
source = sources.pop()
In [41]:
print(source.get("index2"))
{'name': 'index2', 'value': 1.34774, 'err': None, 'free': 0, 'min': 0.0, 'max': 100.0, 'scale': -1, 'datatype': 'float', 'um': ''}
In [42]:
source.set("index2", {"value":1.34774, "min":10})
print(source)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702

Fix the hypothesis for the analysis¶

This method returns the selected sources affected by the change

In [43]:
sources = ag.freeSources('name == "2AGLJ0835-4514"', "flux", True, show=True)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702

Final source hypothesis for the analysis

In [44]:
selectedSources = ag.selectSources('flux > 0')
print(len(selectedSources))
for s in selectedSources:
    print(s)
8

-----------------------------------------------------------
 Source name: 2AGLJ1045-5954 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.8089e-07
	- index : 2.0414
	- Source position (l,b): (287.697, -0.788886)
	- Distance from map center (deg): 24.2159

-----------------------------------------------------------
 Source name: 2AGLJ1045-5735 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.6495e-07
	- index : 2.25973
	- Source position (l,b): (286.672, 1.23211)
	- Distance from map center (deg): 23.4607

-----------------------------------------------------------
 Source name: 2AGLJ1059-5233 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 3.1410e-07
	- index : 1.77974
	- Source position (l,b): (286.128, 6.61213)
	- Distance from map center (deg): 24.4183

-----------------------------------------------------------
 Source name: 2AGLJ1029-5834 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 2.6485e-07
	- index : 1.91101
	- Source position (l,b): (285.221, -0.689424)
	- Distance from map center (deg): 21.7604

-----------------------------------------------------------
 Source name: 2AGLJ1015-5852 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.9174e-07
	- index : 2.03933
	- Source position (l,b): (283.945, -1.85807)
	- Distance from map center (deg): 20.3987

-----------------------------------------------------------
 Source name: 2AGLJ1020-5752 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 2.7247e-07
	- index : 2.12932
	- Source position (l,b): (283.95, -0.621559)
	- Distance from map center (deg): 20.5036

-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource)
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702

-----------------------------------------------------------
 Source name: 2AGLJ1020-5906 (PointSource)
  * Spectrum type: PowerLaw
  * Free parameters: none
  * Initial source parameters:
	- flux (ph/cm2s): 1.3879e-07
	- index : 1.78216
	- Source position (l,b): (284.629, -1.89938)
	- Distance from map center (deg): 21.0794

API: generate maps and perform maximum likelihood estimator analysis¶

Generating maps¶

In [45]:
ag.printOptions("maps")
{ 'binsize': 0.4,
  'energybins': [[100, 300], [300, 1000]],
  'expstep': 4.0,
  'fovbinnumber': 1,
  'mapsize': 50,
  'offaxisangle': 30,
  'proj': 'ARC',
  'projtype': 'WCS',
  'spectralindex': 2.1,
  'timestep': 160,
  'useEDPmatrixforEXP': False}
In [46]:
maplistfile = ag.generateMaps()
Generating maps..please wait.
Fov bins loop:   0%|          | 0/1 [00:00<?, ?it/s]
Energy bins loop: 0it [00:00, ?it/s]

Displaying maps¶

Single figure - multiple subplots¶

  • normType selects a normalization function for the data, possible valuses are {‘linear’, ‘sqrt’, ‘power’, log’, ‘asinh’}, default ‘linear’.
  • regFiles (list, optional) – A list containing region file(s) absolute path.
  • regFileColors (list, optional) – A list with a color for each region file, the length must be the same of regFiles.
  • catalogRegions (str, optional) – a catalog name. The regions that belongs to the catalog will be loaded. It defaults to None.
  • catalogRegionsColor (str, optional) – the color of the regions loaded from the catalog.
In [47]:
ag.displayCtsSkyMaps(smooth=2, regFiles=["$AGILE/catalogs/3EG_1.reg"], regFileColors=["red"], catalogRegions="2AGL", catalogRegionsColor="blue", normType="sqrt")
Generating plot..please wait.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2004-01-01T00:01:07.184' from MJDREF.
Set MJD-OBS to 58026.499988 from DATE-OBS.
Set MJD-END to 58031.499988 from DATE-END'. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2004-01-01T00:01:07.184' from MJDREF.
Set MJD-OBS to 58026.499988 from DATE-OBS.
Set MJD-END to 58031.499988 from DATE-END'. [astropy.wcs.wcs]
Out[47]:
[None]

Multiple figures - one subplot per figure¶

In [48]:
ag.displayExpSkyMaps(singleMode = False)
Generating plot..please wait.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2004-01-01T00:01:07.184' from MJDREF.
Set MJD-OBS to 58026.499988 from DATE-OBS.
Set MJD-END to 58031.499988 from DATE-END'. [astropy.wcs.wcs]
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2004-01-01T00:01:07.184' from MJDREF.
Set MJD-OBS to 58026.499988 from DATE-OBS.
Set MJD-END to 58031.499988 from DATE-END'. [astropy.wcs.wcs]
Out[48]:
[None, None]
In [49]:
ag.displayGasSkyMaps()
Generating plot..please wait.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2004-01-01T00:01:07.184' from MJDREF.
Set MJD-OBS to 58026.499988 from DATE-OBS.
Set MJD-END to 58031.499988 from DATE-END'. [astropy.wcs.wcs]
Out[49]:
[None]

Saving maps¶

In [50]:
ag.displayCtsSkyMaps(smooth=3, saveImage=True)
Generating plot..please wait.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2004-01-01T00:01:07.184' from MJDREF.
Set MJD-OBS to 58026.499988 from DATE-OBS.
Set MJD-END to 58031.499988 from DATE-END'. [astropy.wcs.wcs]
Out[50]:
['/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/plots/analysis_cts_20221022-165125.png']

Estimation of background coefficients¶

You can use the calcBkg() method to estimate the background coefficients.

In [51]:
print("isocoeff: {} galcoeff: {}".format(ag.getOption("isocoeff"), ag.getOption("galcoeff")))
isocoeff: [-1, -1] galcoeff: [-1, -1]
In [52]:
isoBkg, galBkg, maplistfile = ag.calcBkg("2AGLJ0835-4514", galcoeff = [0.7, 0.7], pastTimeWindow = 0)
Computing background coefficients..please wait.
<agilepy.core.MapList.MapList object at 0x7fe3e6fe37f0>
Generating maps..please wait.
Fov bins loop:   0%|          | 0/1 [00:00<?, ?it/s]
Energy bins loop: 0it [00:00, ?it/s]
In [53]:
# calcBkg with pastTimeWindow = 14
# ag.setOptions(galcoeff=[0.469176, 0.699403, 0.199108, 0.533379], isocoeff=[4.27314, 0.976644, 8.12386, 1.24627])
In [54]:
print("isocoeff: {} galcoeff: {}".format(ag.getOption("isocoeff"), ag.getOption("galcoeff")))
isocoeff: [4.08416, 3.84041] galcoeff: [0.7, 0.7]

Maximum likelyhood analysis¶

In [55]:
sourceFiles = ag.mle()
In [56]:
#print results
sources = ag.selectSources("sqrtTS > 0", show=True)
print(len(sources))
for s in sources:
    print(s)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource) => sqrt(ts): 17.008
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
  * Last MLE analysis (2022-10-22 16:52:03.501410):
	- flux (ph/cm2s): 9.0166e-06 +/- 9.1907e-07
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- counts: 170.822 +/- 17.4119
	- upper limit(ph/cm2s): 1.0951e-05
	- ergLog(erg/cm2s): 1.60296e-09 +/- 1.6339e-10
	- galCoeff: [0.7, 0.7]
	- isoCoeff: [4.08416, 3.84041]
	- exposure(cm2s): 18945200.0
	- exp-ratio: 0.499808
	- L_peak: 263.585
	- B_peak: -2.84083
	- Distance from start pos: 8.53774e-07
	- ellipse position:
	    - L: -1
	    - B: -1
	    - Distance from start pos: -1
	    - radius of circle: -1
	    - ellipse:
		  - a: -1
		  - b: -1
		  - phi: -1
-----------------------------------------------------------
1

-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource) => sqrt(ts): 17.008
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
  * Last MLE analysis (2022-10-22 16:52:03.501410):
	- flux (ph/cm2s): 9.0166e-06 +/- 9.1907e-07
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- counts: 170.822 +/- 17.4119
	- upper limit(ph/cm2s): 1.0951e-05
	- ergLog(erg/cm2s): 1.60296e-09 +/- 1.6339e-10
	- galCoeff: [0.7, 0.7]
	- isoCoeff: [4.08416, 3.84041]
	- exposure(cm2s): 18945200.0
	- exp-ratio: 0.499808
	- L_peak: 263.585
	- B_peak: -2.84083
	- Distance from start pos: 8.53774e-07
	- ellipse position:
	    - L: -1
	    - B: -1
	    - Distance from start pos: -1
	    - radius of circle: -1
	    - ellipse:
		  - a: -1
		  - b: -1
		  - phi: -1
-----------------------------------------------------------

Free also position parameter

In [57]:
ag.freeSources('name == "2AGLJ0835-4514"', "pos", True, show=True)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource) => sqrt(ts): 17.008
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux pos
  * Initial source parameters:
	- flux (ph/cm2s): 9.6954e-06
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
  * Last MLE analysis (2022-10-22 16:52:03.501410):
	- flux (ph/cm2s): 9.0166e-06 +/- 9.1907e-07
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- counts: 170.822 +/- 17.4119
	- upper limit(ph/cm2s): 1.0951e-05
	- ergLog(erg/cm2s): 1.60296e-09 +/- 1.6339e-10
	- galCoeff: [0.7, 0.7]
	- isoCoeff: [4.08416, 3.84041]
	- exposure(cm2s): 18945200.0
	- exp-ratio: 0.499808
	- L_peak: 263.585
	- B_peak: -2.84083
	- Distance from start pos: 8.53774e-07
	- ellipse position:
	    - L: -1
	    - B: -1
	    - Distance from start pos: -1
	    - radius of circle: -1
	    - ellipse:
		  - a: -1
		  - b: -1
		  - phi: -1
-----------------------------------------------------------
Out[57]:
[<agilepy.core.source.Source.PointSource at 0x7fe3ff28ce80>]
In [58]:
ag.mle()
Out[58]:
['/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/mle/1/analysis_product_2AGLJ1045-5954.source',
 '/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/mle/1/analysis_product_2AGLJ1045-5735.source',
 '/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/mle/1/analysis_product_2AGLJ1059-5233.source',
 '/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/mle/1/analysis_product_2AGLJ1029-5834.source',
 '/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/mle/1/analysis_product_2AGLJ1015-5852.source',
 '/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/mle/1/analysis_product_2AGLJ1020-5752.source',
 '/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/mle/1/analysis_product_2AGLJ0835-4514.source',
 '/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/mle/1/analysis_product_2AGLJ1020-5906.source']
In [59]:
#print results
sources = ag.selectSources("sqrtTS > 0")
print(len(sources))
for s in sources:
    print(s)
1

-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource) => sqrt(ts): 17.0229
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux pos
  * Initial source parameters:
	- flux (ph/cm2s): 9.0166e-06 +/- 9.1907e-07
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
  * Last MLE analysis (2022-10-22 16:52:06.731217):
	- flux (ph/cm2s): 8.9807e-06 +/- 9.1527e-07
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- counts: 170.14 +/- 17.3399
	- upper limit(ph/cm2s): 1.09073e-05
	- ergLog(erg/cm2s): 1.59656e-09 +/- 1.62714e-10
	- galCoeff: [0.7, 0.7]
	- isoCoeff: [4.08416, 3.84041]
	- exposure(cm2s): 18945200.0
	- exp-ratio: 0
	- L_peak: 263.638
	- B_peak: -2.85605
	- Distance from start pos: 0.0548425
	- ellipse position:
	    - L: 263.647
	    - B: -2.8547
	    - Distance from start pos: 0.0637012
	    - radius of circle: 0.199311
	    - ellipse:
		  - a: 0.196811
		  - b: 0.202633
		  - phi: 42.9394
-----------------------------------------------------------

Save the results of the analysis in a reg file.

In [60]:
regFile = ag.writeSourcesOnFile("source_regions", "reg")
In [61]:
print(regFile)
/root/agilepy_analysis/user-xxx_vela-xxx_20221022-165041/sources_library/source_regions.reg

Display the result of the analysis saved in a reg file.

In [62]:
ag.displayCtsSkyMaps(smooth=2, regFiles=[regFile], regFileColors=["red"], catalogRegions="2AGL", catalogRegionsColor="blue")
Generating plot..please wait.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2004-01-01T00:01:07.184' from MJDREF.
Set MJD-OBS to 58026.499988 from DATE-OBS.
Set MJD-END to 58031.499988 from DATE-END'. [astropy.wcs.wcs]
Out[62]:
[None]

Light curve¶

Fix the position and keep only flux free

In [63]:
ag.freeSources('name == "2AGLJ0835-4514"', "pos", False, show=True)
-----------------------------------------------------------
 Source name: 2AGLJ0835-4514 (PointSource) => sqrt(ts): 17.0229
  * Spectrum type: PLSuperExpCutoff
  * Free parameters: flux
  * Initial source parameters:
	- flux (ph/cm2s): 9.0166e-06 +/- 9.1907e-07
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- Source position (l,b): (263.585, -2.84083)
	- Distance from map center (deg): 0.0702
  * Last MLE analysis (2022-10-22 16:52:06.731217):
	- flux (ph/cm2s): 8.9807e-06 +/- 9.1527e-07
	- index1 : 1.71345
	- cutoffEnergy : 3913.06
	- index2 : 1.34774
	- counts: 170.14 +/- 17.3399
	- upper limit(ph/cm2s): 1.09073e-05
	- ergLog(erg/cm2s): 1.59656e-09 +/- 1.62714e-10
	- galCoeff: [0.7, 0.7]
	- isoCoeff: [4.08416, 3.84041]
	- exposure(cm2s): 18945200.0
	- exp-ratio: 0
	- L_peak: 263.638
	- B_peak: -2.85605
	- Distance from start pos: 0.0548425
	- ellipse position:
	    - L: 263.647
	    - B: -2.8547
	    - Distance from start pos: 0.0637012
	    - radius of circle: 0.199311
	    - ellipse:
		  - a: 0.196811
		  - b: 0.202633
		  - phi: 42.9394
-----------------------------------------------------------
Out[63]:
[<agilepy.core.source.Source.PointSource at 0x7fe3ff28ce80>]
In [64]:
lightCurveData = ag.lightCurveMLE("2AGLJ0835-4514", binsize=86400, position="ellipse")
Computing light curve bins..please wait.
Temporal bin loop:   0%|          | 0/5 [00:00<?, ?it/s]
Generating maps..please wait.
Fov bins loop:   0%|          | 0/1 [00:00<?, ?it/s]
Energy bins loop: 0it [00:00, ?it/s]
Generating maps..please wait.
Fov bins loop:   0%|          | 0/1 [00:00<?, ?it/s]
Energy bins loop: 0it [00:00, ?it/s]
Generating maps..please wait.
Fov bins loop:   0%|          | 0/1 [00:00<?, ?it/s]
Energy bins loop: 0it [00:00, ?it/s]
Generating maps..please wait.
Fov bins loop:   0%|          | 0/1 [00:00<?, ?it/s]
Energy bins loop: 0it [00:00, ?it/s]
Generating maps..please wait.
Fov bins loop:   0%|          | 0/1 [00:00<?, ?it/s]
Energy bins loop: 0it [00:00, ?it/s]
In [65]:
! cat $lightCurveData
time_start_mjd time_end_mjd sqrt(ts) flux flux_err flux_ul gal gal_error iso iso_error l_peak b_peak dist_peak l b r ell_dist a b phi exposure ExpRatio counts counts_err Index Index_Err Par2 Par2_Err Par3 Par3_Err Erglog Erglog_Err Erglog_UL time_start_utc time_end_utc time_start_tt time_end_tt Fix index ULConfidenceLevel SrcLocConfLevel start_l start_b start_flux typefun par2 par3 galmode2 galmode2fit isomode2 isomode2fit edpcor fluxcor integratortype expratioEval expratio_minthr expratio_maxthr expratio_size Emin emax fovmin fovmax albedo binsize expstep phasecode fit_cts fit_fitstatus0 fit_fcn0 fit_edm0 fit_nvpar0 fit_nparx0 fit_iter0 fit_fitstatus1 fit_fcn1 fit_edm1 fit_nvpar1 fit_nparx1 fit_iter1 fit_Likelihood1
58026.49921296296 58027.49921296296 7.34802 944.077e-08 213.085e-08 1418.53e-08 0.7,0.7 0,0 4.08416,3.84041 0,0 263.647 -2.8547 0 -1 -1 -1 -1 -1 -1 -1 3718660.0 0.153787 35.107 7.92393 1.71345 0 3913.06 0 1.34774 0 1.67836e-09 3.78819e-10 2.52182e-09 2017-09-30T11:58:52.000 2017-10-01T11:58:52.000 433857532.0 433943932.0 1 1.71345 2 5.99147 263.647 -2.8547 8.98066e-06 2 3913.06 1.34774 0 0 0 0 1 0 1 1 0 15 10 100,300 300,1000 0,0 60,60 80 0.4 0 6 92 -1 344.763 0.5 0 52 3 0 317.767 7.08173e-17 1 52 3 404.222
58027.49921296296 58028.49921296296 8.88107 1054.87e-08 211.633e-08 1523.64e-08 0.7,0.7 0,0 4.08416,3.84041 0,0 263.647 -2.8547 0 -1 -1 -1 -1 -1 -1 -1 3843970.0 0.422914 40.5489 8.1351 1.71345 0 3913.06 0 1.34774 0 1.87533e-09 3.76236e-10 2.7087e-09 2017-10-01T11:58:52.000 2017-10-02T11:58:52.000 433943932.0 434030332.0 1 1.71345 2 5.99147 263.647 -2.8547 8.98066e-06 2 3913.06 1.34774 0 0 0 0 1 0 1 1 0 15 10 100,300 300,1000 0,0 60,60 80 0.4 0 6 91 -1 341.2 0.5 0 52 3 0 301.763 5.3014e-17 1 52 3 391.377
58028.49921296296 58029.49921296296 7.31826 820.89e-08 198.193e-08 1266.73e-08 0.7,0.7 0,0 4.08416,3.84041 0,0 263.647 -2.8547 0 -1 -1 -1 -1 -1 -1 -1 3788250.0 0.0768935 31.0974 7.50807 1.71345 0 3913.06 0 1.34774 0 1.45936e-09 3.52344e-10 2.25196e-09 2017-10-02T11:58:52.000 2017-10-03T11:58:52.000 434030332.0 434116732.0 1 1.71345 2 5.99147 263.647 -2.8547 8.98066e-06 2 3913.06 1.34774 0 0 0 0 1 0 1 1 0 15 10 100,300 300,1000 0,0 60,60 80 0.4 0 6 96 -1 357.846 0.5 0 52 3 0 331.067 1.29616e-16 1 52 3 422.908
58029.49921296296 58030.49921296296 6.7938 840.137e-08 208.073e-08 1306.49e-08 0.7,0.7 0,0 4.08416,3.84041 0,0 263.647 -2.8547 0 -1 -1 -1 -1 -1 -1 -1 3806190.0 0.346021 31.9772 7.91965 1.71345 0 3913.06 0 1.34774 0 1.49358e-09 3.69907e-10 2.32265e-09 2017-10-03T11:58:52.000 2017-10-04T11:58:52.000 434116732.0 434203132.0 1 1.71345 2 5.99147 263.647 -2.8547 8.98066e-06 2 3913.06 1.34774 0 0 0 0 1 0 1 1 0 15 10 100,300 300,1000 0,0 60,60 80 0.4 0 6 110 -1 404.732 0.5 0 52 3 0 381.654 1.38412e-15 1 52 3 486.109
58030.49921296296 58031.49921296296 7.62835 820.045e-08 190.836e-08 1249.26e-08 0.7,0.7 0,0 4.08416,3.84041 0,0 263.647 -2.8547 0 -1 -1 -1 -1 -1 -1 -1 3793810.0 0.11534 31.111 7.23995 1.71345 0 3913.06 0 1.34774 0 1.45786e-09 3.39264e-10 2.2209e-09 2017-10-04T11:58:52.000 2017-10-05T11:58:52.000 434203132.0 434289532.0 1 1.71345 2 5.99147 263.647 -2.8547 8.98066e-06 2 3913.06 1.34774 0 0 0 0 1 0 1 1 0 15 10 100,300 300,1000 0,0 60,60 80 0.4 0 6 97 -1 365.175 0.5 0 52 3 0 336.08 8.18392e-17 1 52 3 426.148
In [66]:
ag.displayLightCurve("mle")
Generating plot..please wait.

time_start_mjd time_end_mjd sqrt(ts) flux flux_err flux_ul gal gal_error iso iso_error l_peak b_peak dist_peak l b r ell_dist a b phi exposure ExpRatio counts counts_err Index Index_Err Par2 Par2_Err Par3 Par3_Err Erglog Erglog_Err Erglog_UL time_start_utc time_end_utc time_start_tt time_end_tt Fix index ULConfidenceLevel SrcLocConfLevel start_l start_b start_flux typefun par2 par3 galmode2 galmode2fit isomode2 isomode2fit edpcor fluxcor integratortype expratioEval expratio_minthr expratio_maxthr expratio_size Emin emax fovmin fovmax albedo binsize expstep phasecode

In [67]:
ag.displayGenericColumns(lightCurveData, ["exposure"], um=["cm^2 s sr"])

Aperture Photometry¶

In [68]:
ap_file, _ = ag.aperturePhotometry()
In [69]:
! cat $ap_file
433857532.0 433861132.0 163966.55 0 
433861132.0 433864732.0 79051.27 0 
433864732.0 433868332.0 222291.92 3 
433868332.0 433871932.0 124952.15 1 
433871932.0 433875532.0 82674.74 1 
433875532.0 433879132.0 248922.49 3 
433879132.0 433882732.0 72540.14 2 
433882732.0 433886332.0 205541.84 1 
433886332.0 433889932.0 224762.32 1 
433889932.0 433893532.0 92971.98 1 
433893532.0 433897132.0 282159.50 2 
433897132.0 433900732.0 161665.02 2 
433900732.0 433904332.0 117541.07 1 
433904332.0 433907932.0 322960.54 2 
433907932.0 433911532.0 131259.96 2 
433911532.0 433915132.0 169328.03 0 
433915132.0 433918732.0 256623.00 3 
433918732.0 433922332.0 34305.35 0 
433922332.0 433925932.0 215591.35 0 
433925932.0 433929532.0 179317.12 3 
433929532.0 433933132.0 136096.58 1 
433933132.0 433936732.0 204434.05 1 
433936732.0 433940332.0 122829.65 1 
433940332.0 433943932.0 114408.54 3 
433943932.0 433947532.0 237292.69 2 
433947532.0 433951132.0 142309.75 0 
433951132.0 433954732.0 74501.66 1 
433954732.0 433958332.0 212654.44 0 
433958332.0 433961932.0 97756.11 2 
433961932.0 433965532.0 151709.36 1 
433965532.0 433969132.0 213108.45 3 
433969132.0 433972732.0 83285.72 0 
433972732.0 433976332.0 253470.58 1 
433976332.0 433979932.0 211059.30 3 
433979932.0 433983532.0 130823.15 1 
433983532.0 433987132.0 271935.90 3 
433987132.0 433990732.0 122762.61 0 
433990732.0 433994332.0 174535.06 0 
433994332.0 433997932.0 298343.85 3 
433997932.0 434001532.0 88410.96 0 
434001532.0 434005132.0 218154.64 0 
434005132.0 434008732.0 212744.04 2 
434008732.0 434012332.0 83927.18 0 
434012332.0 434015932.0 223713.87 6 
434015932.0 434019532.0 168459.43 0 
434019532.0 434023132.0 125221.63 1 
434023132.0 434026732.0 211054.85 5 
434026732.0 434030332.0 117049.45 1 
434030332.0 434033932.0 88600.91 0 
434033932.0 434037532.0 251330.89 3 
434037532.0 434041132.0 120564.22 0 
434041132.0 434044732.0 86891.09 1 
434044732.0 434048332.0 226131.35 0 
434048332.0 434051932.0 74688.92 1 
434051932.0 434055532.0 194368.68 2 
434055532.0 434059132.0 197891.42 3 
434059132.0 434062732.0 145465.76 2 
434062732.0 434066332.0 268694.53 2 
434066332.0 434069932.0 173918.55 2 
434069932.0 434073532.0 139096.50 1 
434073532.0 434077132.0 301584.55 5 
434077132.0 434080732.0 119217.12 0 
434080732.0 434084332.0 165177.16 1 
434084332.0 434087932.0 237725.83 0 
434087932.0 434091532.0 73409.52 1 
434091532.0 434095132.0 216167.58 1 
434095132.0 434098732.0 148920.65 2 
434098732.0 434102332.0 99830.56 1 
434102332.0 434105932.0 181063.02 0 
434105932.0 434109532.0 109685.66 2 
434109532.0 434113132.0 131412.51 0 
434113132.0 434116732.0 272096.25 4 
434116732.0 434120332.0 121806.07 1 
434120332.0 434123932.0 63449.82 1 
434123932.0 434127532.0 219525.52 2 
434127532.0 434131132.0 122860.73 0 
434131132.0 434134732.0 131316.13 2 
434134732.0 434138332.0 230452.92 0 
434138332.0 434141932.0 84767.49 2 
434141932.0 434145532.0 260401.16 2 
434145532.0 434149132.0 212796.68 0 
434149132.0 434152732.0 103917.15 1 
434152732.0 434156332.0 303023.52 3 
434156332.0 434159932.0 156435.40 2 
434159932.0 434163532.0 143513.99 1 
434163532.0 434167132.0 302959.27 2 
434167132.0 434170732.0 115152.67 0 
434170732.0 434174332.0 202823.59 3 
434174332.0 434177932.0 220312.36 2 
434177932.0 434181532.0 44688.74 1 
434181532.0 434185132.0 225093.94 1 
434185132.0 434188732.0 184473.83 1 
434188732.0 434192332.0 121110.93 0 
434192332.0 434195932.0 244250.17 4 
434195932.0 434199532.0 132818.39 2 
434199532.0 434203132.0 112874.57 1 
434203132.0 434206732.0 212542.28 0 
434206732.0 434210332.0 126377.13 2 
434210332.0 434213932.0 79615.04 0 
434213932.0 434217532.0 229896.45 3 
434217532.0 434221132.0 84485.46 0 
434221132.0 434224732.0 186302.08 1 
434224732.0 434228332.0 208854.94 3 
434228332.0 434231932.0 124951.56 1 
434231932.0 434235532.0 264953.76 1 
434235532.0 434239132.0 168294.21 1 
434239132.0 434242732.0 119351.54 0 
434242732.0 434246332.0 338835.79 1 
434246332.0 434249932.0 108649.67 1 
434249932.0 434253532.0 183795.17 1 
434253532.0 434257132.0 233491.18 5 
434257132.0 434260732.0 87483.43 1 
434260732.0 434264332.0 224055.59 2 
434264332.0 434267932.0 82713.39 0 
434267932.0 434271532.0 137192.32 1 
434271532.0 434275132.0 200398.88 0 
434275132.0 434278732.0 126903.48 2 
434278732.0 434282332.0 120940.45 1 
434282332.0 434285932.0 243282.00 4 
434285932.0 434289532.0 149989.82 1 
In [70]:
ag.displayLightCurve("ap")
Generating plot..please wait.

Cleaning up¶

In [71]:
ag.deleteAnalysisDir()
Out[71]:
True