VU-Cog-Sci / exptools2

Version 2 of exptools (by KnapenLab)
11 stars 9 forks source link

Nr_Frames is not a number and makes experiment crash #18

Open Gilles86 opened 5 years ago

Gilles86 commented 5 years ago

I keep getting errors like this at the end of the experiment. Sometimes they happen and sometimes they don't.

Traceback (most recent call last):
  File "main.py", line 124, in <module>
    session.run()
  File "main.py", line 114, in run
    trial.run()
  File "/Users/gilles/git/exptools2/exptools2/core/trial.py", line 237, in run
    self.get_events()
  File "/Users/gilles/git/exptools2/exptools2/core/trial.py", line 150, in get_events
    self.session.close()
  File "/Users/gilles/git/exptools2/exptools2/core/session.py", line 252, in close
    self.global_log.loc[nonresp_idx, 'nr_frames'] = nr_frames.astype(int)
ValueError: cannot convert float NaN to integer

it seems that at that point self.global_log.loc[nonresp_idx, 'nr_frames'].values[1:] is equal to [nan nan] (or longer, like [nan nan nan nan nan nan nan nan nan nan nan nan nan nan]) and self.nr_frames is a proper number (e.g., 358 in this case).

Can someone explain this line of code? https://github.com/VU-Cog-Sci/exptools2/blob/723454f1256c3a37c9badfa257238e583bc10910/exptools2/core/session.py#L250

lukassnoek commented 5 years ago

The idea is that the Session keeps track of the number of frames that each phase is presented. Technically, a phase only ends when the next one starts (i.e., when the window is flipped). This makes sure the duration equals the time a stimulus/phase is on the screen (and the same logic holds for how the onsets are handled in exptools2, i.e., synced exactly to the window flip). As such, the duration (in number of frames and seconds) of the last trial can only be determined when "closing" the session. In line 250 that you highlighted, this duration in frames of the last phase is append to the existing dataframe with (amongst other things) durations. It seems, then, that the number of frames are not saved correctly during the actual experiment... Does this also happen when running the demo scripts?

Gilles86 commented 5 years ago

I think I understand why this happens now in my experiment. I have events that are not tied to a phase or trial. I want to log them like this:

idx = self.global_log.shape[0]
self.global_log.loc[idx, 'color'] = color
self.global_log.loc[idx, 'event_type'] = 'color change'

But then what is the correct way of doing this?