# Buggy code
def _read_curry_info(curry_paths):
    """Extract info from curry parameter files."""
    curry_params = _read_curry_parameters(curry_paths["info"])
    R = np.eye(4)
    R[[0, 1], [0, 1]] = -1  # rotate 180 deg
    # shift down and back
    # (chosen by eyeballing to make the CTF helmet look roughly correct)
    R[:3, 3] = [0.0, -0.015, -0.12]
    curry_dev_dev_t = Transform("ctf_meg", "meg", R)

    # read labels from label files
    label_fname = curry_paths["labels"]
    types = ["meg", "eeg", "misc"]
    labels = _read_curry_lines(
        label_fname, ["LABELS" + CHANTYPES[key] for key in types]
    )
    sensors = _read_curry_lines(
        label_fname, ["SENSORS" + CHANTYPES[key] for key in types]
    )
    normals = _read_curry_lines(
        label_fname, ["NORMALS" + CHANTYPES[key] for key in types]
    )
    assert len(labels) == len(sensors) == len(normals)

    all_chans = list()
    for key in ["meg", "eeg", "misc"]:
        for ind, chan in enumerate(labels["LABELS" + CHANTYPES[key]]):
            ch = {
                "ch_name": chan,
                "unit": curry_params.unit_dict[key],
                "kind": FIFFV_CHANTYPES[key],
                "coil_type": FIFFV_COILTYPES[key],
            }
            if key == "eeg":
                loc = np.array(sensors["SENSORS" + CHANTYPES[key]][ind], float)
                # XXX just the sensor, where is ref (next 3)?
                assert loc.shape == (3,)
                loc /= 1000.0  # to meters
                loc = np.concatenate([loc, np.zeros(9)])
                ch["loc"] = loc
                # XXX need to check/ensure this
                ch["coord_frame"] = FIFF.FIFFV_COORD_HEAD
            elif key == "meg":
                pos = np.array(sensors["SENSORS" + CHANTYPES[key]][ind], float)
                pos /= 1000.0  # to meters
                pos = pos[:3]  # just the inner coil
                pos = apply_trans(curry_dev_dev_t, pos)
                nn = np.array(normals["NORMALS" + CHANTYPES[key]][ind], float)
                assert np.isclose(np.linalg.norm(nn), 1.0, atol=1e-4)
                nn /= np.linalg.norm(nn)
                nn = apply_trans(curry_dev_dev_t, nn, move=False)
                trans = np.eye(4)
                trans[:3, 3] = pos
                trans[:3, :3] = _normal_orth(nn).T
                ch["loc"] = _coil_trans_to_loc(trans)
                ch["coord_frame"] = FIFF.FIFFV_COORD_DEVICE
            all_chans.append(ch)

    ch_names = [chan["ch_name"] for chan in all_chans]
    info = create_info(ch_names, curry_params.sfreq)
    _make_trans_dig(curry_paths, info, curry_dev_dev_t)

    for ind, ch_dict in enumerate(info["chs"]):
        ch_dict.update(all_chans[ind])
        assert ch_dict["loc"].shape == (12,)
        ch_dict["unit"] = SI_UNITS[all_chans[ind]["unit"][1]]
        ch_dict["cal"] = SI_UNIT_SCALE[all_chans[ind]["unit"][0]]

    return info, curry_params.n_samples, curry_params.is_ascii


