sensors.Utilities
Contains classes and functions to handle the peripherical devices and the the dataflow between devices and the Bokeh application.
Class InitDevices
- class sensors.Utilities.initdevices.InitDevices(config)[source]
Bases:
objectInitializes the audio device, the PiCamera and checks for connected light barriers and their corresponding GPIO pins.
- get_GPIO_IR_pins()[source]
Get information about the GPIO pins with connected IR light barriers and sets GPIO switch for LED flash light to low.
- Returns:
list
- Return type:
integers
- static get_as7341_sensor()[source]
Initialize AS7341 10-channel spectral color sensor if connected.
- Returns:
sensor object if connected else None
- Return type:
object, None
- static get_audio_devices()[source]
Get speaker and microphone devices from the USB dongle.
- Returns:
soundcard objects if connected else None
- Return type:
object, None
- static get_bh1750_sensor()[source]
Initialize bh1750 sensor for ambient light if connected.
- Returns:
sensor object if connected else None
- Return type:
object, None
- static get_bme280_sensor()[source]
Initialize bme280 sensor for relative humidity, barometric pressure and ambient temperature if connected.
- Returns:
sensor objects else None
- Return type:
object, None
- static get_camera()[source]
Initialize PiCamera if connected.
- Returns:
picamera object if connected else None
- Return type:
object, None
- static get_pmsa003i_sensor()[source]
Initialize PMSA003I particulate matter (air quality) sensor if connected.
- Returns:
sensor object if connected else None
- Return type:
object, None
- instance = None
Class PyAudioHandler
- class sensors.Utilities.pyaudiohandler.PyAudioHandler(visual_trigger, visual_ringbuffer)[source]
Bases:
ThreadClass to handle USB dongle input by reading chunks of mono data from the wingbeat device and sending data to the Bokeh application and saving it.
- Parameters:
visual_trigger (Bokeh object) – object created by
sensors.GUIclasses.single_save.SingleSaveTabvisual_ringbuffer (Bokeh object) – object created by
sensors.GUIclasses.audio_stream.StreamAudioTab
- py_error_handler(filename, line, function, err, fmt)[source]
Function to mute ALSA warnings on creation of pyaudio object.
- save_trig_signal()[source]
Method to save a triggered signal to a
wavfile with the corresponding time stamp.- Returns:
triggered raw signal, filename
- Return type:
1D float array, string
- update_audio_data()[source]
Main thread function that gets initialized with the thread generation
PyAudioHandler.start().
Class RingBuffer
Class FrameDecoder
- class sensors.Utilities.frame_decoder.FrameDecoder(config, video_path, data_json)[source]
Bases:
objectClass to decode frames from h264 video.
- Parameters:
config (object) – configuration including data.json template
video_path (string) – folder containing video file
data_json (dict) – json dictionary with import/output-format for KInsecta web app
- frames()[source]
Loops over all the video frames and computes the mean pixel values and the difference to the mean of the preceded frame in each loop. The root mean square (rms) of the mean differences gets updated in each loop and if a frame’s mean difference is five times higher than the current rms, a sequence of frames is saved to disc. If no such trigger event occurs, a sequence of frames from the middle of the video gets saved.
- get_video_filename()[source]
Returns the filename of the video.
- Returns:
filename
- Return type:
string
- more()[source]
Check if frame queue is not empty or if the decoding process is not stopped yet.
- Returns:
flag to decode next frame
- Return type:
boolean
- stop()[source]
Stop the decoding thread and insert None as last queue item. Set corresponding flag.
Class WriteMetaData
- class sensors.Utilities.write_meta_data.WriteMetaData(config, data_json)[source]
Bases:
objectClass to write meta data to
data.json.- Parameters:
config (object) – configuration including sensor objects
data_json (dictionary) – json dictionary with import/output-format for KInsecta web app
- prepare_data_json_upload()[source]
Method deletes keys and child properties that have null values from the
data.json. Does not apply to all keys, some may have null values which won’t violate the import format of the KInsecta Web App.
- write_all_data()[source]
Method that calls all methods to write sensor measurements to
data.jsonand prepares it for upload.
- write_humidity_temperature_air_pressure()[source]
Writes humidity, temperature and air pressure measured with BME280 sensor to
data.json.
- sensors.Utilities.write_meta_data.random() x in the interval [0, 1).
Function Create png from signal
- sensors.Utilities.signal_to_png.create_png_from_signal(signal_file, png_filename, decimation_factor)[source]
Function that saves a
pngfile of the input audio signal and its PSD to the specified file name.- Parameters:
signal_file (string) – absolute path to signal file
png_filename (string) – file name of created png
decimation_factor (int) – downsampling factor
- Returns:
False flag for png save in progress (computation ended)
- Return type:
bool