def test_Instrument_Initialization():
    Instr = Instrument()

    wedge = Wedge.Wedge(position=(0.5, 0, 0), concept='ManyToMany')
    pixels = 33
    split = [12]
    Det = Detector.TubeDetector1D(position=(1.0, 1, 0),
                                  direction=(1, 0, 0),
                                  pixels=pixels,
                                  split=split)
    Ana = Analyser.FlatAnalyser(position=(0.5, 0, 0), direction=(1, 0, 1))

    wedge.append([Det, Det, Ana, Ana, Ana])

    try:
        Instr.initialize()
        assert False
    except ValueError:
        assert True

    try:
        print(Instr.A4)
        assert False
    except RuntimeError:
        assert True

    try:
        print(Instr.Ef)
        assert False
    except RuntimeError:
        assert True

    Instr.append(wedge)
    try:
        Instr.initialize()
        assert False
    except ValueError:
        assert True
    Instr.wedges[0].detectors[0].split = [0, 12, 20, pixels]
    Instr.initialize()

    assert (len(Instr.A4) == 1)
    assert (len(Instr.A4[0]) == 2)
    assert (len(Instr.A4[0][0]) == pixels)
    assert (len(Instr.A4) == len(Instr.Ef))
    assert (len(Instr.A4[0]) == len(Instr.Ef[0]))
    assert (len(Instr.A4[0][0]) == len(Instr.Ef[0][0]))
    assert (Instr.settings['Initialized'] == True)

    try:
        Instr.A4 = []
        assert False
    except NotImplementedError:
        assert True

    try:
        Instr.Ef = []
        assert False
    except NotImplementedError:
        assert True
Example #2
0
def test_Normalization_tables(quick):

    Instr = Instrument(fileName=os.path.join('Data', 'CAMEA_Updated.xml'))
    Instr.initialize()

    NF = os.path.join(dataPath, 'camea2018n000038.hdf')
    #AF = 'TestData/1024/A4Normalization.h5'

    try:
        Instr.generateCalibration(Vanadiumdatafile=NF,
                                  savelocation=os.path.join(dataPath, ''),
                                  plot=False,
                                  tables=[])  # No binning specified
        assert False
    except AttributeError:
        assert True

    try:
        Instr.generateCalibration(Vanadiumdatafile=NF,
                                  savelocation=os.path.join(dataPath, ''),
                                  plot=False,
                                  tables=['Nothing?'])  # Wrong binning
        assert False
    except AttributeError:
        assert True

    if not quick == True:
        Instr.generateCalibration(Vanadiumdatafile=NF,
                                  savelocation=os.path.join(dataPath, ''),
                                  plot=False,
                                  tables=[1, 3, 8],
                                  sampleMass=4.7)
    else:
        Instr.generateCalibration(Vanadiumdatafile=NF,
                                  savelocation=os.path.join(dataPath, ''),
                                  plot=False,
                                  tables=[1],
                                  sampleMass=4.7)