Skip to content

Commit 5cf08bc

Browse files
larsonerWouter Kroot
authored andcommitted
MAINT: Fix CircleCI (mne-tools#13351)
1 parent 1879407 commit 5cf08bc

2 files changed

Lines changed: 30 additions & 27 deletions

File tree

mne/utils/misc.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,27 @@ def _file_like(obj):
358358
return all(callable(getattr(obj, name, None)) for name in ("read", "seek"))
359359

360360

361-
def _fullname(obj):
361+
def _fullname(obj, *, referent=None):
362362
klass = obj.__class__
363363
module = klass.__module__
364-
if module == "builtins":
365-
return klass.__qualname__
366-
return module + "." + klass.__qualname__
364+
name = klass.__qualname__
365+
if module != "builtins":
366+
name = f"{module}.{name}"
367+
if referent is not None:
368+
if isinstance(obj, list | tuple):
369+
for ii, item in enumerate(obj):
370+
if item is referent:
371+
name += f"[{ii}]"
372+
break
373+
elif isinstance(obj, dict):
374+
for key, value in obj.items():
375+
if key is referent:
376+
name += "-key"
377+
break
378+
if value is referent:
379+
name += f"[{key!r}]"
380+
break
381+
return name
367382

368383

369384
def _assert_no_instances(cls, when=""):
@@ -372,7 +387,7 @@ def _assert_no_instances(cls, when=""):
372387
ref = list()
373388
gc.collect()
374389
objs = gc.get_objects()
375-
for obj in objs:
390+
for obj in objs: # e.g., vtkPolyData, Brain, Plotter, etc.
376391
try:
377392
check = isinstance(obj, cls)
378393
except Exception: # such as a weakref
@@ -382,30 +397,33 @@ def _assert_no_instances(cls, when=""):
382397
ref.append(f"Brain._cleaned = {getattr(obj, '_cleaned', None)}")
383398
rr = gc.get_referrers(obj)
384399
count = 0
385-
for r in rr:
400+
for r in rr: # e.g., list, dict, etc. that holds the reference to obj
386401
if (
387402
r is not objs
388403
and r is not globals()
389404
and r is not locals()
390405
and not inspect.isframe(r)
391406
):
407+
name = _fullname(r, referent=obj)
392408
if isinstance(r, list | dict | tuple):
393409
rep = f"len={len(r)}"
394410
r_ = gc.get_referrers(r)
395-
types = (_fullname(x) for x in r_)
396-
types = "/".join(sorted(set(x for x in types if x is not None)))
397-
rep += f", {len(r_)} referrers: {types}"
411+
types = list()
412+
for x in r_:
413+
types.append(_fullname(x, referent=r))
414+
types = " / ".join(sorted(types))
415+
rep += f" | {len(r_)} referrers: {types}"
398416
del r_
399417
else:
400-
rep = repr(r)[:100].replace("\n", " ")
418+
rep = "repr="
419+
rep += repr(r)[:100].replace("\n", " ")
401420
# If it's a __closure__, get more information
402421
if rep.startswith("<cell at "):
403422
try:
404423
rep += f" ({repr(r.cell_contents)[:100]})"
405424
except Exception:
406425
pass
407-
name = _fullname(r)
408-
ref.append(f"{name}: {rep}")
426+
ref.append(f"{name} with {rep}")
409427
count += 1
410428
del r
411429
del rr

tutorials/preprocessing/70_fnirs_processing.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
raw_intensity = mne.io.read_raw_nirx(fnirs_cw_amplitude_dir, verbose=True)
3131
raw_intensity.load_data()
3232

33-
3433
# %%
3534
# Providing more meaningful annotation information
3635
# ------------------------------------------------
@@ -48,7 +47,6 @@
4847
unwanted = np.nonzero(raw_intensity.annotations.description == "15.0")
4948
raw_intensity.annotations.delete(unwanted)
5049

51-
5250
# %%
5351
# Viewing location of sensors over brain surface
5452
# ----------------------------------------------
@@ -89,7 +87,6 @@
8987
n_channels=len(raw_intensity.ch_names), duration=500, show_scrollbars=False
9088
)
9189

