<commit_before>import os
from functools import lru_cache

import opentrons.util.calibration_functions as calib
from numpy import add, subtract
from opentrons import commands, containers, drivers, helpers
from opentrons.broker import subscribe
from opentrons.containers import Container
from opentrons.data_storage import database, old_container_loading,\
    database_migration
from opentrons.drivers.smoothie_drivers import driver_3_0
from opentrons.robot.mover import Mover
from opentrons.robot.robot_configs import load
from opentrons.trackers import pose_tracker
from opentrons.util.log import get_logger

log = get_logger(__name__)

TIP_CLEARANCE_DECK = 20    # clearance when moving between different labware
TIP_CLEARANCE_LABWARE = 5  # clearance when staying within a single labware


class InstrumentMosfet(object):
    """
    Provides access to MagBead's MOSFET.
    """

    def __init__(self, this_robot, mosfet_index):
        self.robot = this_robot
        self.mosfet_index = mosfet_index

    def engage(self):
        """
        Engages the MOSFET.
        """
        self.robot._driver.set_mosfet(self.mosfet_index, True)

    def disengage(self):
        """
        Disengages the MOSFET.
        """
        self.robot._driver.set_mosfet(self.mosfet_index, False)

    def wait(self, seconds):
        """
        Pauses protocol execution.

        Parameters
        ----------
        seconds : int
            Number of seconds to pause for.
        """
        self.robot._driver.wait(seconds)


class InstrumentMotor(object):
    """
    Provides access to Robot's head motor.
    """

    def __init__(self, this_robot, axis):
        self.robot = this_robot
        self.axis = axis

    def move(self, value, mode='absolute'):
        """
        Move plunger motor.

        Parameters
        ----------
        value : int
            A one-dimensional coordinate to move to.
        mode : {'absolute', 'relative'}
        """
        kwargs = {self.axis: value}
        self.robot._driver.move_plunger(
            mode=mode, **kwargs
        )

    def home(self):
        """
        Home plunger motor.
        """
        self.robot._driver.home(self.axis)

    def wait(self, seconds):
        """
        Wait.

        Parameters
        ----------
        seconds : int
            Number of seconds to pause for.
        """
        self.robot._driver.wait(seconds)

    def speed(self, rate):
        """
        Set motor speed.

        Parameters
        ----------
        rate : int
        """
        self.robot._driver.set_plunger_speed(rate, self.axis)
        return self


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:
        container = old_container_loading.get_persisted_container(
            container_name)
        rotated_container = database_migration.rotate_container_for_alpha(
            container)
        database.save_new_container(rotated_container, container_name)

    container.properties['type'] = container_name

    container_x, container_y, container_z = container._coordinates

    # 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


# NOTE: modules are stored in the Containers db table
def _setup_module(module):
    x, y, z = database.load_module(module.name)
    from opentrons.util.vector import Vector<commit_msg>Resin test<commit_after>import os
from functools import lru_cache

import opentrons.util.calibration_functions as calib
from numpy import add, subtract
from opentrons import commands, containers, drivers, helpers
from opentrons.broker import subscribe
from opentrons.containers import Container
from opentrons.data_storage import database, old_container_loading,\
    database_migration
from opentrons.drivers.smoothie_drivers import driver_3_0
from opentrons.robot.mover import Mover
from opentrons.robot.robot_configs import load
from opentrons.trackers import pose_tracker
from opentrons.util.log import get_logger

log = get_logger(__name__)

TIP_CLEARANCE_DECK = 20    # clearance when moving between different labware
TIP_CLEARANCE_LABWARE = 5  # clearance when staying within a single labware


class InstrumentMosfet(object):
    """
    Provides access to MagBead's MOSFET.
    """

    def __init__(self, this_robot, mosfet_index):
        self.robot = this_robot
        self.mosfet_index = mosfet_index

    def engage(self):
        """
        Engages the MOSFET.
        """
        self.robot._driver.set_mosfet(self.mosfet_index, True)

    def disengage(self):
        """
        Disengages the MOSFET.
        """
        self.robot._driver.set_mosfet(self.mosfet_index, False)

    def wait(self, seconds):
        """
        Pauses protocol execution.

        Parameters
        ----------
        seconds : int
            Number of seconds to pause for.
        """
        self.robot._driver.wait(seconds)


class InstrumentMotor(object):
    """
    Provides access to Robot's head motor.
    """

    def __init__(self, this_robot, axis):
        self.robot = this_robot
        self.axis = axis

    def move(self, value, mode='absolute'):
        """
        Move plunger motor.

        Parameters
        ----------
        value : int
            A one-dimensional coordinate to move to.
        mode : {'absolute', 'relative'}
        """
        kwargs = {self.axis: value}
        self.robot._driver.move_plunger(
            mode=mode, **kwargs
        )

    def home(self):
        """
        Home plunger motor.
        """
        self.robot._driver.home(self.axis)

    def wait(self, seconds):
        """
        Wait.

        Parameters
        ----------
        seconds : int
            Number of seconds to pause for.
        """
        self.robot._driver.wait(seconds)

    def speed(self, rate):
        """
        Set motor speed.

        Parameters
        ----------
        rate : int
        """
        self.robot._driver.set_plunger_speed(rate, self.axis)
        return self


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 Exception as e:
        log.debug("This is the exception {}".format(e))
        container = old_container_loading.get_persisted_container(
            container_name)
        rotated_container = database_migration.rotate_container_for_alpha(
            container)
        database.save_new_container(rotated_container, container_name)

    container.properties['type'] = container_name

    container_x, container_y, container_z = container._coordinates

    # 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


# NOTE: modules are stored in the Containers db table
def _setup_module(module):
    x, y, z = database.load_module(module.name)
    from opentrons.util.vector import Vector
{'fraction_non_alphanumeric': 0.08889478572376278, 'fraction_numerical': 0.0021228605545973197, 'mean_word_length': 2.3878651685393257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5803443', 'n_tokens_mistral': 2205, 'n_tokens_neox': 2091, 'n_words': 543}