Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

[solved] logging using information at the end of experiment

frankanayetfrankanayet Posts: 45
edited February 2012 in OpenSesame

Hi Sebastiaan, I have an experiment in which I use some similarity ratings at the end of the experiment to calculate some differences between the stimuli that are compared at the beginning of the experiment. I would like to use the values of the similarity ratings to calculate some things that make data analysis easier like ratios (e.g. bigger/smaller). If I understand how the logger works correctly, I would not be able to write in each row of the log file with the information collected at the end of the experiment because the logger would have already wrote all the information while the experiment is running. Is there any way to make the logger go back and calculate for each presented pair of stimuli a bigger/smaller ratio with the similarity ratings collected at the end of the experiment?

Comments

  • sebastiaansebastiaan Posts: 2,737
    edited 5:00AM

    Hi Frank.

    Yes, your understanding is correct: The logger writes one line at a time and there is no way to go back and change what has been written. If you want to do some processing at the end of the experiment, you'd have to implement a simple logger yourself, using a bit of inline code.

    For example, first initialize an empty list in an inline_script at the start of the experiment:

    global my_log
    # Initialize an empty list
    my_log = []

    At the end of each trial, store the relevant variables as a dictionary in the list (so my_log is a list of dictionaries):

    global my_log
    # Create a dictionary with trial variables
    my_trial = {}
    my_trial["my_var1"] = 10.
    my_trial["my_var2"] = 20.
    # And store it
    my_log.append(my_trial)

    At the end of the experiment, calculate whatever you want to calculate and write my_log to a file:

    global my_log
    # Calculate some new variable
    for my_trial in my_log:
        my_trial["my_ratio"] = my_trial["my_var1"]/my_trial["my_var2"]  
    # Write the logfile
    f = open("my_log.csv", "w")
    # First the header
    f.write(",".join(my_log[0].keys()))
    f.write(chr(10)) # = newline
    # Then the trial data
    for my_trial in my_log: 
        f.write(",".join([str(s) for s in my_trial.values()]))
        f.write(chr(10))
    f.close()

    I would do this in addition to a regular logger, because by writing the data at the end you will lose everything if the experiments crashes or is aborted halfway.

    Hope this helps!

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • ciriaciria Posts: 2
    edited 5:00AM

    Hi Sebastiaan.

    I am enjoying openSesame, it is an excelent program for experiment design. Thank you a lot. Now I need to present stimuli of 20 msec of duration (subliminal), but when I run the experiment I still can see the stimuli. I think this is because the refresh of the screen, but I tried this with other program for experiment design (using the same computer) and I did not see the stimuli. I radically prefer openSesame, but I need a 20 msec stimulus presentation; the goal is that my subject can´t report something presented on the screen. How can I achieve this?

    Thank you Sebastiann.
    My best wishes.

  • sebastiaansebastiaan Posts: 2,737
    edited 5:00AM

    Hi Ciria,

    The duration should indeed be possible given the refresh rate of the monitor, but in your case that should be fine: 20ms will be round up to two frames of 16.7ms (if you have a 60Hz monitor). One reason that participants might be able to see the stimulus is because it is not masked (or is it?). Without masking or making the stimuli extremely dim participants are likely to see them.

    But it might also be an issue of incorrect timing, of course. You can investigate the time_[item name] variables to see if the timing is as you expect it to be. You can also find some tips on proper timing here: http://osdoc.cogsci.nl/miscellaneous/timing

    Good luck!

    Regards,
    Sebastiaan

    PS. In the future, could you perhaps open a new topic when posting a new question? Thanks!

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • frankanayetfrankanayet Posts: 45
    edited February 2012

    Thanks Sebastiaan, a couple of questions though:
    1. How do I get the number of the subject for the log so that the file is called 'my_log_Sub1'?
    2. Just to confirm, the trial inline should be in the 'run' tab right?
    3. In a related but different question... using the regular loggers, I have the logger inserted at the end of the trial loop. However, I want to log some information at the end of the experiment (that is asked outside the trial loop). Where do I put the second logger to include this information? Should it be the same logger twice, or do I have to use different loggers?

    Frank

  • sebastiaansebastiaan Posts: 2,737
    edited 5:00AM

    Hi Frank,

    The subject number is available as subject_nr. So something like the following should give you what you want:

    f = open("my_log_%d.csv" % self.get("subject_nr"), "w")

    For more such variables, see http://osdoc.cogsci.nl/usage/variables-and-conditional-qifq-statements

    Regarding the use of loggers. You can use either the same logger in two different positions, or create a new logger. Either way will work fine, but your logfile will probably look a bit less chaotic if you stick to a single logger. Make sure to enable the Use NA ... setting in the logger, otherwise the variables will be ignored if they are not yet available when the logger is first called.

    And, yes, the run phase is the place to put the script!

    Good luck!

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • frankanayetfrankanayet Posts: 45
    edited February 2012

    Hi Sebastiaan, I am trying to debug the script that nuclides your suggestion but the experiment was done originally on a PC and I don't have access to a PC just now and when I try to run it on a mac it crashes completely and I cannot even get a debug window to figure out what is wrong with it... Can you help me with this?

  • sebastiaansebastiaan Posts: 2,737
    edited 5:00AM

    Hi Frank,

    I'm afraid that, as it says on the download page, Mac OS support is experimental. On some systems it works quite well, on some it doesn't. I don't have a clear picture of when and why the Mac OS packages crash. The issues go deeper than the OpenSesame code: There are hard crashes in the underlying modules, which is why they are not intercepted by the OpenSesame debug window.

    However, you may want to try selecting a different back-end. There's a good chance that one of the back-ends will work.

    I don't have a mac myself, so I'm mostly dependent on others for testing and creating Mac OS packages. That's why Mac OS support still lags behind, unfortunately.

    Good luck!
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • frankanayetfrankanayet Posts: 45
    edited 5:00AM

    Hi Sebastiaan,

    the main problem with the script is that the f = open("my_log.csv", "w") only works if you type the complete path name. If it is not included it complaints that I do not have permission to write on the file. I tried to get the pathname with path = os.getcwd(), but if I replace the full path with the variable 'path' it complains again. Do you have any insight on how to solve this so that the experiment can be run in multiple computers without having to change the pathname individually on each computer?

    Thanks!

  • sebastiaansebastiaan Posts: 2,737
    edited 5:00AM

    Hi Frank,

    Right, I think I misunderstood. I thought the entire program crashed, but it's just an innocent little path-error?

    For your purposes, the easiest way is probably to store the custom logfile in the file pool. This is just a temporary folder somewhere, and you're guaranteed to have write access there (you may not have write access in the working directory). So you could do something like this:

    f = open(os.path.join(self.experiment.pool_folder, "my_log_%d.csv" % self.get("subject_nr")), "w")

    After the experiment you can refresh the pool folder (or maybe that's done automatically) and you will see your logfile. Be sure to use the .opensesame.tar.gz format, otherwise the pool will not be saved!

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • frankanayetfrankanayet Posts: 45
    edited 5:00AM

    Hi Sebastiaan, actually in mac the entire program actually crashes, this bug was probably one of the reasons that caused it to crash but I only received this message when I tried my experiment on the windows side.

  • frankanayetfrankanayet Posts: 45
    edited 5:00AM

    Hi Sebastiaan, the fix worked well. Thanks!

Sign In or Register to comment.