Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
c10a3a3f
Commit
c10a3a3f
authored
5 years ago
by
Harriet Brown
Browse files
Options
Downloads
Patches
Plain Diff
fix FitIncidentSpectrum not correcting for different binning sizes
parent
131eb553
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Framework/PythonInterface/plugins/algorithms/FitIncidentSpectrum.py
+11
-11
11 additions, 11 deletions
...PythonInterface/plugins/algorithms/FitIncidentSpectrum.py
docs/source/algorithms/FitIncidentSpectrum-v1.rst
+4
-4
4 additions, 4 deletions
docs/source/algorithms/FitIncidentSpectrum-v1.rst
with
15 additions
and
15 deletions
Framework/PythonInterface/plugins/algorithms/FitIncidentSpectrum.py
+
11
−
11
View file @
c10a3a3f
...
...
@@ -45,7 +45,7 @@ class FitIncidentSpectrum(PythonAlgorithm):
doc
=
'
Output workspace containing the fit and it
\'
s first derivative.
'
)
self
.
declareProperty
(
name
=
'
Spectrum
Index
'
,
name
=
'
Workspace
Index
'
,
defaultValue
=
0
,
doc
=
'
Workspace index of the spectra to be fitted (Defaults to the first index.)
'
)
...
...
@@ -72,7 +72,7 @@ class FitIncidentSpectrum(PythonAlgorithm):
def
_setup
(
self
):
self
.
_input_ws
=
self
.
getProperty
(
'
InputWorkspace
'
).
value
self
.
_output_ws
=
self
.
getProperty
(
'
OutputWorkspace
'
).
valueAsStr
self
.
_incident_index
=
self
.
getProperty
(
'
Spectrum
Index
'
).
value
self
.
_incident_index
=
self
.
getProperty
(
'
Workspace
Index
'
).
value
self
.
_binning_for_calc
=
self
.
getProperty
(
'
BinningForCalc
'
).
value
self
.
_binning_for_fit
=
self
.
getProperty
(
'
BinningForFit
'
).
value
self
.
_fit_spectrum_with
=
self
.
getProperty
(
'
FitSpectrumWith
'
).
value
...
...
@@ -89,19 +89,19 @@ class FitIncidentSpectrum(PythonAlgorithm):
y_fit
=
np
.
array
(
self
.
_input_ws
.
readY
(
self
.
_incident_index
))
else
:
rebinned
=
Rebin
(
self
.
_input_ws
,
InputWorkspace
=
self
.
_input_ws
,
Params
=
self
.
_binning_for_fit
,
PreserveEvents
=
True
,
StoreInADS
=
False
)
PreserveEvents
=
True
)
x_fit
=
np
.
array
(
rebinned
.
readX
(
self
.
_incident_index
))
y_fit
=
np
.
array
(
rebinned
.
readY
(
self
.
_incident_index
))
rebin_norm
=
x
.
size
/
x_fit
.
size
x_bin_centers
=
0.5
*
(
x
[:
-
1
]
+
x
[
1
:])
if
len
(
x_fit
)
!=
len
(
y_fit
):
x_fit
=
x_fit
[:
-
1
]
x_fit
=
0.5
*
(
x_fit
[:
-
1
]
+
x_fit
[
1
:])
if
self
.
_fit_spectrum_with
==
'
CubicSpline
'
:
# Fit using cubic spline
fit
,
fit_prime
=
self
.
fit_cubic_spline
(
x_fit
,
y_fit
,
x
[:
-
1
]
,
s
=
1e7
)
fit
,
fit_prime
=
self
.
fit_cubic_spline
(
x_fit
,
y_fit
,
x
_bin_centers
,
s
=
1e7
)
elif
self
.
_fit_spectrum_with
==
'
CubicSplineViaMantid
'
:
# Fit using cubic spline via Mantid
fit
,
fit_prime
=
self
.
fit_cubic_spline_via_mantid_spline_smoothing
(
...
...
@@ -112,13 +112,13 @@ class FitIncidentSpectrum(PythonAlgorithm):
MaxNumberOfBreaks
=
0
)
elif
self
.
_fit_spectrum_with
==
'
GaussConvCubicSpline
'
:
# Fit using Gauss conv cubic spline
fit
,
fit_prime
=
self
.
fit_cubic_spline_with_gauss_conv
(
x_fit
,
y_fit
,
x
[:
-
1
]
,
sigma
=
0.5
)
fit
,
fit_prime
=
self
.
fit_cubic_spline_with_gauss_conv
(
x_fit
,
y_fit
,
x
_bin_centers
,
sigma
=
0.5
)
# Create output workspace
unit
=
self
.
_input_ws
.
getAxis
(
0
).
getUnit
().
unitID
()
output_workspace
=
CreateWorkspace
(
DataX
=
x
,
DataY
=
np
.
append
(
fit
,
fit_prime
),
DataY
=
np
.
append
(
fit
,
fit_prime
)
/
rebin_norm
,
UnitX
=
unit
,
NSpec
=
2
,
Distribution
=
False
,
...
...
@@ -126,7 +126,7 @@ class FitIncidentSpectrum(PythonAlgorithm):
StoreInADS
=
False
)
self
.
setProperty
(
"
OutputWorkspace
"
,
output_workspace
)
def
fit_cubic_spline_with_gauss_conv
(
self
,
x_fit
,
y_fit
,
x
,
n_gouss
=
39
,
sigma
=
3
):
def
fit_cubic_spline_with_gauss_conv
(
self
,
x_fit
,
y_fit
,
x
,
n_gouss
=
39
,
sigma
=
3
.0
):
# Fit with Cubic Spline using a Gaussian Convolution to get weights
def
moving_average
(
y
,
n
=
n_gouss
,
sig
=
sigma
):
b
=
signal
.
gaussian
(
n
,
sig
)
...
...
This diff is collapsed.
Click to expand it.
docs/source/algorithms/FitIncidentSpectrum-v1.rst
+
4
−
4
View file @
c10a3a3f
...
...
@@ -102,10 +102,10 @@ Output:
.. testoutput:: ExFitIncidentSpectrum
[
5328.83700775 2330.08408285 1600.78200105 2543.59379589 3249.78956903
2
797.87138465 2050.3366076
1
4
17
.4868309 965.23854845 659.79544224
456.54322031 320.88688262 229.29830975 166.5536716 122.89703604
92.0419568 69.89199835 53.75902111 41.84355559
]
[
3318.3489535 1760.07570573 1901.11829551 3081.98511847 3110.03374921
2
423.17832412 1711.216875
117
0.12096584 797.13759356 547.91281905
381.9735739 270.66392746 195.01094402 142.79582704 106.17020879
80.07657305 61.2047398 47.35976442
]
References
------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment