Skip to content

Commit

Permalink
Model.__call__ -> _get_current_data
Browse files Browse the repository at this point in the history
  • Loading branch information
francisco-dlp committed Oct 9, 2023
1 parent 6c92645 commit 5c3f352
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions hyperspy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def __hash__(self):
# raise an exception when using windows.connect
return id(self)

def __call__(self, non_convolved=False, onlyactive=False, component_list=None, binned=None):
def _get_current_data(self, non_convolved=False, onlyactive=False, component_list=None, binned=None):
"""Evaluate the model numerically. Implementation requested in all sub-classes"""
raise NotImplementedError

Expand Down Expand Up @@ -597,7 +597,7 @@ def _as_signal_iter(self, data, component_list=None,
for index in self.axes_manager:
self.fetch_stored_values(only_fixed=False)
data[self.axes_manager._getitem_tuple][
np.where(self._channel_switches)] = self.__call__(
np.where(self._channel_switches)] = self._get_current_data(
non_convolved=not self.convolved, onlyactive=True).ravel()
pbar.update(1)

Expand Down Expand Up @@ -925,7 +925,7 @@ def _model2plot(self, axes_manager, out_of_range2nans=True):
old_axes_manager = self.axes_manager
self.axes_manager = axes_manager
self.fetch_stored_values()
s = self.__call__(non_convolved=False, onlyactive=True)
s = self._get_current_data(non_convolved=False, onlyactive=True)
if old_axes_manager is not None:
self.axes_manager = old_axes_manager
self.fetch_stored_values()
Expand All @@ -939,7 +939,7 @@ def _model2plot(self, axes_manager, out_of_range2nans=True):
def _model_function(self, param):
self.p0 = param
self._fetch_values_from_p0()
to_return = self.__call__(non_convolved=False, onlyactive=True, binned=self._binned)
to_return = self._get_current_data(non_convolved=False, onlyactive=True, binned=self._binned)
return to_return

@property
Expand Down Expand Up @@ -1068,7 +1068,7 @@ def _linear_fit(self, optimizer="lstsq", calculate_errors=False,
p = twin_parameters_mapping[p]

index = parameters.index(p)
comp_value = self.__call__(
comp_value = self._get_current_data(
component_list=[component], binned=False
)
comp_constant_values = component._compute_constant_term()
Expand All @@ -1077,7 +1077,7 @@ def _linear_fit(self, optimizer="lstsq", calculate_errors=False,

else:
# No free parameters, so component is fixed.
constant_term += self.__call__(
constant_term += self._get_current_data(
component_list=[component], binned=False
)

Expand Down
6 changes: 3 additions & 3 deletions hyperspy/models/model1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def remove(self, things):

remove.__doc__ = BaseModel.remove.__doc__

def __call__(self, non_convolved=False, onlyactive=False,
def _get_current_data(self, non_convolved=False, onlyactive=False,
component_list=None, binned=None,
ignore_channel_switches=False):
"""
Expand Down Expand Up @@ -736,7 +736,7 @@ def _model2plot(self, axes_manager, out_of_range2nans=True):
old_axes_manager = self.axes_manager
self.axes_manager = axes_manager
self.fetch_stored_values()
s = self.__call__(non_convolved=False, onlyactive=True)
s = self._get_current_data(non_convolved=False, onlyactive=True)
if old_axes_manager is not None:
self.axes_manager = old_axes_manager
self.fetch_stored_values()
Expand All @@ -752,7 +752,7 @@ def _residual_for_plot(self,**kwargs):
by the model signal then returns the residual
"""

return self.signal._get_current_data() - self.__call__(ignore_channel_switches=True)
return self.signal._get_current_data() - self._get_current_data(ignore_channel_switches=True)

def plot(self, plot_components=False,plot_residual=False, **kwargs):
"""Plot the current spectrum to the screen and a map with a
Expand Down
4 changes: 2 additions & 2 deletions hyperspy/models/model2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def signal(self, value):
else:
raise WrongObjectError(str(type(value)), 'Signal2D')

def __call__(self, non_convolved=True, onlyactive=False,
def _get_current_data(self, non_convolved=True, onlyactive=False,
component_list=None, binned=None):
"""Returns the corresponding 2D model for the current coordinates
Expand Down Expand Up @@ -389,7 +389,7 @@ def _model2plot(self, axes_manager, out_of_range2nans=True):
old_axes_manager = self.axes_manager
self.axes_manager = axes_manager
self.fetch_stored_values()
s = self.__call__(non_convolved=False, onlyactive=True)
s = self._get_current_data(non_convolved=False, onlyactive=True)
if old_axes_manager is not None:
self.axes_manager = old_axes_manager
self.fetch_stored_values()
Expand Down

0 comments on commit 5c3f352

Please sign in to comment.