예제 #1
0
def test_iterate_channels():
    detector_class = build_detector_class(channel_numbers=(3, 5),
                                          mcaroi_numbers=(4, 6))
    detector = detector_class(prefix="Xsp3:", name="xs3")

    channel_list = list(detector.iterate_channels())
    assert len(channel_list) == 2
예제 #2
0
def test_mcaroi_numbers():
    detector_class = build_detector_class(channel_numbers=(3, 5),
                                          mcaroi_numbers=(4, 6))
    detector = detector_class(prefix="Xsp3:", name="xs3")

    assert detector.get_channel(channel_number=3).mcaroi_numbers == (4, 6)
    assert detector.get_channel(channel_number=5).mcaroi_numbers == (4, 6)
예제 #3
0
def test_get_channel():
    detector_class = build_detector_class(channel_numbers=(3, 5),
                                          mcaroi_numbers=(4, 6))
    detector = detector_class(prefix="Xsp3:", name="xs3")

    channel03 = detector.get_channel(channel_number=3)
    assert channel03.mcarois.mcaroi04.total_rbv.pvname == "Xsp3:MCA3ROI:4:Total_RBV"

    channel05 = detector.get_channel(channel_number=5)
    assert channel05.mcarois.mcaroi06.total_rbv.pvname == "Xsp3:MCA5ROI:6:Total_RBV"

    with pytest.raises(
            ValueError,
            match=re.escape(
                "no channel on detector with prefix 'Xsp3:' has number 2"),
    ):
        detector.get_channel(channel_number=2)

    with pytest.raises(
            ValueError,
            match=re.escape("channel number '4.0' is not an integer"),
    ):
        detector.get_channel(channel_number=4.0)

    with pytest.raises(
            ValueError,
            match=re.escape(
                "channel number '0' is outside the allowed interval [1,16]"),
    ):
        detector.get_channel(channel_number=0)
예제 #4
0
def test_instantiate_detector_class():
    """
    Leave the verification of channel attributes to the previous test,
    focus on PV names here.
    """

    # use this to test detector_parent_classes
    class AnotherParentClass:
        pass

    detector_class = build_detector_class(
        channel_numbers=(14, 15, 16),
        mcaroi_numbers=(47, 48),
        detector_parent_classes=(
            Xspress3Detector,
            AnotherParentClass,
        ),
    )
    assert Xspress3Detector in detector_class.__mro__
    assert AnotherParentClass in detector_class.__mro__

    detector = detector_class(prefix="Xsp3:", name="xs3")

    assert (
        detector.__repr__() == "GeneratedXspress3Detector(channels=("
        "GeneratedXspress3Channel(channel_number=14, mcaroi_numbers=(47, 48)),"
        "GeneratedXspress3Channel(channel_number=15, mcaroi_numbers=(47, 48)),"
        "GeneratedXspress3Channel(channel_number=16, mcaroi_numbers=(47, 48))))"
    )

    assert (detector.channels.channel14.sca.clock_ticks.pvname ==
            "Xsp3:C14SCA:0:Value_RBV")
    assert (detector.channels.channel14.mca_sum.array_data.pvname ==
            "Xsp3:MCASUM14:ArrayData")
    assert detector.channels.channel14.mca.array_data.pvname == "Xsp3:MCA14:ArrayData"
    assert (detector.channels.channel14.mcarois.mcaroi47.total_rbv.pvname ==
            "Xsp3:MCA14ROI:47:Total_RBV")
    assert (detector.channels.channel14.mcarois.mcaroi48.total_rbv.pvname ==
            "Xsp3:MCA14ROI:48:Total_RBV")

    assert (detector.channels.channel15.sca.clock_ticks.pvname ==
            "Xsp3:C15SCA:0:Value_RBV")
    assert (detector.channels.channel15.mca_sum.array_data.pvname ==
            "Xsp3:MCASUM15:ArrayData")
    assert detector.channels.channel15.mca.array_data.pvname == "Xsp3:MCA15:ArrayData"
    assert (detector.channels.channel15.mcarois.mcaroi47.total_rbv.pvname ==
            "Xsp3:MCA15ROI:47:Total_RBV")
    assert (detector.channels.channel15.mcarois.mcaroi48.total_rbv.pvname ==
            "Xsp3:MCA15ROI:48:Total_RBV")

    assert (detector.channels.channel16.sca.clock_ticks.pvname ==
            "Xsp3:C16SCA:0:Value_RBV")
    assert (detector.channels.channel16.mca_sum.array_data.pvname ==
            "Xsp3:MCASUM16:ArrayData")
    assert detector.channels.channel16.mca.array_data.pvname == "Xsp3:MCA16:ArrayData"
    assert (detector.channels.channel16.mcarois.mcaroi47.total_rbv.pvname ==
            "Xsp3:MCA16ROI:47:Total_RBV")
    assert (detector.channels.channel16.mcarois.mcaroi48.total_rbv.pvname ==
            "Xsp3:MCA16ROI:48:Total_RBV")
예제 #5
0
def test_extra_class_members_failure():
    """
    Do not specify an extra class member with the same
    name as one of the detector class members.
    """
    with pytest.raises(TypeError):
        detector_class = build_detector_class(
            channel_numbers=(3, 5),
            mcaroi_numbers=(4, 6),
            extra_class_members={
                "get_channel_count": 10,
            },
        )
예제 #6
0
def test_extra_class_members():
    detector_class = build_detector_class(
        channel_numbers=(3, 5),
        mcaroi_numbers=(4, 6),
        extra_class_members={
            "ten": 10,
            "a_signal": Component(Signal, value=0)
        },
    )

    assert detector_class.ten == 10
    assert isinstance(detector_class.a_signal, Component)

    detector = detector_class(prefix="Xsp3:", name="xs3")

    assert detector.ten == 10
    assert isinstance(detector.a_signal, Signal)
    assert detector.a_signal.get() == 0
예제 #7
0
def test_build_detector_class():
    """
    Verify all channel Components are present.
    """
    detector_class = build_detector_class(channel_numbers=(1, 2, 3),
                                          mcaroi_numbers=(4, 5))
    assert Xspress3Detector in detector_class.__mro__
    assert hasattr(detector_class, "channels")

    # there should be 3 channel attributes: channel01, channel02, channel03
    expected_channel_attr_names = {
        f"channel{channel_i:02d}"
        for channel_i in (1, 2, 3)
    }

    channel_attr_name_re = re.compile(r"channel\d{2}")
    # there should be no other channel_n attributes
    all_channel_attr_names = {
        attr_name
        for attr_name in detector_class.channels.__dir__()
        if channel_attr_name_re.match(attr_name)
    }

    assert expected_channel_attr_names == all_channel_attr_names
        handle.write('# Facility.cycle: %s\n' % BMMuser.cycle)
        handle.write('# Facility.GUP: %d\n' % BMMuser.gup)
        handle.write('# Facility.SAF: %d\n' % BMMuser.saf)
        handle.write('# Column.1: energy (eV)\n')
        for c, mca_number in enumerate(column_list):
            handle.write(f'# Column.{c+2}: MCA{mca_number} (counts)\n')
        handle.write(
            '# ==========================================================\n')
        handle.write('# energy ')

        ## data table
        e = numpy.arange(0, len(
            self.channels.channel01.mca.array_data.get())) * 10
        mca_data_array_list = [
            channel.mca.array_data.get()
            for channel in self.iterate_channels()
        ]
        a = numpy.vstack(mca_data_array_list)
        b = pandas.DataFrame(a.transpose(), index=e, columns=column_list)
        handle.write(b.to_csv(sep=' '))

        handle.flush()
        handle.close()
        print(bold_msg('wrote XRF spectra to %s' % filename))


BMMXspress3Detector_4Element = build_detector_class(
    channel_numbers=(1, 2, 3, 4),
    mcaroi_numbers=range(1, 17),
    detector_parent_classes=(BMMXspress3Detector_4Element_Base, ))
예제 #9
0
def test_get_channel_count():
    detector_class = build_detector_class(channel_numbers=(3, 5),
                                          mcaroi_numbers=(4, 6))
    detector = detector_class(prefix="Xsp3:", name="xs3")

    assert detector.get_channel_count() == 2