#!/usr/bin/env python #Import all of the needed modules import pyLikelihood import math from gt_apps import * from UnbinnedAnalysis import * #Set up some arrays to store the results IntFlux = [] IntFluxErr = [] Gamma = [] GammaErr = [] TS = [] #Set the start time of the first bin to the MET tstart value #Set the end time of the first bin to 604800 seconds later bin_start = 239557417 bin_stop = bin_start + 604800 this_bin = 0 #Loop until you get to the MET tstop value of 248370217 while (bin_stop < 248370217 ): print '**Working on range ('+str(bin_start)+','+str(bin_stop)+')**' print '***Running gtselect***' filter['evclsmin'] = 3 filter['evclsmax'] = 4 filter['ra'] = 238.929 filter['dec'] = 11.1901 filter['rad'] = 10 filter['emin'] = 200 filter['emax'] = 400000 filter['zmax'] = 105 filter['tmin'] = bin_start filter['tmax'] = bin_stop filter['infile'] = 'PG1553_filtered.fits' filter['outfile'] = 'LC_PG1553_filtered_bin'+str(this_bin)+'.fits' filter.run() print '***Running gtmktime***' maketime['scfile'] = 'SC.fits' maketime['filter'] = '(DATA_QUAL==1)&&(LAT_CONFIG==1)&&ABS(ROCK_ANGLE)<52' maketime['roicut'] = 'yes' maketime['evfile'] = 'LC_PG1553_filtered_bin'+str(this_bin)+'.fits' maketime['outfile'] = 'LC_PG1553_filtered_gti_bin'+str(this_bin)+'.fits' maketime.run() print '***Running gtltcube***' expCube['evfile'] = 'LC_PG1553_filtered_gti_bin'+str(this_bin)+'.fits' expCube['scfile'] = 'SC.fits' expCube['outfile'] = 'LC_expCube_bin'+str(this_bin)+'.fits' expCube['dcostheta'] = 0.025 expCube['binsz'] = 1 expCube.run() print '***Running gtexpmap***' expMap['evfile'] = 'LC_PG1553_filtered_gti_bin'+str(this_bin)+'.fits' expMap['scfile'] ='SC.fits' expMap['expcube'] ='LC_expCube_bin'+str(this_bin)+'.fits' expMap['outfile'] ='LC_expMap_bin'+str(this_bin)+'.fits' expMap['irfs'] ='P6_V3_DIFFUSE' expMap['srcrad'] =20 expMap['nlong'] =120 expMap['nlat'] =120 expMap['nenergies'] =20 expMap.run() print '***Running likelihood analysis***' obs = UnbinnedObs('LC_PG1553_filtered_gti_bin'+str(this_bin)+'.fits','SC.fits',expMap='LC_expMap_bin'+str(this_bin)+'.fits',expCube='LC_expCube_bin'+str(this_bin)+'.fits',irfs='P6_V3_DIFFUSE') like = UnbinnedAnalysis(obs,'PG1553_fit2.xml',optimizer='NewMinuit') like.fit(verbosity=0,covar=True) IntFlux.append(like.model['_1FGLJ1555.7+1111'].funcs['Spectrum'].getParam('Integral').value()) Gamma.append(like.model['_1FGLJ1555.7+1111'].funcs['Spectrum'].getParam('Index').value()) IntFluxErr.append(math.sqrt(like.covariance[0][0])) GammaErr.append(math.sqrt(like.covariance[1][1])) TS.append(like.Ts('_1FGLJ1555.7+1111')) #Clean up at the end of this iteration by #deleting some objects and incrementing the #bin start and stop times as well as the bin number del like del obs bin_start = bin_stop bin_stop += 604800 this_bin += 1 #Loop back through the arrays to print out the #results to a file called light_curve.txt bin_start = 239557417 bin_stop = bin_start + 604800 this_bin = 0 file = open("light_curve.txt","w") while (bin_stop < 248370217): print >>file, bin_start, TS[this_bin], IntFlux[this_bin], IntFluxErr[this_bin], Gamma[this_bin], GammaErr[this_bin] bin_start = bin_stop bin_stop += 604800 this_bin += 1 #Close the file at the end file.close()