Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] multidetector xrf fits #711

Draft
wants to merge 74 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
29aeb19
ClassMcaTheory -> LegacyMcaTheory
woutdenolf Aug 14, 2020
913db54
Add features to profiling utilities
woutdenolf Aug 19, 2020
de8ce31
Concatenated fitmodel (WIP)
woutdenolf Aug 11, 2020
dd4abb0
New McaTheory (WIP)
woutdenolf Jan 21, 2021
d06a105
New McaTheory (WIP)
woutdenolf Feb 11, 2021
bd72a59
WIP
woutdenolf Feb 11, 2021
c18ab26
WIP
woutdenolf Feb 11, 2021
a43d5d6
WIP
woutdenolf Feb 11, 2021
f1f3374
Disable Travis
woutdenolf Feb 11, 2021
32b339c
WIP
woutdenolf Feb 11, 2021
638b0ba
fixup
woutdenolf Feb 18, 2021
47ffe30
fixup
woutdenolf Mar 9, 2021
f723cca
fixup
woutdenolf Mar 9, 2021
5ce8295
fixup Model
woutdenolf Mar 9, 2021
ad4ee19
Polynomial models for McaTheory
woutdenolf Mar 9, 2021
77c2327
fixup
woutdenolf Mar 9, 2021
f3b8eea
fixup
woutdenolf Mar 9, 2021
77ed00d
fixup
woutdenolf Mar 9, 2021
16144b6
fixup polymodels
woutdenolf Mar 10, 2021
ea93c0a
fixup
woutdenolf Mar 11, 2021
e4d4220
fixup
woutdenolf Mar 11, 2021
502b41e
fixup
woutdenolf May 6, 2021
f86ee74
fixup
woutdenolf May 7, 2021
9b77af6
fixup
woutdenolf May 7, 2021
75b3c4b
fixup
woutdenolf May 7, 2021
43afc3b
fixup
woutdenolf May 7, 2021
fec5749
fixup
woutdenolf May 7, 2021
caf4a38
fixup
woutdenolf May 26, 2021
69c9b92
parameter decorator
woutdenolf Jun 1, 2021
df22bf3
fixup parameter caching
woutdenolf Jun 2, 2021
6632b1f
fixup
woutdenolf Jun 22, 2021
4351045
fixup
woutdenolf Jun 22, 2021
4d9fb80
fixup
woutdenolf Jun 22, 2021
08dc5f6
fixup
woutdenolf Jun 23, 2021
82f27b4
fixup
woutdenolf Jun 28, 2021
b328f69
fixup
woutdenolf Jun 28, 2021
86f8c34
fixup
woutdenolf Jun 28, 2021
f582ff1
fixup
woutdenolf Jun 28, 2021
cb070c4
fixup
woutdenolf Jun 28, 2021
905fa0e
fixup
woutdenolf Jun 28, 2021
61403b4
fixup
woutdenolf Jun 28, 2021
4603c3c
fixup
woutdenolf Jun 28, 2021
91062c1
fixup
woutdenolf Jun 28, 2021
4ada2f7
fixup
woutdenolf Jun 28, 2021
f059f06
fixup
woutdenolf Jun 29, 2021
0d8104a
fixup
woutdenolf Jun 30, 2021
dc2dc75
fixup
woutdenolf Jun 30, 2021
d8dbe46
fixup
woutdenolf Jun 30, 2021
adb9591
fixup
woutdenolf Jun 30, 2021
dbd9dbf
fixup
woutdenolf Jun 30, 2021
cfb2d4b
fixup
woutdenolf Jun 30, 2021
80162f8
fixup
woutdenolf Jun 30, 2021
4a05afe
fixup
woutdenolf Jun 30, 2021
fce63f9
fixup
woutdenolf Jul 6, 2021
8279d4b
fixup
woutdenolf Jul 6, 2021
5fbb37c
fixup
woutdenolf Jul 7, 2021
57738c5
fixup
woutdenolf Jul 7, 2021
8370f7e
fixup
woutdenolf Jul 7, 2021
2a7a21e
fixup
woutdenolf Jul 22, 2021
cfce49f
fixup
woutdenolf Jul 28, 2021
39ebb49
fixup
woutdenolf Jul 28, 2021
a9920b8
fixup
woutdenolf Jul 28, 2021
b02f089
fixup
woutdenolf Jul 28, 2021
fb449ca
fixup
woutdenolf Aug 10, 2021
6df8a52
fixup
woutdenolf Aug 10, 2021
ce40b45
fixup
woutdenolf Aug 10, 2021
a1ccee8
fixup
woutdenolf Aug 13, 2021
00b0935
fixup
woutdenolf Aug 13, 2021
f637d8d
fixup
woutdenolf Aug 16, 2021
384632a
fixup
woutdenolf Aug 16, 2021
e458033
fixup
woutdenolf Aug 16, 2021
089fcd2
fixup
woutdenolf Aug 17, 2021
0f4b7b2
fixup
woutdenolf Oct 6, 2021
9ca7db9
fixup
woutdenolf Oct 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
63 changes: 33 additions & 30 deletions PyMca5/PyMcaCore/DataObject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/*##########################################################################
# /*##########################################################################
#
# The PyMca X-Ray Fluorescence Toolkit
#
Expand Down Expand Up @@ -32,8 +32,9 @@
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
import numpy


class DataObject(object):
'''
"""
Simple container of an array and associated information.
Basically it has the members:
info: A dictionary
Expand All @@ -47,15 +48,16 @@ class DataObject(object):
x: A list containing arrays to be considered axes
y: A list of data to be considered as signals
m: A list containing the monitor data
'''
"""

GETINFO_DEPRECATION_WARNING = True
GETDATA_DEPRECATION_WARNING = True
SELECT_DEPRECATION_WARNING = True

def __init__(self):
'''
"""
Default Constructor
'''
"""
self.info = {}
self.data = numpy.array([])

Expand All @@ -68,7 +70,7 @@ def getInfo(self):
"""
if DataObject.GETINFO_DEPRECATION_WARNING:
print("DEPRECATION WARNING: DataObject.getInfo()")
DataObject.GETINFO_DEPRECATION_WARNING = False
DataObject.GETINFO_DEPRECATION_WARNING = False
return self.info

def getData(self):
Expand All @@ -77,7 +79,7 @@ def getData(self):
"""
if DataObject.GETDATA_DEPRECATION_WARNING:
print("DEPRECATION WARNING: DataObject.getData()")
DataObject.GETDATA_DEPRECATION_WARNING = False
DataObject.GETDATA_DEPRECATION_WARNING = False
return self.data

def select(self, selection=None):
Expand All @@ -89,78 +91,79 @@ def select(self, selection=None):
DataObject.SELECT_DEPRECATION_WARNING = False
dataObject = DataObject()
dataObject.info = self.info
dataObject.info['selection'] = selection
dataObject.info["selection"] = selection
if selection is None:
dataObject.data = self.data
return dataObject
if type(selection) == dict:
#dataObject.data = self.data #should I set it to none???
# dataObject.data = self.data #should I set it to none???
dataObject.data = None
if 'rows' in selection:
if "rows" in selection:
dataObject.x = None
dataObject.y = None
dataObject.m = None
if 'x' in selection['rows']:
for rownumber in selection['rows']['x']:
if "x" in selection["rows"]:
for rownumber in selection["rows"]["x"]:
if rownumber is None:
continue
if dataObject.x is None:
dataObject.x = []
dataObject.x.append(self.data[rownumber, :])

if 'y' in selection['rows']:
for rownumber in selection['rows']['y']:
if "y" in selection["rows"]:
for rownumber in selection["rows"]["y"]:
if rownumber is None:
continue
if dataObject.y is None:
dataObject.y = []
dataObject.y.append(self.data[rownumber, :])

if 'm' in selection['rows']:
for rownumber in selection['rows']['m']:
if "m" in selection["rows"]:
for rownumber in selection["rows"]["m"]:
if rownumber is None:
continue
if dataObject.m is None:
dataObject.m = []
dataObject.m.append(self.data[rownumber, :])
elif ('cols' in selection) or ('columns' in selection):
if 'cols' in selection:
key = 'cols'
elif ("cols" in selection) or ("columns" in selection):
if "cols" in selection:
key = "cols"
else:
key = 'columns'
key = "columns"
dataObject.x = None
dataObject.y = None
dataObject.m = None
if 'x' in selection[key]:
for rownumber in selection[key]['x']:
if "x" in selection[key]:
for rownumber in selection[key]["x"]:
if rownumber is None:
continue
if dataObject.x is None:
dataObject.x = []
dataObject.x.append(self.data[:, rownumber])

if 'y' in selection[key]:
for rownumber in selection[key]['y']:
if "y" in selection[key]:
for rownumber in selection[key]["y"]:
if rownumber is None:
continue
if dataObject.y is None:
dataObject.y = []
dataObject.y.append(self.data[:, rownumber])

if 'm' in selection[key]:
for rownumber in selection[key]['m']:
if "m" in selection[key]:
for rownumber in selection[key]["m"]:
if rownumber is None:
continue
if dataObject.m is None:
dataObject.m = []
dataObject.m.append(self.data[:, rownumber])
if dataObject.x is None:
if 'Channel0' in dataObject.info:
ch0 = int(dataObject.info['Channel0'])
if "Channel0" in dataObject.info:
ch0 = int(dataObject.info["Channel0"])
else:
ch0 = 0
dataObject.x = [numpy.arange(ch0,
ch0 + len(dataObject.y[0])).astype(numpy.float64)]
dataObject.x = [
numpy.arange(ch0, ch0 + len(dataObject.y[0])).astype(numpy.float64)
]
if not ("selectiontype" in dataObject.info):
dataObject.info["selectiontype"] = "%dD" % len(dataObject.y)
return dataObject
8 changes: 4 additions & 4 deletions PyMca5/PyMcaGui/physics/xrf/McaAdvancedFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
#not a big problem
pass

from PyMca5.PyMcaPhysics.xrf import ClassMcaTheory
FISX = ClassMcaTheory.FISX
from PyMca5.PyMcaPhysics.xrf import LegacyMcaTheory
FISX = LegacyMcaTheory.FISX
if FISX:
FisxHelper = ClassMcaTheory.FisxHelper
FisxHelper = LegacyMcaTheory.FisxHelper
from . import FitParam
from . import McaAdvancedTable
from . import QtMcaAdvancedFitReport
Expand Down Expand Up @@ -291,7 +291,7 @@ def __init__(self, parent=None, name="PyMca - McaAdvancedFit",fl=0,
self.matrixXRFMCSpectrumButton.setToolTip('Calculate Matrix Spectrum Using Monte Carlo')
self.peaksSpectrumButton.setToolTip('Toggle Individual Peaks Spectrum Calculation On/Off')

self.mcafit = ClassMcaTheory.McaTheory()
self.mcafit = LegacyMcaTheory.McaTheory()

self.fitButton.clicked.connect(self.fit)
self.printButton.clicked.connect(self.printActiveTab)
Expand Down
4 changes: 2 additions & 2 deletions PyMca5/PyMcaGui/physics/xrf/XRFMCPyMca.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def _start(self):
#perform a dummy fit till xmimsim-pymca is upgraded
if 0:
import numpy
from PyMca import ClassMcaTheory
from PyMca import LegacyMcaTheory
newFile['fit']['linearfitflag']=1
newFile['fit']['stripflag']=0
newFile['fit']['stripiterations']=0
Expand All @@ -814,7 +814,7 @@ def _start(self):
#xdata = numpy.arange(xmin, xmax + 1) * 1.0
xdata = numpy.arange(0, xmax + 1) * 1.0
ydata = 0.0 + 0.1 * xdata
mcaFit = ClassMcaTheory.McaTheory()
mcaFit = LegacyMcaTheory.McaTheory()
mcaFit.configure(newFile)
mcaFit.setData(x=xdata, y=ydata, xmin=xmin, xmax=xmax)
mcaFit.estimate()
Expand Down
53 changes: 53 additions & 0 deletions PyMca5/PyMcaMath/fitting/model/CachingLinkedModel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import numpy

from .LinkedModel import LinkedModel
from .CachingModel import CachedPropertiesModel


class CachedPropertiesLinkModel(CachedPropertiesModel, LinkedModel):
def _iter_cached_property_ids(self, **cacheoptions):
if self.is_linked and self._in_property_caching_context():
# Yield only the property id's that belong to this model
names = self._cached_property_names()
for propid in super()._iter_cached_property_ids(**cacheoptions):
if propid.property_name in names:
yield propid
else:
yield from super()._iter_cached_property_ids(**cacheoptions)

def _get_property_values(self, **cacheoptions):
values = super()._get_property_values(**cacheoptions)
return self.__extract_values(values, **cacheoptions)

def _set_property_values(self, values, **cacheoptions):
values = self.__insert_values(values, **cacheoptions)
super()._set_property_values(values, **cacheoptions)

def __extract_values(self, values, **cacheoptions):
if not self.is_linked:
return values
# Only the values that belong to this model
data = list()
for propid in self._iter_cached_property_ids(**cacheoptions):
index = self._propid_to_index(propid, **cacheoptions)
data.append(numpy.atleast_1d(values[index]).tolist())

return numpy.concatenate(data)

def __insert_values(self, values, **cacheoptions):
if not self.is_linked:
return values
gvalues = super()._get_property_values(**cacheoptions)
i = 0
for propid in self._iter_cached_property_ids(**cacheoptions):
index = self._propid_to_index(propid, **cacheoptions)
try:
n = len(gvalues[index])
except TypeError:
n = 1
if n == 1:
gvalues[index] = values[i]
else:
gvalues[index] = values[i : i + n]
i += n
return gvalues
Loading