예제 #1
0
        def get_log_point(self, which='next', units=None):
            """
            Get a log data point from the instrument.

            :param str which: Which data point you want. Valid examples
                include ``first``, and ``next``. Consult the instrument
                manual for the complete list
            :param units: Units to attach to the returned data point. If left
                with the value of `None` then the instrument will be queried
                for the current units setting.
            :type units: `~quantities.UnitQuantity`
            :return: The log data point with units
            :rtype: `~quantities.Quantity`
            """
            if units is None:
                units = self.units

            point = [
                s.strip() for s in
                self._ctc.query(
                    'getLog.xy {}, {}'.format(self._chan_name, which)
                ).split(',')
            ]
            return u.Quantity(float(point[0]), 'ms'), \
                   u.Quantity(float(point[1]), units)
def test_lakeshore475_control_slope_limit():
    """
    Get / set slope limit, unitful and not.
    """
    with expected_protocol(
            ik.lakeshore.Lakeshore475,
            [
                "CPARAM?",
                "UNIT?",
                "CPARAM?",
                "UNIT?",
                "UNIT?",
                "CPARAM 1.0,10.0,42.0,42.0",
                "CPARAM?",
                "UNIT?",
                "UNIT?",
                "CPARAM 1.0,10.0,42.0,42.0",
            ],
            [
                "+1.0E+0,+1.0E+1,+4.2E+1,+1.0E+2",
                "2",  # teslas
                "+1.0E+0,+1.0E+1,+4.2E+1,+1.0E+2",
                "2",  # teslas
                "2",
                "+1.0E+0,+1.0E+1,+4.2E+1,+1.0E+2",
                "2",
                "2"
            ],
    ) as lsh:
        assert lsh.control_slope_limit == u.Quantity(100.0, u.V / u.min)
        lsh.control_slope_limit = u.Quantity(42000.0, u.mV / u.min)
        lsh.control_slope_limit = 42.0
def test_apt_mc_motion_timeout(init_kdc101):
    """Set and get motion timeout."""
    with expected_protocol(ik.thorlabs.APTMotorController, [init_kdc101[0]],
                           [init_kdc101[1]],
                           sep="") as apt:
        apt.channel[0].motion_timeout = u.Quantity(100, u.s)
        assert apt.channel[0].motion_timeout == u.Quantity(100, u.s)
예제 #4
0
def test_srsdg645_trigger_source():
    with expected_protocol(ik.srs.SRSDG645, "DLAY?2\nDLAY 3,2,60.0\n",
                           "0,42\n") as ddg:
        ref, t = ddg.channel["A"].delay
        assert ref == ddg.Channels.T0
        assert abs((t - u.Quantity(42, "s")).magnitude) < 1e5
        ddg.channel["B"].delay = (ddg.channel["A"], u.Quantity(1, "minute"))
def test_maui_time_div(init):
    """Get / Set time per division."""
    with expected_protocol(ik.teledyne.MAUI, [init, 'TDIV?', 'TDIV 0.001'],
                           ['1'],
                           sep="\n") as osc:
        assert osc.time_div == u.Quantity(1, u.s)
        osc.time_div = u.Quantity(1, u.ms)
예제 #6
0
        def get_log(self):
            """
            Gets all of the log data points currently saved in the instrument
            memory.

            :return: Tuple of all the log data points. First value is time,
                second is the measurement value.
            :rtype: Tuple of 2x `~quantities.Quantity`, each comprised of
                a numpy array (`numpy.dnarray`).
            """
            # Remember the current units.
            units = self.units

            # Find out how many points there are.
            n_points = int(
                self._ctc.query('getLog.xy? {}'.format(self._chan_name)))

            # Make an empty quantity that size for the times and for the channel
            # values.
            ts = u.Quantity(np.empty((n_points, )), 'ms')
            temps = u.Quantity(np.empty((n_points, )), units)

            # Reset the position to the first point, then save it.
            # pylint: disable=protected-access
            with self._ctc._error_checking_disabled():
                ts[0], temps[0] = self.get_log_point('first', units)
                for idx in range(1, n_points):
                    ts[idx], temps[idx] = self.get_log_point('next', units)

            # Do an actual error check now.
            if self._ctc.error_check_toggle:
                self._ctc.errcheck()

            return ts, temps
