-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental PH-TESS notebook #14
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "463d13f3-c28b-4bc4-89cf-332ceeb55663", | ||
"metadata": {}, | ||
"source": [ | ||
"## <u> Demonstrate some generic techniques for sonifying 1D data:</u>" | ||
] | ||
}, | ||
{ | ||
"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 simulated subjects from the PH-TESS dataset:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fbf7b1b5-79b7-4a2a-a8e9-15f196a15ca6", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"s94812564 = 'https://panoptes-uploads.zooniverse.org/subject_location/c4a2a54a-da3b-4f1d-9823-702549a2806a.txt'\n", | ||
"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(s94812564).text)\n", | ||
"days = np.array(response['x'])\n", | ||
"flux = np.array(response['y'])\n", | ||
"normalised_days = lambda d: d / days.max()\n", | ||
"x = np.array(list(map(normalised_days, days)))\n", | ||
"normalised_flux = lambda f: ((f - flux.min()) / (flux.max() - flux.min()))\n", | ||
"y = np.array(list(map(normalised_flux, flux)))\n", | ||
"\n", | ||
"\n", | ||
"plt.plot(days,y)\n", | ||
"plt.ylabel('Normalised Flux')\n", | ||
"plt.xlabel('Days')\n" | ||
] | ||
}, | ||
{ | ||
"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 = 20.\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": [ | ||
"### <u>Example 1</u> **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*10+1)**-0.7}\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm finding it easier to hear the dips in flux if lower flux => higher pitch, but I'm still experimenting. |
||
"\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": [ | ||
"### <u>Example 2</u> **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*10+1)**-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": [ | ||
"### <u>Example 3</u> **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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line is a holdover from an earlier notebook. Anyway, the examples here are 20 seconds and stereo (panning from left to right as we move along the light curve.)