Commit 7955dfc9afa801c898f446c43b68b0089e0be98d
1 parent
50d6ad88
Integrate code
Showing
2 changed files
with
39 additions
and
32 deletions
scripts/csspec.py
| ... | ... | @@ -23,9 +23,9 @@ import ctools |
| 23 | 23 | import sys |
| 24 | 24 | import tempfile |
| 25 | 25 | |
| 26 | -# ============== # | |
| 27 | -# cstsdist class # | |
| 28 | -# ============== # | |
| 26 | +# ============ # | |
| 27 | +# csspec class # | |
| 28 | +# ============ # | |
| 29 | 29 | class csspec(ctools.cscript): |
| 30 | 30 | """ |
| 31 | 31 | This class implements the creation of spectral points. It derives from |
| ... | ... | @@ -43,14 +43,14 @@ class csspec(ctools.cscript): |
| 43 | 43 | self.version = "1.0.0" |
| 44 | 44 | |
| 45 | 45 | # Initialise some members |
| 46 | - self.obs = None | |
| 46 | + self.obs = None | |
| 47 | 47 | |
| 48 | 48 | # Initialise some members |
| 49 | 49 | if isinstance(argv[0],gammalib.GObservations): |
| 50 | 50 | self.obs = argv[0] |
| 51 | - argv = argv[1:] | |
| 51 | + argv = argv[1:] | |
| 52 | 52 | else: |
| 53 | - self.obs = gammalib.GObservations() | |
| 53 | + self.obs = gammalib.GObservations() | |
| 54 | 54 | self.obs.clear() |
| 55 | 55 | self.m_outfile = "" |
| 56 | 56 | |
| ... | ... | @@ -105,6 +105,7 @@ class csspec(ctools.cscript): |
| 105 | 105 | pars.append(gammalib.GApplicationPar("outfile","f","a","spectrum.fits","","","Output file name")) |
| 106 | 106 | pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) |
| 107 | 107 | pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","PSF cube file (only needed for stacked analysis)")) |
| 108 | + pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Background cube file (only needed for stacked analysis)")) | |
| 108 | 109 | pars.append(gammalib.GApplicationPar("caldb","s","a","dummy","","","Calibration database")) |
| 109 | 110 | pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function")) |
| 110 | 111 | pars.append(gammalib.GApplicationPar("emin","r","h","0.1","","","Lower energy limit for spectral points(TeV)")) |
| ... | ... | @@ -135,7 +136,6 @@ class csspec(ctools.cscript): |
| 135 | 136 | """ |
| 136 | 137 | Get parameters from parfile and setup the observation. |
| 137 | 138 | """ |
| 138 | - # Get parameters | |
| 139 | 139 | # Set observation if not done before |
| 140 | 140 | if self.obs == None or self.obs.size() == 0: |
| 141 | 141 | self.require_inobs("csspec::get_parameters()") |
| ... | ... | @@ -154,14 +154,14 @@ class csspec(ctools.cscript): |
| 154 | 154 | # Get binning flag |
| 155 | 155 | self.m_binned = self["binned"].boolean() |
| 156 | 156 | if self.m_binned: |
| 157 | - self.m_xref = self["xref"].real() | |
| 158 | - self.m_yref = self["yref"].real() | |
| 159 | - self.m_nxpix = self["nxpix"].integer() | |
| 160 | - self.m_nypix = self["nypix"].integer() | |
| 161 | - self.m_binsz = self["binsz"].real() | |
| 157 | + self.m_xref = self["xref"].real() | |
| 158 | + self.m_yref = self["yref"].real() | |
| 159 | + self.m_nxpix = self["nxpix"].integer() | |
| 160 | + self.m_nypix = self["nypix"].integer() | |
| 161 | + self.m_binsz = self["binsz"].real() | |
| 162 | 162 | self.m_coordsys = self["coordsys"].string() |
| 163 | - self.m_proj = self["proj"].string() | |
| 164 | - self.m_ebins = self["nebins"].integer() | |
| 163 | + self.m_proj = self["proj"].string() | |
| 164 | + self.m_ebins = self["nebins"].integer() | |
| 165 | 165 | |
| 166 | 166 | # Read other parameters |
| 167 | 167 | self.m_outfile = self["outfile"].filename() |
| ... | ... | @@ -277,8 +277,8 @@ class csspec(ctools.cscript): |
| 277 | 277 | table.extname("SPECTRUM") |
| 278 | 278 | |
| 279 | 279 | # Add Header for compatibility with gammalib.GMWLSpectrum |
| 280 | - table.card("Instrument", "CTA", "Name of Instrument") | |
| 281 | - table.card("Telescope", "CTA", "Name of Telescope") | |
| 280 | + table.card("INSTRUME", "CTA", "Name of Instrument") | |
| 281 | + table.card("TELESCOP", "CTA", "Name of Telescope") | |
| 282 | 282 | |
| 283 | 283 | # Create FITS table columns |
| 284 | 284 | energy = gammalib.GFitsTableDoubleCol("Energy", self.m_ebounds.size()) |
| ... | ... | @@ -313,7 +313,7 @@ class csspec(ctools.cscript): |
| 313 | 313 | energy[i] = elogmean.TeV() |
| 314 | 314 | |
| 315 | 315 | # Store energy errors |
| 316 | - energy_low[i] = (elogmean - emin).TeV() | |
| 316 | + energy_low[i] = (elogmean - emin).TeV() | |
| 317 | 317 | energy_high[i] = (emax - elogmean).TeV() |
| 318 | 318 | |
| 319 | 319 | # Log information |
| ... | ... | @@ -330,15 +330,18 @@ class csspec(ctools.cscript): |
| 330 | 330 | select["ra"].value("UNDEFINED") |
| 331 | 331 | select["dec"].value("UNDEFINED") |
| 332 | 332 | select.run() |
| 333 | - | |
| 333 | + | |
| 334 | + # Retrieve observation | |
| 334 | 335 | obs = select.obs() |
| 335 | - | |
| 336 | + | |
| 337 | + # Binned analysis | |
| 336 | 338 | if self.m_binned: |
| 337 | - | |
| 339 | + | |
| 340 | + # Header | |
| 338 | 341 | if self.logTerse(): |
| 339 | 342 | self.log.header3("Binning events") |
| 340 | 343 | |
| 341 | - # bin events | |
| 344 | + # Bin events | |
| 342 | 345 | bin = ctools.ctbin(select.obs()) |
| 343 | 346 | bin["usepnt"].boolean(False) |
| 344 | 347 | bin["ebinalg"].string("LOG") |
| ... | ... | @@ -354,10 +357,11 @@ class csspec(ctools.cscript): |
| 354 | 357 | bin["proj"].string(self.m_proj) |
| 355 | 358 | bin.run() |
| 356 | 359 | |
| 360 | + # Header | |
| 357 | 361 | if self.logTerse(): |
| 358 | 362 | self.log.header3("Creating exposure cube") |
| 359 | 363 | |
| 360 | - # create exposure cube | |
| 364 | + # Create exposure cube | |
| 361 | 365 | expcube = ctools.ctexpcube(select.obs()) |
| 362 | 366 | expcube["incube"].filename("NONE") |
| 363 | 367 | expcube["usepnt"].boolean(False) |
| ... | ... | @@ -374,10 +378,11 @@ class csspec(ctools.cscript): |
| 374 | 378 | expcube["proj"].string(self.m_proj) |
| 375 | 379 | expcube.run() |
| 376 | 380 | |
| 381 | + # Header | |
| 377 | 382 | if self.logTerse(): |
| 378 | 383 | self.log.header3("Creating PSF cube") |
| 379 | 384 | |
| 380 | - # create psf cube | |
| 385 | + # Create psf cube | |
| 381 | 386 | psfcube = ctools.ctpsfcube(select.obs()) |
| 382 | 387 | psfcube["incube"].filename("NONE") |
| 383 | 388 | psfcube["usepnt"].boolean(False) |
| ... | ... | @@ -394,10 +399,11 @@ class csspec(ctools.cscript): |
| 394 | 399 | psfcube["proj"].string(self.m_proj) |
| 395 | 400 | psfcube.run() |
| 396 | 401 | |
| 402 | + # Header | |
| 397 | 403 | if self.logTerse(): |
| 398 | 404 | self.log.header3("Creating background cube") |
| 399 | 405 | |
| 400 | - # create background cube | |
| 406 | + # Create background cube | |
| 401 | 407 | bkgcube = ctools.ctbkgcube(select.obs()) |
| 402 | 408 | bkgcube["incube"].filename("NONE") |
| 403 | 409 | bkgcube["usepnt"].boolean(False) |
| ... | ... | @@ -433,10 +439,11 @@ class csspec(ctools.cscript): |
| 433 | 439 | # Set new models to binned observation |
| 434 | 440 | obs.models(models) |
| 435 | 441 | |
| 442 | + # Header | |
| 436 | 443 | if self.logTerse(): |
| 437 | 444 | self.log.header3("Performing fit") |
| 438 | 445 | |
| 439 | - # likelihood | |
| 446 | + # Likelihood | |
| 440 | 447 | like = ctools.ctlike(obs) |
| 441 | 448 | like.run() |
| 442 | 449 | |
| ... | ... | @@ -446,10 +453,11 @@ class csspec(ctools.cscript): |
| 446 | 453 | # Log information |
| 447 | 454 | if self.logTerse(): |
| 448 | 455 | self.log("No event in this bin. Bin is skipped\n") |
| 449 | - | |
| 450 | - flux[i] = 0.0 | |
| 451 | - flux_err[i] = 0.0 | |
| 452 | - TSvalues[i] = 0.0 | |
| 456 | + | |
| 457 | + # Set all values to 0 | |
| 458 | + flux[i] = 0.0 | |
| 459 | + flux_err[i] = 0.0 | |
| 460 | + TSvalues[i] = 0.0 | |
| 453 | 461 | ulim_values[i] = 0.0 |
| 454 | 462 | continue |
| 455 | 463 | |
| ... | ... | @@ -475,7 +483,6 @@ class csspec(ctools.cscript): |
| 475 | 483 | ulimit.run() |
| 476 | 484 | ulimit_value = ulimit.diff_ulimit() |
| 477 | 485 | except: |
| 478 | - | |
| 479 | 486 | if self.logTerse(): |
| 480 | 487 | self.log("Upper limit calculation failed\n") |
| 481 | 488 | ulimit_value = -1.0 | ... | ... |
test/test_cscripts.sh.in
| ... | ... | @@ -191,7 +191,7 @@ $ECHO " ok" |
| 191 | 191 | |
| 192 | 192 | # |
| 193 | 193 | # Test csspec |
| 194 | -# ============= | |
| 194 | +# =========== | |
| 195 | 195 | $ECHO -n "Test csspec: " |
| 196 | 196 | chmod +x @abs_top_srcdir@/scripts/csspec.py |
| 197 | 197 | @abs_top_srcdir@/scripts/csspec.py \ |
| ... | ... | @@ -217,7 +217,7 @@ $ECHO " ok" |
| 217 | 217 | |
| 218 | 218 | # |
| 219 | 219 | # Test csspec Run2 |
| 220 | -# ============= | |
| 220 | +# ================ | |
| 221 | 221 | $ECHO -n "Test csspec: " |
| 222 | 222 | chmod +x @abs_top_srcdir@/scripts/csspec.py |
| 223 | 223 | @abs_top_srcdir@/scripts/csspec.py \ | ... | ... |