Changeset 57ad773 in sasview for src/sas/qtgui/Perspectives/Inversion/InversionLogic.py
- Timestamp:
- Oct 28, 2017 10:02:15 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- d132f33
- Parents:
- e7651ff
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/InversionLogic.py
re7651ff r57ad773 1 import math 2 import pylab 1 3 import numpy as np 2 4 3 5 from sas.qtgui.Plotting.PlotterData import Data1D 6 7 PR_FIT_LABEL = r"$P_{fit}(r)$" 8 PR_LOADED_LABEL = r"$P_{loaded}(r)$" 9 IQ_DATA_LABEL = r"$I_{obs}(q)$" 10 IQ_FIT_LABEL = r"$I_{fit}(q)$" 11 IQ_SMEARED_LABEL = r"$I_{smeared}(q)$" 12 GROUP_ID_IQ_DATA = r"$I_{obs}(q)$" 13 GROUP_ID_PR_FIT = r"$P_{fit}(r)$" 4 14 5 15 … … 9 19 No QStandardModelIndex here. 10 20 """ 21 22 # TODO: Add way to change this value 23 _pr_n_pts = 51 11 24 12 25 def __init__(self, data=None): … … 30 43 return self.data_is_loaded 31 44 32 def new1DPlot(self, return_data):45 def new1DPlot(self, out, pr, q=None): 33 46 """ 34 47 Create a new 1D data instance based on fitting results 35 48 """ 36 # Unpack return data from Calc1D37 x, y, page_id, state, weight,\38 fid, toggle_mode_on, \39 elapsed, index, model,\40 data, update_chisqr, source = return_data41 49 42 # Create the new plot 43 new_plot = Data1D(x=x, y=y) 44 new_plot.is_data = False 45 new_plot.dy = np.zeros(len(y)) 46 _yaxis, _yunit = data.get_yaxis() 47 _xaxis, _xunit = data.get_xaxis() 50 qtemp = pr.x 51 if q is not None: 52 qtemp = q 48 53 49 new_plot.group_id = data.group_id 50 new_plot.id = data.name 51 new_plot.name = model.name + " [" + data.name + "]" 52 new_plot.title = new_plot.name 53 new_plot.xaxis(_xaxis, _xunit) 54 new_plot.yaxis(_yaxis, _yunit) 54 # Make a plot 55 maxq = max(qtemp) 56 57 minq = min(qtemp) 58 59 # Check for user min/max 60 if pr.q_min is not None and maxq >= pr.q_min >= minq: 61 minq = pr.q_min 62 if pr.q_max is not None and maxq >= pr.q_max >= minq: 63 maxq = pr.q_max 64 65 x = pylab.arange(minq, maxq, maxq / 301.0) 66 y = np.zeros(len(x)) 67 err = np.zeros(len(x)) 68 for i in range(len(x)): 69 value = pr.iq(out, x[i]) 70 y[i] = value 71 try: 72 err[i] = math.sqrt(math.fabs(value)) 73 except: 74 err[i] = 1.0 75 print("Error getting error", value, x[i]) 76 77 new_plot = Data1D(x, y) 78 new_plot.name = IQ_FIT_LABEL 79 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 80 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 81 title = "I(q)" 82 new_plot.title = title 83 84 # If we have a group ID, use it 85 if 'plot_group_id' in pr.info: 86 new_plot.group_id = pr.info["plot_group_id"] 87 new_plot.id = IQ_FIT_LABEL 88 89 # If we have used slit smearing, plot the smeared I(q) too 90 if pr.slit_width > 0 or pr.slit_height > 0: 91 x = pylab.arange(minq, maxq, maxq / 301.0) 92 y = np.zeros(len(x)) 93 err = np.zeros(len(x)) 94 for i in range(len(x)): 95 value = pr.iq_smeared(pr.out, x[i]) 96 y[i] = value 97 try: 98 err[i] = math.sqrt(math.fabs(value)) 99 except: 100 err[i] = 1.0 101 print("Error getting error", value, x[i]) 102 103 new_plot = Data1D(x, y) 104 new_plot.name = IQ_SMEARED_LABEL 105 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 106 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 107 # If we have a group ID, use it 108 if 'plot_group_id' in pr.info: 109 new_plot.group_id = pr.info["plot_group_id"] 110 new_plot.id = IQ_SMEARED_LABEL 111 new_plot.title = title 112 113 return new_plot 114 115 def newPRPlot(self, out, pr, cov=None): 116 """ 117 """ 118 # Show P(r) 119 x = pylab.arange(0.0, pr.d_max, pr.d_max / self._pr_n_pts) 120 121 y = np.zeros(len(x)) 122 dy = np.zeros(len(x)) 123 y_true = np.zeros(len(x)) 124 125 total = 0.0 126 pmax = 0.0 127 cov2 = np.ascontiguousarray(cov) 128 129 for i in range(len(x)): 130 if cov2 is None: 131 value = pr.pr(out, x[i]) 132 else: 133 (value, dy[i]) = pr.pr_err(out, cov2, x[i]) 134 total += value * pr.d_max / len(x) 135 136 # keep track of the maximum P(r) value 137 if value > pmax: 138 pmax = value 139 140 y[i] = value 141 142 # if self._normalize_output == True: 143 # y = y / total 144 # dy = dy / total 145 # elif self._scale_output_unity == True: 146 # y = y / pmax 147 # dy = dy / pmax 148 149 if cov2 is None: 150 new_plot = Data1D(x, y) 151 else: 152 new_plot = Data1D(x, y, dy=dy) 153 new_plot.name = PR_FIT_LABEL 154 new_plot.xaxis("\\rm{r}", 'A') 155 new_plot.yaxis("\\rm{P(r)} ", "cm^{-3}") 156 new_plot.title = "P(r) fit" 157 new_plot.id = PR_FIT_LABEL 158 # Make sure that the plot is linear 159 new_plot.xtransform = "x" 160 new_plot.ytransform = "y" 161 new_plot.group_id = GROUP_ID_PR_FIT 55 162 56 163 return new_plot … … 67 174 return the npts contains in data 68 175 """ 69 qmin, qmax , npts = None,None, None176 qmin, qmax = None, None 70 177 if isinstance(data, Data1D): 71 178 try: 72 179 qmin = min(data.x) 73 180 qmax = max(data.x) 74 npts = len(data.x)75 181 except (ValueError, TypeError): 76 182 msg = "Unable to find min/max/length of \n data named %s" % \ … … 88 194 raise ValueError, msg 89 195 qmax = np.sqrt(x * x + y * y) 90 npts = len(data.data) 91 return qmin, qmax, npts 196 return qmin, qmax
Note: See TracChangeset
for help on using the changeset viewer.