From 7f84c6c350e9e50aa6d0c914952c913513b62fe2 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Fri, 15 Nov 2024 16:20:48 +0000 Subject: [PATCH 01/14] support composite specctral regions, and ensure spectral regions are up-to-date n render --- .../cubeviz/plugins/sonify_data/sonify_data.py | 17 ++++++++++++++++- jdaviz/configs/cubeviz/plugins/viewers.py | 17 +++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py index 2c14c1479b..409a16e809 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py @@ -74,7 +74,7 @@ def __init__(self, *args, **kwargs): # TODO: Remove hardcoded range and flux viewer self.spec_viewer = self.app.get_viewer('spectrum-viewer') self.flux_viewer = self.app.get_viewer('flux-viewer') - + @property def user_api(self): expose = [] @@ -95,6 +95,9 @@ def vue_sonify_cube(self, *args): max_wavelength = self.spectral_subset.selected_obj.upper.to_value(u.Unit(display_unit)) self.flux_viewer.update_listener_wls(min_wavelength, max_wavelength, display_unit) + # Ensure the current spectral region bounds are up-to-date at render time + self.update_wavelength_range(None) + # generate the sonified cube self.flux_viewer.get_sonified_cube(self.sample_rate, self.buffer_size, selected_device_index, self.assidx, self.ssvidx, self.pccut, self.audfrqmin, @@ -108,6 +111,18 @@ def vue_start_stop_stream(self, *args): self.stream_active = not self.stream_active self.flux_viewer.stream_active = not self.flux_viewer.stream_active + @observe('spectral_subset_selected') + def update_wavelength_range(self, event): + if not hasattr(self, 'spec_viewer'): + return + display_unit = self.spec_viewer.state.x_display_unit + # is this spectral selection or the entire spectrum? + if hasattr(self.spectral_subset.selected_obj, "subregions"): + wlbounds = self.spectral_subset.selected_obj.subregions + else: + wlbounds = None + self.flux_viewer.update_listener_wls(wlbounds, display_unit) + @observe('volume') def update_volume_level(self, event): self.flux_viewer.update_volume_level(event['new']) diff --git a/jdaviz/configs/cubeviz/plugins/viewers.py b/jdaviz/configs/cubeviz/plugins/viewers.py index 7bba966582..6740966cea 100644 --- a/jdaviz/configs/cubeviz/plugins/viewers.py +++ b/jdaviz/configs/cubeviz/plugins/viewers.py @@ -50,6 +50,8 @@ def __init__(self, *args, **kwargs): self.sonified_cube = None self.stream = None + + self.sonification_wl_ranges = None self.sonification_wl_bounds = None self.sonification_wl_unit = None self.volume_level = None @@ -113,8 +115,8 @@ def update_sonified_cube(self, x, y): self.sonified_cube.newsig = self.sonified_cube.sigcube[x, y, :] self.sonified_cube.cbuff = True - def update_listener_wls(self, w1, w2, wunit): - self.sonification_wl_bounds = (w1, w2) + def update_listener_wls(self, wbounds, wunit): + self.sonification_wl_ranges = wbounds self.sonification_wl_unit = wunit def update_sound_device(self, device_index): @@ -140,11 +142,14 @@ def get_sonified_cube(self, sample_rate, buffer_size, device, assidx, ssvidx, self.sample_rate = sample_rate self.buffer_size = buffer_size - if self.sonification_wl_bounds: + if self.sonification_wl_ranges: wl_unit = getattr(u, self.sonification_wl_unit) - si_wl_bounds = (self.sonification_wl_bounds * wl_unit).to('m') - wdx = np.logical_and(wlens >= si_wl_bounds[0].value, - wlens <= si_wl_bounds[1].value) + wdx = np.zeros(wlens.size).astype(bool) + for r in self.sonification_wl_ranges: + # index just the spectral subregion + wdx = np.logical_or(wdx, + np.logical_and(wlens >= r[0].to('m').value, + wlens <= r[1].to('m').value)) wlens = wlens[wdx] flux = flux[:, :, wdx] From c09b879a3fa9d381469ef4a1a161be4c35c8c3ed Mon Sep 17 00:00:00 2001 From: James Trayford Date: Fri, 15 Nov 2024 19:30:57 +0000 Subject: [PATCH 02/14] sonification plugin options: rearrange, label, defaults. --- .../plugins/sonify_data/sonify_data.py | 2 +- .../plugins/sonify_data/sonify_data.vue | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py index 409a16e809..90a70d91cc 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py @@ -43,7 +43,7 @@ class SonifyData(PluginTemplateMixin, DatasetSelectMixin, SpectralSubsetSelectMi buffer_size = IntHandleEmpty(2048).tag(sync=True) assidx = FloatHandleEmpty(2.5).tag(sync=True) ssvidx = FloatHandleEmpty(0.65).tag(sync=True) - eln = Bool(False).tag(sync=True) + eln = Bool(True).tag(sync=True) audfrqmin = FloatHandleEmpty(50).tag(sync=True) audfrqmax = FloatHandleEmpty(1500).tag(sync=True) pccut = IntHandleEmpty(20).tag(sync=True) diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue index 6443eedde0..5d233022b9 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue @@ -9,12 +9,23 @@ :scroll_to.sync="scroll_to" :disabled_msg="disabled_msg"> - Sonify Cube + Cube Pre-Sonification Options To use Sonify Data, install strauss and restart Jdaviz. You can do this by running pip install strauss in the command line and then launching Jdaviz. - + + Choose the input cube, spectral subset and any advanced sonification options. + + - @@ -133,6 +143,10 @@ Stop stream +<<<<<<< HEAD +======= + Live Sound Options +>>>>>>> 9abf2b3b (sonification plugin options: rearrange, label, defaults.) >>>>>> 9abf2b3b (sonification plugin options: rearrange, label, defaults.) persistent-hint > Volume +<<<<<<< HEAD +======= + + +>>>>>>> 9abf2b3b (sonification plugin options: rearrange, label, defaults.) \ No newline at end of file From bccd33ad6d739277f2458a60108ad8d202f702a7 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Sat, 7 Dec 2024 12:03:51 +0000 Subject: [PATCH 03/14] git push cleanup --- .../cubeviz/plugins/sonify_data/sonify_data.py | 2 +- .../cubeviz/plugins/sonify_data/sonify_data.vue | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py index 90a70d91cc..3a7e39a23d 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py @@ -93,7 +93,7 @@ def vue_sonify_cube(self, *args): display_unit = self.spec_viewer.state.x_display_unit min_wavelength = self.spectral_subset.selected_obj.lower.to_value(u.Unit(display_unit)) max_wavelength = self.spectral_subset.selected_obj.upper.to_value(u.Unit(display_unit)) - self.flux_viewer.update_listener_wls(min_wavelength, max_wavelength, display_unit) + self.flux_viewer.update_listener_wls((min_wavelength, max_wavelength), display_unit) # Ensure the current spectral region bounds are up-to-date at render time self.update_wavelength_range(None) diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue index 5d233022b9..697315b87d 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue @@ -143,10 +143,7 @@ Stop stream -<<<<<<< HEAD -======= Live Sound Options ->>>>>>> 9abf2b3b (sonification plugin options: rearrange, label, defaults.) >>>>>> 9abf2b3b (sonification plugin options: rearrange, label, defaults.) persistent-hint > Volume -<<<<<<< HEAD + -======= - ->>>>>>> 9abf2b3b (sonification plugin options: rearrange, label, defaults.) \ No newline at end of file From 2f334a5869298cf652ea16d673c46e93e4086524 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Mon, 9 Dec 2024 10:07:28 +0000 Subject: [PATCH 04/14] update max adio freq default --- jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py index 3a7e39a23d..cbf240011e 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py @@ -45,7 +45,7 @@ class SonifyData(PluginTemplateMixin, DatasetSelectMixin, SpectralSubsetSelectMi ssvidx = FloatHandleEmpty(0.65).tag(sync=True) eln = Bool(True).tag(sync=True) audfrqmin = FloatHandleEmpty(50).tag(sync=True) - audfrqmax = FloatHandleEmpty(1500).tag(sync=True) + audfrqmax = FloatHandleEmpty(1000).tag(sync=True) pccut = IntHandleEmpty(20).tag(sync=True) volume = IntHandleEmpty(100).tag(sync=True) stream_active = Bool(True).tag(sync=True) From 31ded3b77fa1c6ede910207206828bac99be7222 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Wed, 11 Dec 2024 15:30:06 +0000 Subject: [PATCH 05/14] make some of the advanced options inaccessible, add some better functionality for flux %ile removal --- .../configs/cubeviz/plugins/cube_listener.py | 2 +- .../plugins/sonify_data/sonify_data.py | 7 ++-- .../plugins/sonify_data/sonify_data.vue | 37 ++++++------------- jdaviz/configs/cubeviz/plugins/viewers.py | 11 +++--- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/cube_listener.py b/jdaviz/configs/cubeviz/plugins/cube_listener.py index d862b78a8b..f981e6e8f2 100644 --- a/jdaviz/configs/cubeviz/plugins/cube_listener.py +++ b/jdaviz/configs/cubeviz/plugins/cube_listener.py @@ -43,7 +43,7 @@ def sonify_spectrum(spec, duration, overlap=0.05, system='mono', srate=44100, fm data = {'spectrum': [spec], 'pitch': [1]} # again, use maximal range for the mapped parameters - lims = {'spectrum': ('0', '100')} + lims = {'spectrum': (0, '100')} # set up source sources = Events(data.keys()) diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py index cbf240011e..049b829b25 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py @@ -39,13 +39,14 @@ class SonifyData(PluginTemplateMixin, DatasetSelectMixin, SpectralSubsetSelectMi """ template_file = __file__, "sonify_data.vue" - sample_rate = IntHandleEmpty(44100).tag(sync=True) - buffer_size = IntHandleEmpty(2048).tag(sync=True) + sample_rate = 44100 #IntHandleEmpty(44100).tag(sync=True) + buffer_size = 2048 #IntHandleEmpty(2048).tag(sync=True) assidx = FloatHandleEmpty(2.5).tag(sync=True) ssvidx = FloatHandleEmpty(0.65).tag(sync=True) eln = Bool(True).tag(sync=True) audfrqmin = FloatHandleEmpty(50).tag(sync=True) audfrqmax = FloatHandleEmpty(1000).tag(sync=True) + use_pccut = Bool(True).tag(sync=True) pccut = IntHandleEmpty(20).tag(sync=True) volume = IntHandleEmpty(100).tag(sync=True) stream_active = Bool(True).tag(sync=True) @@ -101,7 +102,7 @@ def vue_sonify_cube(self, *args): self.flux_viewer.get_sonified_cube(self.sample_rate, self.buffer_size, selected_device_index, self.assidx, self.ssvidx, self.pccut, self.audfrqmin, - self.audfrqmax, self.eln) + self.audfrqmax, self.eln, self.use_pccut) # Automatically select spectrum-at-spaxel tool spec_at_spaxel_tool = self.flux_viewer.toolbar.tools['jdaviz:spectrumperspaxel'] diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue index 697315b87d..032b7f4ab9 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue @@ -42,26 +42,6 @@ Advanced Sound Options - - - - - - - + + + + @@ -158,8 +146,7 @@ Volume - - \ No newline at end of file + diff --git a/jdaviz/configs/cubeviz/plugins/viewers.py b/jdaviz/configs/cubeviz/plugins/viewers.py index 6740966cea..4cc4d32d7d 100644 --- a/jdaviz/configs/cubeviz/plugins/viewers.py +++ b/jdaviz/configs/cubeviz/plugins/viewers.py @@ -135,7 +135,7 @@ def update_volume_level(self, level): self.sonified_cube.atten_level = int(1/np.clip((level/100.)**2, MINVOL, 1)) def get_sonified_cube(self, sample_rate, buffer_size, device, assidx, ssvidx, - pccut, audfrqmin, audfrqmax, eln): + pccut, audfrqmin, audfrqmax, eln, use_pccut): spectrum = self.active_image_layer.layer.get_object(statistic=None) wlens = spectrum.wavelength.to('m').value flux = spectrum.flux.value @@ -161,11 +161,12 @@ def get_sonified_cube(self, sample_rate, buffer_size, device, assidx, ssvidx, # make a rough white-light image from the clipped array whitelight = np.expand_dims(clipped_arr.sum(-1), axis=2) - # subtract any percentile cut - clipped_arr -= np.expand_dims(pc_cube, axis=2) + if use_pccut: + # subtract any percentile cut + clipped_arr -= np.expand_dims(pc_cube, axis=2) - # and re-clip - clipped_arr = np.clip(clipped_arr, 0, np.inf) + # and re-clip + clipped_arr = np.clip(clipped_arr, 0, np.inf) self.sonified_cube = CubeListenerData(clipped_arr ** assidx, wlens, duration=0.8, samplerate=sample_rate, buffsize=buffer_size, From e77c1820d8d95bf74f59c3bcd4466343d884a8b2 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Thu, 12 Dec 2024 00:47:45 +0000 Subject: [PATCH 06/14] take out tqdm loop --- jdaviz/configs/cubeviz/plugins/cube_listener.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jdaviz/configs/cubeviz/plugins/cube_listener.py b/jdaviz/configs/cubeviz/plugins/cube_listener.py index f981e6e8f2..e0ba328813 100644 --- a/jdaviz/configs/cubeviz/plugins/cube_listener.py +++ b/jdaviz/configs/cubeviz/plugins/cube_listener.py @@ -3,7 +3,6 @@ import sys import os import time - try: from strauss.sonification import Sonification from strauss.sources import Events From b514570538c211ea38d117a6ba5040d0a20a1e67 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Mon, 30 Dec 2024 23:24:11 +0000 Subject: [PATCH 07/14] strip out unused wl bounds parameters, --- jdaviz/configs/cubeviz/plugins/cube_listener.py | 4 +--- jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py | 6 +++--- jdaviz/configs/cubeviz/plugins/viewers.py | 6 ++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/cube_listener.py b/jdaviz/configs/cubeviz/plugins/cube_listener.py index e0ba328813..0158e3f4f9 100644 --- a/jdaviz/configs/cubeviz/plugins/cube_listener.py +++ b/jdaviz/configs/cubeviz/plugins/cube_listener.py @@ -59,8 +59,7 @@ def sonify_spectrum(spec, duration, overlap=0.05, system='mono', srate=44100, fm class CubeListenerData: def __init__(self, cube, wlens, samplerate=44100, duration=1, overlap=0.05, buffsize=1024, - bdepth=16, wl_bounds=None, wl_unit=None, audfrqmin=50, audfrqmax=1500, - eln=False, vol=None): + bdepth=16, wl_unit=None, audfrqmin=50, audfrqmax=1500, eln=False, vol=None): self.siglen = int(samplerate*(duration-overlap)) self.cube = cube self.dur = duration @@ -74,7 +73,6 @@ def __init__(self, cube, wlens, samplerate=44100, duration=1, overlap=0.05, buff else: self.atten_level = int(np.clip((vol/100)**2, MINVOL, 1)) - self.wl_bounds = wl_bounds self.wl_unit = wl_unit self.wlens = wlens diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py index 049b829b25..51e4607f9a 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py @@ -119,10 +119,10 @@ def update_wavelength_range(self, event): display_unit = self.spec_viewer.state.x_display_unit # is this spectral selection or the entire spectrum? if hasattr(self.spectral_subset.selected_obj, "subregions"): - wlbounds = self.spectral_subset.selected_obj.subregions + wlranges = self.spectral_subset.selected_obj.subregions else: - wlbounds = None - self.flux_viewer.update_listener_wls(wlbounds, display_unit) + wlranges = None + self.flux_viewer.update_listener_wls(wlranges, display_unit) @observe('volume') def update_volume_level(self, event): diff --git a/jdaviz/configs/cubeviz/plugins/viewers.py b/jdaviz/configs/cubeviz/plugins/viewers.py index 4cc4d32d7d..e1c8ea417a 100644 --- a/jdaviz/configs/cubeviz/plugins/viewers.py +++ b/jdaviz/configs/cubeviz/plugins/viewers.py @@ -52,7 +52,6 @@ def __init__(self, *args, **kwargs): self.stream = None self.sonification_wl_ranges = None - self.sonification_wl_bounds = None self.sonification_wl_unit = None self.volume_level = None self.stream_active = True @@ -115,8 +114,8 @@ def update_sonified_cube(self, x, y): self.sonified_cube.newsig = self.sonified_cube.sigcube[x, y, :] self.sonified_cube.cbuff = True - def update_listener_wls(self, wbounds, wunit): - self.sonification_wl_ranges = wbounds + def update_listener_wls(self, wranges, wunit): + self.sonification_wl_ranges = wranges self.sonification_wl_unit = wunit def update_sound_device(self, device_index): @@ -170,7 +169,6 @@ def get_sonified_cube(self, sample_rate, buffer_size, device, assidx, ssvidx, self.sonified_cube = CubeListenerData(clipped_arr ** assidx, wlens, duration=0.8, samplerate=sample_rate, buffsize=buffer_size, - wl_bounds=self.sonification_wl_bounds, wl_unit=self.sonification_wl_unit, audfrqmin=audfrqmin, audfrqmax=audfrqmax, eln=eln, vol=self.volume_level) From ef7436f9f88d1339e850f47efcf1d5b8e2c8078a Mon Sep 17 00:00:00 2001 From: James Trayford Date: Mon, 30 Dec 2024 23:28:38 +0000 Subject: [PATCH 08/14] update CHANGES --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 81b91e64fa..099690ae6c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,8 @@ New Features Cubeviz ^^^^^^^ +- Enhancements for the cube sonification plug-in. [#3372] + Imviz ^^^^^ From 89b76ee7611c036974fcb7e1cbb180b3594b3c78 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Fri, 3 Jan 2025 09:08:34 +0000 Subject: [PATCH 09/14] Update jdaviz/configs/cubeviz/plugins/viewers.py with unit conversion formatting Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com> --- jdaviz/configs/cubeviz/plugins/viewers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/cubeviz/plugins/viewers.py b/jdaviz/configs/cubeviz/plugins/viewers.py index e1c8ea417a..0f373be76f 100644 --- a/jdaviz/configs/cubeviz/plugins/viewers.py +++ b/jdaviz/configs/cubeviz/plugins/viewers.py @@ -147,7 +147,7 @@ def get_sonified_cube(self, sample_rate, buffer_size, device, assidx, ssvidx, for r in self.sonification_wl_ranges: # index just the spectral subregion wdx = np.logical_or(wdx, - np.logical_and(wlens >= r[0].to('m').value, + np.logical_and(wlens >= r[0].to_value(u.m), wlens <= r[1].to('m').value)) wlens = wlens[wdx] flux = flux[:, :, wdx] From eae4323c66c220d920490e43d2d9ebc8b7ad4b12 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Fri, 3 Jan 2025 09:08:51 +0000 Subject: [PATCH 10/14] Update jdaviz/configs/cubeviz/plugins/viewers.py with unit conversion formatting Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com> --- jdaviz/configs/cubeviz/plugins/viewers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/configs/cubeviz/plugins/viewers.py b/jdaviz/configs/cubeviz/plugins/viewers.py index 0f373be76f..d3afd11f02 100644 --- a/jdaviz/configs/cubeviz/plugins/viewers.py +++ b/jdaviz/configs/cubeviz/plugins/viewers.py @@ -148,7 +148,7 @@ def get_sonified_cube(self, sample_rate, buffer_size, device, assidx, ssvidx, # index just the spectral subregion wdx = np.logical_or(wdx, np.logical_and(wlens >= r[0].to_value(u.m), - wlens <= r[1].to('m').value)) + wlens <= r[1].to_value(u.m))) wlens = wlens[wdx] flux = flux[:, :, wdx] From f49785ef7e81395404d40e38b941215b8cd5b17b Mon Sep 17 00:00:00 2001 From: James Trayford Date: Fri, 3 Jan 2025 09:27:25 +0000 Subject: [PATCH 11/14] format and explain RE @pllim suggestions --- jdaviz/configs/cubeviz/plugins/cube_listener.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/cube_listener.py b/jdaviz/configs/cubeviz/plugins/cube_listener.py index 0158e3f4f9..ab9247b7ed 100644 --- a/jdaviz/configs/cubeviz/plugins/cube_listener.py +++ b/jdaviz/configs/cubeviz/plugins/cube_listener.py @@ -3,6 +3,7 @@ import sys import os import time + try: from strauss.sonification import Sonification from strauss.sources import Events @@ -14,7 +15,6 @@ # smallest fraction of the max audio amplitude that can be represented by a 16-bit signed integer MINVOL = 1/(2**15 - 1) - @contextmanager def suppress_stderr(): with open(os.devnull, "w") as devnull: @@ -41,7 +41,9 @@ def sonify_spectrum(spec, duration, overlap=0.05, system='mono', srate=44100, fm data = {'spectrum': [spec], 'pitch': [1]} - # again, use maximal range for the mapped parameters + # set range in spectral flux representing the maximum and minimum sound frequency power: + # 0 (numeric): absolute 0 in flux units, such that any flux above 0 will sound. + # '100' (string): 100th percentile (i.e. maximum value) in spectral flux. lims = {'spectrum': (0, '100')} # set up source From 6922dfe543f54b7a01862730a20a788d8291d446 Mon Sep 17 00:00:00 2001 From: James Trayford Date: Fri, 3 Jan 2025 09:40:04 +0000 Subject: [PATCH 12/14] pep8 formatting --- jdaviz/configs/cubeviz/plugins/cube_listener.py | 3 ++- jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py | 7 ++++--- jdaviz/configs/cubeviz/plugins/viewers.py | 5 ++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/cube_listener.py b/jdaviz/configs/cubeviz/plugins/cube_listener.py index ab9247b7ed..ab3b2e2c85 100644 --- a/jdaviz/configs/cubeviz/plugins/cube_listener.py +++ b/jdaviz/configs/cubeviz/plugins/cube_listener.py @@ -15,6 +15,7 @@ # smallest fraction of the max audio amplitude that can be represented by a 16-bit signed integer MINVOL = 1/(2**15 - 1) + @contextmanager def suppress_stderr(): with open(os.devnull, "w") as devnull: @@ -42,7 +43,7 @@ def sonify_spectrum(spec, duration, overlap=0.05, system='mono', srate=44100, fm data = {'spectrum': [spec], 'pitch': [1]} # set range in spectral flux representing the maximum and minimum sound frequency power: - # 0 (numeric): absolute 0 in flux units, such that any flux above 0 will sound. + # 0 (numeric): absolute 0 in flux units, such that any flux above 0 will sound. # '100' (string): 100th percentile (i.e. maximum value) in spectral flux. lims = {'spectrum': (0, '100')} diff --git a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py index 51e4607f9a..25c4a6a8a5 100644 --- a/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py +++ b/jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py @@ -39,8 +39,9 @@ class SonifyData(PluginTemplateMixin, DatasetSelectMixin, SpectralSubsetSelectMi """ template_file = __file__, "sonify_data.vue" - sample_rate = 44100 #IntHandleEmpty(44100).tag(sync=True) - buffer_size = 2048 #IntHandleEmpty(2048).tag(sync=True) + # Removing UI option to vary these for now + sample_rate = 44100 # IntHandleEmpty(44100).tag(sync=True) + buffer_size = 2048 # IntHandleEmpty(2048).tag(sync=True) assidx = FloatHandleEmpty(2.5).tag(sync=True) ssvidx = FloatHandleEmpty(0.65).tag(sync=True) eln = Bool(True).tag(sync=True) @@ -75,7 +76,7 @@ def __init__(self, *args, **kwargs): # TODO: Remove hardcoded range and flux viewer self.spec_viewer = self.app.get_viewer('spectrum-viewer') self.flux_viewer = self.app.get_viewer('flux-viewer') - + @property def user_api(self): expose = [] diff --git a/jdaviz/configs/cubeviz/plugins/viewers.py b/jdaviz/configs/cubeviz/plugins/viewers.py index d3afd11f02..10883da1de 100644 --- a/jdaviz/configs/cubeviz/plugins/viewers.py +++ b/jdaviz/configs/cubeviz/plugins/viewers.py @@ -142,13 +142,12 @@ def get_sonified_cube(self, sample_rate, buffer_size, device, assidx, ssvidx, self.buffer_size = buffer_size if self.sonification_wl_ranges: - wl_unit = getattr(u, self.sonification_wl_unit) wdx = np.zeros(wlens.size).astype(bool) for r in self.sonification_wl_ranges: # index just the spectral subregion wdx = np.logical_or(wdx, - np.logical_and(wlens >= r[0].to_value(u.m), - wlens <= r[1].to_value(u.m))) + np.logical_and(wlens >= r[0].to_value(u.m), + wlens <= r[1].to_value(u.m))) wlens = wlens[wdx] flux = flux[:, :, wdx] From ff220be865b4f880e2eaf962981cb0c3459c72ba Mon Sep 17 00:00:00 2001 From: James Trayford Date: Mon, 6 Jan 2025 15:03:18 +0000 Subject: [PATCH 13/14] Update CHANGES.rst Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com> --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 099690ae6c..5b7812edad 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,7 +9,7 @@ New Features Cubeviz ^^^^^^^ -- Enhancements for the cube sonification plug-in. [#3372] +- Enhancements for the cube sonification plug-in. [#3377] Imviz ^^^^^ From a58e221e96d157b84846aa09c865dbef16bdfacb Mon Sep 17 00:00:00 2001 From: James Trayford Date: Thu, 9 Jan 2025 13:05:03 +0000 Subject: [PATCH 14/14] Update CHANGES.rst Co-authored-by: Jesse Averbukh --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 5b7812edad..db418fe8b0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,7 +9,7 @@ New Features Cubeviz ^^^^^^^ -- Enhancements for the cube sonification plug-in. [#3377] +- Enhancements for the cube sonification plugin. [#3377] Imviz ^^^^^