Skip to content

Automate TS1 CH4 moderator performance analysis #219

@martyngigg

Description

@martyngigg

The performance of the TS1 methane moderator is currently tracked by fitting peaks from the incident monitor on PEARL. This analysis is run manually within the Mantid software and involves maintaining lists of runs and cycle names to feed into the script, along with executing the actual code.

This procedure can be automated and the output data should be ingested into the data lakehouse to enabled tools such as Superset to view the corresponding plots.

The basics of the analysis amount to the following script:

Script
for i in range(start,end+1):
    if i == 95382:
         continue
    Load(Filename='<file-path>', OutputWorkspace=str(i))
    ws = mtd[str(i)]
    run = ws.getRun()
    pcharge = run.getProtonCharge()
    if pcharge <1.0:
        reject.append(str(i))
        DeleteWorkspace(str(i))
        continue
    NormaliseByCurrent(InputWorkspace=str(i), OutputWorkspace=str(i))
    ExtractSingleSpectrum(InputWorkspace=str(i),WorkspaceIndex=index,
                OutputWorkspace=str(i)+ '_' + str(index))
    CropWorkspace(InputWorkspace=str(i)+ '_' + str(index), Xmin=1100,
            Xmax=19990, OutputWorkspace=str(i)+ '_' + str(index))
    DeleteWorkspace(str(i))
 #Some constraints included to precent divergence
    fit_output = Fit(Function='name=Gaussian,Height=19.2327,\
                        PeakCentre=4843.8,Sigma=1532.64,\
                        constraints=(4600<PeakCentre<5200,1100<Sigma<1900);\
                        name=FlatBackground,A0=16.6099,ties=(A0=16.6099)',
                        InputWorkspace=str(i)+ '_' + str(index),
                        MaxIterations=1000, CreateOutput=True,
                        Output=str(i)+ '_' + str(index) + '_fit',
                        OutputCompositeMembers=True,
                        StartX=3800, EndX=6850, Normalise=True)
    paramTable = fit_output.OutputParameters
    #  This catches some fits where the fit constraints are ignored,
    #   allowing the peak to fall far outside the nominal range
    if paramTable.column(1)[1] < 4600.0 or paramTable.column(1)[1] > 5200.0:
        DeleteWorkspace(str(i)+'_0_fit_Parameters')
        DeleteWorkspace(str(i)+'_0_fit_Workspace')
        DeleteWorkspace(str(i)+'_0')
        DeleteWorkspace(str(i)+'_0_fit_NormalisedCovarianceMatrix')
        reject.append(str(i))
        continue
    else:
        uAmps.append(pcharge)
        peak_centres.append(paramTable.column(1)[1])
        peak_centres_error.append(paramTable.column(2)[1])
        peak_intensity.append(paramTable.column(1)[0])
        peak_intensity_error.append(paramTable.column(2)[0])
        RunNo.append(str(i))
        DeleteWorkspace(str(i)+'_0')
        DeleteWorkspace(str(i)+'_0_fit_Parameters')
        DeleteWorkspace(str(i)+'_0_fit_Workspace')
        DeleteWorkspace(str(i)+'_0_fit_NormalisedCovarianceMatrix')
        
    combined_data=np.column_stack((RunNo, uAmps, peak_intensity,
        peak_intensity_error, peak_centres, peak_centres_error))
    np.savetxt(Path2Save+'\peak_centres_'+cycle+'.csv',
    combined_data, delimiter=", ", fmt='% s',)

The FIA project can provide infrastructure for running the script out fetching the output to ingest into the data lake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions