Feature #2284
csphagen: import off regions from region file
Status: | Closed | Start date: | 11/30/2017 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assigned To: | Specovius Andreas | % Done: | 100% | |
Category: | - | Estimated time: | 30.00 hours | |
Target version: | 1.5.0 | |||
Duration: |
Description
In csphagen: Add option to import off regions e.g. from ds9 region file(s).
Recurrence
No recurrence.
History
#1 Updated by Tibaldo Luigi almost 7 years ago
Some thoughts:
- I think we should support both On and Off regions from files
- I think we should support as input file formats both ds9 reg files and FITS WCS maps (gammalib has already methods to read both, so it’s a piece of cake)
The way I’d do it is to add a second option for the bkgmethod, that would be CUSTOM, in addition to REFLECTED. When the user selects CUSTOM the script would query for the On and Off region files, and pass them to the On/Off constructor.
#2 Updated by Specovius Andreas almost 7 years ago
- Status changed from New to In Progress
- % Done changed from 0 to 60
#3 Updated by Specovius Andreas almost 7 years ago
- % Done changed from 60 to 100
#4 Updated by Specovius Andreas almost 7 years ago
- Status changed from In Progress to Pull request
- Estimated time set to 30.00
Summary of changes on branch 2284-csphagen-load-off-regions in my repository:
Extended background method parameter 'bkgmethod’ with 'CUSTOM’:
If CUSTOM is specified and inobs contains ...
- 1 observation, the user has to specify srcreg and bkgreg parameters (also during runtime) to load the src region and the bkg regions from a file.
- multiple observations in an XML container, the user has to specify the src region parameter at least once in the XML <parameter name=“OnRegion” file=“.."/> and the bkg region parameter in every observation <parameter name=“OffRegions” file=“.."/>.
Region files can be all files that can be handled by GSkyRegions class constructor like ds9 .reg files or FITS WCS.
Added test case for loaded regions:
In principle an existing test case which uses the REFLECTED method is redone but with src and bkg regions loaded from file(s) (method CUSTOM).
The regions that are loaded have been created during the first test case via REFLECTED method. Hence a loading of those should result in the same output files.
It has to be mentioned that the regions for the test case are stored statically. As the output of the REFLECTED and the CUSTOM test case are compared a change of the reflected background placement may introduce inconsistency as the static regions files stay the same. A solution could be to directly use the output region files of the REFLECTED method test case??
Updated csphagen script documentation.
Note:
So far the radius parameter 'rad’ is always queried as soon as it is listed in the pfile. For the CUSTOM method the radius is not directly needed. Nevertheless it will be queried when executing csphagen in the current code version. It can also not be easily switched off by hand as the responsible code is located deep in ctools. Maybe you find a solution for that. I also talked to Luigi about that.
#5 Updated by Tibaldo Luigi almost 7 years ago
I checked out the code and run a few test cases.
I could not reproduce the problem with the parameter rad. For me the code runs without querying the parameter when appropriate
$ csphagen prefix=custom bkgmethod=CUSTOM Input event list or observation definition XML file [obs.xml] Binning algorithm (LIN|LOG|FILE) [LOG] Lower energy limit (TeV) [0.1] Upper energy limit (TeV) [50.] Number of energy bins [30.] Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL] Right Ascension of source region centre (deg) (0-360) [350.85] Declination of source region centre (deg) (-90-90) [58.815] Source region file (ds9 or FITS WCS) [onoff_on.reg] reflected_on.reg Stack multiple observations into single PHA, ARF and RMF files? [yes] Output observation definition XML file [onoff_obs.xml] custom_onoff.xml (ctools) macp0077:classical3 ltibaldo$ ls csphagen.log obs.xml custom_112301_off.reg onoff_obs.xml custom_112302_off.reg reflected_112301_off.reg custom_on.reg reflected_112302_off.reg custom_onoff.xml reflected_on.reg custom_stacked_arf.fits reflected_stacked_arf.fits custom_stacked_pha_off.fits reflected_stacked_pha_off.fits custom_stacked_pha_on.fits reflected_stacked_pha_on.fits custom_stacked_rmf.fits reflected_stacked_rmf.fitsSome comments on the implementation of the CUSTOM method for your consideration:
- I see no use case for which the On region may depend on the observation. I’d recommend to always provide it through an input file.
- If the user provides an input On region file, the source direction should be read from the file, without querying the ra and dec parameters
- To me it seems it would be more natural to create and OffRegions attribute for GCTAObservation (or GObservation) at the gammalib level, and then just read it in csphagen, rather than parsing the xml directly in csphagen; any thoughts Jürgen?
#6 Updated by Specovius Andreas almost 7 years ago
Tibaldo Luigi wrote:
...
Some comments on the implementation of the CUSTOM method for your consideration:
- I see no use case for which the On region may depend on the observation. I’d recommend to always provide it through an input file.
I totally agree with you. The intention was to allow the user to keep things together hence inserting on and off regions at the same place in the obs def xml file. Multiple on region definitions would have replaced each other. Nevertheless I see your point that this could be confusing! I removed the support for on regions in the obs def xml file in the latest commit.
- If the user provides an input On region file, the source direction should be read from the file, without querying the ra and dec parameters
The intention to always query the src direction was to keep things general. For the current implementation of gammalib, assuming to be able to read the src direction from the GSkyRegion instances would again restrict them to be GSkyRegionCircle objects. Am I wrong?
Nevertheless, the last commit now supports automatic reading of the src direction from the src region, at least for GSkyRegionCircle objects.
- To me it seems it would be more natural to create and OffRegions attribute for GCTAObservation (or GObservation) at the gammalib level, and then just read it in csphagen, rather than parsing the xml directly in csphagen; any thoughts Jürgen?
Also to me this seems to be a more robust implementation. The question is whether only csphagen will use that parameter and hence whether it’s worth to add this parameter so deep in gammalib.
#7 Updated by Tibaldo Luigi almost 7 years ago
Thanks Andreas.
Specovius Andreas wrote:
Tibaldo Luigi wrote:
...
- If the user provides an input On region file, the source direction should be read from the file, without querying the ra and dec parameters
The intention to always query the src direction was to keep things general. For the current implementation of gammalib, assuming to be able to read the src direction from the GSkyRegion instances would again restrict them to be GSkyRegionCircle objects. Am I wrong?
Nevertheless, the last commit now supports automatic reading of the src direction from the src region, at least for GSkyRegionCircle objects.
Makes sense, I agree with this solution.
- To me it seems it would be more natural to create and OffRegions attribute for GCTAObservation (or GObservation) at the gammalib level, and then just read it in csphagen, rather than parsing the xml directly in csphagen; any thoughts Jürgen?
Also to me this seems to be a more robust implementation. The question is whether only csphagen will use that parameter and hence whether it’s worth to add this parameter so deep in gammalib.
I’d say Jürgen can judge on this.
#8 Updated by Knödlseder Jürgen almost 7 years ago
- Target version set to 1.5.0
I’m in the process of merging in the code.
I did a bit of refactoring to split the code in the parameter getting and run routines into sub routines.
Concerning the off regions definition in the XML file: I would keep the code for the moment as it is. It would be good to work out specific use cases for custom off regions so that we understand better how these should be handled.
#9 Updated by Knödlseder Jürgen almost 7 years ago
Just recognized one issue with my above proposal: the actual code relies on a XML file, while in principle it should be possible to simply pass an observation container to the script without reading any XML file. This means that the off region handling needs to be implemented at the GammaLib level.
#10 Updated by Knödlseder Jürgen almost 7 years ago
I implemented GCTAObservation::off_regions()
methods for setting and getting the Off regions. The Off regions will be automatically read from an XML file if the OffRegions
parameter exists, and if a CTA observation has Off regions with a non empty filename, it will write the Off regions file name into the XML file.
#11 Updated by Knödlseder Jürgen almost 7 years ago
- Status changed from Pull request to Closed
Code merged into devel
(both GammaLib and ctools).