spectrochempy.stack๏
- stack(*datasets, **kwargs)[source]๏
Stack of
NDDatasetobjects along a new dimension.Any number of
NDDatasetobjects can be stacked. For this operation to be defined the following must be true :all inputs must be valid dataset objects,
units of data and axis must be compatible (rescaling is applied automatically if necessary).
- Parameters:
*datasets (a series of
NDDataset) โ The dataset to be stacked to the current dataset.**kwargs โ Optional keyword parameters.
- Other Parameters:
axis (int, optional, default=0) โ Stacking axis.
axis=0preserves the historical behavior and stacks datasets along a new leading dimension.axis=1is supported for 1D datasets and promotes them to a 2D dataset with profiles stacked as columns.
- Returns:
out โ A
NDDatasetcreated from the stack of thedatasetsdatasets.
See also
concatenateConcatenate
NDDatasetobjects along a given dimension.
Examples
>>> A = scp.read('irdata/nh4y-activation.spg', protocol='omnic') >>> B = scp.read('irdata/nh4y-activation.scp') >>> C = scp.stack(A, B) >>> print(C) NDDataset: [float64] a.u. (shape: (z:2, y:55, x:5549))
Stack 1D profiles as columns in a 2D dataset
>>> t = scp.linspace(0, 1, 5) >>> profiles = [np.exp(-((t - c) ** 2) / 0.05) for c in (0.2, 0.5)] >>> C = scp.stack(profiles, axis=1) >>> C.shape (5, 2)
Create 1D datasets from a coordinate and stack them as columns:
>>> time = scp.Coord.linspace(0, 1, 200, title="time") >>> data1 = scp.exp(-0.5 * ((time.data - 0.25) / 0.10) ** 2) >>> data2 = 0.8 * scp.exp(-0.5 * ((time.data - 0.55) / 0.12) ** 2) >>> c1 = scp.NDDataset(data1, coordset=[time], title="C1") >>> c2 = scp.NDDataset(data2, coordset=[time], title="C2") >>> profiles = scp.stack([c1, c2], axis=1) >>> profiles.shape (200, 2)