# 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.084, 0.954, ..., 0.914, 0.922
Values:array([[0.08414328, 0.95409003, 0.91556799, 0.60699822, 0.68800363],
[0.19432712, 0.46310178, 0.11965925, 0.0197561 , 0.6597149 ],
[0.88885832, 0.46207903, 0.15058648, 0.04347002, 0.84134894],
[0.18437389, 0.44649044, 0.74775448, 0.91441335, 0.92230531]])
[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.084, 0.954, ..., 0.914, 0.922
Values:array([[0.08414328, 0.95409003, 0.91556799, 0.60699822, 0.68800363],
[0.19432712, 0.46310178, 0.11965925, 0.0197561 , 0.6597149 ],
[0.88885832, 0.46207903, 0.15058648, 0.04347002, 0.84134894],
[0.18437389, 0.44649044, 0.74775448, 0.91441335, 0.92230531]])

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.084, 0.954, ..., 0.914, 0.922
σ = 0.614, 0.150, ..., 0.873, 0.458
Values:array([[0.08414328, 0.95409003, 0.91556799, 0.60699822, 0.68800363],
[0.19432712, 0.46310178, 0.11965925, 0.0197561 , 0.6597149 ],
[0.88885832, 0.46207903, 0.15058648, 0.04347002, 0.84134894],
[0.18437389, 0.44649044, 0.74775448, 0.91441335, 0.92230531]])Variances (σ²):array([[0.37671445, 0.02260972, 0.55977924, 0.00832866, 0.26438793],
[0.08672716, 0.93218837, 0.08213386, 0.00172262, 0.50155131],
[0.06016794, 0.32025299, 0.2944995 , 0.53495261, 0.12905676],
[0.14975438, 0.30018028, 0.02047345, 0.76263568, 0.21002915]])
• b
(y, x)
float64
𝟙
0.084, 0.954, ..., 0.914, 0.922
σ = 0.614, 0.150, ..., 0.873, 0.458
Values:array([[0.08414328, 0.95409003, 0.91556799, 0.60699822, 0.68800363],
[0.19432712, 0.46310178, 0.11965925, 0.0197561 , 0.6597149 ],
[0.88885832, 0.46207903, 0.15058648, 0.04347002, 0.84134894],
[0.18437389, 0.44649044, 0.74775448, 0.91441335, 0.92230531]])Variances (σ²):array([[0.37671445, 0.02260972, 0.55977924, 0.00832866, 0.26438793],
[0.08672716, 0.93218837, 0.08213386, 0.00172262, 0.50155131],
[0.06016794, 0.32025299, 0.2944995 , 0.53495261, 0.12905676],
[0.14975438, 0.30018028, 0.02047345, 0.76263568, 0.21002915]])
• c
(y)
float64
𝟙
0.916, 0.120, 0.151, 0.748
σ = 0.748, 0.287, 0.543, 0.143
• aux
()
int64
m
2
Values:array(2)
• x
()
int64
m
2
Values:array(2)
Values:array([0.91556799, 0.11965925, 0.15058648, 0.74775448])Variances (σ²):array([0.55977924, 0.08213386, 0.2944995 , 0.02047345])
• 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])

[9]:

ab
aux [m]x [m] [𝟙] [𝟙]
000.889±0.2450.889±0.245
110.462±0.5660.462±0.566
220.151±0.5430.151±0.543
330.043±0.7310.043±0.731
440.841±0.3590.841±0.359
[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.0841433, 0.95409, ..., 0.914413, 0.922305]  [0.376714, 0.0226097, ..., 0.762636, 0.210029]
b                         float64  [dimensionless]  (y, x)  [0.0841433, 0.95409, ..., 0.914413, 0.922305]  [0.376714, 0.0226097, ..., 0.762636, 0.210029]
c                         float64  [dimensionless]  (y)  [0.915568, 0.119659, 0.150586, 0.747754]  [0.559779, 0.0821339, 0.2945, 0.0204735]
Attributes:
aux                         int64              [m]  ()  [2]
x                           int64              [m]  ()  [2]
scalar                    float64            [m/s]  ()  [1.23]


