Exemplo n.º 1
0
def test_div():
    v1 = Vector(2.0, 4.0, 6.0)
    res = v1 / 2.0

    assert res == Vector(1.0, 2.0, 3.0)
    res = v1 / Vector(2.0, 4.0, 6.0)
    assert res == Vector(1.0, 1.0, 1.0)
Exemplo n.º 2
0
def test_mul():
    v1 = Vector(2.0, 4.0, 6.0)
    res = v1 * 2.0
    assert res == Vector(4.0, 8.0, 12.0)

    res = v1 * Vector(-1.0, -1.0, -1.0)
    assert res == Vector(-2.0, -4.0, -6.0)
Exemplo n.º 3
0
 def flip_coordinates(self, coordinates, mode='absolute'):
     coordinates = Vector(coordinates) * Vector(1, -1, -1)
     if mode == 'absolute':
         offset = Vector(0, 1, 1)
         offset *= self.ot_one_dimensions[self.get_ot_version()]
         coordinates += offset
     return coordinates
Exemplo n.º 4
0
    def test_mul(self):
        v1 = Vector(2.0, 4.0, 6.0)
        res = v1 * 2.0
        self.assertEqual(res, Vector(4.0, 8.0, 12.0))

        res = v1 * Vector(-1.0, -1.0, -1.0)
        self.assertEqual(res, Vector(-2.0, -4.0, -6.0))
Exemplo n.º 5
0
    def test_div(self):
        v1 = Vector(2.0, 4.0, 6.0)
        res = v1 / 2.0

        self.assertEqual(res, Vector(1.0, 2.0, 3.0))
        res = v1 / Vector(2.0, 4.0, 6.0)
        self.assertEqual(res, Vector(1.0, 1.0, 1.0))
Exemplo n.º 6
0
    def convert(self, placeable, coordinates=Vector(0, 0, 0)):
        coordinates = Vector(coordinates)
        path = placeable.get_trace()

        adjusted_coordinates = Vector(0, 0, 0)
        for item in path:
            c = self.calibrated_coordinates.get(item, item._coordinates)
            adjusted_coordinates += c

        return coordinates + adjusted_coordinates
Exemplo n.º 7
0
    def test_init(self):
        v1 = Vector(1, 2, 3)
        v2 = Vector((1, 2, 3))
        v3 = Vector({'x': 1, 'y': 2, 'z': 3})
        v4 = Vector({'x': 1})

        self.assertEqual(v1, (1, 2, 3))
        self.assertEqual(v2, (1, 2, 3))
        self.assertEqual(v3, (1, 2, 3))
        self.assertEqual(v4, Vector(1, 0, 0))
Exemplo n.º 8
0
def test_container_from_container_load():
    robot.reset()
    plate = containers_load(robot, '96-flat', '1')
    if ff.split_labware_definitions():
        actual = plate[0]._coordinates + plate[0].top()[1]
        expected = Vector(14.34, 74.24, 10.50)
    else:
        actual = plate._coordinates
        expected = Vector(14.34, 11.24, 10.50)
    assert plate.get_type() == '96-flat'
    assert actual == expected
Exemplo n.º 9
0
def mainprogram(timez):
    pipette.drop_tip(trash)
    for each in range(timez):
        a, b = 5, 1
        petri_diameter = 85
        theta = 1
        deltaincrease = (petri_diameter / 2 - 2 - a) / b / len(pcr96_1.wells())

        #pick up the tip from the tiprack, the variable each will do the next one
        pipette.pick_up_tip(tiprack.wells(each))

        #loop through each well
        for well in range(96):

            #get water from the water trough
            pipette.aspirate(100, water[each])

            #this portion is to calculate xy coordinates from polar coordinates to find circle
            #a turns the spiral, while b controls the distance between successive turnings
            r = a + b * theta
            x = r * cos(theta)
            y = r * sin(theta)
            theta += deltaincrease

            #these steps are to pick up yeast samples and put them in a sample tray
            ########################################################################################
            pipette.move_to((petri[each],
                             Vector(petri[each]._coordinates.coordinates.x + x,
                                    petri[each]._coordinates.coordinates.y + y,
                                    petri[each]._coordinates.coordinates.z)),
                            'arc')

            pipette.aspirate(100)

            pipette.move_to(
                (petri[each],
                 Vector(petri[each]._coordinates.coordinates.x + x - 1,
                        petri[each]._coordinates.coordinates.y + y - 1,
                        petri[each]._coordinates.coordinates.z)), 'direct')

            pipette.move_to(
                (petri[each],
                 Vector(petri[each]._coordinates.coordinates.x + x + 2,
                        petri[each]._coordinates.coordinates.y + y + 2,
                        petri[each]._coordinates.coordinates.z)), 'direct')

            pipette.dispense(200, pcr[each].wells(well).bottom())


