def test_DataFile():
    try:
        DF = DataFile('/nope.txt')
        assert False
    except:
        assert True

    try:
        DF = DataFile(os.path.join(dataPath, 'CAMEA_Full.xml'))  # Wrong file
        assert False
    except:
        assert True

    files = [
        os.path.join(dataPath, 'camea2018n000137.hdf'),
        os.path.join(dataPath, 'camea2018n000137.nxs')
    ]
    DF1 = DataFile(files[0])
    assertFile(files[1])
    DF2 = DataFile(files[1])
    s = str(DF2)
    sampleS = str(DF2.sample)
    print(str(DF1.sample))
    print(str(DF2.sample))
    assert (DF1.sample == DF2.sample)
예제 #2
0
def test_DataFile_ScanParameter():

    files = [
        os.path.join(dataPath, 'camea2018n000136.hdf'),
        os.path.join(dataPath, 'camea2018n000136.nxs')
    ]
    assertFile(files[1])
    for file in files:
        dfile = DataFile(file)
        assert (dfile.scanParameters[0] == 'rotation_angle')
        assert (len(dfile.scanParameters) == len(dfile.scanUnits))
        assert (len(dfile.scanParameters) == len(dfile.scanValues))
        assert (len(dfile.scanParameters) == 1)
        assert (dfile.scanUnits[0] == 'degree')
예제 #3
0
def test_DataFile_SaveLoad():
    df = DataFile(os.path.join(dataPath, 'camea2018n000136.hdf'))
    df.saveHDF(os.path.join(dataPath, 'camea2018n000136_2.hdf'))
    df2 = DataFile(os.path.join(dataPath, 'camea2018n000136_2.hdf'))
    failed = []

    for att, val in df.__dict__.items():
        if att in ['name',
                   'fileLocation']:  # Name and location are to be different
            continue
        if isinstance(val, np.ndarray):
            if val.dtype == 'O':
                continue
            try:
                test = np.all(np.isclose(val, getattr(df2, att)))
            except:
                test = np.all(val == getattr(df2, att))
        else:
            test = val == getattr(df2, att)
        if not test:
            failed.append(att)
    print(failed)
    assert (len(failed) == 0)
    os.remove(df2.fileLocation)
예제 #4
0
def test_DataFile_equility():
    f1 = DataFile(os.path.join(dataPath, 'camea2018n000136.hdf'))
    print('----------')
    f2 = DataFile(os.path.join(dataPath, 'camea2018n000136.hdf'))
    assert (f1 == f2)
    print('----------')
    f3 = DataFile(f2)
    assert (f1 == f3)
    print('----------')
    f4 = DataFile(os.path.join(dataPath, 'camea2018n000137.hdf'))
    assert (f1 != f4)
    f5 = f2.convert(binning=8)
    f5.saveNXsqom(os.path.join(dataPath, 'camea2018n000136.nxs'))
    f3 = DataFile(os.path.join(dataPath, 'camea2018n000136.nxs'))
    assert (f1 == f3)
    print('----------')
예제 #5
0
def test_DataFile_plotA4():
    plt.ioff()
    import matplotlib
    #matplotlib.use('Agg')
    fileName = os.path.join(dataPath, 'camea2018n000136.hdf')
    fileName2 = os.path.join(dataPath, 'camea2018n000136.nxs')
    file = DataFile(fileName)

    try:
        file.plotA4(binning=20)  # Binning not found in data file
        assert False
    except AttributeError:
        assert True

    fig = file.plotA4(1)
    fig2 = file.plotA4()
    assertFile(fileName2)
    file2 = DataFile(fileName2)
    try:
        file2.plotA4(binning=20)  # Binning not found in data file
        assert False
    except AttributeError:
        assert True

    file2.plotA4(binning=1)
    plt.close('all')
예제 #6
0
def test_updateCalibration():
    calibFiles = [
        os.path.join('Data', 'Normalization80_1.calib'),
        os.path.join('Data', 'Normalization80_3.calib'),
        os.path.join('Data', 'Normalization80_5.calib')
    ]

    df = DataFile(os.path.join(dataPath, 'camea2018n000136.hdf'))
    print(df.I)
    print('----------------------')
    df.loadBinning(1)

    binnings = df.possibleBinnings  # is 1,3,8
    edges = df.instrumentCalibrationEdges

    df.updateCalibration(calibFiles)

    df.loadBinning(1)
    newBinnings = df.possibleBinnings  # is 1,3,8,5
    newEdges = df.instrumentCalibrationEdges
    assert (len(newBinnings) != len(binnings))  # Addition of binning 5
    assert (not np.any(newEdges != edges))  # Check if all elemenst are equal

    df.updateCalibration(calibFiles, overwrite=True)
    df.loadBinning(1)

    newEdges = df.instrumentCalibrationEdges
    assert (np.any(newEdges != edges))  # Check if all elemenst are equal
예제 #7
0
def test_DataFile_Error():
    df = DataFile(os.path.join(dataPath, 'camea2018n000136.hdf'))

    # Not implimented
    try:
        df + df
        assert False
    except NotImplementedError:
        assert True

    df.instrument = 'WrongInstrument'
    try:
        df.convert(binning=1)
        assert False
    except AttributeError:
        assert True

    df2 = DataFile(os.path.join(dataPath, 'camea2018n000136.nxs'))
    try:
        df.saveNXsqom(os.path.join(dataPath, 'saving.nxs'))
        assert False
    except AttributeError:  # File does not have original_file attribute
        assert True

    df2.type = 'WrongType'
    try:
        df2.saveNXsqom(os.path.join(dataPath, 'saving.nxs'))
        assert False
    except AttributeError:  # Manually change type to wrong
        assert True