nD to 1D spectra from a peak position

A macro to demonstrate how to extract sliceData at a (selected) peak Position and create 1D spectra per each dimension.
To run:
open a spectrum display, select a peak of interest, run from the iPython Console / 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