Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt
Created June 7, 2016 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasaarholt/b4197390fc94fd415d323016bfa3f264 to your computer and use it in GitHub Desktop.
Save thomasaarholt/b4197390fc94fd415d323016bfa3f264 to your computer and use it in GitHub Desktop.
Makes the spectrum image "bss_spectra[0]" and the single spectra in "mlls_objects" the same lengths.
# Make signal starting point and length equal
signal_min = bss_spectra[0].axes_manager[-1].axis.min() # This is a float
signal_shortest_len = len(bss_spectra[0].axes_manager[-1].axis) # This is an int
# Get largest value of s
for s in mlls_objects:
if s.axes_manager[0].axis.min() > signal_min:
signal_min = s.axes_manager[0].axis.min()
# Crop all the spectra to start at the same energy index
for i in range(len(mlls_objects)):
mlls_objects[i].crop_spectrum(signal_min, None)
bss_spectra[0].crop_spectrum(signal_min, None)
# Get shortest length of spectra
for s in mlls_objects:
if len(s.axes_manager[0].axis) < signal_shortest_len:
signal_shortest_len = len(s.axes_manager[0].axis)
# Crop all spectra to start at the signal_min index and be as long as signal_shortest_len
# I had to do use the signal_min here as well as before, as otherwise it was one short - look into later.
for i in range(len(mlls_objects)):
mlls_objects[i].crop_spectrum(signal_min, signal_shortest_len)
bss_spectra[0].crop_spectrum(signal_min, signal_shortest_len)
pp.pprint((bss_spectra[0], mlls_objects)) # Use prettyprint (pprint) to print the signals with their length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment