Python Analysis / LATAnalysisScripts / Lightcurves / Fitting Issues



Similar documents
Fermi-LAT Background Estimator

Fermi LAT and GBM Data Access, File Structure and the Standard Tools. Fermi Solar Analysis Workshop GSFC, August 2012 Elizabeth Ferrara - FSSC 1

Magento Search Extension TECHNICAL DOCUMENTATION

EVault for Data Protection Manager. Course 361 Protecting Linux and UNIX with EVault

NaviCell Data Visualization Python API

Solr Bridge Search Installation Guide

Bulk Downloader. Call Recording: Bulk Downloader

RuleBender Tutorial

Computational Mathematics with Python

Python and Cython. a dynamic language. installing Cython factorization again. working with numpy

Automating client deployment

CN=Monitor Installation and Configuration v2.0

ALERT installation setup

Continuous Integration/Testing and why you should assume every change breaks your code

Day 1 - Technology Introduction & Digital Asset Management

Installing LearningBay Enterprise Part 2

Source Detection and Sensitivity Map Generation for XMM Archival Data

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

Creating a DUO MFA Service in AWS

User Management Resource Administrator. UMRA Example Projects. Service Management

GeBro-BACKUP. Die Online-Datensicherung. Manual Pro Backup Client on a NAS

NovaBACKUP xsp Version 15.0 Upgrade Guide

Computational Mathematics with Python

B&K Precision 1785B, 1786B, 1787B, 1788 Power supply Python Library

