order of fits correspond order in graph, fit result window has correct order, see #109

This commit is contained in:
Dominik Demuth 2023-08-07 18:42:10 +02:00
parent 783fe505ba
commit 7febe55929

View File

@ -58,11 +58,18 @@ class GraphDict(OrderedDict):
def list(self):
return [(k, v.title) for k, v in self.items()]
def active(self, key: str):
if key:
return [(self._data[i].id, self._data[i].name) for i in self[key]]
else:
def active(self, key: str, return_val: str = 'both'):
if not key:
return []
else:
if return_val == 'both':
return [(self._data[i].id, self._data[i].name) for i in self[key]]
elif return_val == 'id':
return [self._data[i].id for i in self[key]]
elif return_val == 'name':
return [self._data[i].name for i in self[key]]
else:
raise ValueError(f'return_val got wrong value {return_val!r}')
def current_sets(self, key: str):
if key:
@ -148,6 +155,10 @@ class UpperManagement(QtCore.QObject):
def active_sets(self):
return self.graphs.active(self.current_graph)
@property
def active_id(self):
return self.graphs.active(self.current_graph, return_val='id')
def get_attributes(self, graph_id: str, attr: str) -> dict[str, Any]:
return {self.data[i].id: getattr(self.data[i], attr) for i in self.graphs[graph_id].sets}
@ -431,8 +442,17 @@ class UpperManagement(QtCore.QObject):
m_complex = model_p['complex']
for set_id, set_params in model_p['parameter'].items():
# sets are not in active order but in order they first appeared in fit dialog
# iterate over order of set id in active order and access parameter inside loop
# instead of directly looping
list_ids = list(model_p['parameter'].keys())
set_order = [self.active_id.index(i) for i in list_ids]
for pos in set_order:
set_id = list_ids[pos]
data_i = self.data[set_id]
set_params = model_p['parameter'][set_id]
if we.lower() == 'deltay':
we = data_i.y_err**2
@ -635,7 +655,7 @@ class UpperManagement(QtCore.QObject):
def save_fit_parameter(self, fname: str | pathlib.Path, fit_sets: list[str] = None):
if fit_sets is None:
fit_sets = [s for (s, _) in self.active_sets]
fit_sets = [s for s in self.active_id]
for set_id in fit_sets:
data = self.data[set_id]
@ -1004,7 +1024,7 @@ class UpperManagement(QtCore.QObject):
def show_statistics(self, mode):
x, y, = [], []
for i, _ in self.active_sets:
for i in self.active_id:
_temp = self.data[i]
try:
x.append(float(_temp.name))
@ -1015,7 +1035,7 @@ class UpperManagement(QtCore.QObject):
@QtCore.pyqtSlot()
def calc_magn(self):
new_id = []
for k, _ in self.active_sets:
for k in self.active_id:
dataset = self.data[k]
if isinstance(dataset, SignalContainer):
new_value = dataset.copy(full=True)
@ -1027,7 +1047,7 @@ class UpperManagement(QtCore.QObject):
@QtCore.pyqtSlot()
def center(self):
new_id = []
for k, _ in self.active_sets:
for k in self.active_id:
new_value = self.data[k].copy(full=True)
new_value.x -= new_value.x[np.argmax(new_value.y.real)]
new_id.append(self.add(new_value))
@ -1066,7 +1086,7 @@ class UpperManagement(QtCore.QObject):
def bds_deriv(self):
new_sets = []
for (set_id, _) in self.active_sets:
for set_id in self.active_id:
data_i = self.data[set_id]
diff = data_i.data.diff(log=True)
new_data = Points(x=diff.x, y=-np.pi/2*diff.y.real)
@ -1093,7 +1113,7 @@ class UpperManagement(QtCore.QObject):
self.newData.emit(new_sets, kwargs['graph'])
def skip_points(self, offset: int, step: int, invert: bool = False, copy: bool = False):
for k, _ in self.active_sets:
for k in self.active_id:
src = self.data[k]
if invert:
mask = np.mod(np.arange(offset, src.x.size+offset), step) != 0