Ejemplo n.º 1
0
def xrayFilterRatio(quickAndDirtyXRayRatio):
    def map_xrayRatio(data):
        ratio, ratioStd = quickAndDirtyXRayRatio.getRatio(data)
        return ratio

    pipeLine = mirage_analysis.DataPipeline('XRay', map_xrayRatio, AvgAndStd)
    return pipeLine
Ejemplo n.º 2
0
def returnTotalEnergyPipeline(HighESpecClass):
    BackgroundNoise = HighESpecClass.BackgroundNoise * HighESpecClass.fCperCounts

    def map_function_TotalEnergy(data):
        Spectrum, ____ = HighESpecClass.SpectrumFromImagefC(data)
        SignificanceLevel = 5
        TotalEnergy = determineTotalEnergy(
            HighESpecClass.Energy, (Spectrum.T),
            np.sum(BackgroundNoise, axis=0) * SignificanceLevel)
        return TotalEnergy

    pipeline_TotalEnergy = mirage_analysis.DataPipeline(
        'HighESpec', map_function_TotalEnergy, AvgAndStd)
    return pipeline_TotalEnergy
Ejemplo n.º 3
0
def return95cutoff(HighESpecClass):
    BackgroundNoise = HighESpecClass.BackgroundNoise * HighESpecClass.fCperCounts

    def map_function_CutOffEnergy(data):
        Spectrum, ____ = HighESpecClass.SpectrumFromImagefC(data)
        SignificanceLevel = 5
        MaximumEnergy = determine95percentCharge(
            HighESpecClass.Energy, (Spectrum.T),
            np.sum(BackgroundNoise, axis=0) * SignificanceLevel)
        return MaximumEnergy

    pipeline_CutOff = mirage_analysis.DataPipeline('HighESpec',
                                                   map_function_CutOffEnergy,
                                                   AvgAndStd)
    return pipeline_CutOff
Ejemplo n.º 4
0
def returnTotalEnergy(RunName):
    HighESpecClass = Espec(RunName, ta2_hrr_2019.utils.DATA_FOLDER,
                           'HighESpec')
    BackgroundNoise = HighESpecClass.BackgroundNoise * HighESpecClass.fCperCounts

    def map_function_TotalEnergy(data):
        Spectrum, ____ = HighESpecClass.SpectrumFromImagefC(data)
        SignificanceLevel = 5
        TotalEnergy = determineTotalEnergy(
            HighESpecClass.Energy, (Spectrum.T),
            np.sum(BackgroundNoise, axis=0) * SignificanceLevel)
        return TotalEnergy

    pipeline_TotalEnergy = mirage_analysis.DataPipeline(
        'HighESpec', map_function_TotalEnergy, map_function_AverageCutOff)
    return pipeline_TotalEnergy.run(RunName)
Ejemplo n.º 5
0
def StartSpectrumPlotter(RunName):
    HighESpecClass = Espec(RunName, ta2_hrr_2019.utils.DATA_FOLDER,
                           'HighESpec')

    def map_function_spectrum(data):
        Spectrum, __ = HighESpecClass.SpectrumFromImagefC(data)
        return Spectrum

    pipeline_spectrum = mirage_analysis.DataPipeline('HighESpec',
                                                     map_function_spectrum,
                                                     reduce_function_average)
    IdNumbers, Spectra = pipeline_spectrum.run(RunName)
    ChargeHere = np.trapz(Spectra[0, :, 0], HighESpecClass.Energy[:, 0]) * 1e-3
    legendEntry = [
        'Burst Nr %.0f with %.1f pC above %.0f MeV' %
        (IdNumbers[0], ChargeHere, HighESpecClass.Energy[0, 0])
    ]
    plt.figure()
    plt.plot(HighESpecClass.Energy, Spectra[0])
    for i in range(1, Spectra.shape[0]):
        plt.plot(HighESpecClass.Energy, Spectra[i])
        ChargeHere = np.trapz(Spectra[i, :, 0],
                              HighESpecClass.Energy[:, 0]) * 1e-3
        legendEntry.append(
            'Burst Nr %.0f with %.1f pC above %.0f MeV' %
            (IdNumbers[i], ChargeHere, HighESpecClass.Energy[0, 0]))
    if len(legendEntry) < 8:
        plt.legend(legendEntry)
    else:
        reducedEntry = ['Burst Nr %.0f ' % (IdNumbers[0])]
        for j in range(0, len(legendEntry)):
            print(legendEntry[j])
            reducedEntry.append('Burst Nr %.0f' % (IdNumbers[j]))
        plt.legend(reducedEntry, prop={'size': 6})
    BackgroundNoise = HighESpecClass.BackgroundNoise * HighESpecClass.fCperCounts
    BackgroundNoise = np.sum(BackgroundNoise,
                             axis=0)  #/np.sqrt(BackgroundImage.shape[0])
    SignificanceLevel = 5
    plt.plot(HighESpecClass.Energy, BackgroundNoise * SignificanceLevel, '--k')
    plt.xlabel('Energy [MeV]')
    plt.ylabel('Charge [fC/MeV]')
