Quick start

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.613, 0.283, ..., 0.339, 0.914
      Values:
      array([[0.6131034 , 0.2832231 , 0.48558676, 0.94835275, 0.94932854], [0.00698108, 0.30465546, 0.1835042 , 0.73350568, 0.37126001], [0.30883601, 0.50792822, 0.78048415, 0.4991276 , 0.29868537], [0.44494411, 0.47533736, 0.52786949, 0.33903244, 0.91386923]])
[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.613, 0.283, ..., 0.339, 0.914
      Values:
      array([[0.6131034 , 0.2832231 , 0.48558676, 0.94835275, 0.94932854], [0.00698108, 0.30465546, 0.1835042 , 0.73350568, 0.37126001], [0.30883601, 0.50792822, 0.78048415, 0.4991276 , 0.29868537], [0.44494411, 0.47533736, 0.52786949, 0.33903244, 0.91386923]])

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.613, 0.283, ..., 0.339, 0.914
      σ = 0.218, 0.742, ..., 0.555, 0.009
      Values:
      array([[0.6131034 , 0.2832231 , 0.48558676, 0.94835275, 0.94932854], [0.00698108, 0.30465546, 0.1835042 , 0.73350568, 0.37126001], [0.30883601, 0.50792822, 0.78048415, 0.4991276 , 0.29868537], [0.44494411, 0.47533736, 0.52786949, 0.33903244, 0.91386923]])

      Variances (σ²):
      array([[4.77386198e-02, 5.50171244e-01, 2.81505521e-01, 4.77248288e-01, 7.31849683e-01], [1.35881140e-02, 3.01542696e-01, 2.09810757e-01, 5.11754257e-01, 2.43575149e-02], [4.91394589e-01, 8.41539714e-02, 7.86341743e-02, 8.89500185e-01, 6.78808360e-04], [1.62856494e-01, 5.10978527e-01, 4.69227129e-01, 3.07762829e-01, 7.91210274e-05]])
    • b
      (y, x)
      float64
      0.613, 0.283, ..., 0.339, 0.914
      σ = 0.218, 0.742, ..., 0.555, 0.009
      Values:
      array([[0.6131034 , 0.2832231 , 0.48558676, 0.94835275, 0.94932854], [0.00698108, 0.30465546, 0.1835042 , 0.73350568, 0.37126001], [0.30883601, 0.50792822, 0.78048415, 0.4991276 , 0.29868537], [0.44494411, 0.47533736, 0.52786949, 0.33903244, 0.91386923]])

      Variances (σ²):
      array([[4.77386198e-02, 5.50171244e-01, 2.81505521e-01, 4.77248288e-01, 7.31849683e-01], [1.35881140e-02, 3.01542696e-01, 2.09810757e-01, 5.11754257e-01, 2.43575149e-02], [4.91394589e-01, 8.41539714e-02, 7.86341743e-02, 8.89500185e-01, 6.78808360e-04], [1.62856494e-01, 5.10978527e-01, 4.69227129e-01, 3.07762829e-01, 7.91210274e-05]])
    • c
      (y)
      float64
      0.486, 0.184, 0.780, 0.528
      σ = 0.531, 0.458, 0.280, 0.685
        • aux
          ()
          int64
          m
          2
          Values:
          array(2)
        • x
          ()
          int64
          m
          2
          Values:
          array(2)
      Values:
      array([0.48558676, 0.1835042 , 0.78048415, 0.52786949])

      Variances (σ²):
      array([0.28150552, 0.20981076, 0.07863417, 0.46922713])
    • 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.613103, 0.283223, ..., 0.339032, 0.913869]  [0.0477386, 0.550171, ..., 0.307763, 7.9121e-05]
  b                         float64  [dimensionless]  (y, x)  [0.613103, 0.283223, ..., 0.339032, 0.913869]  [0.0477386, 0.550171, ..., 0.307763, 7.9121e-05]
  c                         float64  [dimensionless]  (y)  [0.485587, 0.183504, 0.780484, 0.527869]  [0.281506, 0.209811, 0.0786342, 0.469227]
    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, -0.405753, ..., 0.41701, 1.12406]  [0.144448, 0.904578, ..., 0.465614, 0.000119702]
  b                         float64            [m/s]  (y, x)  [0, -0.405753, ..., 0.41701, 1.12406]  [0.144448, 0.904578, ..., 0.465614, 0.000119702]
  c                         float64            [m/s]  (y)  [-0.156845, 0.217123, 0.959996, 0.649279]  [0.498113, 0.33798, 0.118966, 0.709894]
    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
Show/Hide data repr Show/Hide attributes
scipp.Variable (320 Bytes)
    • (y: 4, x: 5)
      float64
      m/s
      0.0, -0.406, ..., 0.417, 1.124
      σ = 0.380, 0.951, ..., 0.682, 0.011
      Values:
      array([[ 0. , -0.40575277, -0.15684547, 0.4123567 , 0.41355693], [ 0. , 0.3661395 , 0.21712344, 0.89362526, 0.44806309], [ 0.37986829, 0.62475171, 0.95999551, 0.61392695, 0.36738301], [ 0.54728125, 0.58466496, 0.64927947, 0.4170099 , 1.12405916]])

      Variances (σ²):
      array([[1.44447516e-01, 9.04577832e-01, 4.98113461e-01, 7.94252693e-01, 1.17943914e+00], [4.11149154e-02, 4.76761403e-01, 3.37980152e-01, 7.94790473e-01, 5.74079420e-02], [7.43430874e-01, 1.27316543e-01, 1.18965642e-01, 1.34572483e+00, 1.02696917e-03], [2.46385590e-01, 7.73059414e-01, 7.09893723e-01, 4.65614383e-01, 1.19702202e-04]])
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.406, ..., 0.417, 1.124
      σ = 0.380, 0.951, ..., 0.682, 0.011
      Values:
      array([[ 0. , -0.40575277, -0.15684547, 0.4123567 , 0.41355693], [ 0. , 0.3661395 , 0.21712344, 0.89362526, 0.44806309], [ 0.37986829, 0.62475171, 0.95999551, 0.61392695, 0.36738301], [ 0.54728125, 0.58466496, 0.64927947, 0.4170099 , 1.12405916]])

      Variances (σ²):
      array([[1.44447516e-01, 9.04577832e-01, 4.98113461e-01, 7.94252693e-01, 1.17943914e+00], [4.11149154e-02, 4.76761403e-01, 3.37980152e-01, 7.94790473e-01, 5.74079420e-02], [7.43430874e-01, 1.27316543e-01, 1.18965642e-01, 1.34572483e+00, 1.02696917e-03], [2.46385590e-01, 7.73059414e-01, 7.09893723e-01, 4.65614383e-01, 1.19702202e-04]])
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.406, ..., 0.417, 1.124
      σ = 0.380, 0.951, ..., 0.682, 0.011
      Values:
      array([[ 0. , -0.40575277, -0.15684547, 0.4123567 , 0.41355693], [ 0. , 0.3661395 , 0.21712344, 0.89362526, 0.44806309], [ 0.37986829, 0.62475171, 0.95999551, 0.61392695, 0.36738301], [ 0.54728125, 0.58466496, 0.64927947, 0.4170099 , 1.12405916]])

      Variances (σ²):
      array([[1.44447516e-01, 9.04577832e-01, 4.98113461e-01, 7.94252693e-01, 1.17943914e+00], [4.11149154e-02, 4.76761403e-01, 3.37980152e-01, 7.94790473e-01, 5.74079420e-02], [7.43430874e-01, 1.27316543e-01, 1.18965642e-01, 1.34572483e+00, 1.02696917e-03], [2.46385590e-01, 7.73059414e-01, 7.09893723e-01, 4.65614383e-01, 1.19702202e-04]])
    • b
      (y, x)
      float64
      m/s
      0.0, -0.406, ..., 0.417, 1.124
      σ = 0.380, 0.951, ..., 0.682, 0.011
      Values:
      array([[ 0. , -0.40575277, -0.15684547, 0.4123567 , 0.41355693], [ 0. , 0.3661395 , 0.21712344, 0.89362526, 0.44806309], [ 0.37986829, 0.62475171, 0.95999551, 0.61392695, 0.36738301], [ 0.54728125, 0.58466496, 0.64927947, 0.4170099 , 1.12405916]])

      Variances (σ²):
      array([[1.44447516e-01, 9.04577832e-01, 4.98113461e-01, 7.94252693e-01, 1.17943914e+00], [4.11149154e-02, 4.76761403e-01, 3.37980152e-01, 7.94790473e-01, 5.74079420e-02], [7.43430874e-01, 1.27316543e-01, 1.18965642e-01, 1.34572483e+00, 1.02696917e-03], [2.46385590e-01, 7.73059414e-01, 7.09893723e-01, 4.65614383e-01, 1.19702202e-04]])
    • c
      (y)
      float64
      m/s
      -0.157, 0.217, 0.960, 0.649
      σ = 0.706, 0.581, 0.345, 0.843
        • aux
          ()
          int64
          m
          2
          Values:
          array(2)
        • x
          ()
          int64
          m
          2
          Values:
          array(2)
      Values:
      array([-0.15684547, 0.21712344, 0.95999551, 0.64927947])

      Variances (σ²):
      array([0.49811346, 0.33798015, 0.11896564, 0.70989372])
    • scalar
      ()
      float64
      m/s
      1.23
      Values:
      array(1.23)
[13]:
<module 'scipp' from '/usr/share/miniconda/envs/test/conda-bld/scipp_1642083266382/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib/python3.7/site-packages/scipp/__init__.py'>