Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
v = self.viewer
if v is not None:
v.scene.render()
class Helix(HasTraits):
"""Helix class creates Helix/Spring from tvtk polydata, follows the
usual VTK pipeline and creates an Helix actor, which is passed to
the show_actor() function as an argument.
"""
#####################################################################
# Traits definitions
coils = Int(5)
points = Array('d', shape = (None, 3))
radius = Range(0.01, 1e299, value = 0.2, desc = 'the helix radius')
length = Range(0.01, 1e299, value = 1.0, desc = 'the helix length')
pos = Array(value = (0.0, 0.0, 0.0), desc = 'the helix position')
axis = Array(value = (1.0, 0.0, 0.0), desc = 'the helix axis')
color = vtk_color_trait((1.0, 1.0, 1.0))
x = Range(-1e299, 1e299, 0.0, desc = 'the X coordinate of helix center')
y = Range(-1e299, 1e299, 0.0, desc = 'the Y coordinate of helix center')
z = Range(-1e299, 1e299, 0.0, desc = 'the Z coordinate of helix center')
representation = Enum('s', 'w', 'p')
thickness = Range(0, 1e299, value = 0.01, desc = 'the helix thickness')
visibility = Bool(True)
viewer = Any
polydata = Instance(tvtk.PolyData, ())
property = Instance(tvtk.Property)
tube = Instance(tvtk.TubeFilter, ())
actor = Instance(tvtk.Actor, ()) # tvtk Actor, for the usual pipeline architecture.
scipy.optimize or one of several optimization algorithms from the scikit-learn module.
Needs a-priori delay-and-sum beamforming (:class:`BeamformerBase`).
"""
#: Type of fit method to be used ('LassoLars',
#: 'OMPCV', 'LP', or 'NNLS', defaults to 'NNLS').
#: These methods are implemented in
#: the `scikit-learn `_
#: module or within scipy.optimize respectively.
method = Trait('NNLS','LP','LassoLars', 'OMPCV',
desc="method used for solving deconvolution problem")
#: Weight factor for LassoLars method,
#: defaults to 0.0.
# (Values in the order of 10^⁻9 should produce good results.)
alpha = Range(0.0, 1.0, 0.0,
desc="Lasso weight factor")
#: Maximum number of iterations,
#: tradeoff between speed and precision;
#: defaults to 500
max_iter = Int(500,
desc="maximum number of iterations")
#: Unit multiplier for evaluating, e.g., nPa instead of Pa.
#: Values are converted back before returning.
#: Temporary conversion may be necessary to not reach machine epsilon
#: within fitting method algorithms. Defaults to 1e9.
unit_mult = Float(1e9,
desc = "unit multiplier")
# internal identifier
template = Array
CC = Array
peaks = List
zero=Int(0)
tmp_size = Range(low=2, high=512, value=64, cols=4)
max_pos_x=Property(depends_on=['tmp_size'])
max_pos_y=Property(depends_on=['tmp_size'])
top = Range(low='zero',high='max_pos_y', value=20, cols=4)
left = Range(low='zero',high='max_pos_x', value=20, cols=4)
is_square = Bool
img_plot = Instance(Plot)
tmp_plot = Instance(Plot)
findpeaks = Button
next_img = Button
prev_img = Button
peak_width = Range(low=2, high=200, value=10)
tab_selected = Event
ShowCC = Bool
img_container = Instance(Component)
container = Instance(Component)
colorbar= Instance(Component)
numpeaks_total = Int(0,cols=5)
numpeaks_img = Int(0,cols=5)
OK_custom=OK_custom_handler
cbar_selection = Instance(RangeSelection)
cbar_selected = Event
thresh=Trait(None,None,List,Tuple,Array)
thresh_upper=Float(1.0)
thresh_lower=Float(0.0)
numfiles=Int(1)
img_idx=Int(0)
tmp_img_idx=Int(0)
from numpy import linspace, sin
from enthought.chaco.api import ArrayPlotData, Plot, AbstractOverlay
from enthought.chaco.tools.api import PanTool
from enable.component_editor import ComponentEditor
from enable.api import ColorTrait
from traits.api import Button, Float, Range, HasTraits, Instance
from traitsui.api import Item, View, Group, HGroup, RangeEditor, \
spring, Handler
class CustomOverlay(AbstractOverlay):
x = Float(10, editor=RangeEditor(low=1.0, high=600, mode="slider"))
y = Float(10, editor=RangeEditor(low=1.0, high=500, mode="slider"))
width = Range(10.0, 300, editor=RangeEditor(low=10.0, high=300, mode="slider"))
height = Range(10.0, 300, editor=RangeEditor(low=10.0, high=300, mode="slider"))
color = ColorTrait("red")
traits_view = View(Group(
Item("x"), Item("y"), Item("width"), Item("height"),
Item("color"), orientation = "vertical"
))
def overlay(self, component, gc, view_bounds=None, mode="normal"):
gc.set_fill_color(self.color_)
x = self.x + component.x
y = self.y + component.y
gc.rect(x, y, self.width, self.height)
gc.fill_path()
def _anytrait_changed(self):
# Pattern for finding size infomation embedded in an item description:
size_pat = re.compile(r"^(.*)<(.*)>(.*)$", re.MULTILINE | re.DOTALL)
# Pattern for finding tooltip infomation embedded in an item description:
tooltip_pat = re.compile(r"^(.*)`(.*)`(.*)$", re.MULTILINE | re.DOTALL)
#-------------------------------------------------------------------------
# Trait definitions:
#-------------------------------------------------------------------------
# Reference to an EditorFactory:
ItemEditor = Instance(EditorFactory, allow_none=True)
# Amount of padding to add around an item:
Padding = Range(-15, 15, 0, desc='amount of padding to add around item')
#-------------------------------------------------------------------------
# 'Item' class:
#-------------------------------------------------------------------------
class Item(ViewSubElement):
""" An element in a Traits-based user interface.
Magic:
- Items are rendered as layout elements if :attr:`name` is set to
special values:
* name='', the item is rendered as a static label
# point
x, y, z = self.wpoints_plot[point_id, :]
# Move the outline to the data point.
self.outline.bounds = (x - 0.03, x + 0.03,
y - 0.03, y + 0.03,
z - 0.03, z + 0.03)
k_point = np.array([x, y, z])
k_point_conv = np.dot(np.linalg.inv(self.crystal_structure.inv_lattice_vectors.T), k_point)
self.k_path.append([k_point_conv, ''])
# self.update_plot()
self.plot_path()
self.parent.set_path(self.k_path)
class StructureVisualization(HasTraits):
n_x = Range(1, 40, 1, mode='spinner') # )
n_y = Range(1, 40, 1, mode='spinner') # mode='spinner')
n_z = Range(1, 40, 1, mode='spinner') # mode='spinner')
prop_but = Button(label='Properties')
show_unitcell = Bool(True)
show_bonds = Bool(True)
show_atoms = Bool(True)
edge_atoms = Bool(False)
view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
height=450, width=500, show_label=False),
Group('_', 'n_x', 'n_y', 'n_z', 'show_unitcell', 'show_bonds', 'show_atoms','edge_atoms', orientation='horizontal'),
resizable=True, # We need this to resize with the parent widget
)
scene = Instance(MlabSceneModel, ())
x_min = Range(value=0, low='_x_low', high='_x_high',
enter_set=True, auto_set=False,
desc='minimum x value of the domain')
# Maximum x value.
x_max = Range(value=10000, low='_x_low', high='_x_high',
enter_set=True, auto_set=False,
desc='maximum x value of the domain')
# Minimum y value.
y_min = Range(value=0, low='_y_low', high='_y_high',
enter_set=True, auto_set=False,
desc='minimum y value of the domain')
# Maximum y value.
y_max = Range(value=10000, low='_y_low', high='_y_high',
enter_set=True, auto_set=False,
desc='maximum y value of the domain')
# Minimum z value.
z_min = Range(value=0, low='_z_low', high='_z_high',
enter_set=True, auto_set=False,
desc='minimum z value of the domain')
# Maximum z value.
z_max = Range(value=10000, low='_z_low', high='_z_high',
enter_set=True, auto_set=False,
desc='maximum z value of the domain')
# Sample rate in x.
x_ratio = Range(value=1, low='_min_sample', high='_x_s_high',
enter_set=True, auto_set=False,
desc='the default foreground color of actors')
# The magnification to use when generating images from the render
# window.
magnification = Range(1, 2048, 1,
desc='the magnification used when the screen is saved to an image')
# Specifies the number of frames to use for anti-aliasing when
# saving a scene. This basically increases
# `self.render_window.aa_frames` in order to produce anti-aliased
# figures when a scene is saved to an image. It then restores the
# `aa_frames` in order to get interactive rendering rates.
anti_aliasing_frames = Range(0, 20, 8, desc='number of frames to use for anti-aliasing when saving a scene')
# Default JPEG quality.
jpeg_quality = Range(10, 100, 95, desc='the quality of the JPEG image to produce')
# Default JPEG progressive setting.
jpeg_progressive = Bool(True, desc='if the generated JPEG should be progressive')
# The light manager.
light_manager = Instance(light_manager.LightManager, record=True)
# Is the scene busy or not.
busy = Property(Bool, record=False)
########################################
# Events
# Lifecycle events: there are no opening/opened events since the
# control is actually created in __init__.
class Guest(HasPrivateTraits):
# The name of the guest:
name = Str
# The hotel the guest is staying at:
hotel = Instance(Hotel)
# The room plan the guest has chosen:
plan = Enum('Flop house', 'Cheap', 'Cozy', 'Deluxe')
# The maximum temperature allowed by the guest's plan:
max_temperature = Property(depends_on='plan')
# The current room temperature as set by the guest:
temperature = Range('hotel.min_temperature', 'max_temperature')
# The view of the guest:
view = View(
Item('plan'),
Item('temperature')
)
# Property implementations:
@cached_property
def _get_max_temperature(self):
return {'Flop house': 62,
'Cheap': 66,
'Cozy': 75,
'Deluxe': 85}[self.plan]
# Default values:
class CameraStageMapper(Instrument, HasTraits):
"""
This class sits between a camera and a stage, allowing coordinate conversion.
Coordinate Systems
------------------
We consider the centre of the image to be our current position, and give
the position of each pixel on the camera such that it would be brought to
the centre of the camera image by moving the stage to (-position).
"""
do_calibration = Button()
calibration_distance = Float(7, tooltip="Distance to move in each direction when calibrating, in um")
camera_to_sample = Array(shape=(2,2))
do_autofocus = Button()
autofocus_range = Range(0., 100., 5.)
autofocus_step = Range(0., 10., 0.5)
autofocus_default_ranges = [np.arange(-5,5,0.5),np.arange(-1,1,0.2)]
frames_to_discard = Int(1)
settling_time = Float(0.2)
disable_live_view = True
traits_view = View(
VGroup(
Item(name="calibration_distance"),
Item(name="do_calibration"),
Item(name="autofocus_range"),
Item(name="autofocus_step"),
Item(name="do_autofocus"),
Item(name="camera_to_sample"),
),
title="Camera-Stage Mapper",
)
def __init__(self, camera, stage):