Slice an NDDataset with indices and coordinates

This example shows how to combine standard Python slicing with coordinate-aware slicing on an infrared time series.

import spectrochempy as scp

Load an IR dataset and express the acquisition axis in minutes.

dataset = scp.read_omnic(
    "irdata/CO@Mo_Al2O3.SPG",
    description="CO adsorption, difference spectra",
)
dataset.y = (dataset.y - dataset[0].y).to("minute")
print(dataset)
NDDataset: [float64] a.u. (shape: (y:19, x:3112))

Plot the full dataset once for context.

prefs = scp.preferences
prefs.figure.figsize = (7, 4)
_ = dataset.plot()
plot d slicing

Standard integer slices work as expected on both dimensions.

(4, 3112)
(19, 1556)

Coordinate-aware slicing is often more convenient for spectroscopy work. Using floats slices directly on axis coordinates instead of integer indices.

plot d slicing

The same applies to the time axis.

window = dataset[80.0:180.0, 2300.0:1900.0]
_ = window.plot()
plot d slicing

A single float selects the closest spectrum on that axis.

Coord [y:acquisition timestamp (GMT)] — float64, size: 1, min
size
:
1
title
:
acquisition timestamp (GMT)
coordinates
:
[ 58.32] min
labels
:
[[ 2016-10-18 14:47:54+00:00]
[ *Résultat de Soustraction:04_Mo_Al2O3_calc_0.021torr_LT_after sulf_Oct 18 16:45:00 2016 (GMT+02:00)]]


This ends the example. Uncomment the next line to display the figures when running the script directly with Python.

# scp.show()

Total running time of the script: (0 minutes 0.549 seconds)