diff --git a/examples/SonifyingDataTESS.ipynb b/examples/SonifyingDataTESS.ipynb new file mode 100644 index 0000000..e6624ca --- /dev/null +++ b/examples/SonifyingDataTESS.ipynb @@ -0,0 +1,273 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "03b73a45", + "metadata": {}, + "source": [ + "## Demonstrate some generic techniques for sonifying 1D data:" + ] + }, + { + "cell_type": "markdown", + "id": "37f21355", + "metadata": {}, + "source": [ + "**First, import relevant modules:**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f64e736a", + "metadata": {}, + "outputs": [], + "source": [ + "%reload_ext autoreload \n", + "%autoreload 2\n", + "%matplotlib inline\n", + "import matplotlib.pyplot as plt\n", + "from strauss.sonification import Sonification\n", + "from strauss.sources import Objects\n", + "from strauss import channels\n", + "from strauss.score import Score\n", + "from strauss.generator import Synthesizer\n", + "import IPython.display as ipd\n", + "import os\n", + "from scipy.interpolate import interp1d\n", + "import numpy as np\n", + "import requests\n", + "import json" + ] + }, + { + "cell_type": "markdown", + "id": "c4a3e9c2-e9e3-48ca-a21c-0ae64bb549f6", + "metadata": {}, + "source": [ + "**Now, we load some test data!**\n", + "\n", + "We use a simulated subject from the PH-TESS dataset (subject 94880899 or subject 94880882):" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fbf7b1b5-79b7-4a2a-a8e9-15f196a15ca6", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "s94880899 = 'https://panoptes-uploads.zooniverse.org/subject_location/03caefe6-7d48-4225-9cc0-e5a60f337af8.txt'\n", + "s94880882 = 'https://panoptes-uploads.zooniverse.org/subject_location/7578bd5d-b8da-4c42-8da7-5f897ded018e.txt'\n", + "response = json.loads(requests.get(s94880882).text)\n", + "days = np.array(response['x'])\n", + "normalised_days = lambda d: d / days.max()\n", + "x = np.array(list(map(normalised_days, days)))\n", + "normalised_flux = map(lambda f: f + 0.5,response['y'])\n", + "y = np.array(list(normalised_flux))\n", + "\n", + "\n", + "plt.plot(x,y)\n", + "plt.ylabel('Normalised flux')\n", + "plt.xlabel('Days')" + ] + }, + { + "cell_type": "markdown", + "id": "d0f6edf6-59bf-4bdc-a9e7-c7f097cd08d3", + "metadata": {}, + "source": [ + "**Set up some universal sonification parameters and classes for the examples below**\n", + "\n", + "For all examples we use the `Synthesizer` generator to create a 30 second, mono sonification." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "009d6c9a-fb4c-4cd9-a87d-ccae4f280d89", + "metadata": {}, + "outputs": [], + "source": [ + "# specify audio system (e.g. mono, stereo, 5.1, ...)\n", + "system = \"stereo\"\n", + "\n", + "# length of the sonification in s\n", + "length = 15.\n", + "\n", + "# set up synth and turn on LP filter\n", + "generator = Synthesizer()\n", + "generator.load_preset('pitch_mapper')\n", + "generator.preset_details('pitch_mapper')" + ] + }, + { + "cell_type": "markdown", + "id": "b7a7b7ed-6da8-4694-8aef-df00a7277d42", + "metadata": {}, + "source": [ + "### Example 1   **Pitch Mapping**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7c92480b-345a-4212-883c-b9eded4060d5", + "metadata": {}, + "outputs": [], + "source": [ + "notes = [[\"A2\"]]\n", + "score = Score(notes, length)\n", + "\n", + "data = {'pitch':1.,\n", + " 'time_evo':x,\n", + " 'azimuth':(x*0.5+0.25) % 1,\n", + " 'polar':0.5,\n", + " 'pitch_shift':y**0.7}\n", + "\n", + "# set up source\n", + "sources = Objects(data.keys())\n", + "sources.fromdict(data)\n", + "sources.apply_mapping_functions()\n", + "\n", + "soni = Sonification(score, sources, generator, system)\n", + "soni.render()\n", + "soni.notebook_display()" + ] + }, + { + "cell_type": "markdown", + "id": "285b12a8-ef64-49f9-a851-b011bde05e29", + "metadata": {}, + "source": [ + "### Example 2   **Volume Mapping**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7bed74fc-a506-47d7-aff1-0ea6e200bd8a", + "metadata": {}, + "outputs": [], + "source": [ + "notes = [[\"A2\"]]\n", + "score = Score(notes, length)\n", + "\n", + "data = {'pitch':1.,\n", + " 'time_evo':x,\n", + " 'azimuth':(x*0.5+0.25) % 1,\n", + " 'polar':0.5,\n", + " 'volume':y**0.7}\n", + "\n", + "# set up source\n", + "sources = Objects(data.keys())\n", + "sources.fromdict(data)\n", + "sources.apply_mapping_functions()\n", + "\n", + "soni = Sonification(score, sources, generator, system)\n", + "soni.render()\n", + "soni.notebook_display()" + ] + }, + { + "cell_type": "markdown", + "id": "25f17dd1-fe8c-4b61-8a15-4a3cedb646b4", + "metadata": {}, + "source": [ + "### Example 3   **Filter Cutoff Mapping**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a1efde9b-c4c9-4c0f-b4c5-9d32a2098fb1", + "metadata": {}, + "outputs": [], + "source": [ + "generator = Synthesizer()\n", + "generator.modify_preset({'filter':'on'})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a583f3bd-b57b-4448-8cf2-d30de234a3bd", + "metadata": {}, + "outputs": [], + "source": [ + "notes = [[\"C2\",\"G2\",\"C3\",\"G3\"]]\n", + "score = Score(notes, length)\n", + "\n", + "data = {'pitch':[0,1,2,3],\n", + " 'time_evo':[x]*4,\n", + " 'azimuth':[(x*0.5+0.25) % 1]*4,\n", + " 'polar':[0.5]*4,\n", + " 'cutoff':[y**0.8]*4}\n", + "\n", + "# set up source\n", + "sources = Objects(data.keys())\n", + "sources.fromdict(data)\n", + "sources.apply_mapping_functions()\n", + "\n", + "soni = Sonification(score, sources, generator, system)\n", + "soni.render()\n", + "soni.notebook_display()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17785113-03f2-4f3a-824c-9c3d93ed1530", + "metadata": {}, + "outputs": [], + "source": [ + "generator = Synthesizer()\n", + "generator.load_preset('windy')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d001083d-e5d8-4308-bcc2-f775d963395a", + "metadata": {}, + "outputs": [], + "source": [ + "data = {'pitch':[0,1,2,3],\n", + " 'time_evo':[x],\n", + " 'azimuth':[(x*0.5+0.25) % 1],\n", + " 'polar':[0.5],\n", + " 'cutoff':[y**0.8]}\n", + "sources = Objects(data.keys())\n", + "sources.fromdict(data)\n", + "sources.apply_mapping_functions()\n", + "\n", + "soni = Sonification(score, sources, generator, system)\n", + "soni.render()\n", + "soni.notebook_display()" + ] + } + ], + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}