Changeset 13d86bc in sasmodels for sasmodels/core.py
- Timestamp:
- Aug 26, 2014 9:06:58 AM (10 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- a7684e5
- Parents:
- 32c160a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/core.py
r32c160a r13d86bc 73 73 74 74 75 def fake_data2D(qx, qy=None):75 def empty_data2D(qx, qy=None): 76 76 from sans.dataloader.data_info import Data2D, Detector 77 77 … … 114 114 115 115 116 def empty_data1D(q): 117 from sans.dataloader.data_info import Data1D 118 119 Iq = 100*np.ones_like(q) 120 dIq = np.sqrt(Iq) 121 data = Data1D(q, Iq, dx=0.05*q, dy=dIq) 122 data.filename = "fake data" 123 data.qmin, data.qmax = q.min(), q.max() 124 return data 125 126 116 127 def set_beam_stop(data, radius, outer=None): 117 128 from sans.dataloader.manipulations import Ringcut … … 139 150 140 151 141 def plot_data(data, iq, vmin=None, vmax=None ):142 from numpy.ma import masked_array 152 def plot_data(data, iq, vmin=None, vmax=None, scale='log'): 153 from numpy.ma import masked_array, masked 143 154 import matplotlib.pyplot as plt 144 img = masked_array(iq, data.mask) 145 xmin, xmax = min(data.qx_data), max(data.qx_data) 146 ymin, ymax = min(data.qy_data), max(data.qy_data) 147 plt.imshow(img.reshape(128,128), 148 interpolation='nearest', aspect=1, origin='upper', 149 extent=[xmin, xmax, ymin, ymax], vmin=vmin, vmax=vmax) 150 151 152 def plot_result2D(data, theory, view='linear'): 155 if hasattr(data, 'qx_data'): 156 img = masked_array(iq, data.mask) 157 if scale == 'log': 158 img[(img <= 0) | ~np.isfinite(img)] = masked 159 img = np.log10(img) 160 xmin, xmax = min(data.qx_data), max(data.qx_data) 161 ymin, ymax = min(data.qy_data), max(data.qy_data) 162 plt.imshow(img.reshape(128,128), 163 interpolation='nearest', aspect=1, origin='upper', 164 extent=[xmin, xmax, ymin, ymax], vmin=vmin, vmax=vmax) 165 else: # 1D data 166 if scale == 'linear': 167 idx = np.isfinite(iq) 168 plt.plot(data.x[idx], iq[idx]) 169 else: 170 idx = np.isfinite(iq) & (iq>0) 171 plt.loglog(data.x[idx], iq[idx]) 172 173 174 def plot_result2D(data, theory, view='log'): 153 175 import matplotlib.pyplot as plt 154 from numpy.ma import masked_array, masked 155 #print "not a number",sum(np.isnan(data.data)) 156 #data.data[data.data<0.05] = 0.5 157 mdata = masked_array(data.data, data.mask) 158 mdata[np.isnan(mdata)] = masked 159 if view is 'log': 160 mdata[mdata <= 0] = masked 161 mdata = np.log10(mdata) 162 mtheory = masked_array(np.log10(theory), mdata.mask) 163 else: 164 mtheory = masked_array(theory, mdata.mask) 165 mresid = masked_array((theory-data.data)/data.err_data, data.mask) 166 vmin = min(mdata.min(), mtheory.min()) 167 vmax = max(mdata.max(), mtheory.max()) 168 print np.exp(np.mean(mtheory)), np.std(mtheory),np.max(mtheory),np.min(mtheory) 169 170 plt.subplot(1, 3, 1) 171 plot_data(data, mdata, vmin=vmin, vmax=vmax) 176 resid = (theory-data.data)/data.err_data 177 plt.subplot(131) 178 plot_data(data, data.data, scale=view) 172 179 plt.colorbar() 173 plt.subplot(1 , 3,2)174 plot_data(data, mtheory, vmin=vmin, vmax=vmax)180 plt.subplot(132) 181 plot_data(data, theory, scale=view) 175 182 plt.colorbar() 176 plt.subplot(1, 3, 3) 177 print abs(mresid).max() 178 plot_data(data, mresid) 183 plt.subplot(133) 184 plot_data(data, resid, scale='linear') 179 185 plt.colorbar() 180 186 181 187 182 def plot_result1D(data, theory, view='l inear'):188 def plot_result1D(data, theory, view='log'): 183 189 import matplotlib.pyplot as plt 184 190 from numpy.ma import masked_array, masked … … 218 224 q_vectors = [data.qx_data, data.qy_data] 219 225 else: 220 self.index = (data. mask==0) & (~np.isnan(data.y))226 self.index = (data.x>=data.qmin) & (data.x<=data.qmax) & ~np.isnan(data.y) 221 227 self.iq = data.y[self.index] 222 228 self.diq = data.dy[self.index]
Note: See TracChangeset
for help on using the changeset viewer.