nD to 1D spectra from a peak position

What does the Macro do?

A macro to extract 1D sliceData at a (selected) peak Position and create 1D spectra for each dimension.

How to run the Macro

Open a SpectrumDisplay, select a Peak of interest, then run the macro from the iPython Console or macro editor.


import numpy as np
peak = current.peak
spectrum = peak.spectrum
for dim in spectrum.dimensions:
    pointPositions = np.array(peak.pointPositions, dtype=int)
    data = spectrum.getSliceData(position=list(pointPositions), sliceDim=dim)
    isotopeCodes = spectrum.getByDimensions('isotopeCodes',dimensions=[dim])
    pointCounts = spectrum.getByDimensions('pointCounts', dimensions=[dim])
    dd = {}
    properties = ['spectralWidths', 'spectralWidthsHz', 'spectrometerFrequencies', 'referencePoints', 'referenceValues']
    for p in properties:
        dd[p] = spectrum.getByDimensions(p, [dim])
    sp = project.newEmptySpectrum(name=f'{spectrum.name}-slice-{dim}',isotopeCodes=isotopeCodes, pointCounts=pointCounts, **dd)
    sp.noiseLevel = spectrum.noiseLevel

Credits and References

Luca Mureddu, CCPN team, University of Leicester