# Traceback (RuntimeError)
Data loaded, with preload=False: C:\read_curry example data\PH005_baseline.dat, 70 channels X 76850 points
Leaving device<->head transform as None (no landmarks found)
Reading 0 ... 76849  =      0.000 ...   307.396 secs...
Traceback (most recent call last):
File "c:\Users\todfl\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\ptvsd_launcher.py", line 48, in <module>
main(ptvsdArgs)
File "c:\Users\todfl\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 432, in main
run()
File "c:\Users\todfl\.vscode\extensions\ms-python.python-2020.2.64397\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 87, in _run_code
File "c:\Users\todfl\Documents\Decker\EEG Processing\EEG Processing Code\read_raw_curry error MWE.py", line 7, in <module>
raw = mne.io.read_raw_curry(data_path,preload=True,verbose=True)
File "<decorator-gen-218>", line 20, in read_raw_curry
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\curry\curry.py", line 406, in read_raw_curry
return RawCurry(fname, preload, verbose)
File "<decorator-gen-219>", line 20, in __init__
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\curry\curry.py", line 439, in __init__
super(RawCurry, self).__init__(
File "<decorator-gen-160>", line 20, in __init__
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py", line 247, in __init__
self._preload_data(preload)
File "<decorator-gen-164>", line 20, in _preload_data
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py", line 528, in _preload_data
self._data = self._read_segment(
File "<decorator-gen-162>", line 20, in _read_segment
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py", line 412, in _read_segment
_ReadSegmentFileProtector(self)._read_segment_file(
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py", line 1816, in _read_segment_file
return self.__raw.__class__._read_segment_file(
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\curry\curry.py", line 469, in _read_segment_file
_read_segments_file(
File "C:\ProgramData\Anaconda3\lib\site-packages\mne\io\utils.py", line 221, in _read_segments_file
raise RuntimeError('Incorrect number of samples (%s != %s), '
RuntimeError: Incorrect number of samples (5302650 != 5379500), please report this error to MNE-Python developers

# Fixed code
def _read_curry_info(curry_paths):
    """Extract info from curry parameter files."""
    curry_params = _read_curry_parameters(curry_paths["info"])
    R = np.eye(4)
    R[[0, 1], [0, 1]] = -1  # rotate 180 deg
    # shift down and back
    # (chosen by eyeballing to make the CTF helmet look roughly correct)
    R[:3, 3] = [0.0, -0.015, -0.12]
    curry_dev_dev_t = Transform("ctf_meg", "meg", R)

    # read labels from label files
    label_fname = curry_paths["labels"]
    types = ["meg", "eeg", "misc"]
    labels = _read_curry_lines(
        label_fname, ["LABELS" + CHANTYPES[key] for key in types]
    )
    sensors = _read_curry_lines(
        label_fname, ["SENSORS" + CHANTYPES[key] for key in types]
    )
    normals = _read_curry_lines(
        label_fname, ["NORMALS" + CHANTYPES[key] for key in types]
    )
    assert len(labels) == len(sensors) == len(normals)

    all_chans = list()
    for key in ["meg", "eeg", "misc"]:
        chanidx_is_explicit = (
            len(curry_params.chanidx_in_file["CHAN_IN_FILE" + CHANTYPES[key]]) > 0
        )  # channel index
        # position in the datafile may or may not be explicitly declared,
        # based on the CHAN_IN_FILE section in info file
        for ind, chan in enumerate(labels["LABELS" + CHANTYPES[key]]):
            chanidx = len(all_chans) + 1  # by default, just assume the
            # channel index in the datafile is in order of the channel
            # names as we found them in the labels file
            if chanidx_is_explicit:  # but, if explicitly declared, use
                # that index number
                chanidx = int(
                    curry_params.chanidx_in_file["CHAN_IN_FILE" + CHANTYPES[key]][ind]
                )
            if chanidx <= 0:  # if chanidx was explicitly declared to be ' 0',
                # it means the channel is not actually saved in the data file
                # (e.g. the "Ref" channel), so don't add it to our list.
                # Git issue #8391
                continue
            ch = {
                "ch_name": chan,
                "unit": curry_params.unit_dict[key],
                "kind": FIFFV_CHANTYPES[key],
                "coil_type": FIFFV_COILTYPES[key],
                "ch_idx": chanidx,
            }
            if key == "eeg":
                loc = np.array(sensors["SENSORS" + CHANTYPES[key]][ind], float)
                # XXX just the sensor, where is ref (next 3)?
                assert loc.shape == (3,)
                loc /= 1000.0  # to meters
                loc = np.concatenate([loc, np.zeros(9)])
                ch["loc"] = loc
                # XXX need to check/ensure this
                ch["coord_frame"] = FIFF.FIFFV_COORD_HEAD
            elif key == "meg":
                pos = np.array(sensors["SENSORS" + CHANTYPES[key]][ind], float)
                pos /= 1000.0  # to meters
                pos = pos[:3]  # just the inner coil
                pos = apply_trans(curry_dev_dev_t, pos)
                nn = np.array(normals["NORMALS" + CHANTYPES[key]][ind], float)
                assert np.isclose(np.linalg.norm(nn), 1.0, atol=1e-4)
                nn /= np.linalg.norm(nn)
                nn = apply_trans(curry_dev_dev_t, nn, move=False)
                trans = np.eye(4)
                trans[:3, 3] = pos
                trans[:3, :3] = _normal_orth(nn).T
                ch["loc"] = _coil_trans_to_loc(trans)
                ch["coord_frame"] = FIFF.FIFFV_COORD_DEVICE
            all_chans.append(ch)

    ch_count = len(all_chans)
    assert ch_count == curry_params.n_chans  # ensure that we have assembled
    # the same number of channels as declared in the info (.DAP) file in the
    # DATA_PARAMETERS section. Git issue #8391

    # sort the channels to assure they are in the order that matches how
    # recorded in the datafile.  In general they most likely are already in
    # the correct order, but if the channel index in the data file was
    # explicitly declared we might as well use it.
    all_chans = sorted(all_chans, key=lambda ch: ch["ch_idx"])

    ch_names = [chan["ch_name"] for chan in all_chans]
    info = create_info(ch_names, curry_params.sfreq)
    info["meas_date"] = curry_params.dt_start  # for Git issue #8398
    _make_trans_dig(curry_paths, info, curry_dev_dev_t)

    for ind, ch_dict in enumerate(info["chs"]):
        all_chans[ind].pop("ch_idx")
        ch_dict.update(all_chans[ind])
        assert ch_dict["loc"].shape == (12,)
        ch_dict["unit"] = SI_UNITS[all_chans[ind]["unit"][1]]
        ch_dict["cal"] = SI_UNIT_SCALE[all_chans[ind]["unit"][0]]

    return info, curry_params.n_samples, curry_params.is_ascii