prefs#

Preferences and configuration shared throughout the program.

Saves and loads to a prefs file (default is ~/.perceptivo/prefs.json )

Each runtime has its own set of preferences. When first run, if there is not prefs file detected it populates with defaults (though defaults can be populated at any time by instantiating the object with no arguments and using save, eg.:

prefs = Patient_Prefs()
prefs.save()
class perceptivo.prefs.Runtimes(value)#

Bases: enum.Enum

An enumeration.

patient = 'patient'#
clinician = 'clinician'#
stimuli = 'stimuli'#
perceptivo.prefs.json_dumps_pretty(v, *, default)#
pydantic model perceptivo.prefs.Prefs#

Bases: pydantic.main.BaseModel

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Show JSON schema
{
   "title": "Prefs",
   "type": "object",
   "properties": {
      "loglevel": {
         "title": "Loglevel",
         "default": "DEBUG",
         "enum": [
            "DEBUG",
            "INFO",
            "WARNING",
            "ERROR"
         ],
         "type": "string"
      }
   }
}

Config
  • json_dumps: function = <function json_dumps_pretty at 0x7f07dd545700>

Fields
field loglevel: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR'] = 'DEBUG'#
save(file: pathlib.Path = PosixPath('/home/docs/.perceptivo/prefs.json'))#
classmethod load(file: pathlib.Path = PosixPath('/home/docs/.perceptivo/prefs.json')) perceptivo.prefs.Prefs#
classmethod get_runtime_prefs(runtime: perceptivo.prefs.Runtimes) perceptivo.prefs.Patient_Prefs#
pydantic model perceptivo.prefs.Patient_Prefs#

Bases: perceptivo.prefs.Prefs

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Show JSON schema
{
   "title": "Patient_Prefs",
   "type": "object",
   "properties": {
      "loglevel": {
         "title": "Loglevel",
         "default": "DEBUG",
         "enum": [
            "DEBUG",
            "INFO",
            "WARNING",
            "ERROR"
         ],
         "type": "string"
      },
      "runtime": {
         "default": "patient",
         "allOf": [
            {
               "$ref": "#/definitions/Runtimes"
            }
         ]
      },
      "Audio_Config": {
         "title": "Audio Config",
         "default": {
            "fs": 44100
         },
         "allOf": [
            {
               "$ref": "#/definitions/Audio_Config"
            }
         ]
      },
      "Audiogram_Model": {
         "title": "Audiogram Model",
         "default": {
            "model_type": "Gaussian_Process",
            "args": [],
            "kwargs": {
               "kernel": "length_scale=(100.0, 200.0) length_scale_bounds=(1, 100000.0)"
            }
         },
         "allOf": [
            {
               "$ref": "#/definitions/Psychoacoustic_Model"
            }
         ]
      },
      "Picamera_Params": {
         "title": "Picamera Params",
         "default": {
            "sensor_mode": 0,
            "resolution": [
               1280,
               720
            ],
            "fps": 30,
            "format": "grayscale",
            "output_file": null
         },
         "allOf": [
            {
               "$ref": "#/definitions/Picamera_Params"
            }
         ]
      },
      "picamera_process": {
         "title": "Picamera Process",
         "default": true,
         "type": "boolean"
      },
      "picam_queue_size": {
         "title": "Picam Queue Size",
         "default": 1024,
         "type": "integer"
      },
      "pupil_extractor": {
         "title": "Pupil Extractor",
         "default": "simple",
         "type": "string"
      },
      "pupil_extractor_params": {
         "title": "Pupil Extractor Params",
         "default": {
            "footprint_size": 5,
            "search_scale": 1.5
         },
         "allOf": [
            {
               "$ref": "#/definitions/EllipseExtractor_Params"
            }
         ]
      },
      "collection_params": {
         "title": "Collection Params",
         "default": {
            "collection_wait": 5
         },
         "allOf": [
            {
               "$ref": "#/definitions/Collection_Params"
            }
         ]
      },
      "networking": {
         "title": "Networking",
         "default": {
            "ip": "",
            "clinician_ip": "",
            "eyecam": "Socket(id='patient:eyecam', socket_type='PUSH', protocol='tcp', mode='connect', port=5500, ip='', to=None)",
            "control": "Socket(id='patient:control', socket_type='DEALER', protocol='tcp', mode='connect', port=5600, ip='', to='clinician:control')"
         },
         "allOf": [
            {
               "$ref": "#/definitions/Patient_Networking"
            }
         ]
      }
   },
   "definitions": {
      "Runtimes": {
         "title": "Runtimes",
         "description": "An enumeration.",
         "enum": [
            "patient",
            "clinician",
            "stimuli"
         ]
      },
      "Audio_Config": {
         "title": "Audio_Config",
         "description": "Base class for audio configuration\n\nParams:\n    fs (int): Sampling rate in Hz, default 44100",
         "type": "object",
         "properties": {
            "fs": {
               "title": "Fs",
               "default": 44100,
               "type": "integer"
            }
         }
      },
      "Kernel": {
         "title": "Kernel",
         "description": "Default kernel to use with :class:`.psychophys.model.Gaussian_Process`\n\nUses a kernel with a short length scale for frequency, but a longer length scale for amplitude,\nwhich should be smoother/monotonic where frequency can have an unpredictable shape",
         "type": "object",
         "properties": {
            "length_scale": {
               "title": "Length Scale",
               "default": [
                  100.0,
                  200.0
               ],
               "type": "array",
               "minItems": 2,
               "maxItems": 2,
               "items": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ]
            },
            "length_scale_bounds": {
               "title": "Length Scale Bounds",
               "default": [
                  1,
                  100000.0
               ],
               "type": "array",
               "minItems": 2,
               "maxItems": 2,
               "items": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "number"
                  }
               ]
            }
         }
      },
      "Psychoacoustic_Model": {
         "title": "Psychoacoustic_Model",
         "description": "Parameterization of a psychoacoustic model to use to estimate audiograms and\ncontrol the presentation of stimuli",
         "type": "object",
         "properties": {
            "model_type": {
               "title": "Model Type",
               "default": "Gaussian_Process",
               "enum": [
                  "Gaussian_Process"
               ],
               "type": "string"
            },
            "args": {
               "title": "Args",
               "type": "array",
               "items": {}
            },
            "kwargs": {
               "title": "Kwargs",
               "type": "object",
               "additionalProperties": {
                  "$ref": "#/definitions/Kernel"
               }
            }
         }
      },
      "Picamera_Params": {
         "title": "Picamera_Params",
         "description": "Configuration for a :class:`perceptivo.video.cameras.PiCamera`",
         "type": "object",
         "properties": {
            "sensor_mode": {
               "title": "Sensor Mode",
               "default": 0,
               "type": "integer"
            },
            "resolution": {
               "title": "Resolution",
               "default": [
                  1280,
                  720
               ],
               "type": "array",
               "minItems": 2,
               "maxItems": 2,
               "items": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "integer"
                  }
               ]
            },
            "fps": {
               "title": "Fps",
               "default": 30,
               "type": "integer"
            },
            "format": {
               "title": "Format",
               "default": "grayscale",
               "enum": [
                  "rgb",
                  "grayscale"
               ],
               "type": "string"
            },
            "output_file": {
               "title": "Output File",
               "type": "string",
               "format": "path"
            }
         }
      },
      "EllipseExtractor_Params": {
         "title": "EllipseExtractor_Params",
         "type": "object",
         "properties": {
            "footprint_size": {
               "title": "Footprint Size",
               "default": 5,
               "type": "integer"
            },
            "search_scale": {
               "title": "Search Scale",
               "default": 1.5,
               "type": "number"
            }
         }
      },
      "Collection_Params": {
         "title": "Collection_Params",
         "type": "object",
         "properties": {
            "collection_wait": {
               "title": "Collection Wait",
               "default": 5,
               "type": "number"
            }
         }
      },
      "Socket": {
         "title": "Socket",
         "type": "object",
         "properties": {
            "id": {
               "title": "Id",
               "type": "string"
            },
            "socket_type": {
               "title": "Socket Type",
               "enum": [
                  "REQ",
                  "REP",
                  "PUB",
                  "SUB",
                  "PAIR",
                  "DEALER",
                  "ROUTER",
                  "PULL",
                  "PUSH"
               ],
               "type": "string"
            },
            "protocol": {
               "title": "Protocol",
               "enum": [
                  "tcp",
                  "ipc",
                  "inproc"
               ],
               "type": "string"
            },
            "mode": {
               "title": "Mode",
               "enum": [
                  "connect",
                  "bind"
               ],
               "type": "string"
            },
            "port": {
               "title": "Port",
               "type": "integer"
            },
            "ip": {
               "title": "Ip",
               "default": "*",
               "type": "string"
            },
            "to": {
               "title": "To",
               "type": "string"
            }
         },
         "required": [
            "id",
            "socket_type",
            "protocol",
            "mode",
            "port"
         ]
      },
      "Patient_Networking": {
         "title": "Patient_Networking",
         "type": "object",
         "properties": {
            "ip": {
               "title": "Ip",
               "default": "",
               "type": "string"
            },
            "clinician_ip": {
               "title": "Clinician Ip",
               "default": "",
               "type": "string"
            },
            "eyecam": {
               "title": "Eyecam",
               "default": {
                  "id": "patient:eyecam",
                  "socket_type": "PUSH",
                  "protocol": "tcp",
                  "mode": "connect",
                  "port": 5500,
                  "ip": "",
                  "to": null
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/Socket"
                  }
               ]
            },
            "control": {
               "title": "Control",
               "default": {
                  "id": "patient:control",
                  "socket_type": "DEALER",
                  "protocol": "tcp",
                  "mode": "connect",
                  "port": 5600,
                  "ip": "",
                  "to": "clinician:control"
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/Socket"
                  }
               ]
            }
         }
      }
   }
}

