{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[](https://colab.research.google.com/github/usnistgov/AFL-agent/blob/main/docs/source/how-to/building_xarray_datasets.ipynb)\n", "\n", "# Build an xarray.Dataset from Scratch" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this `How-To` we'll go through the process of building up an xarray.Dataset that could be used as an input to `Pipeline.calculate`. We'll generate random compositions and fake data to go along with these compositions. \n", "\n", "\n", "The dataset generated in this notebook is the basis for the `Building Pipelines` tutorial." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Google Colab Setup\n", "\n", "Only uncomment and run the next cell if you are running this notebook in Google Colab or if don't already have the AFL-agent package installed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install git+https://github.com/usnistgov/AFL-agent.git" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## First Steps" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To begin, let's import the necessary libraries for this document and then make an empty :py:class:`xarray.Dataset`" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 0B\n", "Dimensions: ()\n", "Data variables:\n", " *empty*
<xarray.Dataset> Size: 2kB\n", "Dimensions: (sample: 100, component: 2)\n", "Coordinates:\n", " * component (component) <U1 8B 'A' 'B'\n", "Dimensions without coordinates: sample\n", "Data variables:\n", " composition (sample, component) float64 2kB 1.935 4.339 4.0 ... 7.878 14.33
<xarray.Dataset> Size: 2kB\n", "Dimensions: (sample: 100, component: 2)\n", "Coordinates:\n", " * component (component) <U1 8B 'A' 'B'\n", "Dimensions without coordinates: sample\n", "Data variables:\n", " composition (sample, component) float64 2kB 1.935 4.339 ... 14.33\n", " ground_truth_labels (sample) int64 800B 1 1 1 1 1 0 1 1 ... 1 0 1 1 0 1 1 1" ], "text/plain": [ "
<xarray.Dataset> Size: 124kB\n", "Dimensions: (sample: 100, component: 2, x: 150)\n", "Coordinates:\n", " * component (component) <U1 8B 'A' 'B'\n", " * x (x) float64 1kB 0.001 0.001047 0.001097 ... 0.9547 1.0\n", "Dimensions without coordinates: sample\n", "Data variables:\n", " composition (sample, component) float64 2kB 1.935 4.339 ... 14.33\n", " ground_truth_labels (sample) int64 800B 1 1 1 1 1 0 1 1 ... 1 0 1 1 0 1 1 1\n", " measurement (sample, x) float64 120kB 2.047e+06 1.318e+06 ... 2.065
<xarray.Dataset> Size: 164kB\n", "Dimensions: (sample: 100, component: 2, x: 150, grid: 2500)\n", "Coordinates:\n", " * component (component) <U1 8B 'A' 'B'\n", " * x (x) float64 1kB 0.001 0.001047 0.001097 ... 0.9547 1.0\n", "Dimensions without coordinates: sample, grid\n", "Data variables:\n", " composition (sample, component) float64 2kB 1.935 4.339 ... 14.33\n", " ground_truth_labels (sample) int64 800B 1 1 1 1 1 0 1 1 ... 1 0 1 1 0 1 1 1\n", " measurement (sample, x) float64 120kB 2.047e+06 1.318e+06 ... 2.065\n", " composition_grid (grid, component) float64 40kB 0.0 0.0 ... 10.0 25.0