Commit 4fb7bcac02c4f50e577b9fbbba2941423039d9f2
1 parent
d78abf9b
Add "response" parameter to comobsbin
Showing
4 changed files
with
82 additions
and
39 deletions
doc/source/users/reference_manual/comobsbin.rst
| ... | ... | @@ -24,6 +24,10 @@ General parameters |
| 24 | 24 | ``outfolder [string]`` |
| 25 | 25 | Output folder for files. Put here the location of your COMPTEL data store. |
| 26 | 26 | |
| 27 | +``response <MODEL|SIM2|SIM3> [string]`` | |
| 28 | + Response type specifying whether ``MODEL`` IAQs or simulated IAQs provided | |
| 29 | + in the COMPTEL calibration database should be used. | |
| 30 | + | |
| 27 | 31 | ``ebinalg <FILE|LIN|LOG> [string]`` |
| 28 | 32 | Algorithm for defining energy bins. |
| 29 | 33 | ... | ... |
modules/comscripts/comobsbin.par
| ... | ... | @@ -23,6 +23,7 @@ outfolder, s, a, $COMDATASTORE,,, "Output folder for files" |
| 23 | 23 | # |
| 24 | 24 | # Script parameters |
| 25 | 25 | #================== |
| 26 | +response, s, a, MODEL,MODEL|SIM2|SIM3,, "Response type" | |
| 26 | 27 | ebinalg, s, a, FILE,FILE|LIN|LOG,, "Algorithm for defining energy bins" |
| 27 | 28 | emin, r, a, 0.75,0.05,50.0, "Minimum energy (MeV)" |
| 28 | 29 | emax, r, a, 30.0,0.05,50.0, "Maximum energy (MeV)" | ... | ... |
modules/comscripts/comobsbin.py
| ... | ... | @@ -60,6 +60,7 @@ class comobsbin(ctools.csobservation): |
| 60 | 60 | self.obs().load(self['inobs'].filename()) |
| 61 | 61 | |
| 62 | 62 | # Query parameters |
| 63 | + self['response'].string() | |
| 63 | 64 | self._get_ebounds() |
| 64 | 65 | self._get_phases() |
| 65 | 66 | if not self._phases.is_empty(): |
| ... | ... | @@ -582,63 +583,99 @@ class comobsbin(ctools.csobservation): |
| 582 | 583 | dpsi = self['dpsi'].real() |
| 583 | 584 | dphibar = self['dphibar'].real() |
| 584 | 585 | |
| 586 | + # Get calibration database and response type | |
| 587 | + caldb = gammalib.GCaldb('cgro', 'comptel') | |
| 588 | + response = gammalib.toupper(self['response'].string()) | |
| 589 | + | |
| 585 | 590 | # Initialse list of IAQ names |
| 586 | 591 | iaqnames = [] |
| 587 | 592 | |
| 588 | 593 | # Generate one IAQ for each energy boundary |
| 589 | 594 | for i in range(ebounds.size()): |
| 590 | 595 | |
| 591 | - # Set IAQ filename | |
| 592 | - iaqname = '%s/iaq_%6.6d-%6.6dkeV.fits' % \ | |
| 593 | - (self['outfolder'].string(), | |
| 594 | - ebounds.emin(i).keV(), ebounds.emax(i).keV()) | |
| 595 | - iaqfile = gammalib.GFilename(iaqname) | |
| 596 | + # Handle simulated response | |
| 597 | + if response == 'SIM2' or response == 'SIM3': | |
| 596 | 598 | |
| 597 | - # Set global IAQ filename | |
| 598 | - iaqname_global = '%s/iaq_%6.6d-%6.6dkeV.fits' % \ | |
| 599 | - (self._global_datastore, | |
| 600 | - ebounds.emin(i).keV(), ebounds.emax(i).keV()) | |
| 601 | - iaqfile_global = gammalib.GFilename(iaqname_global) | |
| 599 | + # Write header | |
| 600 | + self._log_header3(gammalib.NORMAL, | |
| 601 | + 'Use CALDB IAQ for %.3f - %.3f MeV' % | |
| 602 | + (ebounds.emin(i).MeV(), ebounds.emax(i).MeV())) | |
| 602 | 603 | |
| 603 | - # Write header | |
| 604 | - self._log_header3(gammalib.NORMAL, 'Compute IAQ for %.3f - %.3f MeV' % \ | |
| 605 | - (ebounds.emin(i).MeV(), ebounds.emax(i).MeV())) | |
| 604 | + # Build response name | |
| 605 | + iaqname = '%s(%.2f-%.2f)MeV(%.0f)deg' % \ | |
| 606 | + (response, ebounds.emin(i).MeV(), ebounds.emax(i).MeV(), | |
| 607 | + dphibar) | |
| 606 | 608 | |
| 607 | - # If IAQ file exists in global datastore then do nothing | |
| 608 | - if iaqfile_global.exists(): | |
| 609 | - iaqname = iaqname_global | |
| 610 | - self._log_value(gammalib.NORMAL, 'Global IAQ file exists', iaqfile_global.url()) | |
| 609 | + # Raise an exception if response does not exist | |
| 610 | + filename = caldb.filename('', '', 'IAQ', '', '', iaqname) | |
| 611 | + if filename.is_empty(): | |
| 612 | + msg = ('Could not find IAQ "'+iaqname+'" in calibration database. ' | |
| 613 | + 'Please select a different response type.') | |
| 614 | + raise RuntimeError(msg) | |
| 611 | 615 | |
| 612 | - # If IAQ file exists then do nothing | |
| 613 | - elif iaqfile.exists(): | |
| 614 | - self._log_value(gammalib.NORMAL, 'Local IAQ file exists', iaqfile.url()) | |
| 616 | + # Log IAQ usage | |
| 617 | + self._log_value(gammalib.NORMAL, 'Use CALDB IAQ', iaqname) | |
| 615 | 618 | |
| 616 | - # ... otherwise compute and save it | |
| 619 | + # Append IAQ name | |
| 620 | + iaqnames.append(iaqname) | |
| 621 | + | |
| 622 | + # ... otherwise handle modeled response | |
| 617 | 623 | else: |
| 618 | 624 | |
| 619 | - # Initialise IAQ | |
| 620 | - iaq = gammalib.GCOMIaq(55.0, dchi, 50.0, dphibar) | |
| 625 | + # Set IAQ filename | |
| 626 | + iaqname = '%s/iaq_%6.6d-%6.6dkeV.fits' % \ | |
| 627 | + (self['outfolder'].string(), | |
| 628 | + ebounds.emin(i).keV(), ebounds.emax(i).keV()) | |
| 629 | + iaqfile = gammalib.GFilename(iaqname) | |
| 630 | + | |
| 631 | + # Set global IAQ filename | |
| 632 | + iaqname_global = '%s/iaq_%6.6d-%6.6dkeV.fits' % \ | |
| 633 | + (self._global_datastore, | |
| 634 | + ebounds.emin(i).keV(), ebounds.emax(i).keV()) | |
| 635 | + iaqfile_global = gammalib.GFilename(iaqname_global) | |
| 636 | + | |
| 637 | + # Write header | |
| 638 | + self._log_header3(gammalib.NORMAL, | |
| 639 | + 'Compute IAQ for %.3f - %.3f MeV' % | |
| 640 | + (ebounds.emin(i).MeV(), ebounds.emax(i).MeV())) | |
| 641 | + | |
| 642 | + # If IAQ file exists in global datastore then do nothing | |
| 643 | + if iaqfile_global.exists(): | |
| 644 | + iaqname = iaqname_global | |
| 645 | + self._log_value(gammalib.NORMAL, | |
| 646 | + 'Global IAQ file exists', iaqfile_global.url()) | |
| 647 | + | |
| 648 | + # If IAQ file exists then do nothing | |
| 649 | + elif iaqfile.exists(): | |
| 650 | + self._log_value(gammalib.NORMAL, | |
| 651 | + 'Local IAQ file exists', iaqfile.url()) | |
| 652 | + | |
| 653 | + # ... otherwise compute and save it | |
| 654 | + else: | |
| 621 | 655 | |
| 622 | - # Set IAQ energy range | |
| 623 | - ebds = gammalib.GEbounds(ebounds.emin(i), ebounds.emax(i)) | |
| 656 | + # Initialise IAQ | |
| 657 | + iaq = gammalib.GCOMIaq(55.0, dchi, 50.0, dphibar) | |
| 624 | 658 | |
| 625 | - # Generate continuum IAQ | |
| 626 | - spectrum = gammalib.GModelSpectralPlaw(1.0,-2.0,gammalib.GEnergy(1.0,'MeV')) | |
| 659 | + # Set IAQ energy range | |
| 660 | + ebds = gammalib.GEbounds(ebounds.emin(i), ebounds.emax(i)) | |
| 627 | 661 | |
| 628 | - # Compute IAQ | |
| 629 | - iaq.set(spectrum, ebds) | |
| 662 | + # Generate continuum IAQ | |
| 663 | + spectrum = gammalib.GModelSpectralPlaw(1.0,-2.0,gammalib.GEnergy(1.0,'MeV')) | |
| 630 | 664 | |
| 631 | - # Save IAQ | |
| 632 | - iaq.save(iaqfile, True) | |
| 665 | + # Compute IAQ | |
| 666 | + iaq.set(spectrum, ebds) | |
| 633 | 667 | |
| 634 | - # Log creation | |
| 635 | - self._log_value(gammalib.NORMAL, 'Local IAQ file created', iaqfile.url()) | |
| 668 | + # Save IAQ | |
| 669 | + iaq.save(iaqfile, True) | |
| 670 | + | |
| 671 | + # Log creation | |
| 672 | + self._log_value(gammalib.NORMAL, 'Local IAQ file created', iaqfile.url()) | |
| 636 | 673 | |
| 637 | - # Log IAQ | |
| 638 | - self._log_string(gammalib.NORMAL, str(iaq)) | |
| 674 | + # Log IAQ | |
| 675 | + self._log_string(gammalib.NORMAL, str(iaq)) | |
| 639 | 676 | |
| 640 | - # Append IAQ filename | |
| 641 | - iaqnames.append(iaqname) | |
| 677 | + # Append IAQ filename | |
| 678 | + iaqnames.append(iaqname) | |
| 642 | 679 | |
| 643 | 680 | # Return |
| 644 | 681 | return iaqnames | ... | ... |
test/test_comobsbin.py
| ... | ... | @@ -79,7 +79,7 @@ class Test(test): |
| 79 | 79 | comobsbin = self._comscript('comobsbin') |
| 80 | 80 | |
| 81 | 81 | # Setup command |
| 82 | - cmd = comobsbin+' inobs="'+self._obs+'" ebinalg="FILE" '+ \ | |
| 82 | + cmd = comobsbin+' inobs="'+self._obs+'" response="MODEL" ebinalg="FILE" '+ \ | |
| 83 | 83 | 'ebinfile="'+self._ebounds+'" phase="NONE" '+ \ |
| 84 | 84 | 'coordsys="GAL" proj="TAN" '+ \ |
| 85 | 85 | 'outfolder="comobsbin_cmd1" outobs="comobsbin_cmd1.xml" '+ \ |
| ... | ... | @@ -93,7 +93,7 @@ class Test(test): |
| 93 | 93 | self._check_result('comobsbin_cmd1.xml', 'comobsbin_cmd1') |
| 94 | 94 | |
| 95 | 95 | # Setup command |
| 96 | - cmd = comobsbin+' inobs="file_that_does_not_exist.xml" ebinalg="FILE" '+ \ | |
| 96 | + cmd = comobsbin+' inobs="file_that_does_not_exist.xml" response="MODEL" ebinalg="FILE" '+ \ | |
| 97 | 97 | 'ebinfile="'+self._ebounds+'" phase="NONE" '+ \ |
| 98 | 98 | 'coordsys="GAL" proj="TAN" '+ \ |
| 99 | 99 | 'outfolder="comobsbin_cmd2" outobs="comobsbin_cmd2.xml" '+ \ |
| ... | ... | @@ -117,6 +117,7 @@ class Test(test): |
| 117 | 117 | # Set-up script |
| 118 | 118 | bin = comscripts.comobsbin() |
| 119 | 119 | bin['inobs'] = self._obs |
| 120 | + bin['response'] = 'MODEL' | |
| 120 | 121 | bin['ebinalg'] = 'FILE' |
| 121 | 122 | bin['ebinfile'] = self._ebounds |
| 122 | 123 | bin['phase'] = 'NONE' | ... | ... |