def test_maui_trigger_delay(init):
    """Get / Set trigger delay."""
    with expected_protocol(ik.teledyne.MAUI,
                           [init, 'TRDL?', 'TRDL 0.001', 'TRDL 1'], ['0.001'],
                           sep="\n") as osc:
        assert osc.trigger_delay == u.Quantity(1, u.ms)
        osc.trigger_delay = u.Quantity(1, u.ms)
        osc.trigger_delay = 1
예제 #8
0
def test_srsdg645_burst_period():
    """
        SRSDG645: Checks getting/setting of enabling T0 output on first
        in burst mode.
        """
    with expected_protocol(ik.srs.SRSDG645, ["BURP?", "BURP 13"],
                           ["100E-9"]) as ddg:
        unit_eq(ddg.burst_period, u.Quantity(100, "ns").rescale(u.s))
        ddg.burst_period = u.Quantity(13, "s")
예제 #9
0
def test_srsdg645_burst_delay():
    """
        SRSDG645: Checks getting/setting of enabling T0 output on first
        in burst mode.
        """
    with expected_protocol(ik.srs.SRSDG645, ["BURD?", "BURD 42"],
                           ["0"]) as ddg:
        unit_eq(ddg.burst_delay, u.Quantity(0, "s"))
        ddg.burst_delay = u.Quantity(42, "s")
def test_maui_channel_scale(init):
    """Get / Set MAUI Channel scale."""
    with expected_protocol(ik.teledyne.MAUI,
                           [init, 'C2:VDIV?', 'C1:VDIV 2.0', 'C2:VDIV 0.4'],
                           ['1'],
                           sep="\n") as osc:
        assert osc.channel[1].scale == u.Quantity(1, u.V)
        osc.channel[0].scale = u.Quantity(2000, u.mV)
        osc.channel[1].scale = 0.4
def test_maui_channel_offset(init):
    """Get / Set MAUI Channel offset."""
    with expected_protocol(ik.teledyne.MAUI,
                           [init, 'C1:OFST?', 'C1:OFST 0.2', 'C3:OFST 2'],
                           ['1'],
                           sep="\n") as osc:
        assert osc.channel[0].offset == u.Quantity(1, u.V)
        osc.channel[0].offset = u.Quantity(200, u.mV)
        osc.channel[2].offset = 2
def test_unitful_property_sendcmd_query(mock_inst):
    """Assert that unitful_property calls sendcmd, query of parent class."""
    # getter
    assert mock_inst.unitful_property == u.Quantity(42, u.K)
    mock_inst.spy_query.assert_called()
    # setter
    value = 13
    mock_inst.unitful_property = u.Quantity(value, u.K)
    assert mock_inst._sendcmd == f"42 {value:e}"
    mock_inst.spy_sendcmd.assert_called()
def test_channel_get_log(channel):
    """Get the full log of a channel.

    Leave error checking activated, because it is run at the end.
    """
    # make some data
    times = [0, 1, 2, 3]
    values = [1.3, 2.4, 3.5, 4.6]

    # variables
    units = ik.srs.SRSCTC100._UNIT_NAMES[ch_name_unit_dict[channel]]
    n_points = len(values)

    # strings for error checking, sending and receiving
    err_check_send = "geterror?"
    err_check_reci = "0,NO ERROR"

    # stich together strings to read all the values
    str_log_next_send = "\n".join(
        [f"getLog.xy {channel}, next" for it in range(1, n_points)])
    str_log_next_reci = "\n".join(
        [f"{times[it]},{values[it]}" for it in range(1, n_points)])

    # make data to compare with
    ts = u.Quantity(np.empty((n_points, )), u.ms)
    temps = u.Quantity(np.empty((n_points, )), units)
    for it, time in enumerate(times):
        ts[it] = u.Quantity(time, u.ms)
        temps[it] = u.Quantity(values[it], units)

    with expected_protocol(
            ik.srs.SRSCTC100,
        [
            ch_names_query,
            err_check_send,
            "getOutput.units?",
            err_check_send,
            ch_names_query,
            err_check_send,
            f"getLog.xy? {channel}",
            err_check_send,
            f"getLog.xy {channel}, first",  # query first point
            str_log_next_send,
            err_check_send
        ],
        [
            ch_names_str, err_check_reci, ",".join(ch_units), err_check_reci,
            ch_names_str, err_check_reci, f"{n_points}", err_check_reci,
            f"{times[0]},{values[0]}", str_log_next_reci, err_check_reci
        ]) as inst:
        ch = inst.channel[channel]
        ts_read, temps_read = ch.get_log()
        # assert the data is correct
        np.testing.assert_equal(ts, ts_read)
        np.testing.assert_equal(temps, temps_read)
