Exemplo n.º 1
0
def Tester():
    import numpy as np
    import matplotlib.pyplot as plt
    from MJOLNIR import _tools
    from MJOLNIR.Data import DataSet
    # To generate a list of data files from nubers
    
    numbers = '457-458,460,461'
    files = _tools.fileListGenerator(numbers,'/home/lass/Dropbox/PhD/CAMEAData/',year=2018)
    
    ## Creating a non-linear distribution of points
    points = np.exp(np.linspace(-1,np.log(10),21))
    
    minimumBinSize = 1
    
    Bins = _tools.binEdges(points,minimumBinSize)
    
    fig,ax = plt.subplots()
    
    ax.scatter(points,np.ones_like(points),c='r',label='Data Points',zorder=2)
    [ax.plot([Bins[i],Bins[i]],[0.5,1.5],'k',zorder=1) for i in range(len(Bins))]
    ax.plot(np.concatenate([Bins,np.flip(Bins)]),np.concatenate([np.ones_like(Bins)*0.5,np.ones_like(Bins)*1.5]),c='k',label='Bins',zorder=1)    
    ax.set_xticks(np.linspace(0,10,11))
    ax.set_yticks([])
    ax.set_ylim(-1,3)
    ax.grid(True,c='k',zorder=0)
    fig.legend()
    fig.savefig('/home/lass/Dropbox/PhD/Software/MJOLNIR/docs/Tutorials/Tools/Binning.png',format='png',dpi=300)
Exemplo n.º 2
0
def test_Powder(show=False):
    import matplotlib.pyplot as plt
    file = 'Data/camea2018n000137.hdf'

    DataObj = DataSet.DataSet(dataFiles=file)
    DataObj.convertDataFile()
    I = DataObj.I
    qx = DataObj.qx
    qy = DataObj.qy
    energy = DataObj.energy
    Norm = DataObj.Norm
    Monitor = DataObj.Monitor

    EBinEdges = _tools.binEdges(energy, tolerance=0.125)

    ax, Data, qbins = DataObj.plotCutPowder(EBinEdges, qMinBin=0.05)
    plt.colorbar(ax.pmeshs[0])

    ax2, Data2, qbins2 = DataSet.plotCutPowder([qx, qy, energy],
                                               I,
                                               Norm,
                                               Monitor,
                                               EBinEdges,
                                               qMinBin=0.05)
    plt.colorbar(ax2.pmeshs[0])

    Data3, qbins3 = DataObj.cutPowder(EBinEdges)

    ax2.set_clim(0, 0.01)
    if show:
        plt.show()
    else:
        if os.path.exists('Data/camea2018n000137.nxs'):
            os.remove('Data/camea2018n000137.nxs')
Exemplo n.º 3
0
def test_DataSet_cutPowder():
    Tolerance = 0.01

    plt.ioff()
    import matplotlib
    matplotlib.use('Agg')

    convertFiles = [os.path.join(dataPath,'camea2018n000136.hdf')]
    
    Datset = DataSet(dataFiles = convertFiles)
    Datset.convertDataFile(saveFile=True)
    mask = np.ones_like(Datset.I.data)

    Datset.mask = mask
    Datset.mask = np.logical_not(mask)
    

    eBins = _tools.binEdges(Datset.energy,0.25)

    ax,D,q = Datset.plotCutPowder(eBins,Tolerance)# Remove to improve test ,vmin=0,vmax=1e-6)
    D2,q2 = Datset.cutPowder(eBins,Tolerance)
    assert(np.all(D.equals(D2)))

    for i in range(len(q)):
        for j in range(len(q[i])):
            assert(np.all(q[i][j]==q2[i][j]))
Exemplo n.º 4
0
def test_DataSet_binEdges():
    X = np.random.rand(100)*3 # array between 0 and 3 -ish
    X.sort()
    tolerance = 0.01
    Bins = _tools.binEdges(X,tolerance=tolerance)

    assert(Bins[0]==X[0]-0.1*tolerance)
    assert(np.isclose(Bins[-1],X[-1],atol=5) or Bins[-1]>X[-1])
    assert(len(Bins)<=3.0/tolerance)
    assert(np.all(np.diff(Bins[:-1])>tolerance*0.99))
Exemplo n.º 5
0
def test_cut2D(show=False):
    import numpy as np
    import matplotlib.pyplot as plt
    file = 'Data/camea2018n000137.hdf'
    DataObj = DataSet.DataSet(dataFiles=file)
    DataObj.convertDataFile()
    energy = DataObj.energy

    EnergyBins = _tools.binEdges(energy, tolerance=0.125)
    q1 = np.array([1.0, 0])
    q2 = np.array([0, 1.0])
    width = 0.1  # 1/A
    minPixel = 0.01

    ax, DataList, qBnLit, centerPos, binDIstance = DataObj.plotCutQE(
        q1, q2, width, minPixel, EnergyBins, rlu=False)
    plt.colorbar(ax.pmeshs[0])

    ax.set_clim(0, 10)
    plt.tight_layout()

    ## Cut and plot 1D
    ax2, DataList, Bins, binCenter, binDistance = DataObj.plotCut1D(
        q1,
        q2,
        width,
        minPixel,
        rlu=False,
        Emin=0.2,
        Emax=1.7,
        plotCoverage=True)
    if show:
        plt.show()
    else:
        if os.path.exists('Data/camea2018n000137.nxs'):
            os.remove('Data/camea2018n000137.nxs')
Exemplo n.º 6
0
def test_binEdges():
    values = np.exp(np.linspace(-0.1, 1, 101))  # Generate non-linear points
    #values[0]-tolerance/2.0 and ends at values[-1]+tolerance/2.0.
    minBin = 0.1
    bins = binEdges(values, minBin)

    assert (np.isclose(bins[0], values[0] - 0.1 * minBin)
            )  # First bin starts at values[0]-tolerance*0.1
    assert (bins[-1] >= values[-1] + 0.1 * minBin
            )  # Last bin ends at values[-1]+tolerance*0.1
    assert (np.all(np.diff(bins) >= minBin * 0.99)
            )  # Assert that all bins are at least of size minBin

    binsCut = binEdges(values, 0.01, startPoint=0.0)
    assert (binsCut[0] >= 0.0)

    binsCut = binEdges(values + np.min(values) + 0.0099,
                       0.01,
                       startPoint=0.0,
                       endPoint=0.5)
    assert (binsCut[0] >= 0.0)
    assert (binsCut[-1] <= 0.5)

    binsCut = binEdges(values + np.min(values) + 0.0101,
                       0.01,
                       startPoint=0.0,
                       endPoint=0.5)
    assert (binsCut[0] > 0.01)

    binsCut = binEdges(np.linspace(0, 0.95, 101),
                       0.01,
                       startPoint=0.0,
                       endPoint=1.0101)
    assert (binsCut[-1] <= 1.0)

    binsCut = binEdges(values - np.max(values) + 1.0,
                       0.01,
                       startPoint=0.0,
                       endPoint=1.01)
    assert (binsCut[-1] <= 1.01)
Exemplo n.º 7
0
def Tester():
    from MJOLNIR.Data import DataSet
    from MJOLNIR import _tools
    import numpy as np
    import matplotlib.pyplot as plt

    numbers = '483-489,494-500'
    fileList = _tools.fileListGenerator(numbers,
                                        '/home/lass/Dropbox/PhD/CAMEAData/',
                                        2018)

    ds = DataSet.DataSet(fileList)
    ds.convertDataFile(saveFile=False)

    # Define the positions to be cut through
    Q1 = np.array([0, 0, 0])
    Q2 = np.array([0, 0, 1])
    Q3 = np.array([-1, 0, 1])
    Q4 = np.array([-1, 0, -1])
    # Collect them into one array
    QPoints = np.array([Q1, Q2, Q3, Q4])

    # Define orthogonal width and minimum pixel size along Q-cut
    width = np.array([0.05, 0.03, 0.05])  # 1/AA
    minPixel = np.array([0.03, 0.01, 0.01])  # 1/AA

    # Define energy bins through the binEdges methods found in _tools
    Energies = np.concatenate(ds.energy, axis=0)
    EnergyBins = np.array([
        _tools.binEdges(Energies, 0.04),
        _tools.binEdges(Energies, 0.1),
        _tools.binEdges(Energies, 0.07)
    ])

    # Create figure into which the plot is made
    fig = plt.figure(figsize=(14, 6))
    ax = fig.gca()

    ax,DataLists,BinListTotal,centerPositionTotal,binDistanceTotal = \
    ds.plotCutQELine(QPoints=QPoints, width=width, minPixel=minPixel, \
                     ax=ax, EnergyBins=EnergyBins, ticks = 12,\
                     vmin=1e-8, vmax=1e-5, tickRound = 4, plotSeperator = True,
                     seperatorWidth=0.5,zorder=10)
    ax.grid(True, zorder=0, c='k')
    fig.savefig(
        '/home/lass/Dropbox/PhD/Software/MJOLNIR/docs/Tutorials/Advanced/plotCutQELineMnF2.png',
        format='png',
        dpi=300)

    # Plot a single cut through the data set

    fig2, ax2 = plt.subplots()
    segID = 2
    # Find all energies in segment
    E = np.array([x[0][-1] for x in centerPositionTotal[segID]])
    # Find index of energies corresponding to the list
    EnergyIndexes = [E.searchsorted(x) for x in np.linspace(1.5, 6.5, 5)]
    plot = 0
    for energyID in EnergyIndexes:
        # Extract data for segment 2 and current energy
        _dataList = DataLists[np.logical_and(
            DataLists['qCut'] == segID,
            DataLists['energyCut'] == energyID)].astype(float)

        Intensity = _dataList['Int'] * 1e5
        Intensity_err = np.divide(
            np.sqrt(_dataList['Intensity']) * _dataList['BinCount'],
            _dataList['Monitor'] * _dataList['Normalization'])

        position = _dataList['L']  # Plotting along L
        Energy = np.mean(_dataList['Energy'])

        ax2.errorbar(position,
                     Intensity + len(EnergyIndexes) - plot,
                     yerr=Intensity_err,
                     fmt='-',
                     label='E = {:.1f} meV'.format(Energy))
        plot += 1
    ax2.set_title('Cut through data along $L$')
    ax2.set_xlabel('L [rlu]')
    ax2.set_ylabel('Int [arb]')
    ax2.legend()
    ax2.grid(True)
    fig2.tight_layout()
    fig2.savefig(
        '/home/lass/Dropbox/PhD/Software/MJOLNIR/docs/Tutorials/Advanced/plotCutQELineMnF21D.png',
        format='png',
        dpi=300)