Ejemplo n.º 6
0
def pltESpecCounts(runName):
    # get the laser information
    bNum, NFEnergy = laserOn_PL.run(runName)

    # get ESpec count
    #bNum2, ESpecCounts = smartESpec_PL.run(runName)
    #ESpecCounts = ESpecCounts - bkgCounts

    HighESpecClass = Espec(runName, ta2_hrr_2019.utils.DATA_FOLDER,
                           'HighESpec')

    def map_function_charge(data):
        Charge, __, __ = HighESpecClass.TotalCharge(data)
        return Charge

    pipeline_charge = mirage_analysis.DataPipeline('HighESpec',
                                                   map_function_charge)
    bNum2, ESpecCharge = pipeline_charge.run(runName)
    ESpecCounts = ESpecCharge * 1e-3

    numBursts = bNum2[-1][0]
    shotsPerBurst = bNum2[-1][1]

    missedShots = np.zeros(numBursts, )
    maxCounts = np.zeros(numBursts, )
    minCounts = np.zeros(numBursts, )
    meanCounts = np.zeros(numBursts, )

    meanLaserEnergy = np.zeros(numBursts, )
    energyThreshold = .5  # 500 mJ

    for burst in range(numBursts):
        # Go through each shot in the burst and pick out remove shots without laser (starts at zero due to range)
        bNew = np.array(bNum)[(np.array(bNum)[:, 0] == burst + 1)]
        bNew2 = np.array(bNum2)[(np.array(bNum2)[:, 0] == burst + 1)]
        _, whichToGet, whichToGet2 = np.intersect1d(bNew[:, 1],
                                                    bNew2[:, 1],
                                                    return_indices=True)
        shotEnergy = NFEnergy[(np.array(bNum)[:, 0] == burst + 1)]
        counts = ESpecCounts[(np.array(bNum2)[:, 0] == burst + 1)]
        shotEnergy = shotEnergy[whichToGet]
        counts = counts[whichToGet2]

        #shotEnergy = NFEnergy[burst*shotsPerBurst: (burst+1)*shotsPerBurst-1]
        #counts  = ESpecCounts[burst*shotsPerBurst: (burst+1)*shotsPerBurst-1]
        indxs = np.where(shotEnergy > energyThreshold)
        missedShots[burst] = shotsPerBurst - np.shape(
            indxs)[1] - 1  # How many shots were missed from the burst
        if missedShots[burst] > 0:
            print('Burst %i : Missed %i Shots' % (burst, missedShots[burst]))

        counts = counts[indxs]
        shotEnergy = shotEnergy[indxs]

        if np.shape(indxs)[1] < 2:
            maxCounts[burst] = 0
            minCounts[burst] = 0
            meanCounts[burst] = 0
            meanLaserEnergy[burst] = 0
        else:
            try:
                maxCounts[burst] = np.amax(counts)
                minCounts[burst] = np.amin(counts)
                meanCounts[burst] = np.mean(counts)
                meanLaserEnergy[burst] = np.mean(shotEnergy)
            except:
                print('Whoops')

    x = np.linspace(1, numBursts, numBursts)

    fig, ax1 = plt.subplots()
    ax2 = ax1.twinx()
    ax1.plot(x, meanCounts, color='blue', alpha=.5)
    ax1.plot(x, maxCounts, color='black', alpha=.1, linewidth=1)
    ax1.plot(x, minCounts, color='black', alpha=.1, linewidth=1)
    ax1.fill_between(x, maxCounts, minCounts, facecolor='gray', alpha=.1)
    ax1.grid(True, linestyle='--', alpha=.5, linewidth=.5)
    ax1.set_ylim([0, np.amax(maxCounts)])
    ax1.set_xlabel('Burst Number')
    ax1.set_ylabel('Average Charge [pC]', color='blue')
    ax1.set_title(runName + ': HighESpec Charge [pC]')
    ax1.set_xlim([1, numBursts])

    ax2.plot(x, 1000 * meanLaserEnergy, color='red', alpha=.1)
    ax2.set_ylabel('Average Laser Energy (mJ)', color='r')
    ax2.set_ylim([0, 1000])
    ax2.set_xlim([1, numBursts])
    return x, meanCounts, maxCounts, minCounts, meanLaserEnergy