Config
  • use_enum_values: bool = True

Fields
field runtime: perceptivo.prefs.Runtimes = 'patient'#
field Audio_Config: perceptivo.types.sound.Audio_Config = Audio_Config(fs=44100)#
field Audiogram_Model: perceptivo.types.psychophys.Psychoacoustic_Model = Psychoacoustic_Model(model_type='Gaussian_Process', args=[], kwargs={'kernel': Kernel(length_scale=(100.0, 200.0), length_scale_bounds=(1, 100000.0))})#
field Picamera_Params: perceptivo.types.video.Picamera_Params = Picamera_Params(sensor_mode=0, resolution=(1280, 720), fps=30, format='grayscale', output_file=None)#
field picamera_process: bool = True#

Run the picamera in a separate Process (using cameras.Picamera_Process . Only True supported for now!

field picam_queue_size: int = 1024#
field pupil_extractor: str = 'simple'#
field pupil_extractor_params: perceptivo.video.pupil.EllipseExtractor_Params = EllipseExtractor_Params(footprint_size=5, search_scale=1.5)#
field collection_params: perceptivo.types.patient.Collection_Params = Collection_Params(collection_wait=5)#
field networking: perceptivo.types.networking.Patient_Networking = Patient_Networking(ip='', clinician_ip='', eyecam=Socket(id='patient:eyecam', socket_type='PUSH', protocol='tcp', mode='connect', port=5500, ip='', to=None), control=Socket(id='patient:control', socket_type='DEALER', protocol='tcp', mode='connect', port=5600, ip='', to='clinician:control'))#
pydantic model perceptivo.prefs.Clinician_Prefs#

Bases: perceptivo.prefs.Prefs

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Show JSON schema
{
   "title": "Clinician_Prefs",
   "type": "object",
   "properties": {
      "loglevel": {
         "title": "Loglevel",
         "default": "DEBUG",
         "enum": [
            "DEBUG",
            "INFO",
            "WARNING",
            "ERROR"
         ],
         "type": "string"
      },
      "networking": {
         "title": "Networking",
         "default": {
            "ip": "",
            "patient_ip": "",
            "eyecam": "Socket(id='clinician:eyecam', socket_type='PULL', protocol='tcp', mode='bind', port=5500, ip='*', to=None)",
            "control": "Socket(id='clinician:control', socket_type='ROUTER', protocol='tcp', mode='bind', port=5600, ip='*', to=None)"
         },
         "allOf": [
            {
               "$ref": "#/definitions/Clinician_Networking"
            }
         ]
      },
      "gui": {
         "title": "Gui",
         "default": {
            "control_panel": {
               "amplitude_range": {
                  "key": "amplitude_range",
                  "name": "Amplitude Range (dBSPL)",
                  "widget_type": "range",
                  "default": {
                     "min": 0.0,
                     "max": 80.0,
                     "n": 8
                  },
                  "args": [],
                  "kwargs": {
                     "limits": [
                        0,
                        100
                     ]
                  }
               },
               "frequency_range": {
                  "key": "frequency_range",
                  "name": "Frequency Range (Hz)",
                  "widget_type": "range",
                  "default": {
                     "min": 0.0,
                     "max": 8000.0,
                     "n": 17
                  },
                  "args": [],
                  "kwargs": {
                     "limits": [
                        0,
                        20000
                     ]
                  }
               },
               "iti": {
                  "key": "iti",
                  "name": "Inter-Trial Interval (s)",
                  "widget_type": "float",
                  "default": 5.0,
                  "args": [],
                  "kwargs": {}
               },
               "iti_jitter": {
                  "key": "iti_jitter",
                  "name": "Inter-Trial Jitter (proportion of ITI)",
                  "widget_type": "float",
                  "default": 0.1,
                  "args": [],
                  "kwargs": {}
               }
            }
         },
         "allOf": [
            {
               "$ref": "#/definitions/GUI_Params"
            }
         ]
      },
      "update_period": {
         "title": "Update Period",
         "default": 0.05,
         "type": "number"
      }
   },
   "definitions": {
      "Socket": {
         "title": "Socket",
         "type": "object",
         "properties": {
            "id": {
               "title": "Id",
               "type": "string"
            },
            "socket_type": {
               "title": "Socket Type",
               "enum": [
                  "REQ",
                  "REP",
                  "PUB",
                  "SUB",
                  "PAIR",
                  "DEALER",
                  "ROUTER",
                  "PULL",
                  "PUSH"
               ],
               "type": "string"
            },
            "protocol": {
               "title": "Protocol",
               "enum": [
                  "tcp",
                  "ipc",
                  "inproc"
               ],
               "type": "string"
            },
            "mode": {
               "title": "Mode",
               "enum": [
                  "connect",
                  "bind"
               ],
               "type": "string"
            },
            "port": {
               "title": "Port",
               "type": "integer"
            },
            "ip": {
               "title": "Ip",
               "default": "*",
               "type": "string"
            },
            "to": {
               "title": "To",
               "type": "string"
            }
         },
         "required": [
            "id",
            "socket_type",
            "protocol",
            "mode",
            "port"
         ]
      },
      "Clinician_Networking": {
         "title": "Clinician_Networking",
         "description": "Default networking properties for the Clinician computer",
         "type": "object",
         "properties": {
            "ip": {
               "title": "Ip",
               "default": "",
               "type": "string"
            },
            "patient_ip": {
               "title": "Patient Ip",
               "default": "",
               "type": "string"
            },
            "eyecam": {
               "title": "Eyecam",
               "default": {
                  "id": "clinician:eyecam",
                  "socket_type": "PULL",
                  "protocol": "tcp",
                  "mode": "bind",
                  "port": 5500,
                  "ip": "*",
                  "to": null
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/Socket"
                  }
               ]
            },
            "control": {
               "title": "Control",
               "default": {
                  "id": "clinician:control",
                  "socket_type": "ROUTER",
                  "protocol": "tcp",
                  "mode": "bind",
                  "port": 5600,
                  "ip": "*",
                  "to": null
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/Socket"
                  }
               ]
            }
         }
      },
      "GUI_Range": {
         "title": "GUI_Range",
         "description": "Range for :class:`.widgets.components.Range_Setter`",
         "type": "object",
         "properties": {
            "min": {
               "title": "Min",
               "type": "number"
            },
            "max": {
               "title": "Max",
               "type": "number"
            },
            "n": {
               "title": "N",
               "type": "integer"
            }
         },
         "required": [
            "min",
            "max",
            "n"
         ]
      },
      "GUI_Param": {
         "title": "GUI_Param",
         "description": "Parameterization for a GUI Parameter itself. ie. How a particular parameter should be represented.\n\nParams:\n    key (GUI_PARAMS): the key used for the parameter\n    name (str): A human readable name for the parameter\n    widget_type (GUI_WIDGETS): A string that indicates the type of widget that should be used.\n        Different ``widget_type`` s may use different widgets, combinations of widgets, and\n        validators, and are thus not strictly isomorphic to a single widget type.\n    default (any): the default value to be set, must correspond to widget type\n    args (list): args to pass to the widget\n    kwargs (dict): kwargs to pass to the widget",
         "type": "object",
         "properties": {
            "key": {
               "title": "Key",
               "enum": [
                  "frequencies",
                  "amplitudes",
                  "log_x",
                  "log_y",
                  "extra_amplitude",
                  "amplitude_step",
                  "amplitude_range",
                  "max_amplitude",
                  "frequency_step",
                  "frequency_range",
                  "iti",
                  "iti_jitter"
               ],
               "type": "string"
            },
            "name": {
               "title": "Name",
               "type": "string"
            },
            "widget_type": {
               "title": "Widget Type",
               "enum": [
                  "int",
                  "float",
                  "range",
                  "tuple",
                  "bool"
               ],
               "type": "string"
            },
            "default": {
               "title": "Default",
               "anyOf": [
                  {
                     "type": "number"
                  },
                  {
                     "type": "integer"
                  },
                  {
                     "$ref": "#/definitions/GUI_Range"
                  },
                  {
                     "type": "array",
                     "items": {}
                  }
               ]
            },
            "args": {
               "title": "Args",
               "type": "array",
               "items": {}
            },
            "kwargs": {
               "title": "Kwargs",
               "type": "object"
            }
         },
         "required": [
            "key",
            "name",
            "widget_type"
         ]
      },
      "Control_Panel_Params": {
         "title": "Control_Panel_Params",
         "description": "Defaults and parameters for :class:`perceptivo.gui.widgets.Control_Panel`",
         "type": "object",
         "properties": {
            "amplitude_range": {
               "title": "Amplitude Range",
               "default": {
                  "key": "amplitude_range",
                  "name": "Amplitude Range (dBSPL)",
                  "widget_type": "range",
                  "default": {
                     "min": 0.0,
                     "max": 80.0,
                     "n": 8
                  },
                  "args": [],
                  "kwargs": {
                     "limits": [
                        0,
                        100
                     ]
                  }
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/GUI_Param"
                  }
               ]
            },
            "frequency_range": {
               "title": "Frequency Range",
               "default": {
                  "key": "frequency_range",
                  "name": "Frequency Range (Hz)",
                  "widget_type": "range",
                  "default": {
                     "min": 0.0,
                     "max": 8000.0,
                     "n": 17
                  },
                  "args": [],
                  "kwargs": {
                     "limits": [
                        0,
                        20000
                     ]
                  }
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/GUI_Param"
                  }
               ]
            },
            "iti": {
               "title": "Iti",
               "default": {
                  "key": "iti",
                  "name": "Inter-Trial Interval (s)",
                  "widget_type": "float",
                  "default": 5.0,
                  "args": [],
                  "kwargs": {}
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/GUI_Param"
                  }
               ]
            },
            "iti_jitter": {
               "title": "Iti Jitter",
               "default": {
                  "key": "iti_jitter",
                  "name": "Inter-Trial Jitter (proportion of ITI)",
                  "widget_type": "float",
                  "default": 0.1,
                  "args": [],
                  "kwargs": {}
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/GUI_Param"
                  }
               ]
            }
         }
      },
      "GUI_Params": {
         "title": "GUI_Params",
         "description": "Container for all parameters to be given to the GUI on init",
         "type": "object",
         "properties": {
            "control_panel": {
               "title": "Control Panel",
               "default": {
                  "amplitude_range": {
                     "key": "amplitude_range",
                     "name": "Amplitude Range (dBSPL)",
                     "widget_type": "range",
                     "default": {
                        "min": 0.0,
                        "max": 80.0,
                        "n": 8
                     },
                     "args": [],
                     "kwargs": {
                        "limits": [
                           0,
                           100
                        ]
                     }
                  },
                  "frequency_range": {
                     "key": "frequency_range",
                     "name": "Frequency Range (Hz)",
                     "widget_type": "range",
                     "default": {
                        "min": 0.0,
                        "max": 8000.0,
                        "n": 17
                     },
                     "args": [],
                     "kwargs": {
                        "limits": [
                           0,
                           20000
                        ]
                     }
                  },
                  "iti": {
                     "key": "iti",
                     "name": "Inter-Trial Interval (s)",
                     "widget_type": "float",
                     "default": 5.0,
                     "args": [],
                     "kwargs": {}
                  },
                  "iti_jitter": {
                     "key": "iti_jitter",
                     "name": "Inter-Trial Jitter (proportion of ITI)",
                     "widget_type": "float",
                     "default": 0.1,
                     "args": [],
                     "kwargs": {}
                  }
               },
               "allOf": [
                  {
                     "$ref": "#/definitions/Control_Panel_Params"
                  }
               ]
            }
         }
      }
   }
}

