append separate cals

Set up

from pathlib import Path
from matplotlib import pyplot as plt  # for inspecting cal pulses
from mkpy import mkh5

MKDIG_PATH = Path("../mkdig_data")

print("mkpy version", mkh5.__version__)

Out:

mkpy version 0.2.7

Create subject, append cals

Use mkh5.append_mkdata() to combine EEG recordings and separately recorded calibration data in a single .h5 file prior to converting A/D samples to \(\mu\) V.

Set EEG and calibration data file names

crw = MKDIG_PATH / "sub000p3.crw"  # EEG recording
log = MKDIG_PATH / "sub000p3.x.log"  # events
yhdr = MKDIG_PATH / "sub000p3.yhdr"  # extra header info

cals_crw = MKDIG_PATH / "sub000c.crw"
cals_log = MKDIG_PATH / "sub000c.log"
cals_yhdr = MKDIG_PATH / "sub000c.yhdr"

Convert .crw/.log to mkh5 format .h5.

p3_h5_f = "example_sub000p3.h5"
p3_h5 = mkh5.mkh5(p3_h5_f)
p3_h5.reset_all()
p3_h5.create_mkdata("sub000", crw, log, yhdr)

Append calibration data to the existing sub000.

p3_h5.append_mkdata("sub000", cals_crw, cals_log, cals_yhdr)

Convert EEG and calibration data A/D to microvolts. set re-usable calibration parameters

cal_kws = dict(
    n_points=5,  # samples to average
    cal_size=10,  # uV
    lo_cursor=-36,  # lo_cursor ms
    hi_cursor=48,  # hi_cursor ms
    cal_ccode=0,  # condition code
)

inspect the calibration pulses

f, ax = p3_h5.plotcals(p3_h5_f, "sub000", **cal_kws)
plt.show()
calibration pulses (recorded N=209) from: example_sub000p3.h5 sub000 n_points=5 cal_size=10 lo_cursor=-36 hi_cursor=48 cal_ccode=0, scale=17.63, trimmed 4, scale=20.30, trimmed 6, scale=20.05, trimmed 2, scale=20.79, trimmed 5, scale=20.57, trimmed 2, scale=40.10, trimmed 5, scale=39.59, trimmed 9, scale=40.74, trimmed 25, scale=40.41, trimmed 12, scale=39.97, trimmed 5, scale=38.81, trimmed 16, scale=35.54, trimmed 12, scale=36.47, trimmed 6, scale=40.55, trimmed 10, scale=37.84, trimmed 13, scale=39.66, trimmed 9, scale=42.00, trimmed 11, scale=39.58, trimmed 7, scale=41.42, trimmed 5, scale=40.46, trimmed 18, scale=40.05, trimmed 22, scale=40.76, trimmed 12, scale=40.66, trimmed 3, scale=39.91, trimmed 13, scale=40.58, trimmed 12, scale=40.35, trimmed 14, scale=40.75, trimmed 21, scale=41.24, trimmed 12, scale=40.69, trimmed 8, scale=40.91, trimmed 8, scale=20.56, trimmed 23, scale=20.64, trimmed 10

Out:

Plotting cals
/usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/mkh5.py:3666: UserWarning: negative event code(s) found for cal condition code 0 -16384
  warnings.warn(msg)
Found cals in /sub000/dblock_4

Convert EEG and calibration data A/D to microvolts.

p3_h5.calibrate_mkdata("sub000", **cal_kws)

Out:

/usr/share/miniconda/envs/env_3.8/lib/python3.8/site-packages/mkpy/mkh5.py:3666: UserWarning: negative event code(s) found for cal condition code 0 -16384
  warnings.warn(msg)
Found cals in /sub000/dblock_4
Calibrating block /sub000/dblock_0 of 5: (31232,)
Calibrating block /sub000/dblock_1 of 5: (32768,)
Calibrating block /sub000/dblock_2 of 5: (31744,)
Calibrating block /sub000/dblock_3 of 5: (32512,)
Calibrating block /sub000/dblock_4 of 5: (28416,)

Total running time of the script: ( 0 minutes 7.960 seconds)

Gallery generated by Sphinx-Gallery