Ejemplo n.º 7
0
def pltESpecSpectrumWaterfall95percentFitness(runName):
    # get the laser information
    bNum, NFEnergy = laserOn_PL.run(runName)

    HighESpecClass = Espec(runName, ta2_hrr_2019.utils.DATA_FOLDER,
                           'HighESpec')

    def map_function_spectrum(data):
        __, Spectrum, __ = HighESpecClass.TotalCharge(data)
        return Spectrum

    pipeline_spectrum = mirage_analysis.DataPipeline('HighESpec',
                                                     map_function_spectrum)
    bNum2, spectra = pipeline_spectrum.run(runName)

    BackgroundNoise = HighESpecClass.BackgroundNoise * HighESpecClass.fCperCounts
    SignificanceLevel = 5
    MaximumEnergy = np.zeros(len(bNum2), )
    for i in range(spectra.shape[0]):
        MaximumEnergy[i] = determine95percentCharge(
            HighESpecClass.Energy, (spectra[i, :, :].T),
            np.sum(BackgroundNoise, axis=0) * SignificanceLevel)
    numBursts = bNum2[-1][0]
    shotsPerBurst = bNum2[-1][1]

    missedShots = np.zeros(numBursts, )
    meanMaxEnergy = np.zeros(numBursts, )
    stdMaxEnergy = np.zeros(numBursts, )
    meanSpectra = np.zeros((numBursts, spectra.shape[2]))

    meanLaserEnergy = np.zeros(numBursts, )
    energyThreshold = .5  # 500 mJ

    for burst in range(numBursts):
        # Go through each shot in the burst and pick out remove shots without laser (starts at zero due to range)
        bNew = np.array(bNum)[(np.array(bNum)[:, 0] == burst + 1)]
        bNew2 = np.array(bNum2)[(np.array(bNum2)[:, 0] == burst + 1)]
        _, whichToGet, whichToGet2 = np.intersect1d(bNew[:, 1],
                                                    bNew2[:, 1],
                                                    return_indices=True)
        shotEnergy = NFEnergy[(np.array(bNum)[:, 0] == burst + 1)]
        shotMaxEnergy = MaximumEnergy[(np.array(bNum2)[:, 0] == burst + 1)]
        RelevantSpectra = spectra[(np.array(bNum2)[:, 0] == burst + 1), 0, :]
        shotEnergy = shotEnergy[whichToGet]
        RelevantSpectra = RelevantSpectra[whichToGet2, :]

        #shotEnergy = NFEnergy[burst*shotsPerBurst: (burst+1)*shotsPerBurst-1]
        #shotMaxEnergy = MaximumEnergy[burst*shotsPerBurst: (burst+1)*shotsPerBurst-1]
        #RelevantSpectra  = spectra[burst*shotsPerBurst: (burst+1)*shotsPerBurst-1, 0, :]
        indxs = np.where(shotEnergy > energyThreshold)
        missedShots[burst] = shotsPerBurst - np.shape(
            indxs)[1] - 1  # How many shots were missed from the burst
        if missedShots[burst] > 0:
            print('Burst %i : Missed %i Shots' % (burst, missedShots[burst]))

        RelevantSpectra = RelevantSpectra[:, :]
        shotEnergy = shotEnergy[:]
        MaxEnergy = shotMaxEnergy[:]
        if np.shape(indxs)[1] < 2:
            meanSpectra[burst, :] = 0
            meanLaserEnergy[burst] = 0
            meanMaxEnergy[burst] = 0
            stdMaxEnergy[burst] = 0
        else:
            try:
                meanSpectra[burst, :] = np.mean(RelevantSpectra, axis=0)
                meanLaserEnergy[burst] = np.mean(shotEnergy)
                meanMaxEnergy[burst] = np.mean(MaxEnergy)
                stdMaxEnergy[burst] = np.std(MaxEnergy) / np.sqrt(
                    len(MaxEnergy))
            except:
                print('Whoops')

    ex = (1, numBursts, np.min(HighESpecClass.Energy),
          np.max(HighESpecClass.Energy))
    fig, ax1 = plt.subplots()
    ax2 = ax1.twinx()
    ax1.imshow(np.flipud(meanSpectra.T), extent=ex,
               aspect='auto')  #x,meanCounts,color='blue',alpha=.5)
    ax1.grid(True, linestyle='--', alpha=.5, linewidth=.5)
    ax1.set_xlim([1, numBursts])
    ax1.set_xlabel('Burst Number')
    ax1.set_ylabel('Spectra [fC/MeV]', color='blue')
    ax1.set_title(runName + ': e- Spectra and Cut Off Energy [fC/MeV]')
    ax1.set_ylim(
        [np.min(HighESpecClass.Energy),
         np.max(HighESpecClass.Energy)])

    x = np.linspace(1, numBursts, numBursts) + 0.5
    ax2.plot(x, meanMaxEnergy, 'w_', alpha=1)
    marker_style1 = dict(color='w', linestyle='none', marker='_',
                         markersize=3)  #markerfacecoloralt='tab:red'
    marker_style2 = dict(color='w', linestyle='none', marker='_', markersize=3)
    ax2.plot(x, meanMaxEnergy + stdMaxEnergy, **marker_style1, alpha=.2)
    ax2.plot(x, meanMaxEnergy - stdMaxEnergy, **marker_style2, alpha=.2)
    #ax2.fill_between(x,meanMaxEnergy + stdMaxEnergy,meanMaxEnergy - stdMaxEnergy,facecolor='w',alpha=.1)
    ax2.set_ylabel('Average e- Cutt Off Energy (mJ)', color='r')
    ax2.set_ylim(
        [np.min(HighESpecClass.Energy),
         np.max(HighESpecClass.Energy)])
    return HighESpecClass.Energy, meanSpectra, x, meanMaxEnergy, stdMaxEnergy
Ejemplo n.º 8
0
def pltESpecSpectrumWaterfall(runName):
    # get the laser information
    bNum, NFEnergy = laserOn_PL.run(runName)

    HighESpecClass = Espec(runName, ta2_hrr_2019.utils.DATA_FOLDER,
                           'HighESpec')

    def map_function_spectrum(data):
        __, Spectrum, __ = HighESpecClass.TotalCharge(data)
        return Spectrum

    pipeline_spectrum = mirage_analysis.DataPipeline('HighESpec',
                                                     map_function_spectrum)
    bNum2, spectra = pipeline_spectrum.run(runName)

    numBursts = bNum2[-1][0]
    shotsPerBurst = bNum2[-1][1]

    missedShots = np.zeros(numBursts, )
    meanSpectra = np.zeros((numBursts, spectra.shape[2]))

    meanLaserEnergy = np.zeros(numBursts, )
    energyThreshold = .5  # 500 mJ

    for burst in range(numBursts):
        # Go through each shot in the burst and pick out remove shots without laser (starts at zero due to range)
        bNew = np.array(bNum)[(np.array(bNum)[:, 0] == burst + 1)]
        bNew2 = np.array(bNum2)[(np.array(bNum2)[:, 0] == burst + 1)]
        _, whichToGet, whichToGet2 = np.intersect1d(bNew[:, 1],
                                                    bNew2[:, 1],
                                                    return_indices=True)
        shotEnergy = NFEnergy[(np.array(bNum)[:, 0] == burst + 1)]
        RelevantSpectra = spectra[(np.array(bNum2)[:, 0] == burst + 1), 0, :]
        shotEnergy = shotEnergy[whichToGet]
        RelevantSpectra = RelevantSpectra[whichToGet2, :]

        #shotEnergy = NFEnergy[burst*shotsPerBurst: (burst+1)*shotsPerBurst-1]
        #RelevantSpectra  = spectra[burst*shotsPerBurst: (burst+1)*shotsPerBurst-1, 0, :]
        indxs = np.where(shotEnergy > energyThreshold)
        missedShots[burst] = shotsPerBurst - np.shape(
            indxs)[1] - 1  # How many shots were missed from the burst
        if missedShots[burst] > 0:
            print('Burst %i : Missed %i Shots' % (burst, missedShots[burst]))
        RelevantSpectra = RelevantSpectra[indxs[0], :]
        shotEnergy = shotEnergy[indxs]

        if np.shape(indxs)[1] < 2:
            meanSpectra[burst, :] = 0
            meanLaserEnergy[burst] = 0
        else:
            try:
                meanSpectra[burst, :] = np.mean(RelevantSpectra, axis=0)
                meanLaserEnergy[burst] = np.mean(shotEnergy)
            except:
                print('Whoops')

    ex = (1, numBursts, np.min(HighESpecClass.Energy),
          np.max(HighESpecClass.Energy))
    fig, ax1 = plt.subplots()
    ax2 = ax1.twinx()
    ax1.imshow(np.flipud(meanSpectra.T), extent=ex,
               aspect='auto')  #x,meanCounts,color='blue',alpha=.5)
    ax1.grid(True, linestyle='--', alpha=.5, linewidth=.5)
    ax1.set_xlim([1, numBursts])
    ax1.set_xlabel('Burst Number')
    ax1.set_ylabel('Spectra [fC/MeV]', color='blue')
    ax1.set_title(runName + ': HighESpec Spectrum above 26 MeV [fC/MeV]')

    x = np.linspace(1, numBursts, numBursts) + 0.5
    ax2.plot(x, 1000 * meanLaserEnergy, 'r.', alpha=1)
    ax2.set_ylabel('Average Laser Energy (mJ)', color='r')
    ax2.set_ylim([0, 1000])
    return HighESpecClass.Energy, meanSpectra, x, meanLaserEnergy
