Commit fb59ef58bbf74f38e7324247935d70a65fb3ea5a
1 parent
6eda1990
Support for reading of the source direction directly from the on region file. If…
… not possible the user will as usually be queried for the source direction.
Showing
1 changed file
with
36 additions
and
18 deletions
cscripts/csphagen.py
| ... | ... | @@ -56,6 +56,22 @@ class csphagen(ctools.csobservation): |
| 56 | 56 | return |
| 57 | 57 | |
| 58 | 58 | # Private methods |
| 59 | + def __query_src_direction(self): | |
| 60 | + """ | |
| 61 | + Set up the source direction parameter. | |
| 62 | + Query relevant parameters. | |
| 63 | + """ | |
| 64 | + self._src_dir = gammalib.GSkyDir() | |
| 65 | + coordsys = self['coordsys'].string() | |
| 66 | + if coordsys == 'CEL': | |
| 67 | + ra = self['ra'].real() | |
| 68 | + dec = self['dec'].real() | |
| 69 | + self._src_dir.radec_deg(ra, dec) | |
| 70 | + elif coordsys == 'GAL': | |
| 71 | + glon = self['glon'].real() | |
| 72 | + glat = self['glat'].real() | |
| 73 | + self._src_dir.lb_deg(glon, glat) | |
| 74 | + | |
| 59 | 75 | def _get_parameters(self): |
| 60 | 76 | """ |
| 61 | 77 | Get parameters from parfile and setup observations |
| ... | ... | @@ -72,23 +88,17 @@ class csphagen(ctools.csobservation): |
| 72 | 88 | # Set energy bounds |
| 73 | 89 | self._ebounds = self._create_ebounds() |
| 74 | 90 | |
| 75 | - # Initialise source position/region querying relevant parameters | |
| 76 | - self._src_dir = gammalib.GSkyDir() | |
| 91 | + # Initialize empty src regions container | |
| 77 | 92 | self._src_reg = gammalib.GSkyRegions() |
| 78 | - coordsys = self['coordsys'].string() | |
| 79 | - if coordsys == 'CEL': | |
| 80 | - ra = self['ra'].real() | |
| 81 | - dec = self['dec'].real() | |
| 82 | - self._src_dir.radec_deg(ra, dec) | |
| 83 | - elif coordsys == 'GAL': | |
| 84 | - glon = self['glon'].real() | |
| 85 | - glat = self['glat'].real() | |
| 86 | - self._src_dir.lb_deg(glon, glat) | |
| 87 | 93 | |
| 88 | 94 | # Query background estimation method and parameters |
| 89 | 95 | bkgmethod = self['bkgmethod'].string() |
| 90 | 96 | if bkgmethod == 'REFLECTED': |
| 91 | 97 | |
| 98 | + # Always query src direction | |
| 99 | + self.__query_src_direction() | |
| 100 | + | |
| 101 | + # Query region parameters | |
| 92 | 102 | self._srcshape = self['srcshape'].string() |
| 93 | 103 | if self._srcshape == 'CIRCLE': |
| 94 | 104 | self._rad = self['rad'].real() |
| ... | ... | @@ -98,6 +108,21 @@ class csphagen(ctools.csobservation): |
| 98 | 108 | |
| 99 | 109 | elif bkgmethod == 'CUSTOM': |
| 100 | 110 | |
| 111 | + # Set up src region. Only 1 region is allowed. | |
| 112 | + src_reg_file = self['srcreg'].filename() | |
| 113 | + self._src_reg = gammalib.GSkyRegions(src_reg_file) | |
| 114 | + | |
| 115 | + if len(self._src_reg) != 1: | |
| 116 | + raise RuntimeError('Only 1 ON region is allowed.') | |
| 117 | + | |
| 118 | + # Set up src direction. Query if neccessary. | |
| 119 | + if isinstance(self._src_reg[0], gammalib.GSkyRegionCircle): | |
| 120 | + self._src_dir = self._src_reg[0].centre() | |
| 121 | + self._rad = self._src_reg[0].radius() | |
| 122 | + else: | |
| 123 | + self.__query_src_direction() | |
| 124 | + | |
| 125 | + # Set up bkg regions | |
| 101 | 126 | obs_file = self['inobs'].filename() |
| 102 | 127 | |
| 103 | 128 | # obs def XML: look for region files |
| ... | ... | @@ -141,13 +166,6 @@ class csphagen(ctools.csobservation): |
| 141 | 166 | # Query bkg region file for single observation |
| 142 | 167 | self._bkg_reg_files[self._bkg_reg_files.keys()[0]] = self['bkgreg'].filename() |
| 143 | 168 | |
| 144 | - # Query src region file and set up the region. Only 1 region is allowed. | |
| 145 | - src_reg_file = self['srcreg'].filename() | |
| 146 | - self._src_reg = gammalib.GSkyRegions(src_reg_file) | |
| 147 | - | |
| 148 | - if len(self._src_reg) > 1: | |
| 149 | - raise RuntimeError('Only 1 ON region is allowed.') | |
| 150 | - | |
| 151 | 169 | self['maxoffset'].real() |
| 152 | 170 | |
| 153 | 171 | # Exclusion map | ... | ... |