expyriment.misc
The misc package.
This package contains miscellaneous classes, modules and functions.
See also expyriment.misc.extras for more misc.
Modules
Classes
Functions
- expyriment.misc.add_fonts(folder)
Add fonts to Expyriment.
All truetype fonts found in the given folder will be added to Expyriment, such that they are found when only giving their name (i.e. without the full path).
- Parameters:
- folderstr or unicode
the full path to the folder to search for
- expyriment.misc.bytes_to_unicode(s, fse=False)
- expyriment.misc.compare_codes(input_code, standard_codes, bitwise_comparison=True)
Helper function to compare input_code with a standard codes.
Returns a boolean and operates by default bitwise.
- Parameters:
- input_codeint
code or bitpattern
- standard_codesint or list
code/bitpattern or list of codes/bitpattern
- bitwise_comparisonbool, optional
(default = True)
- expyriment.misc.create_colours(amount)
Create different and equally spaced RGB colours.
- Parameters:
- amountint
the number of colours to create
- Returns:
- colourslist
a list of colours, each in the form [r, g, b]
- expyriment.misc.download_from_stash(content='all', branch=None)
Download content from the Expyriment stash.
Content will be stored in an Expyriment settings directory (.expyriment or ~expyriment, located in the current user’s home directory).
- Parameters:
- contentstr, optional
the content to install (“examples”, “extras”, “tools”, or “all”) (default=”all”)
- branchstr, optional
a specific branch to get the content from (if not set, the branch corresponding to the current Expyriment release is used) (default=None)
- expyriment.misc.find_font(font)
Find an installed font given a font name.
This will try to match a font installed on the system that is similar to the given font name.
- Parameters:
- fontstr
name of the font
- Returns:
- fontstr
the font that is most similar If no font is found, an empty string will be returned.
- expyriment.misc.get_audio_devices(input_devices=False)
Get the names of available audio devices.
- Parameters:
- input_devicesbool, optional
return input (instead of output) device names (default=False)
- Returns:
- audio_deviceslist
a list of audio device names
- expyriment.misc.get_display_info()
Return information about the available display(s).
- expyriment.misc.get_experiment_secure_hash()
Returns the fingerprint, that is, the first six places of the secure hash (sha1) of the main file of the current experiment.
- Returns:
- hash: string or None
first six places of the experiment secure hash or None, if no main file can be found
Notes
Fingerprints of experiments help to ensure that the correct version is running in the lab. Hash codes are written to all output files and printed in the command line output. If you want to check post hoc the version of your experiment, create the secure hash (sha1) of your expyriment .py-file and compare the first six place with the code in the output file.
- expyriment.misc.get_module_hash_dictionary()
Returns a dictionary with the fingerprints of all modules imported from the local folded.
- Returns:
- hashes: dict
hash dict with all imported modules keys = file names, values = sha hashes
Notes
See get_experiment_secure_hash() for further information about Expyriment secure hashes.
- expyriment.misc.get_monitor_resolution()
Returns the monitor resolution
DEPRECATED! Use get_display_info instead.
- Returns:
- resolution: (int, int)
monitor resolution, screen resolution
- expyriment.misc.get_system_info(as_string=False)
Print system information to standard out and return as a dictionary.
- Parameters:
- as_stringboolean, optional
Print as string instead of dict (default = False)
- expyriment.misc.has_internet_connection()
Return True if computer is connected to internet.
- expyriment.misc.is_android_running()
Return True if Exypriment runs on Android.
- expyriment.misc.is_idle_running()
Return True if IDLE is running.
- expyriment.misc.is_interactive_mode()
Return if Python is running in interactive mode (such as IDLE or IPython)
- Returns:
- interactive_modeboolean
- expyriment.misc.is_ipython_running()
Return True if IPython is running.
- expyriment.misc.list_fonts()
List all fonts installed on the system.
Returns a dictionary where the key is the font name and the value is the absolute path to the font file.
- expyriment.misc.module_hashes_as_string()
helper function that converts dict to str
- expyriment.misc.numpad_digit_code_to_ascii(keycode)
Convert numpad keycode to the ascii code of that particular number
If it is not a keypad digit code, no conversion takes place and the same code will be returned.
- Returns:
- ascii_codeint
- expyriment.misc.py2_round(number, ndigits=0)
Round half away from zero and always return a float.
This method implements the Python 2 way of rounding. For “bankers rounding” (round half to even), please use the builtin round function or Numpy’s around function.
- Parameters:
- numberint or float
the number to be rounded
- ndigitsint
the number of digits to round to (default = 0)
- Returns:
- rounded_numberfloat
the rounded number
- expyriment.misc.string_sort_array(array)
Sorts an array with different types using the string representation. Sorts in place!
- Returns:
- arraylist
the sorted array
- expyriment.misc.unicode_to_bytes(u, fse=False)
- expyriment.misc.which(programme)
Locate a programme file in the user’s path.
This mimics behaviour of UNIX’s ‘which’ command.
- Parameters:
- programmestr
the programme to file to locate
- Returns:
- pathstr or None
the full path to the programme file or None if not found