92-
9390
# %%
9491
# Converting from raw intensity to optical density
9592
# ------------------------------------------------
@@ -99,7 +96,6 @@
9996
raw_od = mne.preprocessing.nirs.optical_density(raw_intensity)
10097
raw_od.plot(n_channels=len(raw_od.ch_names), duration=500, show_scrollbars=False)
10198

102-
10399
# %%
104100
# Evaluating the quality of the data
105101
# ----------------------------------
@@ -118,14 +114,12 @@
118114
ax.hist(sci)
119115
ax.set(xlabel="Scalp Coupling Index", ylabel="Count", xlim=[0, 1])
120116

121-
122117
# %%
123118
# In this example we will mark all channels with a SCI less than 0.5 as bad
124119
# (this dataset is quite clean, so no channels are marked as bad).
125120

126121
raw_od.info["bads"] = list(compress(raw_od.ch_names, sci < 0.5))
127122

128-
129123
# %%
130124
# At this stage it is appropriate to inspect your data
131125
# (for instructions on how to use the interactive data visualisation tool
@@ -134,7 +128,6 @@
134128
# If your data contains lots of artifacts you may decide to apply
135129
# artifact reduction techniques as described in :ref:`ex-fnirs-artifacts`.
136130

137-
138131
# %%
139132
# Converting from optical density to haemoglobin
140133
# ----------------------------------------------
@@ -145,7 +138,6 @@
145138
raw_haemo = mne.preprocessing.nirs.beer_lambert_law(raw_od, ppf=0.1)
146139
raw_haemo.plot(n_channels=len(raw_haemo.ch_names), duration=500, show_scrollbars=False)
147140

148-
149141
# %%
150142
# Removing heart rate from signal
151143
# -------------------------------
@@ -178,7 +170,6 @@
178170
events, event_dict = mne.events_from_annotations(raw_haemo)
179171
fig = mne.viz.plot_events(events, event_id=event_dict, sfreq=raw_haemo.info["sfreq"])
180172

181-
182173
# %%
183174
# Next we define the range of our epochs, the rejection criteria,
184175
# baseline correction, and extract the epochs. We visualize the log of which
@@ -203,7 +194,6 @@
203194
)
204195
epochs.plot_drop_log()
205196

206-
207197
# %%
208198
# View consistency of responses across trials
209199
# -------------------------------------------
@@ -221,7 +211,6 @@
221211
ts_args=dict(ylim=dict(hbo=[-15, 15], hbr=[-15, 15])),
222212
)
223213

224-
225214
# %%
226215
# We can also view the epoched data for the control condition and observe
227216
# that it does not show the expected morphology.
@@ -233,7 +222,6 @@
233222
ts_args=dict(ylim=dict(hbo=[-15, 15], hbr=[-15, 15])),
234223
)
235224

236-
237225
# %%
238226
# View consistency of responses across channels
239227
# ---------------------------------------------
@@ -250,7 +238,6 @@
250238
for ax in axes[:, column]:
251239
ax.set_title(f"{condition}: {ax.get_title()}")
252240

253-
254241
# %%
255242
# Plot standard fNIRS response image
256243
# ----------------------------------
@@ -277,7 +264,6 @@
277264
evoked_dict, combine="mean", ci=0.95, colors=color_dict, styles=styles_dict
278265
)
279266

280-
281267
# %%
282268
# View topographic representation of activity
283269
# -------------------------------------------
@@ -290,7 +276,6 @@
290276
times=times, topomap_args=topomap_args
291277
)
292278

293-
294279
# %%
295280
# Compare tapping of left and right hands
296281
# ---------------------------------------

0 commit comments

Comments
 (0)