Tip—Using Pseudonyms in PsychoPy

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x):
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
Just sharing a tip that others might find useful.

  • Taking participants’ real names means that there’s a risk of their identification. This could be from a hack, accidental data breach, etc; or it could occur if, say, for Open Science Foundation reasons you make your raw data public.
  • I generally do not need participants’ names but I find it useful to have them when I’m looking through a lot of data sets. There’s no good reason for this, but it seems easier/more natural to work with names. I have run experiments in large lab classes, which means that there’s a possibility of two data files being identical because they both began simultaneously (e.g., the data and time in the file or the file name could be the same).
  • I tried asking participants to make up a pseudonym, to avoid these problems but run into new problems:
    • Some participants put their real names in, so could be identified.
    • Some participants used their initials, which sometimes duplicated so files were potentially confusable.
  • This code will generate a pseudonym, from alternating consonants and vowels, which are more-or-less pronounceable so potentially helpful in keeping on top of data processing. I added a couple of digits at the end too, just to make it even less likely that duplicates would appear. The format produces names in CVCVC-DD.
  • In builder view this goes in a Code Component, before the experiment properly starts, under the “Before Experiment” tab
# Jasper 2022-10-01
# This makes a random CVCVC-NN pseudonym that can be used as a unique, anonymous data-file identifier
# This: 
#   1. Avoid the instinct to ask for subjects' real names & assures anonymity √
#   2. Gives a feel for who's who, when processing data √
#   3. When running lots of subjects simultaneously, reduces the risk of date-based file-names being identical √

import random # import the random class

pseudoConsonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'qu', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']
pseudoVowels = ['a','e', 'i', 'o', 'u']
pseudoNumber = ['0','1', '2', '3', '4', '5','6', '7', '8', '9']
pseudo_1 = (random.choice(pseudoConsonants))    # A consonant, please Bob.
pseudo_2 = (random.choice(pseudoVowels))        # A vowel, please Bob.
pseudo_3 = (random.choice(pseudoConsonants))    # A consonant, please Bob.
pseudo_4 = (random.choice(pseudoVowels))        # A vowel, please Bob.
pseudo_5 = (random.choice(pseudoConsonants))    # A consonant, please Bob.
pseudo_6 = (random.choice(pseudoNumber))        # A number, please Bob.
pseudo_7 = (random.choice(pseudoNumber))        # A number, please Bob.
pseudonym = (pseudo_1+pseudo_2+pseudo_3+pseudo_4+pseudo_5+"–"+pseudo_6+pseudo_7) # Make a CVCVC-NN pseudonym 

  • So far, this will create a pseudonym but it won’t be visible.
    • I used a Code Component at the “Begin Routine” tab to include the pseudonym. This was in a section of the experiment that I was recording data from. So whenever a row was added to the output file, the pseudonym was included too:
thisExp.addData('pseudonym',pseudonym)      # add participant's PSEUDONYM to output file.
  • I also included the pseudonym in the output file name. This is via Edit Experimental Info (in the cog icon) and in the data tab:
u'data/%s_%s_%s' % (data.getDateStr(format="%y·%m·%d·%H%M"), expName, pseudonym)
* This adds the build-name and date & time, as well as the pseudonym but you could remove them if you wanted. If so, remove some of the “%s”, which tells Python to look for a particular number (3, here) of elements to create the string that’s used in the file name.
1 Like