ncrystal-python 4.2.8__py3-none-any.whl → 4.2.12__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 +2 -2
- NCrystal/__main__.py +1 -1
- NCrystal/_chooks.py +1 -1
- NCrystal/_cli_cif2ncmat.py +1 -1
- NCrystal/_cli_endf2ncmat.py +1 -1
- NCrystal/_cli_hfg2ncmat.py +1 -1
- NCrystal/_cli_mcstasunion.py +1 -1
- NCrystal/_cli_ncmat2cpp.py +1 -1
- NCrystal/_cli_ncmat2endf.py +1 -1
- NCrystal/_cli_ncmat2hkl.py +1 -1
- NCrystal/_cli_nctool.py +1 -1
- NCrystal/_cli_vdos2ncmat.py +1 -1
- NCrystal/_cli_verifyatompos.py +1 -1
- NCrystal/_cliimpl.py +1 -1
- NCrystal/_cliwrap_config.py +1 -1
- NCrystal/_common.py +1 -1
- NCrystal/_coreimpl.py +1 -1
- NCrystal/_hfgdata.py +1 -1
- NCrystal/_hist.py +297 -0
- NCrystal/_hklobjects.py +1 -1
- NCrystal/_locatelib.py +1 -1
- NCrystal/_miscimpl.py +1 -1
- NCrystal/_mmc.py +3 -269
- NCrystal/_msg.py +1 -1
- NCrystal/_ncmat2cpp_impl.py +1 -1
- NCrystal/_ncmat2endf_impl.py +1 -1
- NCrystal/_ncmatimpl.py +24 -5
- NCrystal/_numpy.py +1 -1
- NCrystal/_sabutils.py +1 -1
- NCrystal/_testimpl.py +1 -1
- NCrystal/api.py +1 -1
- NCrystal/atomdata.py +1 -1
- NCrystal/cfgstr.py +1 -1
- NCrystal/cifutils.py +1 -1
- NCrystal/cli.py +1 -1
- NCrystal/constants.py +1 -1
- NCrystal/core.py +7 -2
- NCrystal/datasrc.py +1 -1
- NCrystal/exceptions.py +1 -1
- NCrystal/hfg2ncmat.py +1 -1
- NCrystal/mcstasutils.py +1 -1
- NCrystal/misc.py +1 -1
- NCrystal/mmc.py +1 -1
- NCrystal/ncmat.py +11 -5
- NCrystal/ncmat2cpp.py +1 -1
- NCrystal/ncmat2endf.py +1 -1
- NCrystal/obsolete.py +1 -1
- NCrystal/plot.py +1 -1
- NCrystal/plugins.py +1 -1
- NCrystal/test.py +1 -1
- NCrystal/vdos.py +1 -1
- {ncrystal_python-4.2.8.dist-info → ncrystal_python-4.2.12.dist-info}/METADATA +1 -1
- ncrystal_python-4.2.12.dist-info/RECORD +58 -0
- ncrystal_python-4.2.8.dist-info/RECORD +0 -57
- {ncrystal_python-4.2.8.dist-info → ncrystal_python-4.2.12.dist-info}/WHEEL +0 -0
- {ncrystal_python-4.2.8.dist-info → ncrystal_python-4.2.12.dist-info}/entry_points.txt +0 -0
- {ncrystal_python-4.2.8.dist-info → ncrystal_python-4.2.12.dist-info}/licenses/LICENSE +0 -0
- {ncrystal_python-4.2.8.dist-info → ncrystal_python-4.2.12.dist-info}/top_level.txt +0 -0
NCrystal/__init__.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
|
@@ -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.12'
|
|
59
59
|
__status__ = "Production"
|
|
60
60
|
__author__ = "NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)"
|
|
61
61
|
__copyright__ = "Copyright 2015-2024 %s"%__author__
|
NCrystal/__main__.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_chooks.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_cif2ncmat.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_endf2ncmat.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_hfg2ncmat.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_mcstasunion.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_ncmat2cpp.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_ncmat2endf.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_ncmat2hkl.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_nctool.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_vdos2ncmat.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cli_verifyatompos.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cliimpl.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_cliwrap_config.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_common.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_coreimpl.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_hfgdata.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
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-2026 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/_hklobjects.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_locatelib.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|
NCrystal/_miscimpl.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ##
|
|
4
4
|
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
5
|
## ##
|
|
6
|
-
## Copyright 2015-
|
|
6
|
+
## Copyright 2015-2026 NCrystal developers ##
|
|
7
7
|
## ##
|
|
8
8
|
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
9
|
## you may not use this file except in compliance with the License. ##
|