Commit e065cfcdf98cf42c4714de060dd918c38a48f47a
Merge branch '1408-adapt-cscripts-to-ctool-base-class' into integration
Showing
6 changed files
with
134 additions
and
131 deletions
scripts/cscaldb.py
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | 21 | import gammalib |
| 22 | +import ctools | |
| 22 | 23 | import sys |
| 23 | 24 | import glob |
| 24 | 25 | import os |
| ... | ... | @@ -27,12 +28,12 @@ import os |
| 27 | 28 | # ============ # |
| 28 | 29 | # cspull class # |
| 29 | 30 | # ============ # |
| 30 | -class cscaldb(gammalib.GApplication): | |
| 31 | +class cscaldb(ctools.cscript): | |
| 31 | 32 | """ |
| 32 | - This class implements the pull distribution generation script. It derives | |
| 33 | - from the GammaLib::GApplication class which provides support for parameter | |
| 34 | - files, command line arguments, and logging. In that way the Python | |
| 35 | - script behaves just as a regular ctool. | |
| 33 | + This class dumps the content of the ctools calibration database. | |
| 34 | + It derives from the ctools.cscript class which provides support for | |
| 35 | + parameter files, command line arguments, and logging. In that way | |
| 36 | + the Python script behaves just as a regular ctool. | |
| 36 | 37 | """ |
| 37 | 38 | def __init__(self, *argv): |
| 38 | 39 | """ |
| ... | ... | @@ -40,16 +41,16 @@ class cscaldb(gammalib.GApplication): |
| 40 | 41 | """ |
| 41 | 42 | # Set name |
| 42 | 43 | self.name = "cscaldb" |
| 43 | - self.version = "0.1.0" | |
| 44 | + self.version = "1.0.0" | |
| 44 | 45 | |
| 45 | 46 | # Make sure that parfile exists |
| 46 | 47 | file = self.parfile() |
| 47 | 48 | |
| 48 | 49 | # Initialise application |
| 49 | 50 | if len(argv) == 0: |
| 50 | - gammalib.GApplication.__init__(self, self.name, self.version) | |
| 51 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 51 | 52 | elif len(argv) ==1: |
| 52 | - gammalib.GApplication.__init__(self, self.name, self.version, *argv) | |
| 53 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 53 | 54 | else: |
| 54 | 55 | raise TypeError("Invalid number of arguments given.") |
| 55 | 56 | ... | ... |
scripts/cspull.py
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | 21 | import gammalib |
| 22 | +import ctools | |
| 22 | 23 | from ctools import obsutils |
| 23 | 24 | import sys |
| 24 | 25 | import csv |
| ... | ... | @@ -27,10 +28,10 @@ import csv |
| 27 | 28 | # ============ # |
| 28 | 29 | # cspull class # |
| 29 | 30 | # ============ # |
| 30 | -class cspull(gammalib.GApplication): | |
| 31 | +class cspull(ctools.cscript): | |
| 31 | 32 | """ |
| 32 | 33 | This class implements the pull distribution generation script. It derives |
| 33 | - from the GammaLib::GApplication class which provides support for parameter | |
| 34 | + from the ctools.cscript class which provides support for parameter | |
| 34 | 35 | files, command line arguments, and logging. In that way the Python |
| 35 | 36 | script behaves just as a regular ctool. |
| 36 | 37 | """ |
| ... | ... | @@ -40,7 +41,7 @@ class cspull(gammalib.GApplication): |
| 40 | 41 | """ |
| 41 | 42 | # Set name |
| 42 | 43 | self.name = "cspull" |
| 43 | - self.version = "0.4.0" | |
| 44 | + self.version = "1.0.0" | |
| 44 | 45 | |
| 45 | 46 | # Initialise some members |
| 46 | 47 | self.obs = None |
| ... | ... | @@ -52,9 +53,9 @@ class cspull(gammalib.GApplication): |
| 52 | 53 | |
| 53 | 54 | # Initialise application |
| 54 | 55 | if len(argv) == 0: |
| 55 | - gammalib.GApplication.__init__(self, self.name, self.version) | |
| 56 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 56 | 57 | elif len(argv) ==1: |
| 57 | - gammalib.GApplication.__init__(self, self.name, self.version, *argv) | |
| 58 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 58 | 59 | else: |
| 59 | 60 | raise TypeError("Invalid number of arguments given.") |
| 60 | 61 | |
| ... | ... | @@ -92,25 +93,30 @@ class cspull(gammalib.GApplication): |
| 92 | 93 | |
| 93 | 94 | # Create default parfile |
| 94 | 95 | pars = gammalib.GApplicationPars() |
| 96 | + pars.append(gammalib.GApplicationPar("inobs","f","h","NONE","","","Event list, counts cube, or observation definition file")) | |
| 95 | 97 | pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model")) |
| 96 | 98 | pars.append(gammalib.GApplicationPar("outfile","f","a","pull.dat","","","Output file name")) |
| 97 | - pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials")) | |
| 99 | + pars.append(gammalib.GApplicationPar("expcube","s","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) | |
| 100 | + pars.append(gammalib.GApplicationPar("psfcube","s","a","NONE","","","PSF cube file (only needed for stacked analysis)")) | |
| 98 | 101 | pars.append(gammalib.GApplicationPar("caldb","s","a","dummy","","","Calibration database")) |
| 99 | 102 | pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function")) |
| 100 | - pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) | |
| 101 | 103 | pars.append(gammalib.GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)")) |
| 102 | 104 | pars.append(gammalib.GApplicationPar("dec","r","a","22.0145","-90","90","Dec of pointing (deg)")) |
| 103 | - pars.append(gammalib.GApplicationPar("emin","r","a","0.1","0.0","","Lower energy limit (TeV)")) | |
| 104 | - pars.append(gammalib.GApplicationPar("emax","r","a","100.0","0.0","","Upper energy limit (TeV)")) | |
| 105 | + pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit (TeV)")) | |
| 106 | + pars.append(gammalib.GApplicationPar("emax","r","a","100.0","","","Upper energy limit (TeV)")) | |
| 107 | + pars.append(gammalib.GApplicationPar("tmin","r","h","0.0","","","Start time (MET in s)")) | |
| 108 | + pars.append(gammalib.GApplicationPar("tmax","r","a","1800.0","","","Duration (in s)")) | |
| 105 | 109 | pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins (0=unbinned)")) |
| 106 | - pars.append(gammalib.GApplicationPar("duration","r","a","1800.0","","","Effective exposure time (s)")) | |
| 110 | + pars.append(gammalib.GApplicationPar("npix","i","h","200","","","Number of pixels for binned")) | |
| 111 | + pars.append(gammalib.GApplicationPar("binsz","r","h","0.05","","","Pixel size for binned (deg/pixel)")) | |
| 107 | 112 | pars.append(gammalib.GApplicationPar("deadc","r","h","0.95","","","Deadtime correction factor")) |
| 108 | - pars.append(gammalib.GApplicationPar("rad","r","h","5.0","","","Radius of ROI (deg)")) | |
| 113 | + pars.append(gammalib.GApplicationPar("rad","r","h","5.0","","","Radius of ROI (deg)")) | |
| 109 | 114 | pars.append(gammalib.GApplicationPar("pattern","s","h","single","","","Observation pattern (single/four)")) |
| 110 | 115 | pars.append(gammalib.GApplicationPar("offset","r","h","1.5","","","Observation pattern offset (deg)")) |
| 111 | - pars.append(gammalib.GApplicationPar("npix","i","h","200","","","Number of pixels for binned")) | |
| 112 | - pars.append(gammalib.GApplicationPar("binsz","r","h","0.05","","","Pixel size for binned (deg/pixel)")) | |
| 116 | + pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials")) | |
| 117 | + pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) | |
| 113 | 118 | pars.append_standard() |
| 119 | + pars.append(gammalib.GApplicationPar("logfile","f","h","cspull.log","","","Log filename")) | |
| 114 | 120 | pars.save(parfile) |
| 115 | 121 | |
| 116 | 122 | # Return |
| ... | ... | @@ -121,39 +127,42 @@ class cspull(gammalib.GApplication): |
| 121 | 127 | Get parameters from parfile and setup the observation. |
| 122 | 128 | """ |
| 123 | 129 | # Get parameters |
| 124 | - if self.model == None: | |
| 125 | - self.m_inmodel = self["inmodel"].filename() | |
| 126 | - self.m_outfile = self["outfile"].filename() | |
| 127 | - self.m_ntrials = self["ntrials"].integer() | |
| 128 | - self.m_caldb = self["caldb"].string() | |
| 129 | - self.m_irf = self["irf"].string() | |
| 130 | - self.m_edisp = self["edisp"].boolean() | |
| 131 | - self.m_ra = self["ra"].real() | |
| 132 | - self.m_dec = self["dec"].real() | |
| 133 | - self.m_emin = self["emin"].real() | |
| 134 | - self.m_emax = self["emax"].real() | |
| 130 | + | |
| 131 | + # Set observation if not done before | |
| 132 | + if self.obs == None or self.obs.size() == 0: | |
| 133 | + self.obs = self.get_observations() | |
| 134 | + | |
| 135 | + # Check for requested pattern and use above | |
| 136 | + # observation parameters to set wobble pattern | |
| 137 | + self.m_pattern = self["pattern"].string() | |
| 138 | + if self.m_pattern == "four": | |
| 139 | + self.obs = self.set_obs() | |
| 140 | + | |
| 141 | + # Get number of energy bins | |
| 135 | 142 | self.m_enumbins = self["enumbins"].integer() |
| 136 | - self.m_duration = self["duration"].real() | |
| 137 | - self.m_deadc = self["deadc"].real() | |
| 138 | - self.m_rad = self["rad"].real() | |
| 139 | - self.m_pattern = self["pattern"].string() | |
| 140 | - self.m_offset = self["offset"].real() | |
| 141 | - self.m_npix = self["npix"].integer() | |
| 142 | - self.m_binsz = self["binsz"].real() | |
| 143 | + | |
| 144 | + # Read parameters for binned if requested | |
| 145 | + if not self.m_enumbins == 0: | |
| 146 | + self.m_npix = self["npix"].integer() | |
| 147 | + self.m_binsz = self["binsz"].real() | |
| 148 | + else: | |
| 149 | + # Set dummy values (required by obsutils) | |
| 150 | + self.m_npix = 0 | |
| 151 | + self.m_binsz = 0.0 | |
| 152 | + | |
| 153 | + # Set models if we have none | |
| 154 | + if self.obs.models().size() == 0: | |
| 155 | + self.obs.models(self["inmodel"].filename()) | |
| 156 | + | |
| 157 | + # Read other parameters | |
| 158 | + self.m_outfile = self["outfile"].filename() | |
| 159 | + self.m_ntrials = self["ntrials"].integer() | |
| 160 | + self.m_edisp = self["edisp"].boolean() | |
| 161 | + self.m_offset = self["offset"].real() | |
| 143 | 162 | |
| 144 | 163 | # Set some fixed parameters |
| 145 | 164 | self.m_log = False # Logging in client tools |
| 146 | 165 | self.m_debug = True # Debugging in client tools |
| 147 | - | |
| 148 | - # Setup observations | |
| 149 | - self.obs = self.set_obs() | |
| 150 | - | |
| 151 | - # Load source model | |
| 152 | - if self.m_inmodel != None: | |
| 153 | - self.model = gammalib.GModels(self.m_inmodel) | |
| 154 | - | |
| 155 | - # Append source model to observation | |
| 156 | - self.obs.models(self.model) | |
| 157 | 166 | |
| 158 | 167 | # Return |
| 159 | 168 | return |
| ... | ... | @@ -163,7 +172,7 @@ class cspull(gammalib.GApplication): |
| 163 | 172 | Set model. |
| 164 | 173 | """ |
| 165 | 174 | # Copy models |
| 166 | - self.model = models.copy() | |
| 175 | + self.obs.models(models.copy()) | |
| 167 | 176 | |
| 168 | 177 | # Return |
| 169 | 178 | return |
| ... | ... | @@ -232,18 +241,19 @@ class cspull(gammalib.GApplication): |
| 232 | 241 | |
| 233 | 242 | Keywords: |
| 234 | 243 | """ |
| 244 | + | |
| 235 | 245 | # Setup observation definition list |
| 236 | 246 | obsdeflist = obsutils.set_obs_patterns(self.m_pattern, \ |
| 237 | - ra=self.m_ra, dec=self.m_dec, \ | |
| 238 | - offset=self.m_offset) | |
| 247 | + ra=self["ra"].real(), dec=self["dec"].real(), \ | |
| 248 | + offset=self["offset"].real()) | |
| 239 | 249 | |
| 240 | 250 | # Create list of observations |
| 241 | 251 | obs = obsutils.set_obs_list(obsdeflist, \ |
| 242 | - tstart=0.0, duration=self.m_duration, \ | |
| 243 | - deadc=self.m_deadc, \ | |
| 244 | - emin=self.m_emin, emax=self.m_emax, \ | |
| 245 | - rad=self.m_rad, \ | |
| 246 | - irf=self.m_irf, caldb=self.m_caldb) | |
| 252 | + tstart=self["tmin"].real(), duration=self["tmax"].real()-self["tmin"].real(), \ | |
| 253 | + deadc=self["deadc"].real(), \ | |
| 254 | + emin=self["emin"].real(), emax=self["emax"].real(), \ | |
| 255 | + rad=self["rad"].real(), \ | |
| 256 | + irf=self["irf"].string(), caldb=self["caldb"].string()) | |
| 247 | 257 | |
| 248 | 258 | # Return observation container |
| 249 | 259 | return obs |
| ... | ... | @@ -319,7 +329,7 @@ class cspull(gammalib.GApplication): |
| 319 | 329 | |
| 320 | 330 | # Compute pull |
| 321 | 331 | fitted_value = par.value() |
| 322 | - real_value = self.model[i][k].value() | |
| 332 | + real_value = self.obs.models()[i][k].value() | |
| 323 | 333 | error = par.error() |
| 324 | 334 | if error != 0.0: |
| 325 | 335 | pull = (fitted_value - real_value) / error | ... | ... |
scripts/csresmap.py
scripts/cssens.py
| ... | ... | @@ -34,6 +34,7 @@ |
| 34 | 34 | # |
| 35 | 35 | # ========================================================================== |
| 36 | 36 | import gammalib |
| 37 | +import ctools | |
| 37 | 38 | from ctools import obsutils |
| 38 | 39 | import sys |
| 39 | 40 | import csv |
| ... | ... | @@ -43,10 +44,10 @@ import math |
| 43 | 44 | # ============ # |
| 44 | 45 | # cssens class # |
| 45 | 46 | # ============ # |
| 46 | -class cssens(gammalib.GApplication): | |
| 47 | +class cssens(ctools.cscript): | |
| 47 | 48 | """ |
| 48 | 49 | This class implements the sensitivity computation script. It derives |
| 49 | - from the GammaLib::GApplication class which provides support for parameter | |
| 50 | + from the ctools.cscript class which provides support for parameter | |
| 50 | 51 | files, command line arguments, and logging. In that way the Python |
| 51 | 52 | script behaves just as a regular ctool. |
| 52 | 53 | """ |
| ... | ... | @@ -56,16 +57,16 @@ class cssens(gammalib.GApplication): |
| 56 | 57 | """ |
| 57 | 58 | # Set name |
| 58 | 59 | self.name = "cssens" |
| 59 | - self.version = "0.4.0" | |
| 60 | + self.version = "1.0.0" | |
| 60 | 61 | |
| 61 | 62 | # Make sure that parfile exists |
| 62 | 63 | file = self.parfile() |
| 63 | 64 | |
| 64 | 65 | # Initialise application |
| 65 | 66 | if len(argv) == 0: |
| 66 | - gammalib.GApplication.__init__(self, self.name, self.version) | |
| 67 | + ctool.cscript.__init__(self, self.name, self.version) | |
| 67 | 68 | elif len(argv) ==1: |
| 68 | - gammalib.GApplication.__init__(self, self.name, self.version, *argv) | |
| 69 | + ctool.cscript.__init__(self, self.name, self.version, *argv) | |
| 69 | 70 | else: |
| 70 | 71 | raise TypeError("Invalid number of arguments given.") |
| 71 | 72 | ... | ... |
scripts/cstsdist.py
| ... | ... | @@ -20,19 +20,19 @@ |
| 20 | 20 | # |
| 21 | 21 | # ========================================================================== |
| 22 | 22 | import gammalib |
| 23 | +import ctools | |
| 23 | 24 | from ctools import obsutils |
| 24 | 25 | import sys |
| 25 | 26 | import csv |
| 26 | -import math | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | # ============== # |
| 30 | 30 | # cstsdist class # |
| 31 | 31 | # ============== # |
| 32 | -class cstsdist(gammalib.GApplication): | |
| 32 | +class cstsdist(ctools.cscript): | |
| 33 | 33 | """ |
| 34 | 34 | This class implements the TS distribution generation script. It derives |
| 35 | - from the GammaLib::GApplication class which provides support for parameter | |
| 35 | + from the ctools.cscript class which provides support for parameter | |
| 36 | 36 | files, command line arguments, and logging. In that way the Python |
| 37 | 37 | script behaves just as a regular ctool. |
| 38 | 38 | """ |
| ... | ... | @@ -42,7 +42,7 @@ class cstsdist(gammalib.GApplication): |
| 42 | 42 | """ |
| 43 | 43 | # Set name |
| 44 | 44 | self.name = "cstsdist" |
| 45 | - self.version = "0.2.0" | |
| 45 | + self.version = "1.0.0" | |
| 46 | 46 | |
| 47 | 47 | # Initialise some members |
| 48 | 48 | self.obs = None |
| ... | ... | @@ -54,9 +54,9 @@ class cstsdist(gammalib.GApplication): |
| 54 | 54 | |
| 55 | 55 | # Initialise application |
| 56 | 56 | if len(argv) == 0: |
| 57 | - gammalib.GApplication.__init__(self, self.name, self.version) | |
| 57 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 58 | 58 | elif len(argv) ==1: |
| 59 | - gammalib.GApplication.__init__(self, self.name, self.version, *argv) | |
| 59 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 60 | 60 | else: |
| 61 | 61 | raise TypeError("Invalid number of arguments given.") |
| 62 | 62 | |
| ... | ... | @@ -94,22 +94,30 @@ class cstsdist(gammalib.GApplication): |
| 94 | 94 | |
| 95 | 95 | # Create default parfile |
| 96 | 96 | pars = gammalib.GApplicationPars() |
| 97 | + pars.append(gammalib.GApplicationPar("inobs","f","h","NONE","","","Event list, counts cube, or observation definition file")) | |
| 97 | 98 | pars.append(gammalib.GApplicationPar("outfile","f","h","ts.dat","","","Output file name")) |
| 98 | - pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials")) | |
| 99 | - pars.append(gammalib.GApplicationPar("caldb","s","a","$GAMMALIB/share/caldb/cta","","","Calibration database")) | |
| 99 | + pars.append(gammalib.GApplicationPar("expcube","s","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) | |
| 100 | + pars.append(gammalib.GApplicationPar("psfcube","s","a","NONE","","","PSF cube file (only needed for stacked analysis)")) | |
| 101 | + pars.append(gammalib.GApplicationPar("caldb","s","a","dummy","","","Calibration database")) | |
| 100 | 102 | pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function")) |
| 101 | - pars.append(gammalib.GApplicationPar("type","s","a","point","","","Source model type (point/gauss/shell/disk)")) | |
| 102 | - pars.append(gammalib.GApplicationPar("index","r","h","-2.48","","","Spectral index")) | |
| 103 | - pars.append(gammalib.GApplicationPar("offset","r","a","0.0","0.0","","Source offset angle (deg)")) | |
| 104 | - pars.append(gammalib.GApplicationPar("bkg","s","a","$GAMMALIB/share/models/bkg_dummy.txt","","","Background model file function (none=power law for E)")) | |
| 105 | - pars.append(gammalib.GApplicationPar("emin","r","a","0.1","0.0","","Lower energy limit (TeV)")) | |
| 106 | - pars.append(gammalib.GApplicationPar("emax","r","a","100.0","0.0","","Upper energy limit (TeV)")) | |
| 103 | + pars.append(gammalib.GApplicationPar("ra","r","h","83.6331","0","360","RA of pointing (deg)")) | |
| 104 | + pars.append(gammalib.GApplicationPar("dec","r","h","22.0145","-90","90","Dec of pointing (deg)")) | |
| 105 | + pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit (TeV)")) | |
| 106 | + pars.append(gammalib.GApplicationPar("emax","r","a","100.0","","","Upper energy limit (TeV)")) | |
| 107 | + pars.append(gammalib.GApplicationPar("tmin","r","h","0.0","","","Start time (MET in s)")) | |
| 108 | + pars.append(gammalib.GApplicationPar("tmax","r","a","1800.0","","","Observation duration (in s)")) | |
| 107 | 109 | pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins (0=unbinned)")) |
| 108 | - pars.append(gammalib.GApplicationPar("duration","r","a","180000.0","","","Effective exposure time (s)")) | |
| 109 | - pars.append(gammalib.GApplicationPar("rad","r","h","5.0","","","Radius of ROI (deg)")) | |
| 110 | 110 | pars.append(gammalib.GApplicationPar("npix","i","h","200","","","Number of pixels for binned")) |
| 111 | 111 | pars.append(gammalib.GApplicationPar("binsz","r","h","0.05","","","Pixel size for binned (deg/pixel)")) |
| 112 | + pars.append(gammalib.GApplicationPar("deadc","r","h","0.95","","","Deadtime correction factor")) | |
| 113 | + pars.append(gammalib.GApplicationPar("rad","r","h","5.0","","","Radius of ROI (deg)")) | |
| 114 | + pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials")) | |
| 115 | + pars.append(gammalib.GApplicationPar("type","s","a","point","","","Source model type (point/gauss/shell/disk)")) | |
| 116 | + pars.append(gammalib.GApplicationPar("index","r","h","-2.48","","","Spectral index")) | |
| 117 | + pars.append(gammalib.GApplicationPar("offset","r","a","0.0","0.0","","Source offset angle (deg)")) | |
| 118 | + pars.append(gammalib.GApplicationPar("bkg","s","a","$CTOOLS/share/models/bkg_dummy.txt","","","Background model file function")) | |
| 112 | 119 | pars.append_standard() |
| 120 | + pars.append(gammalib.GApplicationPar("logfile","f","h","cstsdist.log","","","Log filename")) | |
| 113 | 121 | pars.save(parfile) |
| 114 | 122 | |
| 115 | 123 | # Return |
| ... | ... | @@ -119,38 +127,45 @@ class cstsdist(gammalib.GApplication): |
| 119 | 127 | """ |
| 120 | 128 | Get parameters from parfile and setup the observation. |
| 121 | 129 | """ |
| 122 | - # Get parameters | |
| 130 | + | |
| 131 | + # Set observation if not done before | |
| 132 | + if self.obs == None or self.obs.size() == 0: | |
| 133 | + self.obs = self.get_observations() | |
| 134 | + | |
| 135 | + # Get number of energy bins | |
| 136 | + self.m_enumbins = self["enumbins"].integer() | |
| 137 | + | |
| 138 | + # Read parameters for binned if requested | |
| 139 | + if not self.m_enumbins == 0: | |
| 140 | + self.m_npix = self["npix"].integer() | |
| 141 | + self.m_binsz = self["binsz"].real() | |
| 142 | + else: | |
| 143 | + # Set dummy values (required by obsutils) | |
| 144 | + self.m_npix = 0 | |
| 145 | + self.m_binsz = 0.0 | |
| 146 | + | |
| 147 | + # Get other parameters | |
| 123 | 148 | self.m_outfile = self["outfile"].filename() |
| 124 | 149 | self.m_ntrials = self["ntrials"].integer() |
| 125 | - self.m_caldb = self["caldb"].string() | |
| 126 | - self.m_irf = self["irf"].string() | |
| 127 | 150 | self.m_type = self["type"].string() |
| 128 | 151 | self.m_index = self["index"].real() |
| 129 | 152 | self.m_offset = self["offset"].real() |
| 130 | 153 | self.m_bkg = self["bkg"].string() |
| 131 | - self.m_emin = self["emin"].real() | |
| 132 | - self.m_emax = self["emax"].real() | |
| 133 | - self.m_enumbins = self["enumbins"].integer() | |
| 134 | - self.m_duration = self["duration"].real() | |
| 135 | - self.m_rad = self["rad"].real() | |
| 136 | - self.m_npix = self["npix"].integer() | |
| 137 | - self.m_binsz = self["binsz"].real() | |
| 138 | 154 | |
| 139 | 155 | # Set some fixed parameters |
| 140 | 156 | self.m_log = False # Logging in client tools |
| 141 | 157 | self.m_debug = False # Debugging in client tools |
| 142 | - | |
| 143 | - # Setup observation | |
| 144 | - self.obs = self.set_obs(emin=self.m_emin, emax=self.m_emax) | |
| 145 | - | |
| 146 | - # Initialise models. Note that we centre the point source at the Galactic | |
| 147 | - # center as our observation is also centred at the Galactic centre, so | |
| 148 | - # we're onaxis. | |
| 158 | + | |
| 159 | + pnt = gammalib.GSkyDir() | |
| 160 | + pnt.radec_deg(self["ra"].real(),self["dec"].real()) | |
| 161 | + | |
| 162 | + # Initialise models. Note that we centre the point source at the | |
| 163 | + # center of our observation, so we're onaxis. | |
| 149 | 164 | self.bkg_model = gammalib.GModels() |
| 150 | 165 | self.full_model = gammalib.GModels() |
| 151 | 166 | self.bkg_model.append(self.set_bkg_model()) |
| 152 | 167 | self.full_model.append(self.set_bkg_model()) |
| 153 | - self.full_model.append(self.set_src_model(0.0, self.m_offset, \ | |
| 168 | + self.full_model.append(self.set_src_model(pnt.l_deg(), pnt.b_deg()+self.m_offset, \ | |
| 154 | 169 | flux=0.010, \ |
| 155 | 170 | type=self.m_type, \ |
| 156 | 171 | index=self.m_index)) |
| ... | ... | @@ -166,7 +181,7 @@ class cstsdist(gammalib.GApplication): |
| 166 | 181 | Set model. |
| 167 | 182 | """ |
| 168 | 183 | # Copy models |
| 169 | - self.model = models.copy() | |
| 184 | + self.obs.models(models.copy()) | |
| 170 | 185 | |
| 171 | 186 | # Return |
| 172 | 187 | return |
| ... | ... | @@ -235,35 +250,7 @@ class cstsdist(gammalib.GApplication): |
| 235 | 250 | |
| 236 | 251 | # Return |
| 237 | 252 | return |
| 238 | - | |
| 239 | - def set_obs(self, lpnt=0.0, bpnt=0.0, emin=0.1, emax=100.0): | |
| 240 | - """ | |
| 241 | - Returns an observation container with a single CTA observation. | |
| 242 | - | |
| 243 | - Keywords: | |
| 244 | - lpnt - Galactic longitude of pointing [deg] (default: 0.0) | |
| 245 | - bpnt - Galactic latitude of pointing [deg] (default: 0.0) | |
| 246 | - emin - Minimum energy [TeV] (default: 0.1) | |
| 247 | - emax - Maximum energy [TeV] (default: 100.0) | |
| 248 | - """ | |
| 249 | - # Allocate observation container | |
| 250 | - obs = gammalib.GObservations() | |
| 251 | - | |
| 252 | - # Set single pointing | |
| 253 | - pntdir = gammalib.GSkyDir() | |
| 254 | - pntdir.lb_deg(lpnt, bpnt) | |
| 255 | - | |
| 256 | - # Create CTA observation | |
| 257 | - run = obsutils.set_obs(pntdir, caldb=self.m_caldb, irf=self.m_irf, \ | |
| 258 | - duration=self.m_duration, \ | |
| 259 | - emin=emin, emax=emax, rad=self.m_rad) | |
| 260 | - | |
| 261 | - # Append observation to container | |
| 262 | - obs.append(run) | |
| 263 | - | |
| 264 | - # Return observation container | |
| 265 | - return obs | |
| 266 | - | |
| 253 | + | |
| 267 | 254 | def set_bkg_model(self, fitsigma=False): |
| 268 | 255 | """ |
| 269 | 256 | Setup CTA background model. |
| ... | ... | @@ -343,10 +330,13 @@ class cstsdist(gammalib.GApplication): |
| 343 | 330 | self.log("ERROR: Unknown source type '"+type+"'.\n") |
| 344 | 331 | return None |
| 345 | 332 | source = gammalib.GModelSky(spatial, spectrum) |
| 346 | - | |
| 333 | + | |
| 347 | 334 | # Set source name |
| 348 | 335 | source.name("Test") |
| 349 | - source.tscalc(True) | |
| 336 | + | |
| 337 | + # Turn TS value computation off | |
| 338 | + # since we compute it by hand later on | |
| 339 | + source.tscalc(False) | |
| 350 | 340 | |
| 351 | 341 | # Return source |
| 352 | 342 | return source | ... | ... |
test/test_cscripts.sh.in
| ... | ... | @@ -62,7 +62,7 @@ chmod +x @abs_top_srcdir@/scripts/cspull.py |
| 62 | 62 | emin=0.1 \ |
| 63 | 63 | emax=100.0 \ |
| 64 | 64 | enumbins=0 \ |
| 65 | - duration=1800.0 \ | |
| 65 | + tmax=1800.0 \ | |
| 66 | 66 | deadc=0.95 \ |
| 67 | 67 | rad=5.0 \ |
| 68 | 68 | npix=200 \ |
| ... | ... | @@ -118,7 +118,7 @@ chmod +x @abs_top_srcdir@/scripts/cstsdist.py |
| 118 | 118 | emin=0.1 \ |
| 119 | 119 | emax=100.0 \ |
| 120 | 120 | enumbins=0 \ |
| 121 | - duration=1800.0 \ | |
| 121 | + tmax=1800.0 \ | |
| 122 | 122 | rad=5.0 \ |
| 123 | 123 | npix=200 \ |
| 124 | 124 | binsz=0.05 > cstsdist.log | ... | ... |