How to use the autoprotocol.util.parse_unit function in autoprotocol

To help you get started, we’ve selected a few autoprotocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
Raises
        ------
        ValueError
            if shake `flow_pressure` is not positive
        ValueError
            if mobile phase solvent and resource_id not included
        TypeError
            if `resource_id` is not a string
        ValueError
            if `settle_time` is not positive
        ValueError
            if `processing_time` is not positive

        """
        volume = parse_unit(volume, "milliliter")
        settle_time = parse_unit(settle_time, "second")
        if settle_time <= Unit(0, "second"):
            raise ValueError(f"settle_time: {settle_time} is not positive")

        processing_time = parse_unit(processing_time, "second")
        if processing_time <= Unit(0, "second"):
            raise ValueError(f"processing_time: {processing_time} is not " "positive")

        flow_pressure = parse_unit(flow_pressure, "bar")
        if flow_pressure <= Unit(0, "bar"):
            raise ValueError(f"flow_pressure: {flow_pressure} must be " f"positive.")
        loading_flowrate = parse_unit(loading_flowrate, "ul/s")

        if not is_sample:
            if not resource_id:
                raise ValueError(
                    "A 'resource_id' must be included " "for mobile_phase_params."
github autoprotocol / autoprotocol-python / autoprotocol / liquid_handle / mix.py View on Github external
----------
        volume : Unit

        Notes
        -----
        This method defines what lower level transport-generating methods are
        called and in what order. It can be overwritten when adding an
        entirely new set of transport-generating behavior.

        Return
        ------
        list
            transports corresponding to the mix operation
        """
        self._transports = []
        volume = parse_unit(volume, "ul")

        # No transports if no volume specified
        if volume == Unit("0:ul"):
            return []

        self._transport_pre_buffer(volume)
        self._transport_mix(volume)
        self._transport_blowout(volume)

        return self._transports
github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
If `center` is less than 0
        ValueError
            If `amplitude` is greater than center
        TypeError
            If `magnetize` is not a bool


        See Also
        --------
        Protocol.mag_mix

        """
        if not isinstance(object, Container):
            raise TypeError(f"object: {object} is not a Container")
        duration = parse_unit(duration, "seconds")
        frequency = parse_unit(frequency, "hertz")
        if center is not None:
            center = float(center)
            if center < 0:
                raise ValueError(f"center: {center} must be >= 0")
        if amplitude is not None:
            amplitude = float(amplitude)
        if center is not None and amplitude is not None and amplitude > center:
            raise ValueError(
                f"center: {center} must be greater than or equal to amplitude: "
                f"{amplitude}"
            )
        if magnetize is not None and not isinstance(magnetize, bool):
            raise TypeError(f"magnetize: {magnetize} is not a bool")
        if temperature is not None:
            parse_unit(temperature, "celsius")
github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
if not isinstance(excitation, list):
            raise ValueError("Excitation {} must be a list")
        if not isinstance(emission, list):
            raise ValueError("Emission {} must be a list")

        excitation = [self.wavelength_selection(**_) for _ in excitation]
        emission = [self.wavelength_selection(**_) for _ in emission]

        if num_flashes is not None and not isinstance(num_flashes, int):
            raise ValueError(f"Invalid num_flashes {num_flashes}, must be an int")

        if settle_time is not None:
            settle_time = parse_unit(settle_time, "second")

        if lag_time is not None:
            lag_time = parse_unit(lag_time, "second")

        if integration_time is not None:
            integration_time = parse_unit(integration_time, "second")

        if gain is not None:
            if not isinstance(gain, (int, float)):
                raise TypeError(f"Invalid gain {gain}, must be an int")
            gain = float(gain)
            if not 0 <= gain <= 1:
                raise ValueError(
                    f"Invalid gain {gain}, must be between 0 and 1 (inclusive)."
                )

        if read_position is not None and read_position not in self.READ_POSITIONS:
            raise ValueError(
                f"Invalid read_position {read_position}, must be in "
github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
"""
        Helper method for validating shake params.
        """
        if duration is not None:
            duration = parse_unit(duration, "second")

        if frequency is not None:
            frequency = parse_unit(frequency, "hertz")

        if path and path not in self.SHAKE_PATHS:
            raise ValueError(
                f"Invalid read_position {path}, must be in {self.SHAKE_PATHS}."
            )

        if amplitude is not None:
            amplitude = parse_unit(amplitude, "millimeter")

        params = {
            "duration": duration,
            "frequency": frequency,
            "path": path,
            "amplitude": amplitude,
        }

        params = {k: v for k, v in params.items() if v is not None}

        return params
github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
f"{reference} does not support detection"
            )

        method = detection.get("method")
        duration = detection.get("duration")
        threshold = detection.get("threshold")
        fallback = detection.get("fallback")

        if method is not None and method not in self.z_detection_methods:
            raise ValueError(
                f"detection_method must be one of {self.z_detection_methods} "
                f"but {method} was specified"
            )

        if duration is not None:
            duration = parse_unit(duration, "s")

        if threshold is not None:
            threshold = parse_unit(threshold, ["pascal", "farad"])

        if fallback is not None:
            fallback = self.position_z(**fallback)

        detection["method"] = method
        detection["duration"] = duration
        detection["threshold"] = threshold
        detection["fallback"] = fallback

        return {
            "reference": reference,
            "offset": offset,
            "move_rate": move_rate,
github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
filters (using shortpass/longpass) or monochromators (using ideal)

        Parameters
        ----------
        shortpass : Unit, str, optional
        longpass : Unit, str, optional
        ideal : Unit, str, optional

        Returns
        -------
        dict
            Wavelength selection parameters.
        """

        selection = {
            "shortpass": parse_unit(shortpass, "nanometer") if shortpass else None,
            "longpass": parse_unit(longpass, "nanometer") if longpass else None,
            "ideal": parse_unit(ideal, "nanometer") if ideal else None,
        }

        selection = {k: v for k, v in selection.items() if v is not None}

        return selection
github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
ValueError
            if mobile phase solvent and resource_id not included
        TypeError
            if `resource_id` is not a string
        ValueError
            if `settle_time` is not positive
        ValueError
            if `processing_time` is not positive

        """
        volume = parse_unit(volume, "milliliter")
        settle_time = parse_unit(settle_time, "second")
        if settle_time <= Unit(0, "second"):
            raise ValueError(f"settle_time: {settle_time} is not positive")

        processing_time = parse_unit(processing_time, "second")
        if processing_time <= Unit(0, "second"):
            raise ValueError(f"processing_time: {processing_time} is not " "positive")

        flow_pressure = parse_unit(flow_pressure, "bar")
        if flow_pressure <= Unit(0, "bar"):
            raise ValueError(f"flow_pressure: {flow_pressure} must be " f"positive.")
        loading_flowrate = parse_unit(loading_flowrate, "ul/s")

        if not is_sample:
            if not resource_id:
                raise ValueError(
                    "A 'resource_id' must be included " "for mobile_phase_params."
                )
            if not isinstance(resource_id, str):
                raise TypeError("'resource_id' {} must be a string")
        if is_elute:
github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
Target flowrate
        initial : Unit or str, optional
            Initial flowrate
        cutoff : Unit or str, optional
            Cutoff flowrate
        acceleration : Unit or str, optional
            Volumetric acceleration for initial to target (in ul/s^2)
        deceleration : Unit or str, optional
            Volumetric deceleration for target to cutoff (in ul/s^2)

        Returns
        -------
        dict
            flowrate parameters for a LiquidHandle instruction
        """
        target = parse_unit(target, "ul/s")
        if initial is not None:
            initial = parse_unit(initial, "ul/s")
        if cutoff is not None:
            cutoff = parse_unit(cutoff, "ul/s")
        if acceleration is not None:
            acceleration = parse_unit(acceleration, "ul/s/s")
        if deceleration is not None:
            deceleration = parse_unit(deceleration, "ul/s/s")

        return {
            "target": target,
            "initial": initial,
            "cutoff": cutoff,
            "acceleration": acceleration,
            "deceleration": deceleration,
        }
github autoprotocol / autoprotocol-python / autoprotocol / builders.py View on Github external
Returns
        -------
        dict
            A dict of `collection_condition` parameters.
        """
        if not isinstance(rinse_cycles, int):
            raise TypeError("rinse_cycles must be of type int.")

        if not isinstance(mix_cycles, int):
            raise TypeError("mix_cycles must be of type int.")

        acquisition_volume = parse_unit(acquisition_volume, "ul")
        wait_time = parse_unit(wait_time, "s")
        mix_volume = parse_unit(mix_volume, "ul")
        flowrate = parse_unit(flowrate, "ul/min")

        if stop_criteria is None:
            stop_criteria = self.stop_criteria(volume=acquisition_volume)
        else:
            stop_criteria = self.stop_criteria(**stop_criteria)

        return {
            "acquisition_volume": acquisition_volume,
            "flowrate": flowrate,
            "stop_criteria": stop_criteria,
            "wait_time": wait_time,
            "mix_cycles": mix_cycles,
            "mix_volume": mix_volume,
            "rinse_cycles": rinse_cycles,
        }