sherpa icon indicating copy to clipboard operation
sherpa copied to clipboard

'plot_delchi' discrepancies with plot generated using 'get_delchi_plot' arrays

Open nplee opened this issue 1 year ago • 12 comments

Hi all,

This came in through helpdesk, and I'm able to independently generate a similar case using our standard 3c273.pi example set from the Sherpa threads. It seems like the errors for the x-axis from get_delchi_plot are different than that displayed by plot_delchi.

An example is below:

sherpa In [1]: import matplotlib.pyplot as plt

sherpa In [2]: load_data("3c273.pi")
WARNING: systematic errors were not found in file '3c273.pi'
statistical errors were found in file '3c273.pi' 
but not used; to use them, re-read with use_errors=True
read ARF file 3c273.arf
read RMF file 3c273.rmf
WARNING: systematic errors were not found in file '3c273_bg.pi'
statistical errors were found in file '3c273_bg.pi' 
but not used; to use them, re-read with use_errors=True
read background file 3c273_bg.pi

sherpa In [3]: set_source(powlaw1d.p1)

sherpa In [4]: fit()
WARNING: data set 1 has associated backgrounds, but they have not been subtracted, nor have background models been set
Dataset               = 1
Method                = levmar
Statistic             = chi2gehrels
Initial fit statistic = 8.15838e+10
Final fit statistic   = 50.5351 at function evaluation 25
Data points           = 46
Degrees of freedom    = 44
Probability [Q-value] = 0.231118
Reduced statistic     = 1.14852
Change in statistic   = 8.15838e+10
   p1.gamma       1.72329      +/- 0.0501892   
   p1.ampl        0.000147339  +/- 8.26966e-06 

sherpa In [5]: plot_delchi()

sherpa In [6]: delchiplot = get_delchi_plot()

sherpa In [7]: plt.errorbar(delchiplot.x, delchiplot.y, xerr=delchiplot.xerr, yerr=delchiplot.yerr, ls='none', alpha=0.5)
Out[7]: <ErrorbarContainer object of 3 artists>

delchi_plot

sherpa In [8]: print(delchiplot)
x      = [ 0.1245, 0.2774, 0.3869, 0.5183, 0.6059, 0.6716, 0.7227, 0.7665, 0.803 ,
  0.8395, 0.876 , 0.9198, 0.9709, 1.0147, 1.0658, 1.1169, 1.168 , 1.241 ,
  1.3432, 1.4381, 1.5403, 1.6498, 1.752 , 1.8542, 1.9199, 1.9856, 2.0586,
  2.1389, 2.2338, 2.336 , 2.4893, 2.6499, 2.7886, 2.9711, 3.2339, 3.4748,
  3.6792, 3.9128, 4.1391, 4.4822, 4.8691, 5.1976, 5.6356, 6.2342, 8.2198,
 12.41  ]
y      = [-2.781 , 0.2032, 0.9608, 0.0078, 0.7315, 0.4491, 1.3232, 1.1458, 1.3408,
  0.9502, 1.2498,-0.5242, 1.1126, 0.5169,-0.118 , 1.1878, 0.5615,-0.2275,
 -0.4193, 0.9027, 0.3687, 0.7743,-0.2119, 0.1495, 1.5744, 0.0607, 1.1796,
  0.9005, 0.693 , 0.347 ,-0.2612, 1.079 , 0.7726,-0.09  ,-1.2079, 0.8216,
  0.0689,-0.1063, 0.1506,-2.4796,-0.1243,-0.2364,-0.4672,-0.1275,-0.3884,
  3.5365]
yerr   = [1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,
 1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.]
xerr   = [0.2467,0.0584,0.1606,0.1022,0.073 ,0.0584,0.0438,0.0438,0.0292,0.0438,
 0.0292,0.0584,0.0438,0.0438,0.0584,0.0438,0.0584,0.0876,0.1168,0.073 ,
 0.1314,0.0876,0.1168,0.0876,0.0438,0.0876,0.0584,0.1022,0.0876,0.1168,
 0.1898,0.1314,0.146 ,0.219 ,0.3066,0.1752,0.2336,0.2336,0.219 ,0.4672,
 0.3066,0.3504,0.5256,0.6716,3.2996,5.0808]
xlabel = Energy (keV)
ylabel = Sigma
title  = Sigma Residuals for 3c273.pi
plot_prefs = {'xerrorbars': True, 'yerrorbars': True, 'ecolor': None, 'capsize': 0, 'barsabove': False, 'xlog': False, 'ylog': False, 'linestyle': 'None', 'drawstyle': 'default', 'color': None, 'marker': '.', 'markerfacecolor': None, 'markersize': None, 'alpha': None, 'xaxis': True, 'ratioline': False, 'linecolor': None}

where in the figure, the black figure is from plot_delchi and the translucent red figure is the overplotted pyplot using the get_delchi_plot arrays. From what I understand, the two functions are dependent on the DelchiPlot class:

https://github.com/sherpa/sherpa/blob/767f516b929f7f53ae256a4902edd27fec4303b4/sherpa/plot/init.py#L1957-L2009

The x-errors are the +/- half-width of the energy/wavelength bins and the y-errors are just +/-1; and I'm not convinced that the error bars in the delchi plot are particularly meaningful.

Anyways, the x-error bar array plotted by pyplot.errorbar are larger than that plotted by by plot_delchi even though it doesn't look like the Sherpa function is manipulating the values... from mere speculation makes me wonder if something's going on with how grouping is being handled?

nplee avatar Jul 11 '23 15:07 nplee