Exemplo n.º 8
0
def Tester():
    from MJOLNIR.Data import DataSet
    from MJOLNIR import _tools
    import numpy as np
    import matplotlib.pyplot as plt

    numbers = '483-489,494-500'
    fileList = _tools.fileListGenerator(numbers,
                                        '/home/lass/Dropbox/PhD/CAMEAData/',
                                        2018)

    ds = DataSet.DataSet(fileList)
    ds.convertDataFile(saveFile=False)

    # Define the positions to be cut through
    Q1 = np.array([0, 0, 0])
    Q2 = np.array([0, 0, 1])
    Q3 = np.array([-1, 0, 1])
    Q4 = np.array([-1, 0, -1])
    # Collect them into one array
    QPoints = np.array([Q1, Q2, Q3, Q4])

    # Define orthogonal width and minimum pixel size along Q-cut
    width = np.array([0.05, 0.03, 0.05])  # 1/AA
    minPixel = np.array([0.03, 0.01, 0.01])  # 1/AA

    # Define energy bins through the binEdges methods found in _tools
    Energies = np.concatenate(ds.energy, axis=0)
    EnergyBins = np.array([
        _tools.binEdges(Energies, 0.04),
        _tools.binEdges(Energies, 0.1),
        _tools.binEdges(Energies, 0.07)
    ])


    ax,DataLists,BinListTotal = \
    ds.plotCutQELine(QPoints=QPoints, width=width, minPixel=minPixel, \
                     EnergyBins=EnergyBins, ticks = 12,\
                     vmin=1e-8, vmax=1e-5, plotSeperator = True,
                     seperatorWidth=0.5,zorder=10)
    ax.grid(True, zorder=0, c='k')
    ax.get_figure().savefig(
        '/home/lass/Dropbox/PhD/Software/MJOLNIR/docs/Tutorials/Advanced/plotCutQELineMnF2.png',
        format='png',
        dpi=300)

    # Plot a single cut through the data set

    fig2, ax2 = plt.subplots()
    segID = 2
    # Extract the data from SegmentId
    df = DataLists[segID]

    for energy, EnergyDF in df.groupby('Energy'):

        Intensity = EnergyDF['Int'] * 1e5
        Intensity_err = EnergyDF['Int_err']

        position = EnergyDF['L']  # Plotting along L

        ax2.errorbar(position,
                     Intensity,
                     yerr=Intensity_err,
                     fmt='-',
                     label='E = {:.1f} meV'.format(energy))

    ax2.set_title('Cut through data along $L$')
    ax2.set_xlabel('L [rlu]')
    ax2.set_ylabel('Int [arb]')
    ax2.legend()
    ax2.grid(True)
    fig2.tight_layout()
    fig2.savefig(
        '/home/lass/Dropbox/PhD/Software/MJOLNIR/docs/Tutorials/Advanced/plotCutQELineMnF21D.png',
        format='png',
        dpi=300)