Skip to content

Commit

Permalink
make some of the advanced options inaccessible, add some better funct…
Browse files Browse the repository at this point in the history
…ionality for flux %ile removal
  • Loading branch information
James Trayford committed Dec 23, 2024
1 parent 97bb60d commit ad443b6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/plugins/cube_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 4 additions & 3 deletions jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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']
Expand Down
37 changes: 12 additions & 25 deletions jdaviz/configs/cubeviz/plugins/sonify_data/sonify_data.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,6 @@
<span style="padding: 6px">Advanced Sound Options</span>
</v-expansion-panel-header>
<v-expansion-panel-content class="plugin-expansion-panel-content">
<v-row>
<v-text-field
ref="sample_rate"
type="number"
label="Sample Rate"
v-model.number="sample_rate"
hint="The desired sample rate."
persistent-hint
></v-text-field>
</v-row>
<v-row>
<v-text-field
ref="buffer_size"
type="number"
label="Buffer Size"
v-model.number="buffer_size"
hint="The desired buffer size."
persistent-hint
></v-text-field>
</v-row>
<v-row>
<v-text-field
ref="audfrqmin"
Expand Down Expand Up @@ -102,13 +82,21 @@
persistent-hint
></v-text-field>
</v-row>
<v-row>
<v-row>
<v-switch
v-model="use_pccut"
label="Use Flux Percentile Cut?"
hint="Whether to only sonify flux above a min. percentile (else use absolute values)"
persistent-hint
></v-switch>
</v-row>
<v-row v-if="use_pccut">
<v-text-field
ref="pccut"
type="number"
label="Flux Percentile Cut"
label="Flux Percentile Cut Value"
v-model.number="pccut"
hint="The minimum flux percentile to be heard."
hint="The minimum percentile to be heard."
persistent-hint
></v-text-field>
</v-row>
Expand Down Expand Up @@ -158,8 +146,7 @@
<v-row>
Volume
<glue-throttled-slider label="Volume" wait="300" max="100" step="1" :value.sync="volume" hide-details class="no-hint" />

</v-row>
</v-row>
</j-tray-plugin>
</template>
</template>
11 changes: 6 additions & 5 deletions jdaviz/configs/cubeviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit ad443b6

Please sign in to comment.