Commit ff914df6bcc706739747e64a273c1e548e68041b

Authored by Jürgen Knödlseder
1 parent 5cf58fba

Remove lsmodel script

The lsmodel script has been introduced to illustrate GammaLib usage for Fermi/LAT, it does not belong to the ctools.
cscripts/lsmodel.par deleted
1   -#############################################################################
2   -# #
3   -# Fermi/LAT Science Tools #
4   -# #
5   -# ------------------------------------------------------------------------- #
6   -# #
7   -# File: lsmodel.par #
8   -# Version: 1.1.0 #
9   -# #
10   -# Author: Juergen Knoedlseder #
11   -# Jurgen.Knodlseder@irap.omp.eu #
12   -# IRAP #
13   -# #
14   -# Purpose: Parameter file for the lsmodel script #
15   -# #
16   -#############################################################################
17   -#
18   -# Input and output parameters
19   -#============================
20   -cntmap, f, a, cntmap.fits,,, "Counts map"
21   -expmap, f, a, binned_expmap.fits,,, "Exposure map"
22   -ltcube, f, a, ltcube.fits,,, "Livetime cube"
23   -srcmdl, f, a, crab_model.xml,,, "Source model"
24   -caldb, s, h, ,,, "Calibration database"
25   -irf, s, a, P8R2_SOURCE_V6,,, "Instrument response function"
26   -outfile, f, a, model_cube.fits,,, "Output file name"
27   -
28   -#
29   -# Standard parameters
30   -#====================
31   -chatter, i, h, 2,0,4, "Chattiness of output"
32   -clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
33   -debug, b, h, no,,, "Debugging mode activated"
34   -mode, s, h, ql,,, "Mode of automatic parameters"
35   -logfile, f, h, lsmodel.log,,, "Log filename"
36   -
37   -
38   -
cscripts/lsmodel.py deleted
1   -#! /usr/bin/env python
2   -# ==========================================================================
3   -# Generates model cube for Fermi/LAT data.
4   -#
5   -# Copyright (C) 2014-2016 Juergen Knoedlseder
6   -#
7   -# This program is free software: you can redistribute it and/or modify
8   -# it under the terms of the GNU General Public License as published by
9   -# the Free Software Foundation, either version 3 of the License, or
10   -# (at your option) any later version.
11   -#
12   -# This program is distributed in the hope that it will be useful,
13   -# but WITHOUT ANY WARRANTY; without even the implied warranty of
14   -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15   -# GNU General Public License for more details.
16   -#
17   -# You should have received a copy of the GNU General Public License
18   -# along with this program. If not, see <http://www.gnu.org/licenses/>.
19   -#
20   -# ==========================================================================
21   -import sys
22   -import gammalib
23   -
24   -
25   -# ============= #
26   -# lsmodel class #
27   -# ============= #
28   -class lsmodel(gammalib.GApplication):
29   - """
30   - Generates model cube for Fermi/LAT data.
31   -
32   - This class implements the model map generation script. It derives from
33   - 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.
36   - """
37   -
38   - # Constructor
39   - def __init__(self, *argv):
40   - """
41   - Constructor.
42   - """
43   - # Set name and version
44   - self._name = "lsmodel"
45   - self._version = "1.1.0"
46   -
47   - # Initialise application
48   - if len(argv) == 0:
49   - gammalib.GApplication.__init__(self, self._name, self._version)
50   - elif len(argv) ==1:
51   - gammalib.GApplication.__init__(self, self._name, self._version, *argv)
52   - else:
53   - raise TypeError("Invalid number of arguments given.")
54   -
55   - # Set logger properties
56   - self._log_header()
57   - self._log.date(True)
58   -
59   - # Return
60   - return
61   -
62   -
63   - # Private methods
64   - def _get_parameters(self):
65   - """
66   - Get parameters from parfile.
67   - """
68   - # Query user parameters
69   - self["cntmap"].filename()
70   - self["expmap"].filename()
71   - self["ltcube"].filename()
72   - self["srcmdl"].filename()
73   - self["caldb"].string()
74   - self["irf"].string()
75   -
76   - # Read ahead output parameters
77   - if (self._read_ahead()):
78   - self["outfile"].filename()
79   -
80   - # Write input parameters into logger
81   - if self._logTerse():
82   - self._log_parameters()
83   - self._log("\n")
84   -
85   - # Return
86   - return
87   -
88   -
89   - # Public methods
90   - def run(self):
91   - """
92   - Run the script.
93   - """
94   - # Switch screen logging on in debug mode
95   - if self._logDebug():
96   - self._log.cout(True)
97   -
98   - # Get parameters
99   - self._get_parameters()
100   -
101   - # Write header
102   - if self._logTerse():
103   - self._log("\n")
104   - self._log.header1("Generate model cube")
105   -
106   - # Get user parameters
107   - cntmap = self["cntmap"].filename()
108   - expmap = self["expmap"].filename()
109   - ltcube = self["ltcube"].filename()
110   - srcmdl = self["srcmdl"].filename()
111   - caldb = self["caldb"].string()
112   - irf = self["irf"].string()
113   -
114   - # Set LAT observation
115   - obs = gammalib.GLATObservation()
116   - obs.load_binned(cntmap, expmap, ltcube)
117   - obs.response(irf, caldb)
118   -
119   - # Set model (use first model for the moment)
120   - models = gammalib.GModels(srcmdl)
121   - model = models[0]
122   -
123   - # Get deep copy of GLATEventCube from observation
124   - cube = gammalib.GLATEventCube(obs.events())
125   -
126   - # Fill cube with model values
127   - for i in range(cube.size()):
128   - event = cube[i]
129   - value = model.eval(event, obs) * event.size()
130   - event.counts(value)
131   - cube[i] = event
132   -
133   - # Log cube
134   - if self._logTerse():
135   - self._log(str(cube))
136   - self._log("\n")
137   -
138   - # Return
139   - return
140   -
141   - def execute(self):
142   - """
143   - Execute the script.
144   - """
145   - # Open logfile
146   - self._logFileOpen()
147   -
148   - # Read ahead output parameters
149   - self._read_ahead(True)
150   -
151   - # Run the script
152   - self.run()
153   -
154   - # Save event cube
155   - self.save()
156   -
157   - # Return
158   - return
159   -
160   - def save(self):
161   - """
162   - Save model cube.
163   - """
164   - # Write header
165   - if self._logTerse():
166   - self._log("\n")
167   - self._log.header1("Save model cube")
168   -
169   - # Get outfile parameter
170   - outfile = self["outfile"].filename()
171   -
172   - # Log file name
173   - if self._logTerse():
174   - self._log(gammalib.parformat("Model cube"))
175   - self._log(outfile.url())
176   - self._log("\n")
177   -
178   - # Save event cube
179   - self._cube.save(outfile, self._clobber())
180   -
181   - # Return
182   - return
183   -
184   -
185   -# ======================== #
186   -# Main routine entry point #
187   -# ======================== #
188   -if __name__ == '__main__':
189   -
190   - # Create instance of application
191   - app = lsmodel(sys.argv)
192   -
193   - # Execute application
194   - app.execute()