Download this Jupyter notebook


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)
dims=['y', 'x'], shape=[4, 5], unit=dimensionless, variances=Falsevalues yx

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

[3]:
var
[3]:
Show/Hide data repr Show/Hide attributes
scipp.Variable (160 Bytes)
    • (y: 4, x: 5)
      float64
      0.36, 0.19, ..., 0.1, 0.56
      Values:
      array([[0.35620622, 0.19304515, 0.66822755, 0.9621907 , 0.03204145], [0.94979449, 0.13841741, 0.27123956, 0.57415605, 0.84638204], [0.89359542, 0.79761112, 0.63548611, 0.61090044, 0.30631625], [0.92824375, 0.75823889, 0.74209011, 0.10439147, 0.56136769]])
[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
(dims=['y', 'x'], shape=[4, 5], unit=dimensionless, variances=False)values yx yy(dims=['y'], shape=[4], unit=m, variances=False)values y xx(dims=['x'], shape=[5], unit=m, variances=False)values x
[5]:
Show/Hide data repr Show/Hide attributes
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.36, 0.19, ..., 0.1, 0.56
      Values:
      array([[0.35620622, 0.19304515, 0.66822755, 0.9621907 , 0.03204145], [0.94979449, 0.13841741, 0.27123956, 0.57415605, 0.84638204], [0.89359542, 0.79761112, 0.63548611, 0.61090044, 0.30631625], [0.92824375, 0.75823889, 0.74209011, 0.10439147, 0.56136769]])

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)
(dims=['y', 'x'], shape=[4, 5], unit=dimensionless, variances=True)variances yxvalues yx yy(dims=['y'], shape=[4], unit=m, variances=False)values y xx(dims=['x'], shape=[5], unit=m, variances=False)values x

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)
bb(dims=['y', 'x'], shape=[4, 5], unit=dimensionless, variances=True)variances yxvalues yx aa(dims=['y', 'x'], shape=[4, 5], unit=dimensionless, variances=True)variances yxvalues yx yy(dims=['y'], shape=[4], unit=m, variances=False)values y scala..scalar(dims=[], shape=[], unit=m/s, variances=False)values xx(dims=['x'], shape=[5], unit=m, variances=False)values x auxaux(dims=['x'], shape=[5], unit=m, variances=False)values x

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
bb(dims=['y', 'x'], shape=[4, 5], unit=dimensionless, variances=True)variances yxvalues yx aa(dims=['y', 'x'], shape=[4, 5], unit=dimensionless, variances=True)variances yxvalues yx yy(dims=['y'], shape=[4], unit=m, variances=False)values y cc(dims=['y'], shape=[4], unit=dimensionless, variances=True)variances yvalues y scala..scalar(dims=[], shape=[], unit=m/s, variances=False)values xx(dims=['x'], shape=[5], unit=m, variances=False)values x auxaux(dims=['x'], shape=[5], unit=m, variances=False)values x
[8]:
Show/Hide data repr Show/Hide attributes
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.36, 0.19, ..., 0.1, 0.56
      σ = 0.56, 0.42, ..., 0.73, 0.1
      Values:
      array([[0.35620622, 0.19304515, 0.66822755, 0.9621907 , 0.03204145], [0.94979449, 0.13841741, 0.27123956, 0.57415605, 0.84638204], [0.89359542, 0.79761112, 0.63548611, 0.61090044, 0.30631625], [0.92824375, 0.75823889, 0.74209011, 0.10439147, 0.56136769]])

      Variances (σ²):
      array([[0.31252281, 0.1786297 , 0.10900878, 0.76808841, 0.63674344], [0.01641601, 0.6308399 , 0.10583196, 0.51720851, 0.33267364], [0.39508017, 0.62752704, 0.9755135 , 0.10787153, 0.40062838], [0.01848075, 0.03640689, 0.80584553, 0.52729343, 0.01014745]])
    • b
      (y, x)
      float64
      0.36, 0.19, ..., 0.1, 0.56
      σ = 0.56, 0.42, ..., 0.73, 0.1
      Values:
      array([[0.35620622, 0.19304515, 0.66822755, 0.9621907 , 0.03204145], [0.94979449, 0.13841741, 0.27123956, 0.57415605, 0.84638204], [0.89359542, 0.79761112, 0.63548611, 0.61090044, 0.30631625], [0.92824375, 0.75823889, 0.74209011, 0.10439147, 0.56136769]])

      Variances (σ²):
      array([[0.31252281, 0.1786297 , 0.10900878, 0.76808841, 0.63674344], [0.01641601, 0.6308399 , 0.10583196, 0.51720851, 0.33267364], [0.39508017, 0.62752704, 0.9755135 , 0.10787153, 0.40062838], [0.01848075, 0.03640689, 0.80584553, 0.52729343, 0.01014745]])
    • c
      (y)
      float64
      0.67, 0.27, 0.64, 0.74
      σ = 0.33, 0.33, 0.99, 0.9
        • aux
          ()
          int64
          m
          2
          Values:
          array(2)
        • x
          ()
          int64
          m
          2
          Values:
          array(2)
      Values:
      array([0.66822755, 0.27123956, 0.63548611, 0.74209011])

      Variances (σ²):
      array([0.10900878, 0.10583196, 0.9755135 , 0.80584553])
    • 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.356206, 0.193045, ..., 0.104391, 0.561368]  [0.312523, 0.178630, ..., 0.527293, 0.010147]
  b                         float64  [dimensionless]  (y, x)  [0.356206, 0.193045, ..., 0.104391, 0.561368]  [0.312523, 0.178630, ..., 0.527293, 0.010147]
  c                         float64  [dimensionless]  (y)  [0.668228, 0.271240, 0.635486, 0.742090]  [0.109009, 0.105832, 0.975513, 0.805846]
    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.200688, ..., 0.128402, 0.690482]  [0.945632, 0.743065, ..., 0.797742, 0.015352]
  b                         float64            [m/s]  (y, x)  [0.000000, -0.200688, ..., 0.128402, 0.690482]  [0.945632, 0.743065, ..., 0.797742, 0.015352]
  c                         float64            [m/s]  (y)  [0.383786, -0.834623, 0.781648, 0.912771]  [0.637735, 0.184949, 1.475854, 1.219164]
    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
Show/Hide data repr Show/Hide attributes
scipp.Variable (320 Bytes)
    • (y: 4, x: 5)
      float64
      m/s
      0.0, -0.2, ..., 0.13, 0.69
      σ = 0.97, 0.86, ..., 0.89, 0.12
      Values:
      array([[ 0. , -0.20068812, 0.38378623, 0.7453609 , -0.39872267], [ 0. , -0.9979938 , -0.83462256, -0.46203528, -0.12719731], [ 1.09912236, 0.98106168, 0.78164792, 0.75140754, 0.37676899], [ 1.14173982, 0.93263384, 0.91277084, 0.12840151, 0.69048226]])

      Variances (σ²):
      array([[0.94563151, 0.74306463, 0.63773513, 1.63485672, 1.43614491], [0.04967157, 0.97923347, 0.18494896, 0.80732054, 0.52813774], [0.59771679, 0.94938567, 1.47585437, 0.16319883, 0.60611068], [0.02795953, 0.05507998, 1.21916371, 0.79774224, 0.01535208]])
x
Show/Hide data repr Show/Hide attributes
scipp.Variable (40 Bytes)
    • (x: 5)
      int64
      m
      0, 1, 2, 3, 4
      Values:
      array([0, 1, 2, 3, 4])
y
Show/Hide data repr Show/Hide attributes
scipp.Variable (32 Bytes)
    • (y: 4)
      int64
      m
      0, 1, 2, 3
      Values:
      array([0, 1, 2, 3])
DataArrays:(1)
array
Show/Hide data repr Show/Hide attributes
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.2, ..., 0.13, 0.69
      σ = 0.97, 0.86, ..., 0.89, 0.12
      Values:
      array([[ 0. , -0.20068812, 0.38378623, 0.7453609 , -0.39872267], [ 0. , -0.9979938 , -0.83462256, -0.46203528, -0.12719731], [ 1.09912236, 0.98106168, 0.78164792, 0.75140754, 0.37676899], [ 1.14173982, 0.93263384, 0.91277084, 0.12840151, 0.69048226]])

      Variances (σ²):
      array([[0.94563151, 0.74306463, 0.63773513, 1.63485672, 1.43614491], [0.04967157, 0.97923347, 0.18494896, 0.80732054, 0.52813774], [0.59771679, 0.94938567, 1.47585437, 0.16319883, 0.60611068], [0.02795953, 0.05507998, 1.21916371, 0.79774224, 0.01535208]])
Datasets:(1)
dataset
Show/Hide data repr Show/Hide attributes
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.2, ..., 0.13, 0.69
      σ = 0.97, 0.86, ..., 0.89, 0.12
      Values:
      array([[ 0. , -0.20068812, 0.38378623, 0.7453609 , -0.39872267], [ 0. , -0.9979938 , -0.83462256, -0.46203528, -0.12719731], [ 1.09912236, 0.98106168, 0.78164792, 0.75140754, 0.37676899], [ 1.14173982, 0.93263384, 0.91277084, 0.12840151, 0.69048226]])

      Variances (σ²):
      array([[0.94563151, 0.74306463, 0.63773513, 1.63485672, 1.43614491], [0.04967157, 0.97923347, 0.18494896, 0.80732054, 0.52813774], [0.59771679, 0.94938567, 1.47585437, 0.16319883, 0.60611068], [0.02795953, 0.05507998, 1.21916371, 0.79774224, 0.01535208]])
    • b
      (y, x)
      float64
      m/s
      0.0, -0.2, ..., 0.13, 0.69
      σ = 0.97, 0.86, ..., 0.89, 0.12
      Values:
      array([[ 0. , -0.20068812, 0.38378623, 0.7453609 , -0.39872267], [ 0. , -0.9979938 , -0.83462256, -0.46203528, -0.12719731], [ 1.09912236, 0.98106168, 0.78164792, 0.75140754, 0.37676899], [ 1.14173982, 0.93263384, 0.91277084, 0.12840151, 0.69048226]])

      Variances (σ²):
      array([[0.94563151, 0.74306463, 0.63773513, 1.63485672, 1.43614491], [0.04967157, 0.97923347, 0.18494896, 0.80732054, 0.52813774], [0.59771679, 0.94938567, 1.47585437, 0.16319883, 0.60611068], [0.02795953, 0.05507998, 1.21916371, 0.79774224, 0.01535208]])
    • c
      (y)
      float64
      m/s
      0.38, -0.83, 0.78, 0.91
      σ = 0.8, 0.43, 1.21, 1.1
        • aux
          ()
          int64
          m
          2
          Values:
          array(2)
        • x
          ()
          int64
          m
          2
          Values:
          array(2)
      Values:
      array([ 0.38378623, -0.83462256, 0.78164792, 0.91277084])

      Variances (σ²):
      array([0.63773513, 0.18494896, 1.47585437, 1.21916371])
    • scalar
      ()
      float64
      m/s
      1.23
      Values:
      array(1.23)
[13]:
<module 'scipp' from '/usr/share/miniconda/envs/tempenv/lib/python3.7/scipp/__init__.py'>