#######################################################################################

#drop pippete into trash
        pipette.drop_tip(trash)
    def test_break_down_travel(self):
        # with 3-dimensional points
        p1 = Vector(0, 0, 0)
        p2 = Vector(10, -12, 14)
        res = helpers.break_down_travel(p1, p2, increment=5, mode='absolute')
        self.assertEquals(res[-1], p2)
        self.assertEquals(len(res), 5)

        p1 = Vector(10, -12, 14)
        res = helpers.break_down_travel(Vector(0, 0, 0), p1, mode='relative')
        expected = Vector(0.46537410754407676, -0.5584489290528921,
                          0.6515237505617075)
        self.assertEquals(res[-1], expected)
        self.assertEquals(len(res), 5)
Exemplo n.º 11
0
def test_break_down_travel():
    # with 3-dimensional points
    p1 = Vector(0, 0, 0)
    p2 = Vector(10, -12, 14)
    res = helpers.break_down_travel(p1, p2, increment=5, mode='absolute')
    assert res[-1] == p2
    assert len(res) == 5

    p1 = Vector(10, -12, 14)
    res = helpers.break_down_travel(Vector(0, 0, 0), p1, mode='relative')
    expected = Vector(0.46537410754407676, -0.5584489290528921,
                      0.6515237505617075)
    assert res[-1] == expected
    assert len(res) == 5
Exemplo n.º 12
0
    def test_top_bottom(self):
        deck = Deck()
        slot = Slot()
        plate = self.generate_plate(wells=4,
                                    cols=2,
                                    spacing=(10, 10),
                                    offset=(0, 0),
                                    radius=5,
                                    height=10)
        deck.add(slot, 'A1', (0, 0, 0))
        slot.add(plate)

        self.assertEqual(plate['A1'].bottom(10),
                         (plate['A1'], Vector(5, 5, 10)))
        self.assertEqual(plate['A1'].top(10), (plate['A1'], Vector(5, 5, 20)))
Exemplo n.º 13
0
    def test_calibrated_max_dimension(self):

        expected = self.robot._deck.max_dimensions(self.robot._deck)
        res = self.robot._calibrated_max_dimension()
        self.assertEquals(res, expected)

        p200 = instruments.Pipette(axis='b', name='my-fancy-pancy-pipette')
        plate = containers.load('96-flat', 'A1')
        self.robot.move_head(x=10, y=10, z=10)
        p200.calibrate_position((plate, Vector(0, 0, 0)))

        res = self.robot._calibrated_max_dimension()

        expected = Vector(plate.max_dimensions(plate)) + Vector(10, 10, 10)
        self.assertEquals(res, expected)
Exemplo n.º 14
0
def _load_container_object_from_db(db, container_name: str):
    db_data = db_queries.get_container_by_name(db, container_name)
    if not db_data:
        raise ValueError(
            "No container with name {} found in Containers database"
            .format(container_name)
        )

    container_type, *rel_coords = db_data
    wells = db_queries.get_wells_by_container_name(db, container_name)
    if not wells:
        raise ResourceWarning(
            "No wells for container {} found in ContainerWells database"
            .format(container_name)
        )

    if container_name in SUPPORTED_MODULES:
        container: Placeable = Module()
    else:
        container = Container()

    container.properties['type'] = container_type
    container._coordinates = Vector(rel_coords)
    log.debug("Loading {} with coords {}".format(rel_coords, container_type))
    for well in wells:
        container.add(*_load_well_object_from_db(db, well))
    return container
