Skip to content

pop_load_frombids leaves None in chanlocs fields; pop_saveset raises TypeError on them #538

Closed

Description

@neuromechanist

For a channel with no row in electrodes.tsv, pop_load_frombids leaves theta, radius, X, Y, Z, sph_theta, sph_phi and
sph_radius as None (and chaninfo plotrad and shrink as None). pop_saveset cannot write None:

import json, os, tempfile
import numpy as np
import pyedflib
from eegprep import pop_load_frombids, pop_saveset
root = tempfile.mkdtemp(); eeg_dir = os.path.join(root, "sub-01", "eeg"); os.makedirs(eeg_dir)
json.dump({"Name": "t", "BIDSVersion": "1.9.0", "DatasetType": "raw"}, open(os.path.join(root, "dataset_description.json"), "w"))
names = ["Fz", "Cz", "Pz"]
writer = pyedflib.EdfWriter(os.path.join(eeg_dir, "sub-01_task-x_eeg.edf"), 3, file_type=pyedflib.FILETYPE_EDFPLUS)
writer.setSignalHeaders([{"label": c, "dimension": "uV", "sample_frequency": 250, "physical_min": -500, "physical_max": 500,
                          "digital_min": -32768, "digital_max": 32767, "transducer": "", "prefilter": ""} for c in names])
writer.writeSamples(list(np.random.default_rng(0).standard_normal((3, 2500)) * 20)); writer.close()
open(os.path.join(eeg_dir, "sub-01_task-x_channels.tsv"), "w").write("name\ttype\tunits\n" + "".join(f"{c}\tEEG\tuV\n" for c in names))
open(os.path.join(eeg_dir, "sub-01_electrodes.tsv"), "w").write("name\tx\ty\tz\nFz\t0\t37\t84\nCz\t0\t-34\t105\n")   # no row for Pz
json.dump({"EEGCoordinateSystem": "MNI305", "EEGCoordinateUnits": "mm"}, open(os.path.join(eeg_dir, "sub-01_coordsystem.json"), "w"))
eeg = pop_load_frombids(os.path.join(eeg_dir, "sub-01_task-x_eeg.edf"), bidsevent=False, verbose=False)
print("Pz X:", eeg["chanlocs"][2]["X"])                       # None
pop_saveset(eeg, os.path.join(root, "out.set"))               # TypeError: Could not convert None (type NoneType) to array

Expected: use the same empty value (numeric_null) for every missing numeric field, as pop_load_frombids already does for
channels it clears, or make pop_saveset write None as an empty array. Also: clean_channels already treats None as missing
by an ad hoc conversion, which a consistent empty value would make unnecessary.

Checked on eegprep 0.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions