class Controller(PgImageController): """ TopView Controller """ def __init__(self, qmain: TopView, res=25): super(Controller, self).__init__(qmain) self.atlas = AllenAtlas(res) self.fig_top = self.qwidget = qmain # Setup Coronal slice: width: ml, height: dv, depth: ap self.fig_coronal = SliceView(qmain, waxis=0, haxis=2, daxis=1) self.fig_coronal.setWindowTitle('Coronal Slice') self.set_slice(self.fig_coronal) self.fig_coronal.show() # Setup Sagittal slice: width: ap, height: dv, depth: ml self.fig_sagittal = SliceView(qmain, waxis=1, haxis=2, daxis=0) self.fig_sagittal.setWindowTitle('Sagittal Slice') self.set_slice(self.fig_sagittal) self.fig_sagittal.show() def set_slice(self, fig, coord=0): waxis, haxis, daxis = (fig.ctrl.waxis, fig.ctrl.haxis, fig.ctrl.daxis) # construct the transform matrix image 2 ibl coordinates dw = self.atlas.bc.dxyz[waxis] dh = self.atlas.bc.dxyz[haxis] wl = self.atlas.bc.lim(waxis) - dw / 2 hl = self.atlas.bc.lim(haxis) - dh / 2 fig.ctrl.set_image(self.atlas.slice(coord, axis=daxis, mode='clip'), dw, dh, wl[0], hl[0]) fig.ctrl.slice_coord = coord def set_top(self): img = self.atlas.top.transpose() img[np.isnan(img)] = np.nanmin(img) # img has dims ml, ap dw, dh = (self.atlas.bc.dxyz[0], self.atlas.bc.dxyz[1]) wl, hl = (self.atlas.bc.xlim, self.atlas.bc.ylim) self.set_image(img, dw, dh, wl[0], hl[0])
class ControllerTopView(PgImageController): """ TopView ControllerTopView """ def __init__(self, qmain: TopView, res: int = 25, volume='image', brainmap='Allen'): super(ControllerTopView, self).__init__(qmain) self.volume = volume self.atlas = AllenAtlas(res, brainmap=brainmap) self.fig_top = self.qwidget = qmain # Setup Coronal slice: width: ml, height: dv, depth: ap self.fig_coronal = SliceView(qmain, waxis=0, haxis=2, daxis=1) self.fig_coronal.setWindowTitle('Coronal Slice') self.set_slice(self.fig_coronal) self.fig_coronal.show() # Setup Sagittal slice: width: ap, height: dv, depth: ml self.fig_sagittal = SliceView(qmain, waxis=1, haxis=2, daxis=0) self.fig_sagittal.setWindowTitle('Sagittal Slice') self.set_slice(self.fig_sagittal) self.fig_sagittal.show() def set_slice(self, fig, coord=0, mapping="Allen"): waxis, haxis, daxis = (fig.ctrl.waxis, fig.ctrl.haxis, fig.ctrl.daxis) # construct the transform matrix image 2 ibl coordinates dw = self.atlas.bc.dxyz[waxis] dh = self.atlas.bc.dxyz[haxis] wl = self.atlas.bc.lim(waxis) - dw / 2 hl = self.atlas.bc.lim(haxis) - dh / 2 # the ImageLayer object carries slice kwargs and pyqtgraph ImageSet kwargs # reversed order so the self.im is set with the base layer for layer in reversed(fig.ctrl.image_layers): _slice = self.atlas.slice(coord, axis=daxis, mapping=mapping, **layer.slice_kwargs) fig.ctrl.set_image(layer.image_item, _slice, dw, dh, wl[0], hl[0], **layer.pg_kwargs) fig.ctrl.slice_coord = coord def set_top(self): img = self.atlas.top.transpose() img[np.isnan(img)] = np.nanmin(img) # img has dims ml, ap dw, dh = (self.atlas.bc.dxyz[0], self.atlas.bc.dxyz[1]) wl, hl = (self.atlas.bc.xlim, self.atlas.bc.ylim) self.set_image(self.image_layers[0].image_item, img, dw, dh, wl[0], hl[0]) def set_scatter(self, fig, coord=0): waxis = fig.ctrl.waxis # dealing with coronal slice if waxis == 0: idx = np.where( self.scatter_data_ind[:, 1] == self.atlas.bc.y2i(coord))[0] x = self.scatter_data[idx, 0] y = self.scatter_data[idx, 2] else: idx = np.where( self.scatter_data_ind[:, 0] == self.atlas.bc.x2i(coord))[0] x = self.scatter_data[idx, 1] y = self.scatter_data[idx, 2] fig.ctrl.set_points(x, y) def set_volume(self, volume): self.volume = volume