Exemplo n.º 15
0
    def move(self, mode='absolute', **kwargs):
        self.set_coordinate_system(mode)
        self.set_speed()

        current = self.get_head_position()['target']
        target_point = {
            axis: kwargs.get(axis, 0 if mode == 'relative' else current[axis])
            for axis in 'xyz'
        }

        flipped_vector = self.flip_coordinates(Vector(target_point), mode)
        for axis in 'xyz':
            kwargs[axis] = flipped_vector[axis]

        args = {
            axis.upper(): kwargs.get(axis)
            for axis in 'xyzab' if axis in kwargs
        }
        args.update({"F": max(list(self.speeds.values()))})

        self.check_paused_stopped()
        self.send_command(self.MOVE, **args)
        self.wait_for_ok()
        self.wait_for_arrival()

        arguments = {
            'name': 'move-finished',
            'position': {
                'head': self.get_head_position()["current"],
                'plunger': self.get_plunger_positions()["current"]
            },
            'class': type(self.connection).__name__
        }
        trace.EventBroker.get_instance().notify(arguments)
Exemplo n.º 16
0
    def calibrate(self, calibration_data, location, actual):
        actual = Vector(actual)
        placeable, expected = unpack_location(location)
        coordinates_to_deck = placeable.coordinates(placeable.get_deck())
        expected_to_deck = expected + coordinates_to_deck

        delta = actual - expected_to_deck
        path = placeable.get_path()
        calibration_data = copy.deepcopy(calibration_data)

        current = {'children': calibration_data}
        for i, name in enumerate(path):
            children = current['children']
            if name not in children:
                if i == len(path) - 1:
                    children[name] = {}
                else:
                    children[name] = {'children': {}}
            current = children[name]

        current['delta'] = delta
        self.calibration_data = calibration_data

        self._apply_calibration(calibration_data, self.root_placeable)

        return calibration_data
Exemplo n.º 17
0
def _setup_container(container_name):
    try:
        container = database.load_container(container_name)

    # Database.load_container throws ValueError when a container name is not
    # found.
    except ValueError:
        # First must populate "get persisted container" list
        old_container_loading.load_all_containers_from_disk()
        # Load container from old json file
        container = old_container_loading.get_persisted_container(
            container_name)
        # Rotate coordinates to fit the new deck map
        rotated_container = database_migration.rotate_container_for_alpha(
            container)
        # Save to the new database
        database.save_new_container(rotated_container, container_name)

    container.properties['type'] = container_name
    container_x, container_y, container_z = container._coordinates

    if not fflags.split_labware_definitions():
        # infer z from height
        if container_z == 0 and 'height' in container[0].properties:
            container_z = container[0].properties['height']

    from opentrons.util.vector import Vector
    container._coordinates = Vector(container_x, container_y, container_z)

    return container
Exemplo n.º 18
0
    def from_center(self,
                    x=None,
                    y=None,
                    z=None,
                    r=None,
                    theta=None,
                    h=None,
                    reference=None):
        """
        Accepts a set of (:x:, :y:, :z:) ratios for Cartesian or
        (:r:, :theta:, :h:) rations/angle for Polar and returns
        :Vector: using :reference: as origin
        """
        coords_to_endpoint = None
        if all([isinstance(i, numbers.Number) for i in (x, y, z)]):
            coords_to_endpoint = self.from_cartesian(x, y, z)

        if all([isinstance(i, numbers.Number) for i in (r, theta, h)]):
            coords_to_endpoint = self.from_polar(r, theta, h)

        coords_to_reference = Vector(0, 0, 0)
        if reference:
            coords_to_reference = self.coordinates(reference)

        return coords_to_reference + coords_to_endpoint
Exemplo n.º 19
0
def break_down_travel(p1, target, increment=5, mode='absolute'):
    """
    given two points p1 and target, this returns a list of
    incremental positions or relative steps
    """

    heading = target - p1
    if mode == 'relative':
        heading = target
    length = heading.length()

    length_steps = length / increment
    length_remainder = length % increment

    vector_step = Vector(0, 0, 0)
    if length_steps > 0:
        vector_step = heading / length_steps
    vector_remainder = vector_step * (length_remainder / increment)

    res = []
    if mode == 'absolute':
        for i in range(int(length_steps)):
            p1 = p1 + vector_step
            res.append(p1)
        p1 = p1 + vector_remainder
        res.append(p1)
    else:
        for i in range(int(length_steps)):
            res.append(vector_step)
        res.append(vector_remainder)
    return res
