# Quick start¶

This section provides a quick introduction to scipp. For in depth explanations refer to the sections in the user guide.

[1]:

import numpy as np
import scipp as sc


We start by creating some variables:

[2]:

var = sc.Variable(dims=['y', 'x'], values=np.random.rand(4,5))
sc.show(var)


Type the name of a variable at the end of a cell to generate an HTML respresentation:

[3]:

var

[3]:

scipp.Variable (160 Bytes)
• (y: 4, x: 5)
float64
0.89, 0.68, ..., 0.98, 0.8
Values:array([[0.89480994, 0.68399103, 0.82038829, 0.65867721, 0.44276753],
[0.61658809, 0.41238414, 0.09385746, 0.16852474, 0.57240989],
[0.53857184, 0.14089499, 0.60736968, 0.73385062, 0.45890154],
[0.46095848, 0.0027758 , 0.69946178, 0.97922237, 0.80368585]])
[4]:

x = sc.Variable(dims=['x'], values=np.arange(5), unit=sc.units.m)
y = sc.Variable(dims=['y'], values=np.arange(4), unit=sc.units.m)


We combine the variables into a data array:

[5]:

array = sc.DataArray(
data=var,
coords={'x': x, 'y': y})
sc.show(array)
array

[5]:

scipp.DataArray (232 Bytes)
• y: 4
• x: 5
• x
(x)
int64
m
0, 1, 2, 3, 4
Values:array([0, 1, 2, 3, 4])
• y
(y)
int64
m
0, 1, 2, 3
Values:array([0, 1, 2, 3])
• (y, x)
float64
0.89, 0.68, ..., 0.98, 0.8
Values:array([[0.89480994, 0.68399103, 0.82038829, 0.65867721, 0.44276753],
[0.61658809, 0.41238414, 0.09385746, 0.16852474, 0.57240989],
[0.53857184, 0.14089499, 0.60736968, 0.73385062, 0.45890154],
[0.46095848, 0.0027758 , 0.69946178, 0.97922237, 0.80368585]])

Variables can have uncertainties. Scipp stores these as variances (the square of the standard deviation):

[6]:

array.variances = np.square(np.random.rand(4,5))
sc.show(array)


We create a dataset:

[7]:

dataset = sc.Dataset(
data={'a': var},
coords={'x': x, 'y': y, 'aux': x})
dataset['b'] = array
dataset['scalar'] = 1.23 * (sc.units.m / sc.units.s)
sc.show(dataset)


We can slice variables, data arrays, and datasets using a dimension label and an index or a slice object like i:j:

[8]:

dataset['c'] = dataset['b']['x', 2]
sc.show(dataset)
dataset

[8]:

scipp.Dataset (840 Bytes out of 1.13 KB)
• y: 4
• x: 5
• aux
(x)
int64
m
0, 1, 2, 3, 4
Values:array([0, 1, 2, 3, 4])
• x
(x)
int64
m
0, 1, 2, 3, 4
Values:array([0, 1, 2, 3, 4])
• y
(y)
int64
m
0, 1, 2, 3
Values:array([0, 1, 2, 3])
• a
(y, x)
float64
0.89, 0.68, ..., 0.98, 0.8
σ = 0.42, 0.83, ..., 0.02, 0.02
Values:array([[0.89480994, 0.68399103, 0.82038829, 0.65867721, 0.44276753],
[0.61658809, 0.41238414, 0.09385746, 0.16852474, 0.57240989],
[0.53857184, 0.14089499, 0.60736968, 0.73385062, 0.45890154],
[0.46095848, 0.0027758 , 0.69946178, 0.97922237, 0.80368585]])Variances (σ²):array([[1.76229802e-01, 6.96034078e-01, 3.35406980e-01, 7.92418095e-02,
4.00507698e-01],
[4.63537620e-01, 2.71467827e-01, 4.33764663e-03, 2.84478602e-01,
2.36026746e-02],
[5.63728104e-01, 8.08278144e-02, 5.78965756e-01, 1.46252161e-02,
8.02640577e-01],
[2.28552277e-02, 4.99763761e-01, 4.55787648e-01, 3.57000021e-04,
5.36796929e-04]])
• b
(y, x)
float64
0.89, 0.68, ..., 0.98, 0.8
σ = 0.42, 0.83, ..., 0.02, 0.02
Values:array([[0.89480994, 0.68399103, 0.82038829, 0.65867721, 0.44276753],
[0.61658809, 0.41238414, 0.09385746, 0.16852474, 0.57240989],
[0.53857184, 0.14089499, 0.60736968, 0.73385062, 0.45890154],
[0.46095848, 0.0027758 , 0.69946178, 0.97922237, 0.80368585]])Variances (σ²):array([[1.76229802e-01, 6.96034078e-01, 3.35406980e-01, 7.92418095e-02,
4.00507698e-01],
[4.63537620e-01, 2.71467827e-01, 4.33764663e-03, 2.84478602e-01,
2.36026746e-02],
[5.63728104e-01, 8.08278144e-02, 5.78965756e-01, 1.46252161e-02,
8.02640577e-01],
[2.28552277e-02, 4.99763761e-01, 4.55787648e-01, 3.57000021e-04,
5.36796929e-04]])
• c
(y)
float64
0.82, 0.09, 0.61, 0.7
σ = 0.58, 0.07, 0.76, 0.68
• aux
()
int64
m
2
Values:array(2)
• x
()
int64
m
2
Values:array(2)
Values:array([0.82038829, 0.09385746, 0.60736968, 0.69946178])Variances (σ²):array([0.33540698, 0.00433765, 0.57896576, 0.45578765])
• scalar
()
float64
m/s
1.23
Values:array(1.23)

We can also generate table representations (only 0-D and 1-D) and plots:

[9]:

sc.table(dataset['y', 2])

[10]:

sc.plot(dataset)


Arithmetic operations can be combined with slicing and handle propagation of uncertainties and units:

[11]:

print(dataset)

<scipp.Dataset>
Dimensions: Sizes[y:4, x:5, ]
Coordinates:
aux                         int64              [m]  (x)  [0, 1, ..., 3, 4]
x                           int64              [m]  (x)  [0, 1, ..., 3, 4]
y                           int64              [m]  (y)  [0, 1, 2, 3]
Data:
a                         float64  [dimensionless]  (y, x)  [0.894810, 0.683991, ..., 0.979222, 0.803686]  [0.176230, 0.696034, ..., 0.000357, 0.000537]
b                         float64  [dimensionless]  (y, x)  [0.894810, 0.683991, ..., 0.979222, 0.803686]  [0.176230, 0.696034, ..., 0.000357, 0.000537]
c                         float64  [dimensionless]  (y)  [0.820388, 0.093857, 0.607370, 0.699462]  [0.335407, 0.004338, 0.578966, 0.455788]
Attributes:
aux                         int64              [m]  ()  [2]
x                           int64              [m]  ()  [2]
scalar                    float64            [m/s]  ()  [1.230000]


[12]:

dataset['b']['y', 0:2] -= dataset['y', 0:2]['a']['x', 0]
dataset['b'] *= dataset['scalar']
print(dataset)

<scipp.Dataset>
Dimensions: Sizes[y:4, x:5, ]
Coordinates:
aux                         int64              [m]  (x)  [0, 1, ..., 3, 4]
x                           int64              [m]  (x)  [0, 1, ..., 3, 4]
y                           int64              [m]  (y)  [0, 1, 2, 3]
Data:
a                         float64            [m/s]  (y, x)  [0.000000, -0.259307, ..., 1.204444, 0.988534]  [0.533236, 1.319648, ..., 0.000540, 0.000812]
b                         float64            [m/s]  (y, x)  [0.000000, -0.259307, ..., 1.204444, 0.988534]  [0.533236, 1.319648, ..., 0.000540, 0.000812]
c                         float64            [m/s]  (y)  [-0.091539, -0.642959, 0.747065, 0.860338]  [0.774055, 0.707848, 0.875917, 0.689561]
Attributes:
aux                         int64              [m]  ()  [2]
x                           int64              [m]  ()  [2]
scalar                    float64            [m/s]  ()  [1.230000]



Finally, type the imported name of the scipp module at the end of a cell for a list of all current scipp objects (variables, data arrays, datasets). Click on entries to expand nested sections:

[13]:

sc

