Commit fd75ab1da65d1b5e4c90cb679a57ae03e9732604

Authored by Jürgen Knödlseder
1 parent 3f4775b7

Remove plotting of significance histograms since they require matplotlib

Showing 1 changed file with 0 additions and 92 deletions
modules/comscripts/comobsres.py
@@ -24,7 +24,6 @@ import os @@ -24,7 +24,6 @@ import os
24 import math 24 import math
25 import gammalib 25 import gammalib
26 import ctools 26 import ctools
27 -import matplotlib.pyplot as plt  
28 27
29 28
30 # ======================= # 29 # ======================= #
@@ -499,89 +498,6 @@ class comobsres(ctools.csobservation): @@ -499,89 +498,6 @@ class comobsres(ctools.csobservation):
499 # Return 498 # Return
500 return sig 499 return sig
501 500
502 - def _plot_sighist(self, sighist, nbins=80, sigma_min=-6.0, sigma_max=6.0, fontsize=11, title=None):  
503 - """  
504 - Plot the significance distribution  
505 -  
506 - Parameters  
507 - ----------  
508 - sighist : list of floats  
509 - Significance values  
510 - nbins : int, optional  
511 - Number of histogram bins  
512 - sigma_min : float, optional  
513 - Lower limit of the x axis in the plot  
514 - sigma_max : float, optional  
515 - Upper limit of the x axis in the plot  
516 - fontsize : int, optional  
517 - Font size for axes  
518 - title : str, optional  
519 - Title string  
520 - """  
521 - # Compute bin edges, hence use nbins+1  
522 - binwidth = (sigma_max - sigma_min) / float(nbins)  
523 - bin_edges = [sigma_min + binwidth*i for i in range(nbins+1)]  
524 -  
525 - # Draw significance histogram  
526 - f, ax = plt.subplots()  
527 - y, _, _ = plt.hist(sighist, bins=bin_edges, histtype='step', color='k')  
528 -  
529 - # Set initial Gaussian parameters  
530 - y_max = float(y.max())  
531 - par1 = gammalib.GOptimizerPar('Norm', y_max)  
532 - par2 = gammalib.GOptimizerPar('Mean', 0.0)  
533 - par3 = gammalib.GOptimizerPar('Sigma', 1.0)  
534 - pars = gammalib.GOptimizerPars()  
535 - pars.append(par1)  
536 - pars.append(par2)  
537 - pars.append(par3)  
538 -  
539 - # Set fit function  
540 - x = [0.5*(bin_edges[i]+bin_edges[i+1]) for i in range(nbins)]  
541 - fct = gaussian(x, y)  
542 -  
543 - # Optimize function and compute errors  
544 - opt = gammalib.GOptimizerLM()  
545 - opt.optimize(fct, pars)  
546 - opt.errors(fct, pars)  
547 -  
548 - # Recover parameters and errors  
549 - norm = pars[0].value()  
550 - e_norm = pars[0].error()  
551 - mean = pars[1].value()  
552 - e_mean = pars[1].error()  
553 - sigma = pars[2].value()  
554 - e_sigma = pars[2].error()  
555 -  
556 - # Draw text box  
557 - msg = 'mean: %.3f +/- %.3f \n width: %.3f +/- %.3f' % \  
558 - (mean, e_mean, sigma, e_sigma)  
559 - ax.text(0.97, 0.95, msg, ha='right', va='top',  
560 - bbox=dict(edgecolor='red', facecolor='white'),  
561 - transform=ax.transAxes, fontsize=8)  
562 -  
563 - # Plot the normal  
564 - yvals = [norm * math.exp(-0.5*(x-mean)**2/(sigma**2)) for x in bin_edges]  
565 - ax.plot(bin_edges, yvals, 'r-')  
566 -  
567 - # Configure the plot  
568 - ax.set_ylim(0.5, ax.get_ylim()[1]*2.5)  
569 - ax.set_xlim(sigma_min, sigma_max)  
570 - ax.set_xlabel('Significance', fontsize=fontsize)  
571 - ax.set_ylabel('Entries', fontsize=fontsize)  
572 - ax.grid()  
573 - ax.set_yscale('log')  
574 -  
575 - # Add title  
576 - if title != None:  
577 - ax.set_title(title)  
578 -  
579 - # Save figure  
580 - plt.savefig(title+'.png')  
581 -  
582 - # Return  
583 - return  
584 -  
585 501
586 # Public methods 502 # Public methods
587 def run(self): 503 def run(self):
@@ -666,10 +582,6 @@ class comobsres(ctools.csobservation): @@ -666,10 +582,6 @@ class comobsres(ctools.csobservation):
666 # Fill residual map 582 # Fill residual map
667 sig = self._fill_map(dre, drm, imap) 583 sig = self._fill_map(dre, drm, imap)
668 584
669 - # Generate significance histogram  
670 - if self['png'].boolean():  
671 - self._plot_sighist(sig, title='%s_map' % (fname))  
672 -  
673 # Build DRI residuals 585 # Build DRI residuals
674 if self['dri'].boolean(): 586 if self['dri'].boolean():
675 587
@@ -679,10 +591,6 @@ class comobsres(ctools.csobservation): @@ -679,10 +591,6 @@ class comobsres(ctools.csobservation):
679 # Generate residual data space 591 # Generate residual data space
680 sig = self._compute_residual_dri(dre, drm, imap, '%s' % fname, group) 592 sig = self._compute_residual_dri(dre, drm, imap, '%s' % fname, group)
681 593
682 - # Generate significance histogram  
683 - if self['png'].boolean():  
684 - self._plot_sighist(sig, title='%s_dri' % fname)  
685 -  
686 # Return 594 # Return
687 return 595 return
688 596