Exemplo n.º 20
0
    def _calibrated_max_dimension(self, container=None):
        """
        Returns a Vector, each axis being the calibrated maximum
        for all instruments
        """
        if not self._instruments or not self.containers():
            if container:
                return container.max_dimensions(self._deck)
            return self._deck.max_dimensions(self._deck)

        def _max_per_instrument(placeable):
            """
            Returns list of Vectors, one for each Instrument's farthest
            calibrated coordinate for the supplied placeable
            """
            return [
                instrument.calibrator.convert(
                    placeable, placeable.max_dimensions(placeable))
                for instrument in self._instruments.values()
            ]

        container_max_coords = []
        if container:
            container_max_coords = _max_per_instrument(container)
        else:
            for c in self.containers().values():
                container_max_coords += _max_per_instrument(c)

        max_coords = [
            max(container_max_coords,
                key=lambda coordinates: coordinates[axis])[axis]
            for axis in range(3)
        ]

        return Vector(max_coords)
Exemplo n.º 21
0
    def move(self, mode='absolute', **kwargs):
        self.set_coordinate_system(mode)

        axis_called = [ax for ax in 'xyz' if ax in kwargs]

        current = self.get_head_position()['target']
        log.debug('Current Head Position: {}'.format(current))
        target_point = {
            axis: kwargs.get(axis, 0 if mode == 'relative' else current[axis])
            for axis in 'xyz'
        }
        log.debug('Destination: {}'.format(target_point))

        flipped_vector = self.flip_coordinates(Vector(target_point), mode)
        for axis in 'xyz':
            kwargs[axis] = flipped_vector[axis]

        args = {
            axis.upper(): kwargs.get(axis)
            for axis in 'xyzab' if axis in kwargs
        }

        if axis_called:
            this_head_speed = min([self.speeds[l] for l in axis_called])
            args.update({"F": this_head_speed})
        args.update({"a": self.speeds['a']})
        args.update({"b": self.speeds['b']})

        return self.consume_move_commands(args)
Exemplo n.º 22
0
def test_container_from_container_load(robot):
    robot.reset()
    plate = containers_load(robot, '96-flat', '1')
    actual = plate._coordinates
    expected = Vector(14.34, 11.24, 10.50)
    assert plate.get_type() == '96-flat'
    assert actual == expected
Exemplo n.º 23
0
    def test_dispense_move_to(self):
        x, y, z = (161.0, 116.7, 3.0)
        well = self.plate[0]
        pos = well.from_center(x=0, y=0, z=-1, reference=self.plate)
        location = (self.plate, pos)

        self.robot._driver.move_head(x=x, y=y, z=z)

        self.p200.calibrate_position(location)

        self.robot.home(enqueue=False)

        self.p200.aspirate(100, location)
        self.p200.dispense(100, location)
        self.robot.run()

        driver = self.robot._driver

        current_plunger_pos = driver.get_plunger_positions()['current']
        current_head_pos = driver.get_head_position()['current']

        self.assertEqual(current_head_pos,
                         Vector({
                             'x': 161.0,
                             'y': 116.7,
                             'z': 3.0
                         }))
        self.assertDictEqual(current_plunger_pos, {'a': 0, 'b': 10.0})
Exemplo n.º 24
0
    def test_calibrate_placeable(self):
        self.p200.delete_calibration_data()
        well = self.plate[0]
        pos = well.from_center(x=0, y=0, z=0, reference=self.plate)
        location = (self.plate, pos)

        well_deck_coordinates = well.center(well.get_deck())
        dest = well_deck_coordinates + Vector(1, 2, 3)

        self.robot._driver.move_head(x=dest['x'], y=dest['y'], z=dest['z'])

        self.p200.calibrate_position(location)

        expected_calibration_data = {
            'A2': {
                'children': {
                    '96-flat': {
                        'delta': (1.0, 2.0, 3.0),
                        'type': '96-flat'
                    }
                }
            }
        }

        self.assertDictEqual(self.p200.calibration_data,
                             expected_calibration_data)
Exemplo n.º 25
0
    def add(self, child, name=None, coordinates=Vector(0, 0, 0)):
        """
        Adds child to the :Placeable:, storing it's :name: and :coordinates:

        This method is used to add :Well:s to the :Container:,
        add :Slot:s to :Deck:, etc
        """
        if not name:
            name = str(child)

        if name in self.children_by_name:
            del self.children_by_name[name]

        child._coordinates = Vector(coordinates)
        child.parent = self
        self.children_by_name[name] = child
        self.children_by_reference[child] = name