Variables:(3)
var
scipp.Variable (320 Bytes)
• (y: 4, x: 5)
float64
m/s
0.0, -0.26, ..., 1.2, 0.99
σ = 0.73, 1.15, ..., 0.02, 0.03
Values:array([[ 0.        , -0.25930726, -0.09153862, -0.29044326, -0.55601216],
[ 0.        , -0.25117087, -0.64295867, -0.55111792, -0.05433918],
[ 0.66244337,  0.17330084,  0.74706471,  0.90263627,  0.56444889],
[ 0.56697894,  0.00341423,  0.86033799,  1.20444352,  0.9885336 ]])Variances (σ²):array([[5.33236134e-01, 1.31964802e+00, 7.74055288e-01, 3.86503000e-01,
8.72546163e-01],
[1.40257213e+00, 1.11198974e+00, 7.07848491e-01, 1.13167374e+00,
7.36994551e-01],
[8.52864249e-01, 1.22284400e-01, 8.75917292e-01, 2.21264895e-02,
1.21431493e+00],
[3.45776740e-02, 7.56092594e-01, 6.89561133e-01, 5.40105331e-04,
8.12120073e-04]])
x
scipp.Variable (40 Bytes)
• (x: 5)
int64
m
0, 1, 2, 3, 4
Values:array([0, 1, 2, 3, 4])
y
scipp.Variable (32 Bytes)
• (y: 4)
int64
m
0, 1, 2, 3
Values:array([0, 1, 2, 3])
DataArrays:(1)
array
scipp.DataArray (392 Bytes)
• y: 4
• x: 5
• x
(x)
int64
m
0, 1, 2, 3, 4
Values:array([0, 1, 2, 3, 4])
• y
(y)
int64
m
0, 1, 2, 3
Values:array([0, 1, 2, 3])
• (y, x)
float64
m/s
0.0, -0.26, ..., 1.2, 0.99
σ = 0.73, 1.15, ..., 0.02, 0.03
Values:array([[ 0.        , -0.25930726, -0.09153862, -0.29044326, -0.55601216],
[ 0.        , -0.25117087, -0.64295867, -0.55111792, -0.05433918],
[ 0.66244337,  0.17330084,  0.74706471,  0.90263627,  0.56444889],
[ 0.56697894,  0.00341423,  0.86033799,  1.20444352,  0.9885336 ]])Variances (σ²):array([[5.33236134e-01, 1.31964802e+00, 7.74055288e-01, 3.86503000e-01,
8.72546163e-01],
[1.40257213e+00, 1.11198974e+00, 7.07848491e-01, 1.13167374e+00,
7.36994551e-01],
[8.52864249e-01, 1.22284400e-01, 8.75917292e-01, 2.21264895e-02,
1.21431493e+00],
[3.45776740e-02, 7.56092594e-01, 6.89561133e-01, 5.40105331e-04,
8.12120073e-04]])
Datasets:(1)
dataset
scipp.Dataset (840 Bytes out of 1.13 KB)
• y: 4
• x: 5
• aux
(x)
int64
m
0, 1, 2, 3, 4
Values:array([0, 1, 2, 3, 4])
• x
(x)
int64
m
0, 1, 2, 3, 4
Values:array([0, 1, 2, 3, 4])
• y
(y)
int64
m
0, 1, 2, 3
Values:array([0, 1, 2, 3])
• a
(y, x)
float64
m/s
0.0, -0.26, ..., 1.2, 0.99
σ = 0.73, 1.15, ..., 0.02, 0.03
Values:array([[ 0.        , -0.25930726, -0.09153862, -0.29044326, -0.55601216],
[ 0.        , -0.25117087, -0.64295867, -0.55111792, -0.05433918],
[ 0.66244337,  0.17330084,  0.74706471,  0.90263627,  0.56444889],
[ 0.56697894,  0.00341423,  0.86033799,  1.20444352,  0.9885336 ]])Variances (σ²):array([[5.33236134e-01, 1.31964802e+00, 7.74055288e-01, 3.86503000e-01,
8.72546163e-01],
[1.40257213e+00, 1.11198974e+00, 7.07848491e-01, 1.13167374e+00,
7.36994551e-01],
[8.52864249e-01, 1.22284400e-01, 8.75917292e-01, 2.21264895e-02,
1.21431493e+00],
[3.45776740e-02, 7.56092594e-01, 6.89561133e-01, 5.40105331e-04,
8.12120073e-04]])
• b
(y, x)
float64
m/s
0.0, -0.26, ..., 1.2, 0.99
σ = 0.73, 1.15, ..., 0.02, 0.03
Values:array([[ 0.        , -0.25930726, -0.09153862, -0.29044326, -0.55601216],
[ 0.        , -0.25117087, -0.64295867, -0.55111792, -0.05433918],
[ 0.66244337,  0.17330084,  0.74706471,  0.90263627,  0.56444889],
[ 0.56697894,  0.00341423,  0.86033799,  1.20444352,  0.9885336 ]])Variances (σ²):array([[5.33236134e-01, 1.31964802e+00, 7.74055288e-01, 3.86503000e-01,
8.72546163e-01],
[1.40257213e+00, 1.11198974e+00, 7.07848491e-01, 1.13167374e+00,
7.36994551e-01],
[8.52864249e-01, 1.22284400e-01, 8.75917292e-01, 2.21264895e-02,
1.21431493e+00],
[3.45776740e-02, 7.56092594e-01, 6.89561133e-01, 5.40105331e-04,
8.12120073e-04]])
• c
(y)
float64
m/s
-0.09, -0.64, 0.75, 0.86
σ = 0.88, 0.84, 0.94, 0.83
• aux
()
int64
m
2
Values:array(2)
• x
()
int64
m
2
Values:array(2)
Values:array([-0.09153862, -0.64295867,  0.74706471,  0.86033799])Variances (σ²):array([0.77405529, 0.70784849, 0.87591729, 0.68956113])
• scalar
()
float64
m/s
1.23
Values:array(1.23)
[13]:

<module 'scipp' from '/usr/share/miniconda/conda-bld/scipp_1636551670183/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/lib/python3.7/site-packages/scipp/__init__.py'>