Introduction to the Fermi analysis

Setting up your account

The Fermi data is openly available through the Fermi Science Center here:

To analyze the data, we'll use Enrico, a python wrapper for the Fermi Science Tools.

To get started you need to have a computer with ssh installed (to connect to a remote server). This is available by default in Mac OS X and Linux but you may need to download and install some software if you're using a Windows machine.

Open a terminal and connect with tehanu

> ssh <youruser>

If you don't have a Nevis account, ask your mentor to contact Bill Seligman to create one for you.

When you do get your new account, you need to change the password to something that is unique, longer than 8 charecters, and not your username. To do this, run this command:

> passwd

Follow the prompts, and remember your password. Password managers like Lastpass can make this easier.

The first time you log in (and only the first time) run this command:

> /a/home/tehanu/santander/hs2017/

This will add information to your account profile about where to find Enrico and the Fermi Science Tools. It should print out "Done!".

You will also want to add some certain things to your .bashrc file. The .bashrc is a script that runs each and every time you log in. We're going to add some paths to allow you to more easily certain progams.

First get to your home directory:

> cd

Then open up .bashrc in the text editor of your choice. If you would feel more comfortable with a GUI, try:

> gedit .bashrc

If you can't open a graphical application over ssh, try:

> vim .bashrc

You must excersize care here, as this is a rather important file.

To the end of the document, insert the following line:

export PATH=/a/home/tehanu/jkatz5671/HEASARC/heasoft-6.19/x86_64-unknown-linux-gnu-libc2.12/bin:/a/data/tehanu/santander/software/condor-utils:/a/data/tehanu/santander/software/utils/anaconda/bin:/a/data/tehanu/santander/veritas/ana/condor:/a/data/tehanu/santander/software/ctools-ctools-00-07-01/build/bin:/a/data/tehanu/santander/software/gammalib-00-08-01/build//bin:/a/data/tehanu/santander/software/cmake/build/bin:/a/home/jkatz5671/ds9:/a/data/tehanu/santander/software/bbftp-client-3.2.0/build/bin:/usr/nevis/root-05.34.26/bin:/usr/nevis/gcc-4.9.2/bin:/a/home/tehanu/jkatz5671/etc/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/a/home/tehanu/jkatz5671/bin:/a/data/tehanu/santander/software/VBF/build/bin:/a/data/tehanu/santander/software/EventDisplay/v470/scripts/VTS/:/a/data/tehanu/santander/software/EventDisplay/v470/bin:/a/data/tehanu/santander/software/protobuf-2.5.0/build/bin:/a/home/tehanu/jkatz5671/etc/fv5.3:/a/home/tehanu/jkatz5671/bin:/a/home/tehanu/jkatz5671/ds9dir/_

This allows you to launch ds9, a progam that lets you view fits image files, with a simple command.

Once this step is completed, log out of tehanu/milne by typing "exit" and hitting return.

Log back into tehanu/milne using the ssh command above and run this command, you'll have to run this command every time you want to start working with the Fermi analysis :

> fermisetup

This command should print out this:

Adding Enrico to PATH and PYTHONPATH
Setting environment variables for data file locations
Run enrico_setupcheck to check if you are set up correctly.
Check your PATH and PYTHONPATH if enrico_setup is not found or gives an error.

A primer on how to plot data with python in a jupyter notebook

You can use the Nevis python notebook server here: which you can access using your Nevis account and password. More info on jupyter (previously known as ipython) is available here:

An intro to how to create plots with jupyter notebooks is available here:

An introduction to simple shell commands

The most important commands to know are those getting and looking around.

The directory "tree" of linux

Running your first analysis

For the first analysis we'll follow the tutorial written by Jonathan Katz available here:

A useful tutorial to get you aquainted with the command line can be found here:

We'll analyze data for the blazar PG 1553+113 following the tutorial put together by Fermi here:

First, navigate to /data/

If you already have your own data directory, navigate there and move on. Otherwise, you'll need to make one.