[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, 1.07003, ..., 1.12473, 1.13444]  [1.13986, 0.604138, ..., 1.15379, 0.317753]
b                         float64            [m/s]  (y, x)  [0, 1.07003, ..., 1.12473, 1.13444]  [1.13986, 0.604138, ..., 1.15379, 0.317753]
c                         float64            [m/s]  (y)  [1.02265, -0.0918415, 0.185221, 0.919738]  [1.41682, 0.25547, 0.445548, 0.0309743]
Attributes:
aux                         int64              [m]  ()  [2]
x                           int64              [m]  ()  [2]
scalar                    float64            [m/s]  ()  [1.23]



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, 1.070, ..., 1.125, 1.134
σ = 1.068, 0.777, ..., 1.074, 0.564
Values:array([[ 0.        ,  1.07003451,  1.0226524 ,  0.64311157,  0.74274824],
[ 0.        ,  0.33059283, -0.09184148, -0.21472236,  0.57242697],
[ 1.09329573,  0.56835721,  0.18522137,  0.05346812,  1.0348592 ],
[ 0.22677989,  0.54918324,  0.91973801,  1.12472843,  1.13443554]])Variances (σ²):array([[1.13986258, 0.60413754, 1.4168213 , 0.58253172, 0.96992379],
[0.26241904, 1.5415173 , 0.25546984, 0.13381567, 0.8900065 ],
[0.09102808, 0.48451075, 0.4455483 , 0.8093298 , 0.19524997],
[0.22656341, 0.45414275, 0.03097428, 1.15379152, 0.3177531 ]])
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, 1.070, ..., 1.125, 1.134
σ = 1.068, 0.777, ..., 1.074, 0.564
Values:array([[ 0.        ,  1.07003451,  1.0226524 ,  0.64311157,  0.74274824],
[ 0.        ,  0.33059283, -0.09184148, -0.21472236,  0.57242697],
[ 1.09329573,  0.56835721,  0.18522137,  0.05346812,  1.0348592 ],
[ 0.22677989,  0.54918324,  0.91973801,  1.12472843,  1.13443554]])Variances (σ²):array([[1.13986258, 0.60413754, 1.4168213 , 0.58253172, 0.96992379],
[0.26241904, 1.5415173 , 0.25546984, 0.13381567, 0.8900065 ],
[0.09102808, 0.48451075, 0.4455483 , 0.8093298 , 0.19524997],
[0.22656341, 0.45414275, 0.03097428, 1.15379152, 0.3177531 ]])
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, 1.070, ..., 1.125, 1.134
σ = 1.068, 0.777, ..., 1.074, 0.564
Values:array([[ 0.        ,  1.07003451,  1.0226524 ,  0.64311157,  0.74274824],
[ 0.        ,  0.33059283, -0.09184148, -0.21472236,  0.57242697],
[ 1.09329573,  0.56835721,  0.18522137,  0.05346812,  1.0348592 ],
[ 0.22677989,  0.54918324,  0.91973801,  1.12472843,  1.13443554]])Variances (σ²):array([[1.13986258, 0.60413754, 1.4168213 , 0.58253172, 0.96992379],
[0.26241904, 1.5415173 , 0.25546984, 0.13381567, 0.8900065 ],
[0.09102808, 0.48451075, 0.4455483 , 0.8093298 , 0.19524997],
[0.22656341, 0.45414275, 0.03097428, 1.15379152, 0.3177531 ]])
• b
(y, x)
float64
m/s
0.0, 1.070, ..., 1.125, 1.134
σ = 1.068, 0.777, ..., 1.074, 0.564
Values:array([[ 0.        ,  1.07003451,  1.0226524 ,  0.64311157,  0.74274824],
[ 0.        ,  0.33059283, -0.09184148, -0.21472236,  0.57242697],
[ 1.09329573,  0.56835721,  0.18522137,  0.05346812,  1.0348592 ],
[ 0.22677989,  0.54918324,  0.91973801,  1.12472843,  1.13443554]])Variances (σ²):array([[1.13986258, 0.60413754, 1.4168213 , 0.58253172, 0.96992379],
[0.26241904, 1.5415173 , 0.25546984, 0.13381567, 0.8900065 ],
[0.09102808, 0.48451075, 0.4455483 , 0.8093298 , 0.19524997],
[0.22656341, 0.45414275, 0.03097428, 1.15379152, 0.3177531 ]])
• c
(y)
float64
m/s
1.023, -0.092, 0.185, 0.920
σ = 1.190, 0.505, 0.667, 0.176
• aux
()
int64
m
2
Values:array(2)
• x
()
int64
m
2
Values:array(2)
Values:array([ 1.0226524 , -0.09184148,  0.18522137,  0.91973801])Variances (σ²):array([1.4168213 , 0.25546984, 0.4455483 , 0.03097428])
• scalar
()
float64
m/s
1.23
Values:array(1.23)
[13]:

<module 'scipp' from '/home/runner/work/scipp/scipp/.tox/docs/lib/python3.8/site-packages/scipp/__init__.py'>