Ejemplo n.º 9
0
def HighESpecTotalCountsPipeline():
    HighESpec_pipeline = mirage_analysis.DataPipeline('HighESpec', sumShot,
                                                      nullFun)
    return HighESpec_pipeline
Ejemplo n.º 10
0
def HighESpecAvgCountsPipeline():
    HighESpec_pipeline = mirage_analysis.DataPipeline('HighESpec',
                                                      meanShotCounts, nullFun)
    return HighESpec_pipeline
Ejemplo n.º 11
0

def smartNF_RF(data):
    return np.sum(data)  # Return the mean of the pixels in each image


def smartNF_MF(data):
    # return the mean pixel value
    return np.sum(data.astype(float))


def BackgroundMean(datalist):
    return np.mean(datalist)


laserOn_PL = mirage_analysis.DataPipeline('PreCompNF', laserOn_MF)  # energy

laserOn_Pre = mirage_analysis.DataPipeline('PreCompNF', smartNF_RF)
laserOn_HASO = mirage_analysis.DataPipeline('HASONF', smartNF_RF)

smartPreNFBG = mirage_analysis.DataPipeline('PreCompNF', smartNF_MF,
                                            BackgroundMean)
smartHASONFBG = mirage_analysis.DataPipeline('PreCompNF', smartNF_MF,
                                             BackgroundMean)


