{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0ea7bcf5-2a0f-4f16-a2a5-d628d7b159f7",
   "metadata": {},
   "source": [
    "# Tutorial notebook: minimal working example\n",
    "Here we use some minimal example data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0bb698e7-3808-42d8-976e-571c7d383849",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ac428d3-34a1-4acb-806b-fe4249e3f937",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load your data. Here we're creating random data.\n",
    "coords = np.random.randn( 20000, 3 )\n",
    "fields = np.random.random(size=coords[:,0].size)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34ecbc6c-a09f-4017-9c0e-5768cd91276a",
   "metadata": {},
   "source": [
    "## Format Data for Firefly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2154b107-f405-443c-b607-737c78e37dfb",
   "metadata": {},
   "outputs": [],
   "source": [
    "from firefly.data_reader import ArrayReader"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a24861c-00af-4aa5-9c4c-41f439d65c1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_arrayReader = ArrayReader(\n",
    "    coords,\n",
    "    fields=fields,\n",
    "    write_to_disk=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dabdb04f-71ad-4b1c-9c73-211300a75fef",
   "metadata": {},
   "source": [
    "## Display Inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf3fd1b8-f568-4558-b8f3-4c6751d4f32b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from firefly.server import spawnFireflyServer,quitAllFireflyServers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e2fa016-019c-482a-a039-114816ecee37",
   "metadata": {},
   "outputs": [],
   "source": [
    "process = spawnFireflyServer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0493ceed-85af-4e50-a6b4-95801a4e37ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import IFrame\n",
    "url = \"http://localhost:5500/combined\"\n",
    "IFrame(url, width=1000, height=500)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2261db30-3211-482a-adbc-a3f2983199fd",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Send data to the server.\n",
    "# Wait until it loads to run this command\n",
    "my_arrayReader.sendDataViaFlask()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83c11899-5ca2-4a58-91e1-6818988f3603",
   "metadata": {},
   "outputs": [],
   "source": [
    "return_code = quitAllFireflyServers()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d04aaa5d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
