Basic Demos¶
Our examples will showcase how easy it is to use a VPixx device with our package.
Tip
We will be using an object-oriented approach to use VPixx devices. If you are more comfortable programming using a more imperative/functional way but you still want to use Python, you can use the Libdpx Wrapper module, which is a simple wrapper for our ANSI C SDK.
Example 1 - Setting up a device in High-bit depth grey-scale mode.¶
You must first consider which device you have. In this example we will use a VIEWPixx3D.
1from pypixxlib.viewpixx import VIEWPixx3D
2# viewpixx and VIEWPixx3D would need to be replaced by the appropriate devices.
3my_device = VIEWPixx3D() # Opens and initiates the device
4my_device.setVideoMode('M16') # Set the right video mode
5my_device.updateRegisterCache() # Update the device
Example 2 - Setting up a PROPixx to display in 480 Hz.¶
This example is only meant for the PROPixx as it is the only device able to display stimuli at 480 Hz. To do so, we limit our resolution to 1/4 of the screen to display 4 times faster. Indeed, your stimulus needs to be created as follow:
Quadrant 1 |
Quadrant 2 |
Quadrant 3 |
Quadrant 4 |
One frame at 120 Hz will represent 4 frames at 480 Hz on the PROPixx, and each of those 4 frames must be put in order in the quadrants 1, 2, 3 and 4.
1from pypixxlib.propixx import PROPixx
2my_device = PROPixx()
3my_device.setDlpSequencerProgram('QUAD4X')
4my_device.updateRegisterCache()
5# You can now send you stimulus at 120 Hz to be displayed at 480 Hz!
Example 3 - Setting up a PROPixx to display in 1440 Hz.¶
1440 Hz is very similar to 480 Hz in the set-up process. To get 1440 Hz, we use the fact that every quadrants defined above has three channels of information (RGB). Quadrant 1’s red information will define the first frame we display at 1440 Hz, Quadrant 2’s red will be the 2nd, and after red we use green information, then blue. In other words: Q1R, Q2R, Q3R, Q4R, Q1G, Q2G, Q3G, Q4G, Q1B, Q2B, Q3B, Q4B. This allows us to have 12 high speed frames every normal speed frame, giving 1440 Hz.
1from pypixxlib.propixx import PROPixx
2my_device = PROPixx()
3my_device.setDlpSequencerProgram('QUAD12X')
4my_device.updateRegisterCache()
5# You can now send you stimulus at 120 Hz to be displayed at 1440 Hz!
Example 4 - Setting up a PROPixx for a 3D experiment.¶
In this example, we will set up the PROPixx for rear projection, ceiling mode and use of a polariser. We will also set the PROPixx so that it keeps this configuration after a power down. We will also have the PROPixx Controller send out audio stimuli.
There exists four ways to set up the polariser, depending on what you wish to achieve.
If the video source is set to
SWTP3D
:my_device.setVideoSource('SWTP3D')
If you are using Blue Lines to sync your 3D stimulus:
my_device.setVideoBlueLine(True)
If you are using the red and blue 3D sequencer mode:
my_device.setDlpSequencerProgram('RB3D')
You can manually activate the polariser,(this is called VESA Free Run mode):
my_device.setVesaFreeRun(True)
1from pypixxlib.propixx import PROPixx, PROPixxCTRL
2from pypixxlib._libdpx import DPxSelectDevice
3my_device = PROPixx()
4my_device_controller = PROPixxCTRL()
5
6
7my_device.setRearProjectionMode(True)# Sets the projector to read-projection mode.
8my_device.setCeilingMountMode(True) # Sets the projector to ceiling-mount mode.
9my_device.setVesaFreeRun(True) # Sets the VESA port to work with the polariser.
10my_device.updateRegisterCache() # Update the new modes to the device.
11my_device.setCustomStartupConfig() # The projector will remember this configuration.
12# The audio is done on the controller, so the next functions use the controller object.
13my_device_controller.audio.initializeCodec() # Configures initial CODEC state.
14my_device_controller.audio.setLeftRightMode('mono') # Set which mode the audio will be output.
15my_device_controller.audio.setAudioBuffer(0, 64) # Set the audio to start at address 0, and size 64.
16
17
18# Now we must create the audio stimulus.
19# This is done by simply filling a list with a sound wave.
20audio_stim = []
21import math
22for i in range(32):
23 audio_stim.append(int(32767 * math.sin(2.0 * math.pi * i / 32.0)))
24my_device_controller.writeRam(0, audio_stim) # Write the audio stimulus in the ram.
25my_device_controller.audio.setVolume(0.25)
26my_device_controller.updateRegisterCache() # Send everything to the device.
27
28# We must at this point create the audio schedule
29# The first parameter is the schedule onset, which we set to 0,
30# meaning that the first schedule tick will occur immediately once the schedule starts.
31# The second and third parameters indicate that the audio samples will be played at 40 kHz.
32# The forth parameter is a schedule counter, indicating the number of ticks
33# that the schedule should run before stopping.
34# We'll run it for 16000 samples, which will take 16000/40000 = 400 ms.
35
36my_device_controller.audio.setAudioSchedule(0, 40000, 'hz', 16000)
37my_device_controller.audio.startScheduleLeft()
38my_device_controller.updateRegisterCache()
39# Close the devices
40my_device.close()
41my_device_controller.close()
Example 5 - Changing the back-light intensity on a VIEWPixx¶
Our VIEWPixx offer a customizable back-light level, should you wish to work with specific luminance values.
1from pypixxlib.viewpixx import VIEWPixxEEG
2my_device = VIEWPixxEEG() # Create an instance of your device.
3my_device.setBacklightIntensity(35) # Value between 0-255 for the intensity.
4my_device.updateRegisterCache() # Send the value to the device.
5my_device.getBacklightIntensity() # Double check our value was sent and applied
635
Example 6 - Recording changes in digital-in¶
If you are running an experiment that sends triggers over a DB-25 cable, it is possible to record those changes with a DATAPixx.
1from pypixxlib.datapixx import DATAPixx
2my_device = DATAPixx()
3din_state = my_device.din.getValue()
4# Start your experiment
5experiement_is_running = True
6while experiement_is_running:
7 old_state = din_state
8 my_device.updateRegisterCache()
9 din_state = my_device.din.getValue()
10 if old_state is not din_state: # Something triggered.
11 # Now we want to check, for example, if pin 6 triggered.
12 if (old_state & 2**6) is not (din_state & 2**6):
13 print 'Pin 6 triggered!'
14 experiement_is_running = False
15 else:
16 print 'Pin 6 is in the same state as before'
17# Finish your experiment
Example 7 - How to verify the chromacity and luminance of the colors of your device using i1Device¶
Most of our devices come calibrated as D65, but if you want to verify the calibration or get a specific value for a colour/brightness, you can use the i1Display and i1Pro modules.
1from pypixxlib.i1 import I1Display # We will use an i1Display here
2
3
4# Initialize the device.
5my_device = I1Display()
6my_device.setCurrentCalibration('RGB LED') # We will be using a device with RGB LEDs
7print 'Current calibration is: ', my_device.getCurrentCalibration() # Verify we have the right calibration
8
9# Set the color/intensity you wish to measure
10my_device.runMeasurement()
11print 'next acquisition' # Change to the next color/intensity
12my_device.runMeasurement()
13print 'next acquisition' # Change to the next color/intensity
14my_device.runMeasurement()
15
16results = my_device.getAllMeasurement() # Get a list of all measurements
17for i in range(len(results)):
18 print results[i] # Print the different measurements
19
20my_device.printLatestMeasurement() # If you want to print your latest measurement
21
22my_device.close() # Close the device.