ncrystal-python 4.2.6__py3-none-any.whl → 4.2.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- NCrystal/__init__.py +1 -1
- NCrystal/_hist.py +297 -0
- NCrystal/_mmc.py +2 -268
- NCrystal/_ncmatimpl.py +11 -3
- NCrystal/core.py +6 -1
- NCrystal/ncmat.py +10 -4
- {ncrystal_python-4.2.6.dist-info → ncrystal_python-4.2.10.dist-info}/METADATA +1 -1
- {ncrystal_python-4.2.6.dist-info → ncrystal_python-4.2.10.dist-info}/RECORD +12 -11
- {ncrystal_python-4.2.6.dist-info → ncrystal_python-4.2.10.dist-info}/WHEEL +0 -0
- {ncrystal_python-4.2.6.dist-info → ncrystal_python-4.2.10.dist-info}/entry_points.txt +0 -0
- {ncrystal_python-4.2.6.dist-info → ncrystal_python-4.2.10.dist-info}/licenses/LICENSE +0 -0
- {ncrystal_python-4.2.6.dist-info → ncrystal_python-4.2.10.dist-info}/top_level.txt +0 -0
NCrystal/__init__.py
CHANGED
|
@@ -55,7 +55,7 @@ For detailed usage conditions and licensing of this open source project, see:
|
|
|
55
55
|
|
|
56
56
|
#NB: Synchronize meta-data below with fields in setup.py+template_setup.py.in meta data:
|
|
57
57
|
__license__ = "Apache 2.0, http://www.apache.org/licenses/LICENSE-2.0"
|
|
58
|
-
__version__ = '4.2.
|
|
58
|
+
__version__ = '4.2.10'
|
|
59
59
|
__status__ = "Production"
|
|
60
60
|
__author__ = "NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)"
|
|
61
61
|
__copyright__ = "Copyright 2015-2024 %s"%__author__
|
NCrystal/_hist.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
|
|
2
|
+
################################################################################
|
|
3
|
+
## ##
|
|
4
|
+
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
|
+
## ##
|
|
6
|
+
## Copyright 2015-2025 NCrystal developers ##
|
|
7
|
+
## ##
|
|
8
|
+
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
|
+
## you may not use this file except in compliance with the License. ##
|
|
10
|
+
## You may obtain a copy of the License at ##
|
|
11
|
+
## ##
|
|
12
|
+
## http://www.apache.org/licenses/LICENSE-2.0 ##
|
|
13
|
+
## ##
|
|
14
|
+
## Unless required by applicable law or agreed to in writing, software ##
|
|
15
|
+
## distributed under the License is distributed on an "AS IS" BASIS, ##
|
|
16
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ##
|
|
17
|
+
## See the License for the specific language governing permissions and ##
|
|
18
|
+
## limitations under the License. ##
|
|
19
|
+
## ##
|
|
20
|
+
################################################################################
|
|
21
|
+
|
|
22
|
+
# In this internal file we provide a histogram class which can be used to load
|
|
23
|
+
# the JSON data representing the (likewise internal) histograms from
|
|
24
|
+
# "NCrystal/internal/utils/NCHists.hh".
|
|
25
|
+
|
|
26
|
+
__all__ = ['Hist1D']
|
|
27
|
+
|
|
28
|
+
from ._numpy import _np, _ensure_numpy, _np_linspace
|
|
29
|
+
|
|
30
|
+
class Hist1D:
|
|
31
|
+
|
|
32
|
+
def __init__( self, data ):
|
|
33
|
+
if data=='_no_init_':
|
|
34
|
+
return
|
|
35
|
+
_ensure_numpy()
|
|
36
|
+
self.__stats = data.get('stats')
|
|
37
|
+
self.__title = data['title']
|
|
38
|
+
hb = data['bindata']
|
|
39
|
+
self.__xmin = hb['xmin']
|
|
40
|
+
self.__xmax = hb['xmax']
|
|
41
|
+
self.__nbins = hb['nbins']
|
|
42
|
+
self.__y = _np.asarray(hb['content'],dtype=float)
|
|
43
|
+
esq = hb.get('errorsq')
|
|
44
|
+
self.__yerrsq = ( _np.asarray(esq,dtype=float)
|
|
45
|
+
if esq is not None
|
|
46
|
+
else None )
|
|
47
|
+
self.__yerr = None
|
|
48
|
+
assert self.__nbins == len(self.__y)
|
|
49
|
+
assert self.__yerrsq is None or self.__nbins == len(self.__yerrsq)
|
|
50
|
+
|
|
51
|
+
def clone( self, rebin_factor = 1 ):
|
|
52
|
+
c = Hist1D('_no_init_')
|
|
53
|
+
c.__stats = self.__stats
|
|
54
|
+
c.__title = self.__title
|
|
55
|
+
c.__xmin = self.__xmin
|
|
56
|
+
c.__xmax = self.__xmax
|
|
57
|
+
c.__nbins = self.__nbins
|
|
58
|
+
c.__y = self.__y.copy()
|
|
59
|
+
c.__yerrsq = self.__yerrsq.copy() if self.__yerrsq is not None else None
|
|
60
|
+
c.__yerr = self.__yerr.copy() if self.__yerr is not None else None
|
|
61
|
+
if rebin_factor > 1:
|
|
62
|
+
c.rebin( rebin_factor )
|
|
63
|
+
return c
|
|
64
|
+
|
|
65
|
+
def integrate( self, xlow, xhigh, tolerance = 1e-5 ):
|
|
66
|
+
"""
|
|
67
|
+
Returns integrated contents of the histogram over the area
|
|
68
|
+
[xlow,xhigh] along with the error of that value in a tuple
|
|
69
|
+
(content,error).
|
|
70
|
+
|
|
71
|
+
This is done translating xlow and xhigh to exact bin edges and then
|
|
72
|
+
calling integrate_bins. If that is not possible within the
|
|
73
|
+
tolerance, an exception is raised.
|
|
74
|
+
|
|
75
|
+
"""
|
|
76
|
+
if not ( xhigh >= xlow ):
|
|
77
|
+
from .exceptions import NCBadInput
|
|
78
|
+
raise NCBadInput('Invalid integration range requested.')
|
|
79
|
+
|
|
80
|
+
bw = self.binwidth
|
|
81
|
+
def _findedge(x):
|
|
82
|
+
if x <= self.__xmin:
|
|
83
|
+
return 0
|
|
84
|
+
if x >= self.__xmax:
|
|
85
|
+
return self.nbins
|
|
86
|
+
r = ( x - self.__xmin ) / bw
|
|
87
|
+
ir = int(r+0.5)
|
|
88
|
+
if abs(r-ir) > tolerance:
|
|
89
|
+
from .exceptions import NCBadInput
|
|
90
|
+
raise NCBadInput(f'Value {x} does not correspond exactly'
|
|
91
|
+
' to a bin edge within the tolerance.')
|
|
92
|
+
return ir
|
|
93
|
+
e_low = _findedge(xlow)
|
|
94
|
+
e_high = _findedge(xhigh)
|
|
95
|
+
if e_low == e_high:
|
|
96
|
+
return ( 0.0, 0.0 )
|
|
97
|
+
assert e_low >= 0
|
|
98
|
+
assert e_low < e_high < self.nbins
|
|
99
|
+
return self.integrate_bins( e_low, e_high - 1 )
|
|
100
|
+
|
|
101
|
+
def integrate_bins( self, bin_low = None, bin_up = None ):
|
|
102
|
+
"""
|
|
103
|
+
Returns integrated contents of the bins [bin_low,bin_up[ along with
|
|
104
|
+
the error of that value in a tuple (content,error).
|
|
105
|
+
|
|
106
|
+
If bin_low is None the integration will start at the first bin and
|
|
107
|
+
include the underflow bin.
|
|
108
|
+
|
|
109
|
+
If bin_up is None the integration will end at the last bin and
|
|
110
|
+
include the overflow bin.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
add_overflow, add_underflow = False, False
|
|
114
|
+
if bin_low is None:
|
|
115
|
+
add_underflow = True
|
|
116
|
+
bin_low = 0
|
|
117
|
+
underflow_c = self.stats.get('underflow')
|
|
118
|
+
underflow_e2 = self.stats.get('underflow_errorsq')
|
|
119
|
+
if bool(underflow_c is None) != bool(underflow_e2 is None):
|
|
120
|
+
from .exceptions import NCBadInput
|
|
121
|
+
raise NCBadInput('Inconsistent underflow info')
|
|
122
|
+
if underflow_c is None:
|
|
123
|
+
add_underflow = False
|
|
124
|
+
|
|
125
|
+
if bin_up is None:
|
|
126
|
+
add_overflow = True
|
|
127
|
+
bin_up = self.__nbins
|
|
128
|
+
overflow_c = self.stats.get('overflow')
|
|
129
|
+
overflow_e2 = self.stats.get('overflow_errorsq')
|
|
130
|
+
if bool(overflow_c is None) != bool(overflow_e2 is None):
|
|
131
|
+
from .exceptions import NCBadInput
|
|
132
|
+
raise NCBadInput('Inconsistent overflow info')
|
|
133
|
+
if overflow_c is None:
|
|
134
|
+
add_overflow = False
|
|
135
|
+
|
|
136
|
+
bin_low, bin_up = int(bin_low), int(bin_up)
|
|
137
|
+
if bin_up < bin_low or bin_low<0 or bin_up > self.__nbins:
|
|
138
|
+
from .exceptions import NCBadInput
|
|
139
|
+
raise NCBadInput('Invalid bin range requested')
|
|
140
|
+
content_integral = self.__y[bin_low:bin_up].sum()
|
|
141
|
+
if add_underflow:
|
|
142
|
+
content_integral += underflow_c
|
|
143
|
+
if add_overflow:
|
|
144
|
+
content_integral += overflow_c
|
|
145
|
+
if self.__yerrsq is None:
|
|
146
|
+
#unweighted, just base erros on contents:
|
|
147
|
+
return ( content_integral, _np.sqrt(content_integral) )
|
|
148
|
+
errorsq_integral = self.__yerrsq[bin_low:bin_up].sum()
|
|
149
|
+
if add_underflow:
|
|
150
|
+
errorsq_integral += underflow_e2
|
|
151
|
+
if add_overflow:
|
|
152
|
+
errorsq_integral += overflow_e2
|
|
153
|
+
return ( content_integral, _np.sqrt(errorsq_integral) )
|
|
154
|
+
|
|
155
|
+
def add_contents( self, other_hist ):
|
|
156
|
+
o = other_hist
|
|
157
|
+
assert self.__xmin == o.__xmin
|
|
158
|
+
assert self.__xmax == o.__xmax
|
|
159
|
+
assert self.__nbins == o.__nbins
|
|
160
|
+
self.__stats = {}
|
|
161
|
+
self.__title = '<edited>'
|
|
162
|
+
self.__y += o.__y
|
|
163
|
+
self.__yerr = None
|
|
164
|
+
if self.__yerrsq is None:
|
|
165
|
+
if o.__yerrsq is None:
|
|
166
|
+
pass#done
|
|
167
|
+
else:
|
|
168
|
+
self.__yerrsq = self.__y + o.__yerrsq
|
|
169
|
+
else:
|
|
170
|
+
if o.__yerrsq is None:
|
|
171
|
+
self.__yerrsq += o.__y
|
|
172
|
+
else:
|
|
173
|
+
self.__yerrsq += o.__yerrsq
|
|
174
|
+
|
|
175
|
+
def rebin( self, rebin_factor ):
|
|
176
|
+
assert self.__nbins % rebin_factor == 0
|
|
177
|
+
def _dorebin(x):
|
|
178
|
+
return _np.sum( x.reshape( len(x)//rebin_factor, rebin_factor ),
|
|
179
|
+
axis=1)
|
|
180
|
+
self.__y = _dorebin(self.__y)
|
|
181
|
+
self.__yerr = None
|
|
182
|
+
if self.__yerrsq is not None:
|
|
183
|
+
self.__yerrsq = _dorebin(self.__yerrsq)
|
|
184
|
+
self.__nbins = self.__nbins // rebin_factor
|
|
185
|
+
assert self.__yerrsq is None or len(self.__yerrsq)==len(self.__y)
|
|
186
|
+
assert self.__nbins==len(self.__y)
|
|
187
|
+
|
|
188
|
+
@property
|
|
189
|
+
def stats( self ):
|
|
190
|
+
return self.__stats or {}
|
|
191
|
+
|
|
192
|
+
@property
|
|
193
|
+
def errors( self ):
|
|
194
|
+
if self.__yerr is None:
|
|
195
|
+
self.__yerr = _np.sqrt( self.errors_squared )
|
|
196
|
+
return self.__yerr
|
|
197
|
+
|
|
198
|
+
@property
|
|
199
|
+
def errors_squared( self ):
|
|
200
|
+
return ( self.__yerrsq
|
|
201
|
+
if self.__yerrsq is not None
|
|
202
|
+
else self.__y )
|
|
203
|
+
|
|
204
|
+
@property
|
|
205
|
+
def content( self ):
|
|
206
|
+
return self.__y
|
|
207
|
+
|
|
208
|
+
@property
|
|
209
|
+
def title( self ):
|
|
210
|
+
return self.__title
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def xmin( self ):
|
|
214
|
+
return self.__xmin
|
|
215
|
+
|
|
216
|
+
@property
|
|
217
|
+
def xmax( self ):
|
|
218
|
+
return self.__xmax
|
|
219
|
+
|
|
220
|
+
@property
|
|
221
|
+
def binwidth( self ):
|
|
222
|
+
return (self.__xmax-self.__xmin)/self.__nbins
|
|
223
|
+
|
|
224
|
+
@property
|
|
225
|
+
def nbins( self ):
|
|
226
|
+
return self.__nbins
|
|
227
|
+
|
|
228
|
+
@property
|
|
229
|
+
def bincenters( self ):
|
|
230
|
+
halfbw = 0.5*self.binwidth
|
|
231
|
+
return _np_linspace(self.__xmin+halfbw,
|
|
232
|
+
self.__xmax-halfbw,
|
|
233
|
+
self.__nbins)
|
|
234
|
+
|
|
235
|
+
@property
|
|
236
|
+
def binedges( self ):
|
|
237
|
+
return _np_linspace(self.__xmin,
|
|
238
|
+
self.__xmax,
|
|
239
|
+
self.__nbins+1)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _hist_curve( self, error_offset = 0.0 ):
|
|
243
|
+
be = self.binedges
|
|
244
|
+
y = self.content
|
|
245
|
+
if error_offset:
|
|
246
|
+
y += self.errors * error_offset
|
|
247
|
+
cx = _np.empty(self.__nbins*2)
|
|
248
|
+
cy = _np.empty(self.__nbins*2)
|
|
249
|
+
i = 0
|
|
250
|
+
for ibin in range(self.__nbins):
|
|
251
|
+
cx[i] = be[ibin]
|
|
252
|
+
cy[i] = y[ibin]
|
|
253
|
+
i+=1
|
|
254
|
+
cx[i] = be[ibin+1]
|
|
255
|
+
cy[i] = y[ibin]
|
|
256
|
+
i+=1
|
|
257
|
+
return cx,cy
|
|
258
|
+
|
|
259
|
+
def errorbar_args( self, style = True, **kwargs ):
|
|
260
|
+
d = {'x':self.bincenters,
|
|
261
|
+
'y':self.content,'xerr':0.5*self.binwidth,
|
|
262
|
+
'yerr':self.errors }
|
|
263
|
+
if style:
|
|
264
|
+
d.update({'fmt':'.',#dont connect with line
|
|
265
|
+
'mec':'black','mfc':'black',
|
|
266
|
+
#'ms':4,'mew':1,
|
|
267
|
+
'ecolor':'black','elinewidth':1.0 })
|
|
268
|
+
d.update(kwargs)
|
|
269
|
+
return d
|
|
270
|
+
|
|
271
|
+
def bar_args( self, style = True, **kwargs ):
|
|
272
|
+
d = {'x' : self.binedges[:-1],
|
|
273
|
+
'height': self.content,
|
|
274
|
+
'width': self.binwidth,
|
|
275
|
+
'align':'edge'
|
|
276
|
+
}
|
|
277
|
+
d.update(kwargs)
|
|
278
|
+
return d
|
|
279
|
+
|
|
280
|
+
def plot_hist( self, plt=None, axis=None, style=True, label=None,
|
|
281
|
+
show_errors=True, do_show = True, set_xlim = True ):
|
|
282
|
+
if not plt and not axis:
|
|
283
|
+
from .plot import _import_matplotlib_plt
|
|
284
|
+
plt = _import_matplotlib_plt()
|
|
285
|
+
if not axis:
|
|
286
|
+
axis = plt.gca()
|
|
287
|
+
axis.bar(**self.bar_args(label=label))
|
|
288
|
+
if show_errors:
|
|
289
|
+
( error_markers,
|
|
290
|
+
ecaplines,
|
|
291
|
+
ebarlinecols ) = axis.errorbar(**self.errorbar_args())
|
|
292
|
+
|
|
293
|
+
xmin,xmax,binwidth = self.xmin, self.xmax, self.binwidth
|
|
294
|
+
if set_xlim:
|
|
295
|
+
axis.set_xlim(xmin-1e-6*binwidth,xmax+1e-6*binwidth)
|
|
296
|
+
if do_show and plt:
|
|
297
|
+
plt.show()
|
NCrystal/_mmc.py
CHANGED
|
@@ -74,274 +74,6 @@ def runsim_diffraction_pattern( cfgstr, *,
|
|
|
74
74
|
mmc_geomcfg = str(geomcfg),
|
|
75
75
|
mmc_srccfg = str(srccfg) )
|
|
76
76
|
|
|
77
|
-
class Hist1D:
|
|
78
|
-
|
|
79
|
-
def __init__( self, data ):
|
|
80
|
-
if data=='_no_init_':
|
|
81
|
-
return
|
|
82
|
-
self.__stats = data.get('stats')
|
|
83
|
-
self.__title = data['title']
|
|
84
|
-
hb = data['bindata']
|
|
85
|
-
self.__xmin = hb['xmin']
|
|
86
|
-
self.__xmax = hb['xmax']
|
|
87
|
-
self.__nbins = hb['nbins']
|
|
88
|
-
self.__y = _np.asarray(hb['content'],dtype=float)
|
|
89
|
-
esq = hb.get('errorsq')
|
|
90
|
-
self.__yerrsq = ( _np.asarray(esq,dtype=float)
|
|
91
|
-
if esq is not None
|
|
92
|
-
else None )
|
|
93
|
-
self.__yerr = None
|
|
94
|
-
assert self.__nbins == len(self.__y)
|
|
95
|
-
assert self.__yerrsq is None or self.__nbins == len(self.__yerrsq)
|
|
96
|
-
|
|
97
|
-
def clone( self, rebin_factor = 1 ):
|
|
98
|
-
c = Hist1D('_no_init_')
|
|
99
|
-
c.__stats = self.__stats
|
|
100
|
-
c.__title = self.__title
|
|
101
|
-
c.__xmin = self.__xmin
|
|
102
|
-
c.__xmax = self.__xmax
|
|
103
|
-
c.__nbins = self.__nbins
|
|
104
|
-
c.__y = self.__y.copy()
|
|
105
|
-
c.__yerrsq = self.__yerrsq.copy() if self.__yerrsq is not None else None
|
|
106
|
-
c.__yerr = self.__yerr.copy() if self.__yerr is not None else None
|
|
107
|
-
if rebin_factor > 1:
|
|
108
|
-
c.rebin( rebin_factor )
|
|
109
|
-
return c
|
|
110
|
-
|
|
111
|
-
def integrate( self, xlow, xhigh, tolerance = 1e-5 ):
|
|
112
|
-
"""
|
|
113
|
-
Returns integrated contents of the histogram over the area
|
|
114
|
-
[xlow,xhigh] along with the error of that value in a tuple
|
|
115
|
-
(content,error).
|
|
116
|
-
|
|
117
|
-
This is done translating xlow and xhigh to exact bin edges and then
|
|
118
|
-
calling integrate_bins. If that is not possible within the
|
|
119
|
-
tolerance, an exception is raised.
|
|
120
|
-
|
|
121
|
-
"""
|
|
122
|
-
if not ( xhigh >= xlow ):
|
|
123
|
-
from .exceptions import NCBadInput
|
|
124
|
-
raise NCBadInput('Invalid integration range requested.')
|
|
125
|
-
|
|
126
|
-
bw = self.binwidth
|
|
127
|
-
def _findedge(x):
|
|
128
|
-
if x <= self.__xmin:
|
|
129
|
-
return 0
|
|
130
|
-
if x >= self.__xmax:
|
|
131
|
-
return self.nbins
|
|
132
|
-
r = ( x - self.__xmin ) / bw
|
|
133
|
-
ir = int(r+0.5)
|
|
134
|
-
if abs(r-ir) > tolerance:
|
|
135
|
-
from .exceptions import NCBadInput
|
|
136
|
-
raise NCBadInput(f'Value {x} does not correspond exactly'
|
|
137
|
-
' to a bin edge within the tolerance.')
|
|
138
|
-
return ir
|
|
139
|
-
e_low = _findedge(xlow)
|
|
140
|
-
e_high = _findedge(xhigh)
|
|
141
|
-
if e_low == e_high:
|
|
142
|
-
return ( 0.0, 0.0 )
|
|
143
|
-
assert e_low >= 0
|
|
144
|
-
assert e_low < e_high < self.nbins
|
|
145
|
-
return self.integrate_bins( e_low, e_high - 1 )
|
|
146
|
-
|
|
147
|
-
def integrate_bins( self, bin_low = None, bin_up = None ):
|
|
148
|
-
"""
|
|
149
|
-
Returns integrated contents of the bins [bin_low,bin_up[ along with
|
|
150
|
-
the error of that value in a tuple (content,error).
|
|
151
|
-
|
|
152
|
-
If bin_low is None the integration will start at the first bin and
|
|
153
|
-
include the underflow bin.
|
|
154
|
-
|
|
155
|
-
If bin_up is None the integration will end at the last bin and
|
|
156
|
-
include the overflow bin.
|
|
157
|
-
"""
|
|
158
|
-
|
|
159
|
-
add_overflow, add_underflow = False, False
|
|
160
|
-
if bin_low is None:
|
|
161
|
-
add_underflow = True
|
|
162
|
-
bin_low = 0
|
|
163
|
-
underflow_c = self.stats.get('underflow')
|
|
164
|
-
underflow_e2 = self.stats.get('underflow_errorsq')
|
|
165
|
-
if bool(underflow_c is None) != bool(underflow_e2 is None):
|
|
166
|
-
from .exceptions import NCBadInput
|
|
167
|
-
raise NCBadInput('Inconsistent underflow info')
|
|
168
|
-
if underflow_c is None:
|
|
169
|
-
add_underflow = False
|
|
170
|
-
|
|
171
|
-
if bin_up is None:
|
|
172
|
-
add_overflow = True
|
|
173
|
-
bin_up = self.__nbins
|
|
174
|
-
overflow_c = self.stats.get('overflow')
|
|
175
|
-
overflow_e2 = self.stats.get('overflow_errorsq')
|
|
176
|
-
if bool(overflow_c is None) != bool(overflow_e2 is None):
|
|
177
|
-
from .exceptions import NCBadInput
|
|
178
|
-
raise NCBadInput('Inconsistent overflow info')
|
|
179
|
-
if overflow_c is None:
|
|
180
|
-
add_overflow = False
|
|
181
|
-
|
|
182
|
-
bin_low, bin_up = int(bin_low), int(bin_up)
|
|
183
|
-
if bin_up < bin_low or bin_low<0 or bin_up > self.__nbins:
|
|
184
|
-
from .exceptions import NCBadInput
|
|
185
|
-
raise NCBadInput('Invalid bin range requested')
|
|
186
|
-
content_integral = self.__y[bin_low:bin_up].sum()
|
|
187
|
-
if add_underflow:
|
|
188
|
-
content_integral += underflow_c
|
|
189
|
-
if add_overflow:
|
|
190
|
-
content_integral += overflow_c
|
|
191
|
-
if self.__yerrsq is None:
|
|
192
|
-
#unweighted, just base erros on contents:
|
|
193
|
-
return ( content_integral, _np.sqrt(content_integral) )
|
|
194
|
-
errorsq_integral = self.__yerrsq[bin_low:bin_up].sum()
|
|
195
|
-
if add_underflow:
|
|
196
|
-
errorsq_integral += underflow_e2
|
|
197
|
-
if add_overflow:
|
|
198
|
-
errorsq_integral += overflow_e2
|
|
199
|
-
return ( content_integral, _np.sqrt(errorsq_integral) )
|
|
200
|
-
|
|
201
|
-
def add_contents( self, other_hist ):
|
|
202
|
-
o = other_hist
|
|
203
|
-
assert self.__xmin == o.__xmin
|
|
204
|
-
assert self.__xmax == o.__xmax
|
|
205
|
-
assert self.__nbins == o.__nbins
|
|
206
|
-
self.__stats = {}
|
|
207
|
-
self.__title = '<edited>'
|
|
208
|
-
self.__y += o.__y
|
|
209
|
-
self.__yerr = None
|
|
210
|
-
if self.__yerrsq is None:
|
|
211
|
-
if o.__yerrsq is None:
|
|
212
|
-
pass#done
|
|
213
|
-
else:
|
|
214
|
-
self.__yerrsq = self.__y + o.__yerrsq
|
|
215
|
-
else:
|
|
216
|
-
if o.__yerrsq is None:
|
|
217
|
-
self.__yerrsq += o.__y
|
|
218
|
-
else:
|
|
219
|
-
self.__yerrsq += o.__yerrsq
|
|
220
|
-
|
|
221
|
-
def rebin( self, rebin_factor ):
|
|
222
|
-
assert self.__nbins % rebin_factor == 0
|
|
223
|
-
def _dorebin(x):
|
|
224
|
-
return _np.sum( x.reshape( len(x)//rebin_factor, rebin_factor ),
|
|
225
|
-
axis=1)
|
|
226
|
-
self.__y = _dorebin(self.__y)
|
|
227
|
-
self.__yerr = None
|
|
228
|
-
if self.__yerrsq is not None:
|
|
229
|
-
self.__yerrsq = _dorebin(self.__yerrsq)
|
|
230
|
-
self.__nbins = self.__nbins // rebin_factor
|
|
231
|
-
assert self.__yerrsq is None or len(self.__yerrsq)==len(self.__y)
|
|
232
|
-
assert self.__nbins==len(self.__y)
|
|
233
|
-
|
|
234
|
-
@property
|
|
235
|
-
def stats( self ):
|
|
236
|
-
return self.__stats or {}
|
|
237
|
-
|
|
238
|
-
@property
|
|
239
|
-
def errors( self ):
|
|
240
|
-
if self.__yerr is None:
|
|
241
|
-
self.__yerr = _np.sqrt( self.errors_squared )
|
|
242
|
-
return self.__yerr
|
|
243
|
-
|
|
244
|
-
@property
|
|
245
|
-
def errors_squared( self ):
|
|
246
|
-
return ( self.__yerrsq
|
|
247
|
-
if self.__yerrsq is not None
|
|
248
|
-
else self.__y )
|
|
249
|
-
|
|
250
|
-
@property
|
|
251
|
-
def content( self ):
|
|
252
|
-
return self.__y
|
|
253
|
-
|
|
254
|
-
@property
|
|
255
|
-
def title( self ):
|
|
256
|
-
return self.__title
|
|
257
|
-
|
|
258
|
-
@property
|
|
259
|
-
def xmin( self ):
|
|
260
|
-
return self.__xmin
|
|
261
|
-
|
|
262
|
-
@property
|
|
263
|
-
def xmax( self ):
|
|
264
|
-
return self.__xmax
|
|
265
|
-
|
|
266
|
-
@property
|
|
267
|
-
def binwidth( self ):
|
|
268
|
-
return (self.__xmax-self.__xmin)/self.__nbins
|
|
269
|
-
|
|
270
|
-
@property
|
|
271
|
-
def nbins( self ):
|
|
272
|
-
return self.__nbins
|
|
273
|
-
|
|
274
|
-
@property
|
|
275
|
-
def bincenters( self ):
|
|
276
|
-
halfbw = 0.5*self.binwidth
|
|
277
|
-
return _np_linspace(self.__xmin+halfbw,
|
|
278
|
-
self.__xmax-halfbw,
|
|
279
|
-
self.__nbins)
|
|
280
|
-
|
|
281
|
-
@property
|
|
282
|
-
def binedges( self ):
|
|
283
|
-
return _np_linspace(self.__xmin,
|
|
284
|
-
self.__xmax,
|
|
285
|
-
self.__nbins+1)
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
def _hist_curve( self, error_offset = 0.0 ):
|
|
289
|
-
be = self.binedges
|
|
290
|
-
y = self.content
|
|
291
|
-
if error_offset:
|
|
292
|
-
y += self.errors * error_offset
|
|
293
|
-
cx = _np.empty(self.__nbins*2)
|
|
294
|
-
cy = _np.empty(self.__nbins*2)
|
|
295
|
-
i = 0
|
|
296
|
-
for ibin in range(self.__nbins):
|
|
297
|
-
cx[i] = be[ibin]
|
|
298
|
-
cy[i] = y[ibin]
|
|
299
|
-
i+=1
|
|
300
|
-
cx[i] = be[ibin+1]
|
|
301
|
-
cy[i] = y[ibin]
|
|
302
|
-
i+=1
|
|
303
|
-
return cx,cy
|
|
304
|
-
|
|
305
|
-
def errorbar_args( self, style = True, **kwargs ):
|
|
306
|
-
d = {'x':self.bincenters,
|
|
307
|
-
'y':self.content,'xerr':0.5*self.binwidth,
|
|
308
|
-
'yerr':self.errors }
|
|
309
|
-
if style:
|
|
310
|
-
d.update({'fmt':'.',#dont connect with line
|
|
311
|
-
'mec':'black','mfc':'black',
|
|
312
|
-
#'ms':4,'mew':1,
|
|
313
|
-
'ecolor':'black','elinewidth':1.0 })
|
|
314
|
-
d.update(kwargs)
|
|
315
|
-
return d
|
|
316
|
-
|
|
317
|
-
def bar_args( self, style = True, **kwargs ):
|
|
318
|
-
d = {'x' : self.binedges[:-1],
|
|
319
|
-
'height': self.content,
|
|
320
|
-
'width': self.binwidth,
|
|
321
|
-
'align':'edge'
|
|
322
|
-
}
|
|
323
|
-
d.update(kwargs)
|
|
324
|
-
return d
|
|
325
|
-
|
|
326
|
-
def plot_hist( self, plt=None, axis=None, style=True, label=None,
|
|
327
|
-
show_errors=True, do_show = True, set_xlim = True ):
|
|
328
|
-
if not plt and not axis:
|
|
329
|
-
from .plot import _import_matplotlib_plt
|
|
330
|
-
plt = _import_matplotlib_plt()
|
|
331
|
-
if not axis:
|
|
332
|
-
axis = plt.gca()
|
|
333
|
-
axis.bar(**self.bar_args(label=label))
|
|
334
|
-
if show_errors:
|
|
335
|
-
( error_markers,
|
|
336
|
-
ecaplines,
|
|
337
|
-
ebarlinecols ) = axis.errorbar(**self.errorbar_args())
|
|
338
|
-
|
|
339
|
-
xmin,xmax,binwidth = self.xmin, self.xmax, self.binwidth
|
|
340
|
-
if set_xlim:
|
|
341
|
-
axis.set_xlim(xmin-1e-6*binwidth,xmax+1e-6*binwidth)
|
|
342
|
-
if do_show and plt:
|
|
343
|
-
plt.show()
|
|
344
|
-
|
|
345
77
|
class Results:
|
|
346
78
|
|
|
347
79
|
def __init__( self,
|
|
@@ -367,6 +99,7 @@ def runsim_diffraction_pattern( cfgstr, *,
|
|
|
367
99
|
datadict = json.loads(json_details)
|
|
368
100
|
mainhist_dict['stats'] = datadict.get('main_stats')
|
|
369
101
|
|
|
102
|
+
from ._hist import Hist1D
|
|
370
103
|
hists = [ Hist1D( mainhist_dict ) ]
|
|
371
104
|
hists += [ Hist1D( h )
|
|
372
105
|
for h in (datadict.get('breakdown_hists',[])) ]
|
|
@@ -433,6 +166,7 @@ def runsim_diffraction_pattern( cfgstr, *,
|
|
|
433
166
|
if breakdown_mode:
|
|
434
167
|
hist = None
|
|
435
168
|
else:
|
|
169
|
+
from ._hist import Hist1D
|
|
436
170
|
if hist is None:
|
|
437
171
|
hist = self.__hists[0]
|
|
438
172
|
assert isinstance(hist,Hist1D)
|
NCrystal/_ncmatimpl.py
CHANGED
|
@@ -912,9 +912,17 @@ class NCMATComposerImpl:
|
|
|
912
912
|
self.create_ncmat( cfg_params = cfg_params ) )
|
|
913
913
|
return p
|
|
914
914
|
|
|
915
|
-
def load(self,cfg_params,force
|
|
916
|
-
|
|
917
|
-
|
|
915
|
+
def load( self, cfg_params, force,
|
|
916
|
+
doInfo = True, doScatter = True, doAbsorption = True ):
|
|
917
|
+
key = ( cfg_params, doInfo, doScatter, doAbsorption )
|
|
918
|
+
if force or self.__loadcache is None or self.__loadcache[0] != key:
|
|
919
|
+
self.__loadcache = ( key,
|
|
920
|
+
_nc_core.directLoad( self.create_ncmat(),
|
|
921
|
+
cfg_params = cfg_params,
|
|
922
|
+
dtype = 'ncmat',
|
|
923
|
+
doInfo = doInfo,
|
|
924
|
+
doScatter = doScatter,
|
|
925
|
+
doAbsorption = doAbsorption) )
|
|
918
926
|
return self.__loadcache[1]
|
|
919
927
|
|
|
920
928
|
def plot_xsect( self, composer, cfg_params, kwargs_plot_xsect ):
|
NCrystal/core.py
CHANGED
|
@@ -1763,7 +1763,12 @@ def directLoad( data, cfg_params='', *, dtype='',
|
|
|
1763
1763
|
if len(p)>=2 and p[-1] and p[-1].isalpha() and p[-1] not in ('gz','tgz','bz2','zip','tar'):
|
|
1764
1764
|
dtype = dtype
|
|
1765
1765
|
|
|
1766
|
-
rawi,raws,rawa = _rawfct['multicreate_direct'](content,
|
|
1766
|
+
rawi,raws,rawa = _rawfct['multicreate_direct']( content,
|
|
1767
|
+
dtype,
|
|
1768
|
+
cfg_params,
|
|
1769
|
+
doInfo,
|
|
1770
|
+
doScatter,
|
|
1771
|
+
doAbsorption )
|
|
1767
1772
|
info = Info( ('_rawobj_',rawi) ) if rawi else None
|
|
1768
1773
|
scatter = Scatter( ('_rawobj_',raws) ) if raws else None
|
|
1769
1774
|
absorption = Absorption( ('_rawobj_',rawa) ) if rawa else None
|
NCrystal/ncmat.py
CHANGED
|
@@ -662,15 +662,21 @@ class NCMATComposer:
|
|
|
662
662
|
return self.__impl.register_as( virtual_filename = virtual_filename,
|
|
663
663
|
cfg_params = cfg_params )
|
|
664
664
|
|
|
665
|
-
def load(self, cfg_params = None, *, force = False
|
|
665
|
+
def load( self, cfg_params = None, *, force = False,
|
|
666
|
+
doInfo = True, doScatter = True, doAbsorption = True ):
|
|
666
667
|
"""Will create NCMAT and load it with the directLoad(..) function of the
|
|
667
668
|
NCrystal.core module. The cfg_params parameter can be used to apply cfg
|
|
668
669
|
parameters (e.g. cfg_params="temp=200K;dcutoff=0.1")., while force=True
|
|
669
670
|
will prevent the NCMATComposer from simply returning a previously loaded
|
|
670
671
|
material (usually one should just leave the default force=False value
|
|
671
|
-
untouched).
|
|
672
|
-
|
|
673
|
-
|
|
672
|
+
untouched). The doInfo / doScatter / doAbsorption flags can be used to
|
|
673
|
+
only load selected objects for a potential speedup.
|
|
674
|
+
"""
|
|
675
|
+
return self.__impl.load( cfg_params = cfg_params,
|
|
676
|
+
force = force,
|
|
677
|
+
doInfo = doInfo,
|
|
678
|
+
doScatter = doScatter,
|
|
679
|
+
doAbsorption = doAbsorption )
|
|
674
680
|
|
|
675
681
|
def plot_xsect( self, cfg_params = None, **kwargs_plot_xsect ):
|
|
676
682
|
"""
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
NCrystal/__init__.py,sha256=
|
|
1
|
+
NCrystal/__init__.py,sha256=pxbgi15N65ft2i8Le4XgyWBcR4ZqZeW1uk3C7DDMDyc,4152
|
|
2
2
|
NCrystal/__main__.py,sha256=tYOeVhY6joHahgtnBwNgcBDd-WXYQoHFmpslk2TAlTY,3624
|
|
3
3
|
NCrystal/_chooks.py,sha256=blZZ4IWjZDYAS7YLhmqxjYKl2IArcE4dotZXoziDE48,43713
|
|
4
4
|
NCrystal/_cli_cif2ncmat.py,sha256=Hmp8MWV7d3Bzu_5Ekiik9Pdv43yNyZygun8HtqShn78,14626
|
|
@@ -16,15 +16,16 @@ NCrystal/_cliwrap_config.py,sha256=RPawApLbRrZRTkWdAP3JK_eTtU_nfPrARYcnfF1-7sE,2
|
|
|
16
16
|
NCrystal/_common.py,sha256=YNQ9xm6lqtc_E75RRvCSGVTunJkr-T6BMOmGRa1kj0k,19860
|
|
17
17
|
NCrystal/_coreimpl.py,sha256=dWBPwbdb8l8Bi3wfDaaQVyqSqTQzwDfs1oEIJR9KTiQ,5727
|
|
18
18
|
NCrystal/_hfgdata.py,sha256=uYTB_xHTHVN8Vw91wr7_kXi18ileHJGNyVjnSi-Ss7g,62828
|
|
19
|
+
NCrystal/_hist.py,sha256=8JBLsfjdopzDyrpqoOaKCMGRL6W0R2UKPjiknxR7Zac,10866
|
|
19
20
|
NCrystal/_hklobjects.py,sha256=wQAUe3tD6UncSW-qfuyAh5jSGnA_2kzvE5-HZ43s3xQ,4974
|
|
20
21
|
NCrystal/_is_std.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
22
|
NCrystal/_locatelib.py,sha256=VCzJQEyOZfOonzah3wTyLndaO8XZRYZmA5oES9xptpI,9504
|
|
22
23
|
NCrystal/_miscimpl.py,sha256=SF1RriTZXgF4uINON6UZqY4vtroJZJ_HuoGaV0tMuK0,17380
|
|
23
|
-
NCrystal/_mmc.py,sha256=
|
|
24
|
+
NCrystal/_mmc.py,sha256=hVXrrJxN6s2a0uxNF2EgqO2xVq2OLU7P0emIG9g1JCQ,19448
|
|
24
25
|
NCrystal/_msg.py,sha256=wBJk0kGHusm0xXSt8KNYq6iIO_cubnznvnJ5Erl87EU,2624
|
|
25
26
|
NCrystal/_ncmat2cpp_impl.py,sha256=D_knqsv92EnaPJlufE3fJe2fnETnyQ8k9TbMwpXmxZs,18383
|
|
26
27
|
NCrystal/_ncmat2endf_impl.py,sha256=rcKHdvIsrsl9SPRoWcmgXk4TR-NRwY79E1JydtW-J4Q,62918
|
|
27
|
-
NCrystal/_ncmatimpl.py,sha256
|
|
28
|
+
NCrystal/_ncmatimpl.py,sha256=-vPYyBUDc0SCXTqPwm2pB-xbsqM6DCwQe5R34avcUAo,95561
|
|
28
29
|
NCrystal/_numpy.py,sha256=SwFcvrNBDqP647guedRdFeISsC8b4VvGm9McFyF1gJQ,2924
|
|
29
30
|
NCrystal/_sabutils.py,sha256=vZD2wB42r48_0EZKPTS6q5sKN1RGgjWi2zVuVvtbdGk,4798
|
|
30
31
|
NCrystal/_testimpl.py,sha256=UPP2b4aaOTPxdUpfqPWgWIwg-BFZbeaivFxnrE7sO_M,21418
|
|
@@ -34,14 +35,14 @@ NCrystal/cfgstr.py,sha256=IVrMagRTD0TkAhuJkWkGKsJCX4ezG8Tf9uyfkhRjMgY,3741
|
|
|
34
35
|
NCrystal/cifutils.py,sha256=zdYKqxVmzIahj9AKPZl-ISOi-SSWOMaJ_4iJ-v0ImdE,78824
|
|
35
36
|
NCrystal/cli.py,sha256=OMUi3NZEwKwvx1fRzNDwWG9Yb-Vm49kkyiMu9NHHTlM,4395
|
|
36
37
|
NCrystal/constants.py,sha256=ldOyJAAhW0tBNDVexqTw1rxvcmwCnGJOueurXS44Plw,5919
|
|
37
|
-
NCrystal/core.py,sha256=
|
|
38
|
+
NCrystal/core.py,sha256=D7wOKLciHpNu5EZI0_vtpcRkf-XAkQQErLbxu4VdmzI,83606
|
|
38
39
|
NCrystal/datasrc.py,sha256=wAmpYjLMB5w8_0J4qRFtKMZ-RoFvyu8DMOouQDB6xac,9978
|
|
39
40
|
NCrystal/exceptions.py,sha256=7L61coTf_Sy8gjrsn7BNCu1cvOyAx0dWrihlV7AqgLM,2679
|
|
40
41
|
NCrystal/hfg2ncmat.py,sha256=10FbQNxYzdSjTMG2F1DCq7LiQ7xvd1gjFkrZFjj-GKg,10189
|
|
41
42
|
NCrystal/mcstasutils.py,sha256=7IRfwefvaXQORBV1Qibn88vb9OKMvIn_qfQoEt8-G3U,18540
|
|
42
43
|
NCrystal/misc.py,sha256=KmbmW2PB2roQReqLtn-RWse30f6w7gOmJPb7cId_-ME,14083
|
|
43
44
|
NCrystal/mmc.py,sha256=LQ0IXMgJexpSPrGYwZZm6bAh5Bo6y2z5CjezFAFy1UE,1948
|
|
44
|
-
NCrystal/ncmat.py,sha256=
|
|
45
|
+
NCrystal/ncmat.py,sha256=Gwrf1u2P4UeWQNvSXKhWHHCOibbMFmTlx0fyfE0DgOY,42966
|
|
45
46
|
NCrystal/ncmat2cpp.py,sha256=_gXxXgbPcCmn0XnLx0h_dS_N3s4d18RORDSgSeVTgG4,4398
|
|
46
47
|
NCrystal/ncmat2endf.py,sha256=1T1I08mWRG_yBhdb20dzEaVJMC0OeF2BYm2qY-L9BHg,12504
|
|
47
48
|
NCrystal/obsolete.py,sha256=v2HzQFqdrLaGm6bWNqioGwMdQMAhuWYSbTEF2He_HbY,3451
|
|
@@ -49,9 +50,9 @@ NCrystal/plot.py,sha256=oymblLRKTfE2xCsX4W7H6cXIKxDNV7rr6Z4dZnCJjt0,19975
|
|
|
49
50
|
NCrystal/plugins.py,sha256=U4EF25DlYE8aO6uoG5Ptyia5Nj08LCrVl7973BCIkDI,2440
|
|
50
51
|
NCrystal/test.py,sha256=fH6OfjvQ2KJRYaooYVGFsp4QJGj_WC4QRq1bPd36vwg,2731
|
|
51
52
|
NCrystal/vdos.py,sha256=DL3UtaCMLaY-bBB6ztT1qZKYfO44INeEpgra_9JAyMo,47607
|
|
52
|
-
ncrystal_python-4.2.
|
|
53
|
-
ncrystal_python-4.2.
|
|
54
|
-
ncrystal_python-4.2.
|
|
55
|
-
ncrystal_python-4.2.
|
|
56
|
-
ncrystal_python-4.2.
|
|
57
|
-
ncrystal_python-4.2.
|
|
53
|
+
ncrystal_python-4.2.10.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
54
|
+
ncrystal_python-4.2.10.dist-info/METADATA,sha256=bCyoH_AFcozyS7XF9HG1vdaiEIsgApsN50Bx99RHuBY,16275
|
|
55
|
+
ncrystal_python-4.2.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
56
|
+
ncrystal_python-4.2.10.dist-info/entry_points.txt,sha256=I9Nz-pdriq2xHbYRAw-yUaI33jQwVbNRy8-3mCVe_jE,521
|
|
57
|
+
ncrystal_python-4.2.10.dist-info/top_level.txt,sha256=VIJdIQMfLIbKpFXA8xm0fKY5okz8s5IHrZTYDSH18y0,9
|
|
58
|
+
ncrystal_python-4.2.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|