def test_channel_offset(channel, val_read, val_unitless, val_millivolt):
    """Get / set offset."""
    val_read = u.Quantity(val_read, u.V)
    val_unitful = u.Quantity(val_millivolt, u.mV)
    with expected_protocol(ik.tektronix.TekAWG2000, [
            f"FG:CH{channel+1}:OFFS?", f"FG:CH{channel+1}:OFFS {val_unitless}",
            f"FG:CH{channel+1}:OFFS {val_unitful.rescale(u.V).magnitude}"
    ], [f"{val_read.magnitude}"]) as inst:
        assert inst.channel[channel].offset == val_read
        inst.channel[channel].offset = val_unitless
        inst.channel[channel].offset = val_unitful
예제 #15
0
def test_yaml_quantity_tag():
    yaml_data = StringIO(u"""
a:
    b: !Q 37 tesla
    c: !Q 41.2 inches
    d: !Q 98
""")
    data = yaml.load(yaml_data, Loader=yaml.Loader)
    assert data['a']['b'] == u.Quantity(37, 'tesla')
    assert data['a']['c'] == u.Quantity(41.2, 'inches')
    assert data['a']['d'] == 98
def test_channel_frequency(channel, val_read, val_unitless, val_kilohertz):
    """Get / set offset."""
    val_read = u.Quantity(val_read, u.Hz)
    val_unitful = u.Quantity(val_kilohertz, u.kHz)
    with expected_protocol(ik.tektronix.TekAWG2000, [
            f"FG:FREQ?", f"FG:FREQ {val_unitless}HZ",
            f"FG:FREQ {val_unitful.rescale(u.Hz).magnitude}HZ"
    ], [f"{val_read.magnitude}"]) as inst:
        assert inst.channel[channel].frequency == val_read
        inst.channel[channel].frequency = val_unitless
        inst.channel[channel].frequency = val_unitful
def test_get_log_point_with_unit():
    """Get a log point and include a unit query."""
    channel = ch_names[0]
    unit = ik.srs.SRSCTC100._UNIT_NAMES[ch_units[0]]
    values = (13, 42)
    which = "first"
    values_out = (u.Quantity(float(values[0]),
                             u.ms), u.Quantity(float(values[1]), unit))
    with expected_protocol(ik.srs.SRSCTC100,
                           [ch_names_query, f"getLog.xy {channel}, {which}"],
                           [ch_names_str, f"{values[0]},{values[1]}"]) as inst:
        with inst._error_checking_disabled():
            assert (inst.channel[channel].get_log_point(
                which=which, units=unit) == values_out)
def test_maui_math_op_derivative(init):
    """Set math channel, derivative operator."""
    with expected_protocol(ik.teledyne.MAUI, [
            init, "F1:DEFINE EQN,'DERI(C1)',VERSCALE,1000000.0,"
            "VEROFFSET,0,ENABLEAUTOSCALE,ON",
            "F1:DEFINE EQN,'DERI(C3)',VERSCALE,5.0,"
            "VEROFFSET,1.0,ENABLEAUTOSCALE,OFF"
    ], [],
                           sep="\n") as osc:
        osc.math[0].operator.derivative(0)
        osc.math[0].operator.derivative(2,
                                        vscale=u.Quantity(5000, u.mV / u.s),
                                        voffset=u.Quantity(60, u.V / u.min),
                                        autoscale=False)
def test_apt_mc_position_encoder(init_kdc101):
    """Get unitful position of encoder, in counts."""
    with expected_protocol(
            ik.thorlabs.APTMotorController,
        [
            init_kdc101[0],
            ThorLabsPacket(  # read position
                message_id=ThorLabsCommands.MOT_REQ_ENCCOUNTER,
                param1=0x01,
                param2=0x00,
                dest=0x50,
                source=0x01,
                data=None).pack()
        ],
        [
            init_kdc101[1],
            ThorLabsPacket(message_id=ThorLabsCommands.MOT_GET_ENCCOUNTER,
                           param1=None,
                           param2=None,
                           dest=0x50,
                           source=0x01,
                           data=struct.pack('<Hl', 0x01, -20000)).pack()
        ],
            sep="") as apt:
        assert apt.channel[0].position_encoder == u.Quantity(-20000, 'counts')