Exemplo n.º 26
0
    def test_create_arc(self):
        p200 = instruments.Pipette(axis='b', name='my-fancy-pancy-pipette')
        plate = containers.load('96-flat', 'A1')
        plate2 = containers.load('96-flat', 'B1')

        self.robot.move_head(x=10, y=10, z=10)
        p200.calibrate_position((plate, Vector(0, 0, 0)))
        self.robot.move_head(x=10, y=10, z=100)
        p200.calibrate_position((plate2, Vector(0, 0, 0)))

        res = self.robot._create_arc((0, 0, 0), plate[0])
        expected = [{'z': 100}, {'x': 0, 'y': 0}, {'z': 0}]
        self.assertEquals(res, expected)

        res = self.robot._create_arc((0, 0, 0), plate[0])
        expected = [{'z': 20.5 + 5}, {'x': 0, 'y': 0}, {'z': 0}]
        self.assertEquals(res, expected)
Exemplo n.º 27
0
def rotate_container_for_alpha(container):
    container = add_offset(container)
    _, _, z = container._coordinates
    # Change container coordinates to be at the origin + top of container
    container._coordinates = Vector(0, 0, z)
    transpose_coordinates([well for well in container.wells()])

    return container
Exemplo n.º 28
0
    def from_center(self,
                    x=None,
                    y=None,
                    z=None,
                    r=None,
                    theta=None,
                    h=None,
                    reference=None):
        """
        Accepts a set of ratios for Cartesian or ratios/angle for Polar
        and returns :py:class:`.Vector` using ``reference`` as origin.

        Though both polar and cartesian arguments are accepted, only one
        set should be used at the same time, and the set selected should be
        entirely used. In addition, all variables in the set should be used.

        For instance, if you want to use cartesian coordinates, you must
        specify all of ``x``, ``y``, and ``z`` as numbers; if you want to
        use polar coordinates, you must specify all of ``theta``, ``r`` and
        ``h`` as numbers.

        While ``theta`` is an absolute angle in radians, the other values are
        actually ratios which are multiplied by the relevant dimensions of the
        placeable on which ``from_center`` is called. For instance, calling
        ``from_center(x=0.5, y=0.5, z=0.5)`` does not mean "500 micromenters
        from the center in each dimension", but "half the x size, half the y
        size, and half the z size from the center". Similarly,
        ``from_center(r=0.5, theta=3.14, h=0.5)`` means "half the radius
        dimension at 180 degrees, and half the height upwards".

        :param x: Ratio of the x dimension of the placeable to move from the
                  center.
        :param y: Ratio of the y dimension of the placeable to move from the
                  center.
        :param z: Ratio of the z dimension of the placeable to move from the
                  center.
        :param r: Ratio of the radius to move from the center.
        :param theta: Angle in radians at which to move the percentage of the
                      radius specified by ``r`` from the center.
        :param h: Percentage of the height to move up in z from the center.
        :param reference: If specified, an origin to add to the offset vector
                          specified by the other arguments.
        :returns: A vector from either the origin or the specified reference.
                  This can be passed into any :py:class:`.Robot` or
                  :py:class:`.Pipette` method ``location`` argument.
        """
        coords_to_endpoint = None
        if all([isinstance(i, numbers.Number) for i in (x, y, z)]):
            coords_to_endpoint = self.from_cartesian(x, y, z)

        if all([isinstance(i, numbers.Number) for i in (r, theta, h)]):
            coords_to_endpoint = self.from_polar(r, theta, h)

        coords_to_reference = Vector(0, 0, 0)
        if reference:
            coords_to_reference = self.coordinates(reference)

        return coords_to_reference + coords_to_endpoint
Exemplo n.º 29
0
    def add(self, child, name=None, coordinates=Vector(0, 0, 0)):
        """
        Adds child to the :Placeable:, storing it's :name: and :coordinates:

        This method is used to add :Well:s to the :Container:,
        add :Slot:s to :Deck:, etc
        """
        if not name:
            name = str(child)

        if name in self.children_by_name:
            raise Exception(
                'Child with the name {} already exists'.format(name))

        child._coordinates = Vector(coordinates)
        child.parent = self
        self.children_by_name[name] = child
        self.children_by_reference[child] = name
Exemplo n.º 30
0
def transpose_coordinates(wells):
    # Calculate XY coordinates based on width of container
    # TODO (Laura 7/27/2018): This only works for SBS footprint containers.
    # Will need to be changed once correct geometry system implemented
    w = 85.48
    for well in wells:
        curr_x, curr_y, z = well._coordinates
        offset_y = w - curr_x
        well._coordinates = Vector(curr_y, offset_y, z)