def pltNFEnergies(runName, bkgRunName):
    # get the laser information in J:
    bNum, NFEnergy = laserOn_PL.run(runName)
    # background counts for both NFs:
    bNum, bkgCounts = smartPreNFBG.run(bkgRunName)
Ejemplo n.º 12
0
def xrayAvgCountsPipeline():
    xray_pipeline = mirage_analysis.DataPipeline('XRay', meanShotCounts,
                                                 nullFun)
    return xray_pipeline
Ejemplo n.º 13
0
def eProfileSquaredPipe():
    eprofile_pipeline = mirage_analysis.DataPipeline('EProfile',
                                                     meanShotCountsSquared,
                                                     AvgAndStd)
    return eprofile_pipeline
Ejemplo n.º 14
0
def HighESpecAverageBandCounts_punisher():
    HighESpec_pipeline = mirage_analysis.DataPipeline(
        'HighESpec', meanBandHighESpecCounts_punisher, nullFun)
    return HighESpec_pipeline
Ejemplo n.º 15
0
def HighESpecAverageWeightedCounts():
    HighESpec_pipeline = mirage_analysis.DataPipeline(
        'HighESpec', meanWeightedHighESpecCounts, nullFun)
    return HighESpec_pipeline
Ejemplo n.º 16
0
    return (data * energyCalibration -.0025)

def laserOn_MF(data):
    data = np.sum((data).astype(float))
    data  = preComp_NF_energy(data)
    return np.sum(data)

def smartESpec_MF(data):
    data = data -2**15
    # return the mean pixel value
    return np.mean(data.astype(float))

def smartESpec_RF(data):
    return np.mean(data,axis=0) # Return the sum of the pixels in each image

laserOn_PL = mirage_analysis.DataPipeline('PreCompNF',laserOn_MF)
smartESpec_PL = mirage_analysis.DataPipeline('ESpec', smartESpec_MF)
smartESpecBG_PL = mirage_analysis.DataPipeline('ESpec', smartESpec_MF,smartESpec_RF)


def pltESpecCounts(runName,bkgRunName):
    
    bNum, bkgCounts = smartESpecBG_PL.run(bkgRunName)
    bkgCounts = np.mean(bkgCounts)

    # get the laser information
    bNum, NFEnergy = laserOn_PL.run(runName)

    # get ESpec count
    bNum2, ESpecCounts = smartESpec_PL.run(runName)
    ESpecCounts = ESpecCounts - bkgCounts
Ejemplo n.º 17
0
    data = np.sum((data).astype(float))
    data = preComp_NF_energy(data)
    return np.sum(data)


def smartXray_MF(data):
    data = data - 2**15
    # return the mean pixel value
    return np.mean(data.astype(float))


def smartXray_RF(data):
    return np.mean(data, axis=0)  # Return the sum of the pixels in each image


laserOn_PL = mirage_analysis.DataPipeline('PreCompNF', laserOn_MF)
smartXray_PL = mirage_analysis.DataPipeline('XRay', smartXray_MF)
smartXrayBG_PL = mirage_analysis.DataPipeline('XRay', smartXray_MF,
                                              smartXray_RF)


def pltXrayCounts(runName, bkgRunName):

    bNum, bkgCounts = smartXrayBG_PL.run(bkgRunName)
    bkgCounts = np.mean(bkgCounts)

    # get the laser information
    bNum, NFEnergy = laserOn_PL.run(runName)

    # get xray count
    bNum2, xRayCounts = smartXray_PL.run(runName)
Ejemplo n.º 18
0
def xrayTotalCountsPipeline():
    xray_pipeline = mirage_analysis.DataPipeline('XRay', sumShot, nullFun)
    return xray_pipeline