Auto Head Fix Util and Base Classes

AHF_Base

AHF_Base.py

The base upon which everything else is built

class AHF_Base.AHF_Base(taskP, settingsDictP)

Defines conventions for classes used for accesing hardware and doing subtasks in AutoHeadFix code Each class has a static method, config_user_get, to create or edit a settings dictionary, and will be inititialized with a settings dictionary. The setup function does hardware initialization, or other inititialization.

abstract static about()

Returns a brief message describing your sub-class, used when asking user to pick a sub-class of this class

config_subject_get(starterDict={})
Returns

dict – the default dictionary for individualized parameters

abstract static config_user_get(starterDict={})

static method that querries user for settings, with default responses from starterDict, and returns starterDict with settings as edited by the user.

config_user_subject_get(starterDict={})

Prompts the user for individualized parameters, with default responses from starterDict, and returns starterDict with settings as edited by the user.

abstract hardwareTest()

Tests functionality, gives user a chance to change settings. :Returns: bool – True if any settings have changed

abstract setdown()

oppposite of setup. Releases any hardware resouces. can be run before editing settings so GPIO pins can be reused, for example. This strategy should be used in hardwareTest method.

abstract setup()

does hardware initialization with(possibly updated) info in self.settingsDict Run by __init__, or can be run separately after editing the settingsDict

Returns

code

bool whether setup completed without errors

AHF_ClassAndDictUtils

AHF_ClassAndDictUtils.Class_from_file(nameTypeStr, nameStr)

Imports a module from a fileName(stripped of the .py) and returns the class

Assumes the class is named the same as the module. To get

AHF_ClassAndDictUtils.Dict_to_file(anyDict, nameTypeStr, nameStr, typeSuffix, dir='')

Saves a dicitonary as JSON encoded text file

AHF_ClassAndDictUtils.Dict_to_obj_fields(anObject, aDict)

Sets attributes for the object anObject from the keys and values of dictionay aDict

AHF_ClassAndDictUtils.Edit_dict(anyDict, longName)

Edits values in a passed in dict, in a generic way, not having to know ahead of time the name and type of each setting Assumption is made that lists/tuples contain only strings, ints, or float types, and that all members of any list/tuple are same type

AHF_ClassAndDictUtils.File_exists(nameTypeStr, nameStr, typeSuffix)

Returns true if a file with name ‘AHF_’ + nameTypeStr + ‘_’ + nameStr + typeSuffix exists in current directory

AHF_ClassAndDictUtils.File_from_user(nameTypeStr, longName, typeSuffix, makeNew=False)

Static method that trawls through current folder looking for python files matching nameTypeStr

Allows user to choose from the list of files found. Files are recognized by names starting with ‘AHF_’ + nameTypeStr’ + ‘_’ and ending with ‘.typeSuffix’ Raises: FileNotFoundError if no nameStr class files found

AHF_ClassAndDictUtils.File_to_dict(nameTypeStr, nameStr, typeSuffix, dir='')

Sets attributes for the object anObject from the keys and values of dictionay aDict loaded from the file

AHF_ClassAndDictUtils.File_to_obj_fields(nameTypeStr, nameStr, typeSuffix, anObject, dir='')

Sets attributes for the object anObject from the keys and values of dictionay aDict loaded from the file

AHF_ClassAndDictUtils.Obj_fields_to_file(anObject, nameTypeStr, nameStr, typeSuffix, dir='')

Writes a file containing a json dictionary of all the fields of the object anObject

AHF_ClassAndDictUtils.Show_ordered_dict(objectDict, longName)

Dumps standard dictionary settings into an ordered dictionary, prints settings to screen in a numbered fashion from the ordered dictionary, making it easy to select a setting to change. Returns an ordered dictionary of {number:(key:value),} used by edit_dict function

AHF_HardwareTester

AHF_HardwareTester.hardwareTester(task)

Hardware Tester for Auto Head Fixing, allows you to verify the various hardware bits are working

AHF_Task

We copy all variables from cage settings and exp settings, plus references to all created objects, into a single object called Task

class AHF_Task.Task(fileName='', object=None)

The plan is to copy all variables from settings, user, into a single object The object will have fields for things loaded from hardware config dictionary and experiment config dictionary as well as fields for objects created when program runs(headFixer, TagReader, rewarder, camera, stimulator) Objects that are created will have a dictionary of their own as an entry in the main dictionay Using the same names in the object fields as in the dictionary, and only loading one dictionary from a combined settings file, we don’t need a dictionary while thr program is running because the task object can recreate the dict with self.__dict__

saveSettings()

Saves current configuration stored in the task object into AHF_task_*.jsn Call this function after modifying the contents of the task to save your changes

Param

none

Returns

nothing

setup()

Sets up hardware and other objects that need setting up, each object is made by initing a class with a dictionary