> mkdir <your username>

Now navigate there, and make another directory inside that will be for your analysis. This will help keep things organized later on. Avoid special characters or spaces. This is a good rule to follow always, it'll prevent headaches if you can avoid letting them get into any file names.

> mkdir PG1553113data (or something similarly descriptive)

Run fermisetup in the directory you want to use for your analysis

> fermisetup

Create a configuration file with enrico called myanalysis.conf by running the enrico_config command:

> enrico_config myanalysis.conf

It will ask for different paramaters associated with the source we want to analyze. The most important ones are the position of the source (Right Ascension and Declination), the energy range of the gamma rays we want to consider in our analysis (Emin, Emax), the times we want to consider (Tmin, Tmax), and the radius of the region in the sky to consider around the source (which we call the Region of Interest, or ROI). For our analysis, we'll get the values from the section of the Fermi tutorial called "Get the data". Namely:

  • Search Center (RA,Dec) = (238.929,11.1901)
  • Radius = 20 degrees
  • Start Time (MET) = 239557417 seconds (2008-08-04T15:43:37)
  • Stop Time (MET) = 256970880 seconds (2009-02-22T04:48:00)
  • Minimum Energy = 100 MeV
  • Maximum Energy = 300000 MeV
All other values (output directories, tag, spectral model, redshift, etc) can be left set to the default values (which enrico shows in square brackets) by just pressing enter when asked. This is how it would look when running enrico_config (notice that I didn't enter a value for those fields where the default was OK):

> enrico_config myanalysis.conf

[Message]: Please provide the following required options [default] :
Output directory [/a/home/tehanu/santander/noimagination] :
Target Name : PG1553
Right Ascension: 238.929
Declination: 11.1901
redshift, no effect if null [0] :
Options are : PowerLaw, PowerLaw2, LogParabola, PLExpCutoff, Generic
Generic is design to allow the user to fit with non-supported models
EBL absorption can be added for PowerLaw2, LogParabola, PLExpCutoff
Spectral Model [PowerLaw] :
ROI Size [15] : 20
FT2 file [/a/data/tehanu/santander/software/fermi/enrico/Data/download/lat_spacecraft_merged.fits] :
FT1 list of files [/a/data/tehanu/santander/software/fermi/enrico/Data/download/events.lis] :
tag [LAT_Analysis] :
Start time [239557418] : 239557417
End time [334165418] : 256970880
Emin [100] :
Emax [300000] :
evclass [128] :
evtype [3] :
Corresponding IRFs = ('P8R2_SOURCE_V6', ['BACK', 'FRONT'])
Is this ok? [y] :
Corresponding zmax = 90

Once you enter all the values, you'll have the myanalysis.conf file in your folder:

> ls myanalysis.conf


The next step is to produce and XML file with all the sources in the vicinity of PG 1553:

> enrico_xml myanalysis.conf

This should print out:

use the default location of the catalog
use the default catalog
Use the catalog : /a/data/tehanu/santander/software/fermi/enrico/Data/catalog/
(84.002691737453972, 84.002691737453972, '3FGL J0921.8+6215')
[Message]: Summary of the XML model generation
Add 74 sources in the ROI of 22.0 ( 20.0 + 2 ) degrees
4 sources have free parameters inside 3.0 degrees
0 source(s) is (are) extended
Iso model file /a/data/tehanu/santander/software/fermi/enrico/Data/diffuse/iso_P8R2_SOURCE_V6_v06.txt
Galactic model file /a/data/tehanu/santander/software/fermi/enrico/Data/diffuse/gll_iem_v06.fits
[Message]: write the Xml file in /a/home/tehanu/santander/noimagination/PG1553_PowerLaw_model.xml

Running long processes

The processing of the Fermi data can (and will) take several hours, depending on how much data you're analyzing. You may not want to leave your computer connected to Nevis during this time, but if you close the terminal running the analysis the processing stops. There are two main ways to run the analysis without your computer remainng logged in, screen and nohup. With screen, the server runs not only the commands but also the command line interface, so your computer is not needed to keep the process alive. screen's additional level of abstraction can add minor techincal complication, but allows a persisitent terminal session for running a series of commands. nohup is different. nohup (no-hangup) "daemonizes" the process so that it runs in the background. This way, you run the command and immediately return to a shell prompt. This is probably more straightforward for most analysis tasks.

Here's how to use screen:

> screen

Set up your Fermi variables again

> fermisetup

And now you can continue running the analysis inside the screen.

If you want to close your computer and/or disconnect from Nevis while the analysis is still running, you need to first "detach the screen" in which the analysis is running. To do that you need to first press "Ctrl + D" and then "A" in your keyboard. That should bring you back to the original session where you logged into tehanu/milne.

If you want to connect again with the session running the analysis, once in tehanu/milne you need to run:

> screen -r

Hit "Ctrl + D" and then "A" to exit.

Here's how to use nohup:

> nohup <command> &

This will make an output file called nohup.out. If you want to save your file to a specific name, try this:

> nohup "<command> > <filename>.out" &

Here's how this works:

nohup <command> runs the command with nohup. Because nohup doesn't need to stay connected, rather than outputting its contents into the terminal window, it outputs into a file. You can tell it what file to output with the > <filename>.out part of the command. The > says "take the output of this and put it into this file." The quotes in the command are important, as they ensure nohup is being applied to the whole command, not just the enrico_lc portion.

Running the SED creator

Once the xml file is created, run the SED step of the analysis to calculate the energy spectrum (which is the number of photons detected by Fermi from this source per unit area, unit time and unit energy) of PG 1553 during the time period considered:

> enrico_sed myanalysis.conf

This step should take several hours, so make sure you run it when you don't need to disconnect your computer from the network during that time.

Once this is finished, you should be able to run this command to plot the results from the analysis, which will be located in a folder called "Spectrum":

> enrico_plot_sed myanalysis.conf

To see the images produced by the analysis run this command:

> display Spectrum/SED_PG1553_PowerLaw.png

Running the Light Curve creator

We may also want to calculate the "light curve" of a source, namely how the flux (~brightness) of that source in gamma rays changed with time. To do that, we need to run:

> enrico_lc myanalysis.conf

and wait until it finishes. Once it completes, run:

> enrico_plot_lc myanalysis.conf

to see the results. Use the "display" command to look at the .png files created by the light curve step.


  1. Check that your commands are correctly typed.
  2. Check to see if any of your filenames contain spaces or special characters.
  3. Check to see if any errors were produced during the processing. Pay attention to what's being written to screen during the processing to see if any errors can be quickly fixed. For instance, a "file not found" error could mean that the name of a file was incorrectly entered.
  4. Good ol' Google and/or post the question to our Slack channel

Time conversion and source coordinates

Time conversion tools

The Fermi analysis uses MET (mission elapsed time) in seconds as the time frame of reference. To convert between standard dates, modified julian days, and MET please use this NASA webpage:

Source location in RA and Dec

The position of the source to analyze needs to be degrees for both Right Ascension (RA) and Declination (Dec), which are respectively the celestial equivalents of Longitude and Latitude for the Earth. For more information on this coordinate system check the wikipedia entry for the Equatorial Coordinate System:

There are several coordinate engines on the web but most of them provide the RA in hours, minutes, and seconds instead of degrees so the easiest way to find it is to use the Fermi database interface here: Simply enter the name of your source in the "Object name or coordinates" field of the form and press enter. The position in RA, Dec in degrees should be given in a table in the next page under "Equatorial Coordinates (degrees)"

-- Marcos Santander - 2017-06-23

Edited by -- Jonathan Katz - 2017-07-10


Edit | Attach | Watch | Print version | History: r11 | r9 < r8 < r7 < r6 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r7 - 2017-07-13 - JonathanKatz
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback