{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example usage\n", "\n", "Here we will demonstrate how to use `pyvlasiator` to process Vlasiator data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Downloading demo data\n", "\n", "If you don't have Vlasiator data to start with, you can download demo data with the following:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "import requests\n", "import tarfile\n", "import os\n", "\n", "url = \"https://raw.githubusercontent.com/henry2004y/vlsv_data/master/testdata.tar.gz\"\n", "testfiles = url.rsplit(\"/\", 1)[1]\n", "r = requests.get(url, allow_redirects=True)\n", "open(testfiles, \"wb\").write(r.content)\n", "path = \"./data\"\n", "if not os.path.exists(path):\n", " os.makedirs(path)\n", "with tarfile.open(testfiles) as file:\n", " file.extractall(path)\n", "os.remove(testfiles)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loading VLSV data\n", "\n", "### Read meta data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "from pyvlasiator.vlsv import Vlsv\n", "\n", "file = \"data/bulk.1d.vlsv\"\n", "meta = Vlsv(file)\n", "meta" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Read parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "t = meta.read_parameter(\"time\")\n", "t" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Read variable" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "data = meta.read_variable(\"CellID\")\n", "data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting\n", "\n", "To enable plotting functionalities, we need to first import the corresponding submodule:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "import pyvlasiator.plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1D" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "meta.plot(\"proton/vg_rho\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2D" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "file = \"data/bulk.2d.vlsv\"\n", "meta = Vlsv(file)\n", "meta.pcolormesh(\"vg_b_vol\", comp=1)\n", "meta.streamplot(\"proton/vg_v\", comp=\"xy\", color=\"w\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Field solver grid variables are also supported via the same APIs:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "meta.pcolormesh(\"fg_b\", comp=1)\n", "meta.streamplot(\"fg_b\", comp=\"xy\", color=\"w\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2D slice of 3D AMR data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "file = \"data/bulk.amr.vlsv\"\n", "meta = Vlsv(file)\n", "meta.pcolormesh(\"proton/vg_rho\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## VDF" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "julia" } }, "outputs": [], "source": [ "file = \"data/bulk.1d.vlsv\"\n", "meta = Vlsv(file)\n", "loc = [2.0, 0.0, 0.0]\n", "meta.vdfslice(loc)" ] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }