Skip to content

Commit

Permalink
remove redundant code and use enum name
Browse files Browse the repository at this point in the history
  • Loading branch information
MialLewis committed Oct 9, 2023
1 parent 198379e commit 722550b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 32 deletions.
2 changes: 1 addition & 1 deletion src/mslice/plotting/plot_window/slice_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def get_slice_cache(self):

def get_cached_workspace(self):
cached_slice = self.get_slice_cache()
return getattr(cached_slice, IntensityCache.get_slice_type(self.intensity_type))
return getattr(cached_slice, self.intensity_type.name.lower())

def update_workspaces(self):
self._slice_plotter_presenter.update_displayed_workspaces()
Expand Down
19 changes: 0 additions & 19 deletions src/mslice/presenters/slice_plotter_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
from mslice.models.workspacemanager.workspace_provider import get_workspace_handle
from mslice.plotting.plot_window.overplot_interface import plot_overplot_line, remove_line
from mslice.presenters.presenter_utility import PresenterUtility
from mslice.plotting.pyplot import CATEGORY_SLICE
from mslice.util.intensity_correction import IntensityType, IntensityCache


class SlicePlotterPresenter(PresenterUtility):

def __init__(self):
self._main_presenter = None
self._slice_cache = {}
self._cache_intensity_correction_methods()

def plot_slice(self, selected_ws, x_axis, y_axis, intensity_start, intensity_end, norm_to_one, colourmap):
workspace = get_workspace_handle(selected_ws)
Expand Down Expand Up @@ -115,19 +112,3 @@ def set_sample_temperature(self, workspace_name, temp):

def workspace_selection_changed(self):
pass

def _cache_intensity_correction_methods(self):
cat = CATEGORY_SLICE
IntensityCache.cache_method(cat, IntensityType.SCATTERING_FUNCTION, self.show_scattering_function)
IntensityCache.cache_method(cat, IntensityType.CHI, self.show_dynamical_susceptibility)
IntensityCache.cache_method(cat, IntensityType.CHI_MAGNETIC,
self.show_dynamical_susceptibility_magnetic)
IntensityCache.cache_method(cat, IntensityType.D2SIGMA, self.show_d2sigma)
IntensityCache.cache_method(cat, IntensityType.SYMMETRISED, self.show_symmetrised)
IntensityCache.cache_method(cat, IntensityType.GDOS, self.show_gdos)
IntensityCache.cache_slice_type(IntensityType.SCATTERING_FUNCTION, "scattering_function")
IntensityCache.cache_slice_type(IntensityType.CHI, "chi")
IntensityCache.cache_slice_type(IntensityType.CHI_MAGNETIC, "chi_magnetic")
IntensityCache.cache_slice_type(IntensityType.D2SIGMA, "d2sigma")
IntensityCache.cache_slice_type(IntensityType.SYMMETRISED, "symmetrised")
IntensityCache.cache_slice_type(IntensityType.GDOS, "gdos")
12 changes: 0 additions & 12 deletions src/mslice/util/intensity_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class IntensityCache:
__action_dict = {}
__method_dict_cut = {}
__method_dict_slice = {}
__slice_cache_type = {}
__description_dict = {IntensityType.SCATTERING_FUNCTION: "scattering_function",
IntensityType.CHI: "dynamical_susceptibility",
IntensityType.CHI_MAGNETIC: "dynamical_susceptibility_magnetic",
Expand Down Expand Up @@ -63,17 +62,6 @@ def get_method(cls, category, intensity_correction_type):
else:
raise KeyError("method related to the intensity correction type not found")

@classmethod
def cache_slice_type(cls, intensity_correction_type, name):
if intensity_correction_type not in cls.__slice_cache_type:
cls.__slice_cache_type[intensity_correction_type] = name

@classmethod
def get_slice_type(cls, intensity_correction_type):
if intensity_correction_type not in cls.__slice_cache_type:
raise KeyError("intensity correction cached type not found")
return cls.__slice_cache_type[intensity_correction_type]

@classmethod
def get_intensity_type_from_desc(cls, description):
if description in cls._IntensityCache__description_dict.values():
Expand Down

0 comments on commit 722550b

Please sign in to comment.