Commit df63061716852876316c375abf71fd4c727b07f2

Authored by Josh Cardenzana
1 parent 74c93801

Remove need for 'math' module in show_spectrum.py (#2938)

examples/show_spectrum.py
... ... @@ -19,7 +19,6 @@
19 19 #
20 20 # ==========================================================================
21 21 import sys
22   -import math
23 22 try:
24 23 import matplotlib.pyplot as plt
25 24 plt.figure()
... ... @@ -177,8 +176,8 @@ def plot_dloglike(spec):
177 176 """
178 177 # Establish the bounds on the x,y plot
179 178 ymin,ymax = plt.gca().get_ylim()
180   - ymin = math.log10(ymin)
181   - ymax = math.log10(ymax)
  179 + ymin = np.log10(ymin)
  180 + ymax = np.log10(ymax)
182 181 steps = 1000
183 182 y_bounds = np.linspace(ymin, ymax, steps+1)
184 183 fluxpnts = []
... ...
test/test_csspec.py
... ... @@ -234,6 +234,32 @@ class Test(test):
234 234 # Check result file
235 235 self._check_result_file('csspec_py5.fits', 2)
236 236  
  237 + # Set-up unbinned csspec with likelihood profile (no multi-processing)
  238 + spec = cscripts.csspec()
  239 + spec['inobs'] = self._events
  240 + spec['inmodel'] = self._model
  241 + spec['srcname'] = 'Crab'
  242 + spec['caldb'] = self._caldb
  243 + spec['irf'] = self._irf
  244 + spec['method'] = 'AUTO'
  245 + spec['ebinalg'] = 'LOG'
  246 + spec['enumbins'] = 2
  247 + spec['emin'] = 1.0
  248 + spec['emax'] = 100.0
  249 + spec['nthreads'] = 1
  250 + spec['dll_sigstep'] = 2.5
  251 + spec['dll_sigmax'] = 5
  252 + spec['outfile'] = 'csspec_py6.fits'
  253 + spec['logfile'] = 'csspec_py6.log'
  254 + spec['chatter'] = 2
  255 + spec['publish'] = True
  256 +
  257 + # Run csspec script
  258 + spec.execute()
  259 +
  260 + # Check result file
  261 + self._check_result_file('csspec_py6.fits', 2, 5)
  262 +
237 263 # Return
238 264 return
239 265  
... ... @@ -277,7 +303,7 @@ class Test(test):
277 303 return
278 304  
279 305 # Check result file
280   - def _check_result_file(self, filename, bins):
  306 + def _check_result_file(self, filename, bins, lbins=0):
281 307 """
282 308 Check result file
283 309 """
... ... @@ -290,8 +316,33 @@ class Test(test):
290 316 # Check dimensions
291 317 self.test_value(spectrum.nrows(), bins,
292 318 'Check for %d rows in spectrum' % bins)
293   - self.test_value(spectrum.ncols(), 8,
294   - 'Check for 8 columns in spectrum')
295 319  
  320 + # Make sure that the header keywords are present
  321 + req_keywords = ['SED_TYPE', 'UL_CONF']
  322 + for keyword in req_keywords:
  323 + self.test_assert(spectrum.has_card(keyword),
  324 + 'Check that SED has \'%s\' keyword' % keyword)
  325 +
  326 + # Do checks specific to likelihood profile table
  327 + flux_keys = spectrum.card('SED_TYPE').string()
  328 + flux_keys = flux_keys.split(',')
  329 + if lbins > 0:
  330 + # Should be 13 columns
  331 + self.test_value(spectrum.ncols(), 13,
  332 + 'Check for 8 columns in spectrum')
  333 + self.test_value(flux_keys[0], 'likelihood',
  334 + 'Check that \'SED_TYPE\' card is \'likelihood\'')
  335 + # Make sure the profile has the appropriate entries
  336 + self.test_value(spectrum['norm_scan'].elements(0), lbins,
  337 + 'Check for %d rows in flux scan profile' % lbins)
  338 + self.test_value(spectrum['dloglike_scan'].elements(0), lbins,
  339 + 'Check for %d rows in likelihood profile' % lbins)
  340 + else:
  341 + # Should be 10 columns
  342 + self.test_value(spectrum.ncols(), 10,
  343 + 'Check for 8 columns in spectrum')
  344 + self.test_value(flux_keys[0], 'norm',
  345 + 'Check that \'SED_TYPE\' card is \'norm\'')
  346 +
296 347 # Return
297 348 return
... ...