Skip to content

Commit 2ba0cf4

Browse files
authored
Merge pull request #591 from int-brain-lab/hotfix/2.21.3
Hotfix/2.21.3
2 parents f5186d1 + 8aa48eb commit 2ba0cf4

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

brainbox/ephys_plots.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ def line_amp_plot(spike_amps, spike_depths, spike_times, chn_coords, d_bin=10, d
395395
return data
396396

397397

398-
def plot_brain_regions(channel_ids, channel_depths=None, brain_regions=None, display=True, ax=None, title=None, label='left'):
398+
def plot_brain_regions(channel_ids, channel_depths=None, brain_regions=None, display=True, ax=None,
399+
title=None, label='left', **kwargs):
399400
"""
400401
Plot brain regions along probe, if channel depths is provided will plot along depth otherwise along channel idx
401402
:param channel_ids: atlas ids for each channel
@@ -404,6 +405,7 @@ def plot_brain_regions(channel_ids, channel_depths=None, brain_regions=None, dis
404405
:param display: whether to output plot
405406
:param ax: axis to plot on
406407
:param title: title for plot
408+
:param kwargs: additional keyword arguments for bar plot
407409
:return:
408410
"""
409411

@@ -432,8 +434,10 @@ def plot_brain_regions(channel_ids, channel_depths=None, brain_regions=None, dis
432434

433435
for reg, col in zip(regions, region_colours):
434436
height = np.abs(reg[1] - reg[0])
437+
bar_kwargs = dict(edgecolor='w', width=1)
438+
bar_kwargs.update(**kwargs)
435439
color = col / 255
436-
ax.bar(x=0.5, height=height, width=1, color=color, bottom=reg[0], edgecolor='w')
440+
ax.bar(x=0.5, height=height, color=color, bottom=reg[0], **kwargs)
437441
if label == 'right':
438442
ax.yaxis.tick_right()
439443
ax.set_yticks(region_labels[:, 0].astype(int))

brainbox/io/spikeglx.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from pathlib import Path
44
import time
55
import json
6+
import string
7+
import random
68

79
import numpy as np
810
from one.alf.io import remove_uuid_file
@@ -141,12 +143,11 @@ def read(self, nsel=slice(0, 10000), csel=slice(None), sync=True, volts=True):
141143
n0 = self.chunks['chunk_bounds'][first_chunk]
142144
_logger.debug(f'Streamer: caching sample {n0}, (t={n0 / self.fs})')
143145
self.cache_folder.mkdir(exist_ok=True, parents=True)
144-
sr = self._download_raw_partial(first_chunk=first_chunk, last_chunk=last_chunk)
146+
sr, file_cbin = self._download_raw_partial(first_chunk=first_chunk, last_chunk=last_chunk)
145147
if not volts:
146148
data = np.copy(sr._raw[nsel.start - n0:nsel.stop - n0, csel])
147149
else:
148150
data = sr[nsel.start - n0: nsel.stop - n0, csel]
149-
150151
sr.close()
151152
if self.remove_cached:
152153
shutil.rmtree(self.target_dir)
@@ -159,16 +160,20 @@ def _download_raw_partial(self, first_chunk=0, last_chunk=0):
159160
:param first_chunk:
160161
:param last_chunk:
161162
:return: spikeglx.Reader of the current chunk, Pathlib.Path of the directory where it is stored
163+
:return: cbin local path
162164
"""
163165
assert str(self.url_cbin).endswith('.cbin')
164166
webclient = self.one.alyx
165167
relpath = Path(self.url_cbin.replace(webclient._par.HTTP_DATA_SERVER, '.')).parents[0]
166168
# write the temp file into a subdirectory
167169
tdir_chunk = f"chunk_{str(first_chunk).zfill(6)}_to_{str(last_chunk).zfill(6)}"
168-
target_dir = Path(self.cache_folder, relpath, tdir_chunk)
169-
self.target_dir = target_dir
170-
Path(target_dir).mkdir(parents=True, exist_ok=True)
171-
ch_file_stream = target_dir.joinpath(self.file_chunks.name).with_suffix('.stream.ch')
170+
# for parallel processes, there is a risk of collisions if the removed cached flag is set to True
171+
# if the folder is to be removed append a unique identifier to avoid having duplicate names
172+
if self.remove_cached:
173+
tdir_chunk += ''.join([random.choice(string.ascii_letters) for _ in np.arange(10)])
174+
self.target_dir = Path(self.cache_folder, relpath, tdir_chunk)
175+
Path(self.target_dir).mkdir(parents=True, exist_ok=True)
176+
ch_file_stream = self.target_dir.joinpath(self.file_chunks.name).with_suffix('.stream.ch')
172177

173178
# Get the first sample index, and the number of samples to download.
174179
i0 = self.chunks['chunk_bounds'][first_chunk]
@@ -186,7 +191,7 @@ def _download_raw_partial(self, first_chunk=0, last_chunk=0):
186191
cmeta_stream = json.load(f)
187192
if (cmeta_stream.get('chopped_first_sample', None) == i0 and
188193
cmeta_stream.get('chopped_total_samples', None) == total_samples):
189-
return spikeglx.Reader(ch_file_stream.with_suffix('.cbin'), ignore_warnings=True)
194+
return spikeglx.Reader(ch_file_stream.with_suffix('.cbin'), ignore_warnings=True), ch_file_stream
190195

191196
else:
192197
shutil.copy(self.file_chunks, ch_file_stream)
@@ -224,7 +229,7 @@ def _download_raw_partial(self, first_chunk=0, last_chunk=0):
224229
try:
225230
cbin_local_path = webclient.download_file(
226231
self.url_cbin, chunks=(first_byte, n_bytes),
227-
target_dir=target_dir, clobber=True, return_md5=False)
232+
target_dir=self.target_dir, clobber=True, return_md5=False)
228233
break
229234
except Exception as e:
230235
retries += 1
@@ -238,4 +243,4 @@ def _download_raw_partial(self, first_chunk=0, last_chunk=0):
238243
assert cbin_local_path_renamed.exists()
239244

240245
reader = spikeglx.Reader(cbin_local_path_renamed, ignore_warnings=True)
241-
return reader
246+
return reader, cbin_local_path

ibllib/atlas/flatmaps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def plot_swanson_vector(acronyms=None, values=None, ax=None, hemisphere=None, br
252252
def format_coord(x, y):
253253
ind = sw[int(y), int(x)]
254254
ancestors = br.ancestors(br.id[ind])['acronym']
255-
return f'sw-{ind}, x={x:1.4f}, y={y:1.4f}, aid={br.id[ind]}-{br.acronym[ind]} \n {ancestors}'
255+
return f'sw-{ind}, {ancestors}, aid={br.id[ind]}-{br.acronym[ind]} \n {br.name[ind]}'
256256

257257
ax.format_coord = format_coord
258258

@@ -324,7 +324,7 @@ def plot_swanson(acronyms=None, values=None, ax=None, hemisphere=None, br=None,
324324
def format_coord(x, y):
325325
ind = s2a[int(y), int(x)]
326326
ancestors = br.ancestors(br.id[ind])['acronym']
327-
return f'sw-{ind}, x={x:1.4f}, y={y:1.4f}, aid={br.id[ind]}-{br.acronym[ind]} \n {ancestors}'
327+
return f'sw-{ind}, {ancestors}, aid={br.id[ind]}-{br.acronym[ind]} \n {br.name[ind]}'
328328

329329
ax.format_coord = format_coord
330330
return ax

release_notes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Develop
2+
### features
3+
- show atlas names in swanson plot
4+
- allow user to define mask regions in swanson plot
5+
16
## Release 2.21
27
# Release Notes 2.21.2 2023-02-24
38
### bugfixes

0 commit comments

Comments
 (0)