- CML Data Readers version: 0.9.8
- Python version: 3.7.9
- Operating System: Linux(?) (I'm using rhino)
Description
PTSA's representation of time is usually in seconds while cmlreaders uses milliseconds. For most purposes this is fine but occasionally when using functions in PTSA that alter the time attribute this runs you into trouble. For instance, adding a mirror buffer when rel_start is not equal to 0 will screw things up. This is because it uses the plugged in duration (in seconds) to compute the new time scale (https://github.com/pennmem/ptsa_new/blob/a4e9298fc369b83139bae1bd73f2a512332a4656/ptsa/data/timeseries.py#L495).
See below for an example taken from the cmlreaders documentation (https://pennmem.github.io/cmlreaders/html/classifier.html) (with a slight modification).
What I Did
from cmlreaders import CMLReader, get_data_index
reader = CMLReader("R1111M", "FR1")
pairs = reader.load("pairs")
events = reader.load_events(["R1111M"], ["FR1"])
eeg = reader.load_eeg(events=events.events.words,
rel_start=100,
rel_stop=1600,
scheme=pairs)
ts_orig = eeg.to_ptsa()
ts = ts_orig.add_mirror_buffer(1)
print(ts.time.data[0], ts.time.data[-1])
print(ts_orig.time.data[0], ts_orig.time.data[-1])
The output of this is:
99.0 102.498
100.0 1598.0
There is an easy fix here which is to just transform the time dimension by hand before calling add_mirror_buffer, e.g.,
ts_orig['time'] = ts_orig['time'] / 1000 # using PTSA time scale
ts_orig = ts_orig.add_mirror_buffer(1)
ts_orig['time'] = ts_orig['time'] * 1000
However it seems like this should be done automatically so that people don't get tricked by this in the future. I'm not sure if the fix should be in PTSA or cmlreaders but posting this here so at least people are aware of the issue (since it comes up even in the (slightly modified) example code).
Description
PTSA's representation of time is usually in seconds while cmlreaders uses milliseconds. For most purposes this is fine but occasionally when using functions in PTSA that alter the time attribute this runs you into trouble. For instance, adding a mirror buffer when rel_start is not equal to 0 will screw things up. This is because it uses the plugged in duration (in seconds) to compute the new time scale (https://github.com/pennmem/ptsa_new/blob/a4e9298fc369b83139bae1bd73f2a512332a4656/ptsa/data/timeseries.py#L495).
See below for an example taken from the cmlreaders documentation (https://pennmem.github.io/cmlreaders/html/classifier.html) (with a slight modification).
What I Did
The output of this is:
99.0 102.498
100.0 1598.0
There is an easy fix here which is to just transform the time dimension by hand before calling add_mirror_buffer, e.g.,
However it seems like this should be done automatically so that people don't get tricked by this in the future. I'm not sure if the fix should be in PTSA or cmlreaders but posting this here so at least people are aware of the issue (since it comes up even in the (slightly modified) example code).