Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
removed if-elses
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdelgrosso committed May 24, 2021
1 parent d71cca5 commit c9bbb67
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions slicereg/gui/atlas_section_window/viewmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,36 @@ def __post_init__(self):
HasObservableAttributes.__init__(self)
self._model.register(self.update)

@property
def section_image_name(self):
return f"{self.plane}_section_image"

@property
def image_coords_name(self):
return f"{self.plane}_image_coords"

def update(self, changed: str):
update_funs = {
'x': self._update_depth,
'y': self._update_depth,
'z': self._update_depth,
self.image_coords_name: self._update_image_coords,
self.section_image_name: self._update_section_image,
self._depth_coord: self._update_depth,
self._image_coords_name: self._update_image_coords,
self._section_image_name: self._update_section_image,
}
if (render_fun := update_funs.get(changed)) is not None:
render_fun()

def _update_image_coords(self):
self.image_coords = getattr(self._model, self.image_coords_name)
self.image_coords = getattr(self._model, self._image_coords_name)

def _update_section_image(self):
if (section_image := getattr(self._model, self.section_image_name)) is not None:
if (section_image := getattr(self._model, self._section_image_name)) is not None:
self.atlas_section_image = section_image

def _update_depth(self):
if self.plane == 'coronal':
self.depth = self._model.x
elif self.plane == 'axial':
self.depth = self._model.y
elif self.plane == 'sagittal':
self.depth = self._model.z
self.depth = getattr(self._model, self._depth_coord)

@property
def _section_image_name(self):
return f"{self.plane}_section_image"

@property
def _depth_coord(self):
return {'coronal': 'x', 'axial': 'y', 'sagittal': 'z'}[self.plane]

@property
def _image_coords_name(self):
return f"{self.plane}_image_coords"

@property
def clim(self) -> Tuple[float, float]:
Expand Down

0 comments on commit c9bbb67

Please sign in to comment.