Config
  • json_dumps: function = <function json_dumps_pretty at 0x7f07dd545700>

Fields
field networking: perceptivo.types.networking.Clinician_Networking = Clinician_Networking(ip='', patient_ip='', eyecam=Socket(id='clinician:eyecam', socket_type='PULL', protocol='tcp', mode='bind', port=5500, ip='*', to=None), control=Socket(id='clinician:control', socket_type='ROUTER', protocol='tcp', mode='bind', port=5600, ip='*', to=None))#
field gui: perceptivo.types.gui.GUI_Params = GUI_Params(control_panel=Control_Panel_Params(amplitude_range=GUI_Param(key='amplitude_range', name='Amplitude Range (dBSPL)', widget_type='range', default=GUI_Range(min=0.0, max=80.0, n=8), args=[], kwargs={'limits': (0, 100)}), frequency_range=GUI_Param(key='frequency_range', name='Frequency Range (Hz)', widget_type='range', default=GUI_Range(min=0.0, max=8000.0, n=17), args=[], kwargs={'limits': (0, 20000)}), iti=GUI_Param(key='iti', name='Inter-Trial Interval (s)', widget_type='float', default=5.0, args=[], kwargs={}), iti_jitter=GUI_Param(key='iti_jitter', name='Inter-Trial Jitter (proportion of ITI)', widget_type='float', default=0.1, args=[], kwargs={})))#
field update_period: float = 0.05#
perceptivo.prefs.get(field: str, file: pathlib.Path = PosixPath('/home/docs/.perceptivo/prefs.json'))#
perceptivo.prefs.set_global(prefs: perceptivo.prefs.Prefs)#
perceptivo.prefs.get_global() perceptivo.prefs.Prefs#