Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions mne/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,27 @@ def _file_like(obj):
return all(callable(getattr(obj, name, None)) for name in ("read", "seek"))


def _fullname(obj):
def _fullname(obj, *, referent=None):
klass = obj.__class__
module = klass.__module__
if module == "builtins":
return klass.__qualname__
return module + "." + klass.__qualname__
name = klass.__qualname__
if module != "builtins":
name = f"{module}.{name}"
if referent is not None:
if isinstance(obj, list | tuple):
for ii, item in enumerate(obj):
if item is referent:
name += f"[{ii}]"
break
elif isinstance(obj, dict):
for key, value in obj.items():
if key is referent:
name += "-key"
break
if value is referent:
name += f"[{key!r}]"
break
return name


def _assert_no_instances(cls, when=""):
Expand All @@ -372,7 +387,7 @@ def _assert_no_instances(cls, when=""):
ref = list()
gc.collect()
objs = gc.get_objects()
for obj in objs:
for obj in objs: # e.g., vtkPolyData, Brain, Plotter, etc.
try:
check = isinstance(obj, cls)
except Exception: # such as a weakref
Expand All @@ -382,30 +397,33 @@ def _assert_no_instances(cls, when=""):
ref.append(f"Brain._cleaned = {getattr(obj, '_cleaned', None)}")
rr = gc.get_referrers(obj)
count = 0
for r in rr:
for r in rr: # e.g., list, dict, etc. that holds the reference to obj
if (
r is not objs
and r is not globals()
and r is not locals()
and not inspect.isframe(r)
):
name = _fullname(r, referent=obj)
if isinstance(r, list | dict | tuple):
rep = f"len={len(r)}"
r_ = gc.get_referrers(r)
types = (_fullname(x) for x in r_)
types = "/".join(sorted(set(x for x in types if x is not None)))
rep += f", {len(r_)} referrers: {types}"
types = list()
for x in r_:
types.append(_fullname(x, referent=r))
types = " / ".join(sorted(types))
rep += f" | {len(r_)} referrers: {types}"
del r_
else:
rep = repr(r)[:100].replace("\n", " ")
rep = "repr="
rep += repr(r)[:100].replace("\n", " ")
# If it's a __closure__, get more information
if rep.startswith("<cell at "):
try:
rep += f" ({repr(r.cell_contents)[:100]})"
except Exception:
pass
name = _fullname(r)
ref.append(f"{name}: {rep}")
ref.append(f"{name} with {rep}")
count += 1
del r
del rr
Expand Down
15 changes: 0 additions & 15 deletions tutorials/preprocessing/70_fnirs_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
raw_intensity = mne.io.read_raw_nirx(fnirs_cw_amplitude_dir, verbose=True)
raw_intensity.load_data()


# %%
# Providing more meaningful annotation information
# ------------------------------------------------
Expand All @@ -48,7 +47,6 @@
unwanted = np.nonzero(raw_intensity.annotations.description == "15.0")
raw_intensity.annotations.delete(unwanted)


# %%
# Viewing location of sensors over brain surface
# ----------------------------------------------
Expand Down Expand Up @@ -89,7 +87,6 @@
n_channels=len(raw_intensity.ch_names), duration=500, show_scrollbars=False
)


# %%
# Converting from raw intensity to optical density
# ------------------------------------------------
Expand All @@ -99,7 +96,6 @@
raw_od = mne.preprocessing.nirs.optical_density(raw_intensity)
raw_od.plot(n_channels=len(raw_od.ch_names), duration=500, show_scrollbars=False)


# %%
# Evaluating the quality of the data
# ----------------------------------
Expand All @@ -118,14 +114,12 @@
ax.hist(sci)
ax.set(xlabel="Scalp Coupling Index", ylabel="Count", xlim=[0, 1])


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

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


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


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


# %%
# Removing heart rate from signal
# -------------------------------
Expand Down Expand Up @@ -178,7 +170,6 @@
events, event_dict = mne.events_from_annotations(raw_haemo)
fig = mne.viz.plot_events(events, event_id=event_dict, sfreq=raw_haemo.info["sfreq"])


# %%
# Next we define the range of our epochs, the rejection criteria,
# baseline correction, and extract the epochs. We visualize the log of which
Expand All @@ -203,7 +194,6 @@
)
epochs.plot_drop_log()


# %%
# View consistency of responses across trials
# -------------------------------------------
Expand All @@ -221,7 +211,6 @@
ts_args=dict(ylim=dict(hbo=[-15, 15], hbr=[-15, 15])),
)


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


# %%
# View consistency of responses across channels
# ---------------------------------------------
Expand All @@ -250,7 +238,6 @@
for ax in axes[:, column]:
ax.set_title(f"{condition}: {ax.get_title()}")


# %%
# Plot standard fNIRS response image
# ----------------------------------
Expand All @@ -277,7 +264,6 @@
evoked_dict, combine="mean", ci=0.95, colors=color_dict, styles=styles_dict
)


# %%
# View topographic representation of activity
# -------------------------------------------
Expand All @@ -290,7 +276,6 @@
times=times, topomap_args=topomap_args
)


# %%
# Compare tapping of left and right hands
# ---------------------------------------
Expand Down
Loading