{ "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.\n", "We recommend importing Scipp with the alias `sc`, i.e., `import scipp as sc`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import scipp as sc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start by creating some variables:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = sc.arange('x', 5, unit='m')\n", "y = sc.linspace('y', 0.0, 1.0, num=4, unit='m')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Type the name of a variable at the end of a cell to generate an HTML representation:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "y" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can initialize the values of a variable from a NumPy array:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "rng = np.random.default_rng(12345)\n", "var = sc.array(dims=['y', 'x'], values=rng.random((4, 5)))\n", "sc.show(var)" ] }, { "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(data=var, 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 = array.copy()\n", "array.variances = np.square(rng.random((4, 5)))\n", "sc.show(array)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We create a dataset:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "dataset = sc.Dataset(data={'a': var}, coords={'x': x, 'y': y, 'aux': x})\n", "dataset['b'] = array\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": { "tags": [] }, "outputs": [], "source": [ "sliced = dataset['b']['x', 2]\n", "sc.show(sliced)\n", "sliced" ] }, { "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": { "tags": [] }, "outputs": [], "source": [ "sc.table(dataset['y', 2])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "sc.plot(dataset['a'])" ] }, { "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": { "tags": [] }, "outputs": [], "source": [ "print(dataset)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "dataset['a']['y', 0:2] -= dataset['y', 0:2]['a']['x', 0]\n", "dataset['b'] *= 1.23 * sc.Unit('m/s')\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": { "tags": [] }, "outputs": [], "source": [ "sc" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.16" } }, "nbformat": 4, "nbformat_minor": 4 }