Database manager does something that sounds trivial. It makes it easy to setup a new database for searching with Mascot. It also makes it easy to

]project-open[ V3.0. Operations & Maintenance Guide

MAGENTO QUICK START. Magento users New and relatively new Mostly on Community Ed. > 1 year; 16% Not at all yet; 33% 3 mo.

NLP Programming Tutorial 0 - Programming Basics

Java with Eclipse: Setup & Getting Started

The Build Process. of (GNU Tools for ARM Embedded Processors)

Structural Health Monitoring Tools (SHMTools)

Implementing and Administering an Enterprise SharePoint Environment

Outlook Web App (Online)... 3 Outlook 2013 (Desktop) Apple Mail Mobile Devices Android iphone... 40

Pete Helgren Ruby On Rails on i

HR Onboarding Solution

TUTORIAL ECLIPSE CLASSIC VERSION: ON SETTING UP OPENERP 6.1 SOURCE CODE UNDER WINDOWS PLATFORM. by Pir Khurram Rashdi

Quick and Easy Web Maps with Google Fusion Tables. SCO Technical Paper

HOWTO: Setting up WP7 monitoring tools with GLite

Yale Software Library

Instructions for update installation of ElsaWin 5.00

Incremental Backup Script. Jason Healy, Director of Networks and Systems

EVALUATION ONLY. WA2088 WebSphere Application Server 8.5 Administration on Windows. Student Labs. Web Age Solutions Inc.

MatrixSSL Getting Started

Documentation and Project Organization

Integrating Apache Web Server with Tomcat Application Server

ATLAS Tier 3

MS Project Tutorial. CS 587 Software Project Management Instructor: Dr. Atef Bader. Prepared by Milton Hurtado

EVault Software. Course 361 Protecting Linux and UNIX with EVault

SUMMARY. Satellite is an application Two Sigma wrote to monitor, alert, and auto-administer our Mesos clusters.

WebIOPi. Installation Walk-through Macros

Local Caching Servers (LCS): User Manual

E6893 Big Data Analytics: Demo Session for HW I. Ruichi Yu, Shuguan Yang, Jen-Chieh Huang Meng-Yi Hsu, Weizhen Wang, Lin Haung.

Fermilab Central Web Service Site Owner User Manual. DocDB: CS-doc-5372

How To Back Up Your Pplsk Data On A Pc Or Mac Or Mac With A Backup Utility (For A Premium) On A Computer Or Mac (For Free) On Your Pc Or Ipad Or Mac On A Mac Or Pc Or

Computer Science and Engineering Linux Cisco VPN Client Installation and Setup Guide

Supported platforms & compilers Required software Where to download the packages Geant4 toolkit installation (release 9.6)

Basic SQL Server operations

How do I Install and Configure MS Remote Desktop for the Haas Terminal Server on my Mac?

FrontDesk Installation And Configuration

Source Code Management for Continuous Integration and Deployment. Version 1.0 DO NOT DISTRIBUTE

Mitglied der Helmholtz-Gemeinschaft UNICORE. Uniform Access to JSC Resources. Michael Rambadt, 20.

CONVERTING FROM NETKEEPER ISAM v6.32 to NETKEEPER SQL

ECE 4893: Internetwork Security Lab 12: Web Security

For Introduction to Java Programming, 5E By Y. Daniel Liang

Ricardo Perdigao, Solutions Architect Edsel Garcia, Principal Software Engineer Jean Munro, Senior Systems Engineer Dan Mitchell, Principal Systems

Monitoring disk stats with Cacti

Source Code Review Using Static Analysis Tools

Installation Manual v2.0.0

DevKey Documentation. Release 0.1. Colm O Connor

Arena Tutorial 1. Installation STUDENT 2. Overall Features of Arena

No Frills Command Line Magento

freeradius A High Performance, Open Source, Pluggable, Scalable (but somewhat complex) RADIUS Server Aurélien Geron, Wifirst, 7 janvier 2011

Secure File Transfer Installation. Sender Recipient Attached FIles Pages Date. Development Internal/External None 11 6/23/08

Computational Mathematics with Python

cloud-kepler Documentation

Table of Contents. OpenDrive Drive 2. Installation 4 Standard Installation Unattended Installation

Amon Agent. User Guide

Install guide for Websphere 7.0

How do I Install and Configure MS Remote Desktop for the Haas Terminal Server on my Mac?

SecureVault Online Backup Service Client Installation Guide

Getting Started With Delegated Administration

Introducing Xcode Source Control

Brakeman and Jenkins: The Duo Detects Defects in Ruby on Rails Code

Monitoring Oracle Enterprise Performance Management System Release Deployments from Oracle Enterprise Manager 12c

Integrating Secure FTP into Data Services

SimbaEngine SDK 9.4. Build a C++ ODBC Driver for SQL-Based Data Sources in 5 Days. Last Revised: October Simba Technologies Inc.

Multi-Router Traffic Grapher (MRTG)

TaxonHub Client. What is Taxon? TaxonHub Client. The Open Source project. suggest-term. admin. Strategy for version numbers

DiskBoss. File & Disk Manager. Version 2.0. Dec Flexense Ltd. info@flexense.com. File Integrity Monitor

LDAPCON Sébastien Bahloul

USING USB FLASH DISK WITH TCMS V2

Secrets of Event Viewer for Active Directory Security Auditing Lepide Software

Qualys API Limits. July 10, Overview. API Control Settings. Implementation

PassBy[ME] - Bugzilla integration on

The Web Pro Miami, Inc. 615 Santander Ave, Unit C Coral Gables, FL T: info@thewebpro.com

System Administration of a C-TOOLS Server

Lab 2-2: Exploring Threads

GTk+ and GTkGLExt Build Process for Windows 32- bit

Measuring the performance of a Wired network

XMap 7 Administration Guide. Last updated on 12/13/2009

Transcription:

Python Analysis / LATAnalysisScripts / Lightcurves / Fitting Issues Jeremy S. Perkins, FSSC Fermi Summer School 2012 You probably should follow along with the data I m using today and go back to your ROI after the tutorial.

Introduction Python is a programming language similar to Tcl, Perl, Ruby, Scheme or Java Very clear, readable syntax Embeddable within apps as a scripting interface http://wiki.python.org/moin/beginnersguide http://python4astronomers.github.com/ All of the Science Tools are included as python modules with some additional capabilities like Upper limits Direct access to results (and data)

Quick Usage: [user@localhost ~]$ python Python 2.7.2 (default, Apr 10 2012, 10:33:45) [GCC 4.2.1 (Apple Inc. build 5666)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pylikelihood >>> from UnbinnedAnalysis import * >>> help(unbinnedanalysis) Check out the python tutorial for examples: http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/ python_tutorial.html We re going to use the LATAnalysisScripts today instead which is are modules built on top of the python interface.

Philosophy and Why Should You Care LATAnalysisScripts is a set of three python libraries to make the analysis of LAT data straightforward and powerful. Uses standard python tools to make installation and use easy and intuitive. Vetted by the FSSC so should be official Checks for many common errors Easy to document, easy to use, easy to repeat Documentation! Exposes special features.

LATAnalysisScripts Structure Three independent libraries (quickanalysis, quicklike and quickplot). A single config file A common naming convention for files. Detailed, clear error reporting Detailed, clear logging of results and commands.

Download and Install Download and install pyds9 [user@localhost ~]$ wget http://hea-www.harvard.edu/saord/download/ds9/ python/pyds9-1.3.tar.gz [user@localhost ~]$ tar zxvf pyds9-1.3.tar.gz [user@localhost ~]$ cd pyds9-1.3 [user@localhost ~]$ python setup.py install Copy make2fglxml into the python tree [user@localhost ~]$ cp make2fglxml.py $FERMI_DIR/lib/python2.7/sitepackages/ Unpack and intall LATAnalysisScripts [user@localhost ~]$ tar zxvf LATAnalysisScripts-1.9.tar.gz [user@localhost ~]$ cd LATAnalysisScripts-1.9 [user@localhost ~]$ python setup.py install

Our Simple Analysis We re going to derive an upper limit on Swift J164449.3+573451 during a short time period. Search Center (RA,Dec) = (251.2054,+57.5808) Radius = 30 degrees Start Time (MET) = 322963202 seconds (2011-03-28T00:00:00) Stop Time (MET) = 323568002 seconds (2011-04-04T00:00:00) Minimum Energy = 100 MeV Maximum Energy = 300000 MeV http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/data/ LATAnalysisScripts/L120404155224B0489E7F72_PH00.fits http://fermi.gsfc.nasa.gov/ssc/data/analysis/scitools/data/ LATAnalysisScripts/L120404155224B0489E7F72_SC00.fits

Initialize the analysis [user@localhost]$ quickanalysis -i Creating example configuration file called example.cfg 2012-02-01 11:56:00,717 - quickanalysis - INFO - Created quickanalysis object: irfs=p7source_v6, verbosity=0, binned=false, base=example, eventclass=2, rad=10, tmin=indef, ra=0, emin=100, emax=300000, tmax=indef, dec=0, zmax=100, binsize=0.1, 2012-02-01 11:56:00,718 - quickanalysis - INFO - wrote common config to example.cfg. 2012-02-01 11:56:00,718 - quickanalysis - INFO - wrote quickanalysis config to example.cfg. [user@localhost]$ cp example.cfg SwiftJ1644.cfg Now open SwiftJ1644.cfg in a text editor.

SwiftJ1644.cfg Common Section quickanalysis Section

Some housekeeping. [user@localhost]$ ls -1 *PH* > SwiftJ1644.list [user@localhost]$ ln -s L120404155224B0489E7F72_SC00.fits SwiftJ1644_SC.fits Now run... [user@localhost]$ quickanalysis -a -n SwiftJ1644...output suppressed. This does everything up to the likelihood calculation and stores all of the output in a log file called SwiftJ1644_quickAnalysis.log.

Create a Model File [user@localhost]$ quickanalysis -x -n SwiftJ1644 Creating XML model file from 2FGL 2012-02-01 13:48:49,305 - quickanalysis - INFO - Reading from config file (SwiftJ1644.cfg) 2012-02-01 13:48:49,306 - quickanalysis - INFO - Reading common variables... 2012-02-01 13:48:49,306 - quickanalysis - INFO - Reading quickanalysis variables... 2012-02-01 13:48:49,307 - quickanalysis - INFO - Created quickanalysis object: irfs=p7source_v6, verbosity=0, base=swiftj1644, binned=false, eventclass=2, rad=20, tmin=322963202, emin=100, emax=300000, tmax=323568002, binsize=0.1, ra=251.2054, zmax=100, dec=57.5808, 2012-02-01 13:48:49,307 - quickanalysis - CRITICAL - SwiftJ1644_model.xml doesn't exist. 2012-02-01 13:48:49,307 - quickanalysis - INFO - SwiftJ1644_model.xml doesn't exist, will create a new one. This is make2fglxml version 04r1. For use with the gll_psc_v02.fit and gll_psc_v05.fit and later LAT catalog files. Creating file and adding sources for 2FGL Added 33 point sources and 0 extended sources 2012-02-01 13:48:50,298 - quickanalysis - INFO - NOTE: if there are extended sources in your ROI, make sure the correspoinding diffuse template is in the working directory.

This model doesn t include our source of interest. Add the following to the top of the SwiftJ1644_model.xml file <source name="swiftj1644" type="pointsource"> <spectrum type="powerlaw2"> <parameter free="true" max="10000.0" min="0.0001" name="integral" scale="1e-07" value="1.0"/> <parameter free="true" max="5.0" min="0.0" name="index" scale="-1.0" value="2.0"/> <parameter free="false" max="500000.0" min="20.0" name="lowerlimit" scale="1.0" value="100.0"/> <parameter free="false" max="500000.0" min="20.0" name="upperlimit" scale="1.0" value="300000.0"/> </spectrum> <spatialmodel type="skydirfunction"> <parameter free="false" max="360.0" min="-360.0" name="ra" scale="1.0" value="251.2054"/> <parameter free="false" max="90.0" min="-90.0" name="dec" scale="1.0" value="57.5808"/> </spatialmodel> </source>

Edit your SwiftJ1644.cfg file to include the quicklike configuration section (you can also run quicklike -i to generate and example). [quicklike] sourcename = SwiftJ1644 model = SwiftJ1644_model.xml drmtol = 0.1 mintol = 0.0001

Start up python and setup the likelihood session. [user@localhost]$ python Python 2.6.5 (r265:79063, Nov 9 2010, 12:49:33) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>from quicklike import * >>>ql = quicklike('swiftj1644', True)...output supressed >>>ql.makeobs()...output supressed >>>ql.initmin(modelfile="swiftj1644_model.xml")...output supressed

Unload our source of interest and do the fit without it first. >>>ql.unloadsource('swiftj1644') 2012-02-02 12:50:51,589 - quicklike - INFO - Removed SwiftJ1644 from the model and saved it. >>>ql.fitmin()...some output suppressed 2012-02-02 12:55:08,062 - quicklike - INFO - NEWMINUIT Fit Finished. Total TS: -11469.3411544 2012-02-02 12:55:08,063 - quicklike - INFO - NEWMINUIT Fit Status: 156 2012-02-02 12:55:08,063 - quicklike - INFO - NEWMINUIT fit Distance: 1.35106292821e-05 2012-02-02 12:55:08,063 - quicklike - ERROR - NEWMINUIT DID NOT CONVERGE!!! 2012-02-02 12:55:08,063 - quicklike - ERROR - The fit failed the following tests: HasMadePosDefCovar HasPosDefCovar HasAccurateCovar...some output suppressed Note that our fit didn t converge... Let s see if we can figure out why...

Check for parameters at their limits >>>ql.paramsatlimit() 2012-02-02 15:51:32,050 - quicklike - ERROR - The Prefactor (0.000100002150128) of _2FGLJ1531.0+5725 is close (2.1501276315e-05) to its lower limit (0.0001) 2012-02-02 15:51:32,062 - quicklike - ERROR - The Index (4.99999994135) of _2FGLJ1604.6+5710 is close (1.17301164337e-08) to its upper limit (5.0) 2012-02-02 15:51:32,063 - quicklike - ERROR - The Index (4.92274288596) of _2FGLJ1656.5+6012 is close (0.0154514228086) to its upper limit (5.0) 2012-02-02 15:51:32,065 - quicklike - ERROR - The Index (4.98785968966) of _2FGLJ1559.0+5627 is close (0.00242806206775) to its upper limit (5.0) Reload our source and check for weak sources. >>>ql.reloadsource() 2012-02-02 15:52:42,865 - quicklike - INFO - Reloaded saved source. >>>ql.removeweak()...output supressed Remove all the free sources with TS < 1.0 >>>ql.removeweak(tslimit=1.0, RemoveFree=True)...output supressed

Unload our source again and re-fit. >>>ql.reloadsource() >>>ql.removeweak(tslimit=0.0, RemoveFree=True, RemoveFixed=True) >>>ql.unloadsource('swiftj1644') 2012-02-02 17:26:51,589 - quicklike - INFO - Removed SwiftJ1644 from the model and saved it. >>>ql.fitmin() 2012-02-02 17:27:01,039 - quicklike - INFO - NEWMINUIT Fit Finished. Total TS: -11470.0702022 2012-02-02 17:27:01,039 - quicklike - INFO - NEWMINUIT Fit Status: 0 2012-02-02 17:27:01,039 - quicklike - INFO - NEWMINUIT fit Distance: 3.52763544413e-06 It converged, but let s double check for problems. >>>ql.paramsatlimit() 2012-02-02 17:29:45,456 - quicklike - ERROR - The Index (4.99999570933) of _2FGLJ1559.0+5627 is close (8.58133958737e-07) to its upper limit (5.0) Looks like we re having trouble fitting this parameter. Let s try fixing it to the catalog value.

Copy the output of our fit to a new file. >>>exit() [user@localhost]$ cp SwiftJ1644_likeMinuit.xml SwiftJ1644_minimal.xml Open this new file in a text editor and set the index of 2FGLJ1559.0+5627 to it s catalog value (2.09846) and set it to fixed (free= 0 ). Also, make sure that SwiftJ1644 is there somewhere.

Let s do this again with our new model. [user@localhost]$ python Python 2.6.5 (r265:79063, Nov 9 2010, 12:49:33) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>from quicklike import * >>>ql = quicklike('swiftj1644', True)...output supressed >>>ql.makeobs()...output supressed >>>ql.initmin(modelfile="swiftj1644_minimal.xml")...output supressed >>>ql.unloadsource('swiftj1644') 2012-02-02 17:38:14,752 - quicklike - INFO - Removed SwiftJ1644 from the model and saved it. >>>ql.fitmin()...output supressed 2012-02-02 17:39:57,667 - quicklike - INFO - NEWMINUIT Fit Finished. Total TS: -11470.7003776 2012-02-02 17:39:57,668 - quicklike - INFO - NEWMINUIT Fit Status: 0 2012-02-02 17:39:57,668 - quicklike - INFO - NEWMINUIT fit Distance: 3.4341373915e-05 >>>ql.paramsatlimit() It converges and the parameters are ok.

Calculate the upper limit. >>>ql.reloadsource() 2012-02-09 17:41:08,647 - quicklike - INFO - Reloaded saved source. >>>ql.calcupper('swiftj1644', Emax=10000)...output supressed 2012-02-02 17:45:50,554 - quicklike - INFO - SwiftJ1644 UL: 3.48e-07 ph/cm^2/s for emin=100.0, emax=10000.0, delta(loglike) =1.35

Useful Functions (more details via the help function) calcupper: calculates an upper limit customerange: changes the range of the fit paramsatlimit: prints out any parameters that are at their limits printsource: prints the details of a specific source removeweak: removes weak sources unloadsource: removes a source but saves it reloadsource: restores the source that was unloaded

Also lots in python... Check out our documentation. Use the help function. Ask the help desk. Use the LATAnalysisScripts as an example You could even contribute! The scripts are on github and you can add features or fix bugs.

Notes on Light Curves Types of Light Curves: Regular Binning with likelihood Adaptive Binning with likelihood Aperture photometry

Lightcurve How To Perform a standard analysis over the full energy range ( DC Analysis). Determine your binning (~TS DC/25). Prepare a model file: Freeze all spectral shapes of background sources Freeze all parameters of weak sources (~TS DC/Nbin < 4 or 9) Freeze the spectral shape of your SoI? Decide when to show upper limits vs. flux points Use gtselect (or the gt_app filter in python) to bin the data and run the likelihood method. Check for problems (see next slide, pertains to DC analysis as well). Compute upper limits if needed.

Gotchas Common problem is that the fit doesn t converge and the error matrix isn t calculated. Then the error bars are wrong and any modeling based on those data will be wrong.

How to check Fluxerr/Flux vs. sqrt(npred)/npred

Also, look for convergence. When using the MINUIT optimizer look for output that says ERR MATRIX NOT POS-DEF. Get the return code from MINUIT/NEW- MINUIT (look at the LATAnalysisScripts for how to do this).

How to Fix (pertains to DC analysis as well) Problem is usually a parameter at the limit Usually spectral shapes - just freeze them. Weak background sources - freeze them or remove them. Try increasing the overall tolerance In python do >>> like.tol = 1e-8 In gtlike set ftol = 1e-8 on command line Simplify, Simplify, Simplify. More parameters means more complexity. Freeze parameters from the outside in.

Break... What do you want to do? Some suggestions: Work up a quick loop to generate a light curve of the 3C 279 data. Use python to refine the model of your favorite source. Look in the user contributed tools for more tasty treats. Use pyfits to load in the IRF data (or any data in FITS format).