{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Quick start\n", "\n", "This section provides a quick introduction to `scipp`.\n", "For in depth explanations refer to the sections in the user guide." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import scipp as sc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start by creating some variables:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "var = sc.Variable(dims=['y', 'x'], values=np.random.rand(4,5))\n", "sc.show(var)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Type the name of a variable at the end of a cell to generate an HTML respresentation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "var" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = sc.Variable(dims=['x'], values=np.arange(5), unit=sc.units.m)\n", "y = sc.Variable(dims=['y'], values=np.arange(4), unit=sc.units.m)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We combine the variables into a data array:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "array = sc.DataArray(\n", " data=var,\n", " coords={'x': x, 'y': y})\n", "sc.show(array)\n", "array" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Variables can have uncertainties.\n", "Scipp stores these as variances (the square of the standard deviation):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "array.variances = np.square(np.random.rand(4,5))\n", "sc.show(array)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We create a dataset:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset = sc.Dataset(\n", " data={'a': var},\n", " coords={'x': x, 'y': y, 'aux': x})\n", "dataset['b'] = array\n", "dataset['scalar'] = 1.23 * (sc.units.m / sc.units.s)\n", "sc.show(dataset)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can slice variables, data arrays, and datasets using a dimension label and an index or a slice object like `i:j`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset['c'] = dataset['b']['x', 2]\n", "sc.show(dataset)\n", "dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also generate table representations (only 0-D and 1-D) and plots:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sc.table(dataset['y', 2])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sc.plot(dataset)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Arithmetic operations can be combined with slicing and handle propagation of uncertainties and units:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(dataset)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dataset['b']['y', 0:2] -= dataset['y', 0:2]['a']['x', 0]\n", "dataset['b'] *= dataset['scalar']\n", "print(dataset)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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).\n", "Click on entries to expand nested sections:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sc" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }