Commit c6d08e4c56251e8a0f0e383b42af09ff20f74f37
1 parent
4e528698
Allow setting of regions from FITS files in csphagen
Showing
1 changed file
with
35 additions
and
7 deletions
cscripts/csphagen.py
| ... | ... | @@ -140,6 +140,34 @@ class csphagen(ctools.csobservation): |
| 140 | 140 | # Return |
| 141 | 141 | return |
| 142 | 142 | |
| 143 | + def _get_regions(self, filename): | |
| 144 | + """ | |
| 145 | + Get regions from DS9 file or FITS file | |
| 146 | + | |
| 147 | + Parameters | |
| 148 | + ---------- | |
| 149 | + filename : `~gammalib.GFilename` | |
| 150 | + Filename | |
| 151 | + | |
| 152 | + Returns | |
| 153 | + ------- | |
| 154 | + regs : `~gammalib.GSkyRegions` | |
| 155 | + Region container | |
| 156 | + """ | |
| 157 | + # If filename is a FITS file then load region map and append to | |
| 158 | + # list of regions | |
| 159 | + if filename.is_fits(): | |
| 160 | + map = gammalib.GSkyRegionMap(filename) | |
| 161 | + regs = gammalib.GSkyRegions() | |
| 162 | + regs.append(map) | |
| 163 | + | |
| 164 | + # ... otherwise load DS9 file | |
| 165 | + else: | |
| 166 | + regs = gammalib.GSkyRegions(filename) | |
| 167 | + | |
| 168 | + # Return region container | |
| 169 | + return regs | |
| 170 | + | |
| 143 | 171 | def _get_parameters_bkgmethod_reflected(self): |
| 144 | 172 | """ |
| 145 | 173 | Get parameters for REFLECTED background method |
| ... | ... | @@ -177,18 +205,18 @@ class csphagen(ctools.csobservation): |
| 177 | 205 | """ |
| 178 | 206 | # Set up source region |
| 179 | 207 | filename = self['srcregfile'].filename() |
| 180 | - self._src_reg = gammalib.GSkyRegions(filename) | |
| 208 | + self._src_reg = self._get_regions(filename) | |
| 181 | 209 | |
| 182 | 210 | # Raise an exception if there is more than one source region |
| 183 | 211 | if len(self._src_reg) != 1: |
| 184 | 212 | raise RuntimeError('Only one On region is allowed') |
| 185 | 213 | |
| 186 | 214 | # Set up source direction. Query parameters if neccessary. |
| 187 | - if isinstance(self._src_reg[0], gammalib.GSkyRegionCircle): | |
| 188 | - self._src_dir = self._src_reg[0].centre() | |
| 189 | - self._rad = self._src_reg[0].radius() | |
| 190 | - else: | |
| 191 | - self._query_src_direction() | |
| 215 | + #if isinstance(self._src_reg[0], gammalib.GSkyRegionCircle): | |
| 216 | + # self._src_dir = self._src_reg[0].centre() | |
| 217 | + # self._rad = self._src_reg[0].radius() | |
| 218 | + #else: | |
| 219 | + # self._query_src_direction() | |
| 192 | 220 | |
| 193 | 221 | # Make sure that all CTA observations have an Off region by loading the |
| 194 | 222 | # Off region region the parameter 'bkgregfile' for all CTA observations |
| ... | ... | @@ -197,7 +225,7 @@ class csphagen(ctools.csobservation): |
| 197 | 225 | if obs.classname() == 'GCTAObservation': |
| 198 | 226 | if obs.off_regions().is_empty(): |
| 199 | 227 | filename = self['bkgregfile'].filename() |
| 200 | - regions = gammalib.GSkyRegions(filename) | |
| 228 | + regions = self._get_regions(filename) | |
| 201 | 229 | obs.off_regions(regions) |
| 202 | 230 | |
| 203 | 231 | # Return | ... | ... |