open-cogsci / datamatrix

An intuitive, Pythonic way to work with tabular data
https://pydatamatrix.eu/
GNU General Public License v3.0
25 stars 10 forks source link

Blinkreconstruct fuction doesn't work when processing pupil diameter data #8

Closed leeweizhe1993 closed 5 years ago

leeweizhe1993 commented 5 years ago

Hi Sebastiaan, I tried to use blinkreconstruct function to rebuild the pupil data in diameter unit(mm), the data type is like: image The outcome more like a linear interpolation after I delivered the data to the blinkreconstruct function, and only area data- which means int type- can be properly processed: image

I tried both convet the area to diameter before reconstruct- which I mentioned above- and after reconstruct, only the latter approach succeed.

Approach 1:

def area_2_dia(area):
    return round(256 * sqrt(float(area) / pi) / 1000, 2)
df = pd.read_csv("Report//Sample//Sample_09_f_25E.csv")['LEFT_PUPIL_SIZE'][:1500]
df.replace('.', np.nan, inplace = True)
dm = DataMatrix(length=1500)
dm.base = df.map(area_2_dia)    #convet to diameter before reconstruct
dm.recon = blinkreconstruct(dm.base, maxdur=1000)

x = np.linspace(0, 3000, 1500)
y1 = dm.base
y2 = dm.recon
plt.figure()
plt.legend("base .vs recon")
plt.plot(x, y1, 'r')
plt.plot(x, y2, 'b')
plt.show()

image

Approach 2:

def area_2_dia(area):
    return round(256 * sqrt(float(area) / pi) / 1000, 2)
df = pd.read_csv("Report//Sample//Sample_09_f_25E.csv")['LEFT_PUPIL_SIZE'][:1500]
df.replace('.', np.nan, inplace = True)
dm = DataMatrix(length=1500)
dm.base = df
dm.recon = blinkreconstruct(dm.base, maxdur=1000)

x = np.linspace(0, 3000, 1500)
y1 = list(map(area_2_dia,dm.base))         #convet to diameter after reconstruct
y2 = list(map(area_2_dia, dm.recon))
plt.figure()
plt.legend("base .vs recon")
plt.plot(x, y1, 'r')
plt.plot(x, y2, 'b')
plt.show()

image

I guess use int type data is recommended XD. @smathot

Thanks Weizhe Li

smathot commented 5 years ago

Hi,

The reason that it doesn't work if you convert the signal to mm diameter is that the default values for the parameters have been chosen such that they work fairly well with the arbitrary units as recorded by the EyeLink. So if you want to use the function on a different type of signal, or data from a different eye tracker, you have to choose different values for these parameters. That can be finicky though. The data type doesn't matter, as long as the missing data is nan.

Does that answer your question?

Cheers, Sebastiaan

leeweizhe1993 commented 5 years ago

Got it, Thanks a lot