예제 #20
0
 def burst_period(self):
     """
     Gets/sets the burst period. The burst period sets the time
     between delay cycles during a burst. The burst period may
     range from 100 ns to 2000 – 10 ns in 10 ns steps.
     """
     return u.Quantity(float(self.query("BURP?")), u.s)
예제 #21
0
def test_cc1_dwell_new_firmware():
    with expected_protocol(ik.qubitekk.CC1,
                           [":ACKN OF", "FIRM?", "DWEL?", ":DWEL 2"],
                           ["", "Firmware v2.010", "8"],
                           sep="\n") as cc:
        unit_eq(cc.dwell_time, u.Quantity(8, "s"))
        cc.dwell_time = 2
예제 #22
0
def test_cc1_dwell_old_firmware():
    with expected_protocol(ik.qubitekk.CC1,
                           [":ACKN OF", "FIRM?", "DWEL?", ":DWEL 2"],
                           ["Unknown Command", "Firmware v2.001", "8000", ""],
                           sep="\n") as cc:
        unit_eq(cc.dwell_time, u.Quantity(8, "s"))
        cc.dwell_time = 2
예제 #23
0
def test_cc1_delay():
    with expected_protocol(ik.qubitekk.CC1,
                           [":ACKN OF", "FIRM?", "DELA?", ":DELA 2"],
                           ["", "Firmware v2.010", "8", ""],
                           sep="\n") as cc:
        unit_eq(cc.delay, u.Quantity(8, "ns"))
        cc.delay = 2
예제 #24
0
        def max_travel(self):
            """
            Gets the maximum travel for the specified piezo channel.

            :type: `~quantities.Quantity`
            :units: Nanometers
            """
            pkt = _packets.ThorLabsPacket(
                message_id=_cmds.ThorLabsCommands.PZ_REQ_MAXTRAVEL,
                param1=self._idx_chan,
                param2=0x00,
                dest=self._apt.destination,
                source=0x01,
                data=None)
            resp = self._apt.querypacket(pkt)

            # Not all APT piezo devices support querying the maximum travel
            # distance. Those that do not simply ignore the PZ_REQ_MAXTRAVEL
            # packet, so that the response is empty.
            if resp is None:
                return NotImplemented

            # chan, int_maxtrav
            _, int_maxtrav = struct.unpack('<HH', resp.data)
            return int_maxtrav * u.Quantity(100, 'nm')
예제 #25
0
 def burst_delay(self):
     """
     Gets/sets the burst delay. When burst mode is enabled the DG645
     delays the first burst pulse relative to the trigger by the
     burst delay. The burst delay may range from 0 ps to < 2000 s
     with a resolution of 5 ps.
     """
     return u.Quantity(float(self.query("BURD?")), u.s)
예제 #26
0
    def holdoff(self):
        """
        Gets/sets the trigger holdoff time.

        :type: `~quantities.Quantity` or `float`
        :units: As passed, or s if not specified.
        """
        return u.Quantity(float(self.query("HOLD?")), u.s)
예제 #27
0
    def trigger_rate(self):
        """
        Gets/sets the rate of the internal trigger.

        :type: `~quantities.Quantity` or `float`
        :units: As passed or Hz if not specified.
        """
        return u.Quantity(float(self.query("TRAT?")), u.Hz)
예제 #28
0
        def std_dev(self):
            """
            Gets the standard deviation for the specified channel as determined
            by the statistics gathering.

            :type: `~quantities.Quantity`
            """
            return u.Quantity(float(self._get('SD')), self.units)
예제 #29
0
        def average(self):
            """
            Gets the average measurement for the specified channel as
            determined by the statistics gathering.

            :type: `~quantities.Quantity`
            """
            return u.Quantity(float(self._get('average')), self.units)
예제 #30
0
def test_lcc25_voltage2():
    with expected_protocol(ik.thorlabs.LCC25, [
            "volt2?",
            "volt2=10.0",
    ], ["volt2?", "20", ">volt2=10.0", ">"],
                           sep="\r") as lcc:
        unit_eq(lcc.voltage2, u.Quantity(20, "V"))
        lcc.voltage2 = 10.0