def test_compose_beam_gaussian(self): beam = GaussianBeam(energy_eV=1, diameter_m=1) sf = SampleFigure(None, [beam], []) for perspective in self.perspectives: c = sf._compose_beam_gaussian(beam, perspective, 2.0) self.assertEqual(len(c), 1)
def __init__(self, parent=None): super().__init__(parent) # Variables figure = Figure((6, 6)) self.ax = figure.add_axes([0.0, 0.0, 1.0, 1.0]) self.ax.xaxis.set_visible(False) self.ax.yaxis.set_visible(False) self.sample_figure = SampleFigure() # Widgets self.canvas = FigureCanvas(figure) self.toolbar = PerspectiveToolbar() # Layouts layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.canvas) layout.addWidget(self.toolbar, 0, QtCore.Qt.AlignRight) self.setLayout(layout) # Signals self.toolbar.perspectiveChanged.connect(self._on_perspective_changed) # Defaults self.setPerspective(Perspective.XZ)
def samplefigure(): return SampleFigure()
def test_draw_beam(self): beam = GaussianBeam(energy_eV=1, diameter_m=1) sf = SampleFigure(None, [beam], []) sf._draw_beam(self.ax, beam, Perspective.XZ, 2.0) self.assertEqual(len(self.ax.collections), 1)
def _compose_sample(self, sample, patches_counts): for perspective, expected in zip(self.perspectives, patches_counts): sf = SampleFigure(sample) method = sf.sample_draw_methods[sample.__class__] patches = method(sample, perspective, 2.0) self.assertEqual(expected, len(patches))
def test_draw_sample(self): sample = SubstrateSample(self.mat_ds) sf = SampleFigure(sample) sf._draw_sample(self.ax, sample, Perspective.XZ, 2.0) self.assertEqual(len(self.ax.collections), 1)
def test_draw_nothing(self): sf = SampleFigure() sf.draw(self.ax) self.assertEqual(len(self.ax.collections), 0)
class SampleFigureWidget(QtWidgets.QWidget): def __init__(self, parent=None): super().__init__(parent) # Variables figure = Figure((6, 6)) self.ax = figure.add_axes([0.0, 0.0, 1.0, 1.0]) self.ax.xaxis.set_visible(False) self.ax.yaxis.set_visible(False) self.sample_figure = SampleFigure() # Widgets self.canvas = FigureCanvas(figure) self.toolbar = PerspectiveToolbar() # Layouts layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.canvas) layout.addWidget(self.toolbar, 0, QtCore.Qt.AlignRight) self.setLayout(layout) # Signals self.toolbar.perspectiveChanged.connect(self._on_perspective_changed) # Defaults self.setPerspective(Perspective.XZ) def _on_perspective_changed(self): self.sample_figure.perspective = self.toolbar.perspective() self.draw() def draw(self): self.ax.clear() self.sample_figure.draw(self.ax) scalebar = ScaleBar(1.0, location="lower left") self.ax.add_artist(scalebar) self.canvas.draw() def clear(self): self.sample_figure.sample = None self.sample_figure.beams.clear() self.sample_figure.trajectories.clear() self.draw() def setSample(self, sample): self.sample_figure.sample = sample self.draw() def addBeam(self, beam): self.sample_figure.beams.append(beam) self.draw() def perspective(self): return self.toolbar.perspective() def setPerspective(self, perspective): self.toolbar.setPerspective(perspective) self.draw()
def plot(self): tilt_rad = math.radians(self._slider_tilt_deg.value()) rotation_rad = math.radians(self._slider_rotation_deg.value()) layer = [ Layer(RE, 10e-9), Layer(OS, 15e-9), Layer(IR, 20e-9), Layer(PT, 5e-9) ] sample_cls = self._combo_sample.currentData() if sample_cls == SubstrateSample: sample = SubstrateSample(DS, tilt_rad=tilt_rad, rotation_rad=rotation_rad) elif sample_cls == InclusionSample: sample = InclusionSample(DS, AU, 0.5e-6, tilt_rad=tilt_rad, rotation_rad=rotation_rad) elif sample_cls == HorizontalLayerSample: sample = HorizontalLayerSample(DS, layer, tilt_rad=tilt_rad, rotation_rad=rotation_rad) elif sample_cls == VerticalLayerSample: sample = VerticalLayerSample(DS, RG, layer, tilt_rad=tilt_rad, rotation_rad=rotation_rad) elif sample_cls == SphereSample: sample = SphereSample(AU, 0.5e-6, tilt_rad=tilt_rad, rotation_rad=rotation_rad) else: sample = None beam_cls = self._combo_beam.currentData() if beam_cls == GaussianBeam: beams = [GaussianBeam(42.0, 5e-9)] else: beams = [] # trajectory_cls = self._combo_trajectory.currentData() # TODO handle trajectories trajectories = [] sf = SampleFigure(sample, beams, trajectories) if self.radio_yz.isChecked(): sf.perspective = Perspective.YZ elif self.radio_xy.isChecked(): sf.perspective = Perspective.XY else: sf.perspective = Perspective.XZ self._figure.clf() ax = self._figure.add_subplot(111) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) sf.draw(ax) scalebar = ScaleBar(1.0, location="lower left") ax.add_artist(scalebar) self._canvas.draw_idle()