Пример #1
0
def allAvailableDataSources(runDir, forceUpdate=False):
    if runDataDict["runDir"] is not None and runDataDict[
            "runData"] is not None and not forceUpdate and runDataDict[
                "runDir"] == runDir:
        # no action needed the dictionary runDataDict contains already the data we are interested in and user does not neccesarily desires the update
        pass
    else:
        runDataDict["runData"] = kd.RunDirectory(runDir)
        runDataDict["runDir"] = runDir
    return runDataDict["runData"].all_sources
Пример #2
0
def allImages(runNumber, path='/gpfs/exfel/exp/SQS/201921/p002430/raw'):
    '''
    finds mean scattering and plots and returns that image
    input:
        runNumber: to analyze
        path: to experiment H5s
    '''
    run = runFormat(runNumber)
    runData = kd.RunDirectory(path + run)
    trainIds = runData.train_ids

    scatImages = np.asarray(
        runData.get_array('SQS_DPU_LIC/CAM/YAG_UPSTR:daqOutput',
                          'data.image.pixels'))

    return scatImages, trainIds
Пример #3
0
def analyzeMaximumImages(runNumber,
                         path='/gpfs/exfel/exp/SQS/201921/p002430/raw',
                         maskRadius=100,
                         nlargest=10):
    '''
    finds maximum scattering images and plots that image, saving to saveDir
    input:
        runNumber: to analyze
        path: to experiment H5s
        maskRadius: radius below which to ignore for determining max scattering
        nlargest: number of largest images to plot
    '''
    run = runFormat(runNumber)
    runData = kd.RunDirectory(path + run)
    trainIds = runData.train_ids

    scatImages = np.asarray(
        runData.get_array('SQS_DPU_LIC/CAM/YAG_UPSTR:daqOutput',
                          'data.image.pixels'))

    NT, NX, NY = scatImages.shape
    xs = np.arange(NX)
    ys = np.arange(NY)
    YY, XX = np.meshgrid(ys, xs)
    RR = np.sqrt((XX - NX / 2.)**2 + (YY - NY / 2.)**2)
    MASK = RR < maskRadius

    maskedScats = np.copy(scatImages)
    maskedScats[:, MASK] = 0.

    scaledScat = np.sum(maskedScats, (1, 2))
    indMaxToMin = np.argsort(scaledScat)[-nlargest:]

    fig, axes = plt.subplots(nlargest, 1, figsize=(10, 100))

    for idx, ax in enumerate(axes):
        realInd = indMaxToMin[idx]
        plotme = scatImages[realInd, :, :].squeeze()
        im = ax.imshow(plotme.astype(float))
        ax.set_title('run %d and tid %d' % (runNumber, trainIds[realInd]))

    plt.show()
    plt.pause(2)

    del scatImages
    del maskedScats
Пример #4
0
def getData(runDir, devicePath, dataPath, forceUpdate=False):
    '''
        Returns Data from given adress / device using Karabo Data or using already loaded data if no update forced and run already loaded
        run_dir - directory of run files (hdf5)
        device_path - path for device in hdf5 file eg "SQS_AQS_MOV/MOTOR/Y_DOWNSTR"
        data_path - path to data within hdf5 device path eg "actualPosition.value"
    '''
    if runDataDict["runDir"] is not None and runDataDict[
            "runData"] is not None and not forceUpdate and runDataDict[
                "runDir"] == runDir:
        # no action needed the dictionary runDataDict contains already the data we are interested in and user does not neccesarily desires the update
        pass
    else:
        runDataDict["runData"] = kd.RunDirectory(runDir)
        runDataDict["runDir"] = runDir

    data = runDataDict["runData"].get_array(devicePath, dataPath)

    return data
Пример #5
0
def getTrainIds(runDir, forceUpdate=False):
    '''
    Gets train IDs of specified run
        inputs 
            runNumber = number of run of interest
            path = path for data; defined at the top
        outputs
            array of train IDs 

    '''
    if runDataDict["runDir"] is not None and runDataDict[
            "runData"] is not None and not forceUpdate and runDataDict[
                "runDir"] == runDir:
        # no action needed the dictionary runDataDict contains already the data we are interested in and user does not neccesarily desires the update
        pass
    else:
        runDataDict["runData"] = kd.RunDirectory(runDir)
        runDataDict["runDir"] = runDir

    return runDataDict["runData"].train_ids
Пример #6
0
def analyzeAverageImage(
        runNumber,
        path='/gpfs/exfel/exp/SQS/201921/p002430/raw',  ###imagePath
        maskRadius=100):
    '''
    finds mean scattering and plots and returns that image
    input:
        runNumber: to analyze
        path: to experiment H5s
        maskRadius: radius below which to ignore for determining max scattering
        saveDir: path to save picture to
    '''
    run = runFormat(runNumber)
    runData = kd.RunDirectory(path + run)
    trainIds = runData.train_ids

    scatImages = np.asarray(
        runData.get_array('SQS_DPU_LIC/CAM/YAG_UPSTR:daqOutput',
                          'data.image.pixels'))
    scatMean = np.mean(scatImages, 0).astype(float)

    return scatMean
Пример #7
0
def analyzeMaximumImage(runNumber,
                        path='/gpfs/exfel/exp/SQS/201921/p002430/raw',
                        maskRadius=100):
    '''
    finds maximum scattering and plots that image
    input:
        runNumber: to analyze
        path: to experiment H5s
        maskRadius: radius below which to ignore for determining max scattering
        saveDir: path to save picture to
    '''
    run = runFormat(runNumber)
    runData = kd.RunDirectory(path + run)
    trainIds = runData.train_ids

    scatImages = np.asarray(
        runData.get_array('SQS_DPU_LIC/CAM/YAG_UPSTR:daqOutput',
                          'data.image.pixels'))

    NT, NX, NY = scatImages.shape
    xs = np.arange(NX)
    ys = np.arange(NY)
    YY, XX = np.meshgrid(ys, xs)
    RR = np.sqrt((XX - NX / 2.)**2 + (YY - NY / 2.)**2)
    MASK = RR < maskRadius

    maskedScats = np.copy(scatImages)
    maskedScats[:, MASK] = 0.

    scaledScat = np.sum(maskedScats, (1, 2))

    indMax = np.argmax(scaledScat)
    indMin = np.argmin(scaledScat)

    scatMax = scatImages[indMax, :, :].astype(float)
    scatMean = np.mean(scatImages, 0).astype(float)

    plt.figure(5)
    plt.imshow(scatMax)
    plt.title('Max scattering from run %d' % runNumber)
    plt.colorbar()
    plt.show()
    plt.pause(2)

    plt.figure(5)
    plt.imshow(
        np.log(
            np.abs(scatMax / np.sum(scatMax.flatten()) -
                   scatMean / np.sum(scatMean.flatten()))))
    plt.title(
        'Log of difference between scatMax/intensity-scatMean/intensity from run %d'
        % runNumber)
    plt.colorbar()
    plt.show()
    plt.pause(2)

    plt.figure(5)
    plt.imshow(scatMean)
    plt.title('Mean from run %d' % runNumber)
    plt.colorbar()
    plt.show()
    plt.pause(2)

    del scatImages
    del maskedScats

    return scatMax, trainIds[indMax]
def correlationPlots(run, Path, roi1, offset):
    '''
    outputs a scatter plot correlating FEL pulse intensity to light peak
    inputs
        run = run number of interest
        Path = path to data
        roi = region of interest in TOF for integration
        offset = offset for +/- 1 error
    returns the correlation number and scatter plot

    '''
    runf = xfel.runFormat(run)
    runData = kd.RunDirectory(Path + runf)

    pixels, tofs, trainIds = xfel.getRunTOF(run,
                                            Path,
                                            tofrange=(265000,
                                                      285000))  ###tofrange
    pulse_E = np.asarray(
        runData.get_array('SA3_XTD10_XGM/XGM/DOOCS:output',
                          'data.intensityTD'))
    scatImagesini = np.asarray(
        runData.get_array('SQS_DPU_LIC/CAM/YAG_UPSTR:daqOutput',
                          'data.image.pixels'))

    integratedROI1s = []

    pulseEnergies = []
    if offset > 0:
        for ind, elem in enumerate(trainIds[0:len(trainIds) - offset]):
            train_pos = np.where(trainIds == elem)[0][0]
            temp_E = pulse_E[1, :]
            pos = max(enumerate(temp_E), key=(lambda a: a[1]))
            run_E = pulse_E[:, pos[0]]
            train_E = run_E[train_pos + offset]
            pulseEnergies.append(train_E)

            integratedROI1s.append(
                np.sum((tofs[train_pos])[(roi1[0] < pixels)
                                         & (pixels < roi1[1])]))
    else:

        for ind, elem in enumerate(trainIds):

            train_pos = np.where(trainIds == elem)[0][0]
            #print (train_pos)

            temp_E = pulse_E[1, :]
            #print (temp_E)

            pos = max(enumerate(temp_E), key=(lambda a: a[1]))
            run_E = pulse_E[:, pos[0]]
            #print (run_E)

            train_E = run_E[train_pos + offset]
            pulseEnergies.append(train_E)

            integratedROI1s.append(
                np.sum((tofs[train_pos])[(roi1[0] < pixels)
                                         & (pixels < roi1[1])]))

    plt.scatter(pulseEnergies, integratedROI1s)
    plt.xlabel('pulse energy')
    plt.ylabel('integrated ROI from TOF')

    return
Пример #9
0
#!/usr/bin/env python3

import karabo_data

run_path = '/gpfs/exfel/exp/SPB/201701/p002012/proc/r0243'

run = karabo_data.RunDirectory(run_path)

run = run.select("*/DET/*", "*")

run = run.select_trains(
    karabo_data.by_id[[76961506, 76961507, 76961508, 76961509]])

run.write("data_subset.h5")