Skip to content

Commit

Permalink
Merge pull request #98 from BciPy/system-info
Browse files Browse the repository at this point in the history
System info
  • Loading branch information
lawhead authored Oct 19, 2020
2 parents eac3ef6 + 72f6898 commit 991e398
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 29 deletions.
14 changes: 9 additions & 5 deletions bci_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from bcipy.display.display_main import init_display_window
from bcipy.helpers.acquisition import init_eeg_acquisition
from bcipy.helpers.task import print_message
Expand Down Expand Up @@ -44,14 +45,17 @@ def bci_main(parameters: dict, user: str, exp_type: int, mode: str) -> bool:
'exp_type': exp_type
}

# TODO: Update parameters before init_save_data_structure so sys info gets written to the file
# update our parameters file with system related information
parameters.update(get_system_info())
sys_info = get_system_info()
parameters.update(sys_info)

# configure bcipy session logging
configure_logger(
save_folder,
log_name=parameters['log_name'],
version=parameters['bcipy_version'])
configure_logger(save_folder,
log_name=parameters['log_name'],
version=parameters['bcipy_version'])

logging.getLogger(__name__).info(sys_info)

return execute_task(task_type, parameters, save_folder)

Expand Down
8 changes: 2 additions & 6 deletions bcipy/display/display_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from psychopy import visual
from bcipy.helpers.system_utils import get_system_info
from bcipy.helpers.system_utils import get_screen_resolution


def init_display_window(parameters):
Expand All @@ -16,12 +16,8 @@ def init_display_window(parameters):
# Check is full_screen mode is set and get necessary values
if parameters['full_screen']:

# get relevant info about the system
info = get_system_info()

# set window attributes based on resolution
window_height = info['resolution'][1]
window_width = info['resolution'][0]
window_width, window_height = get_screen_resolution()

# set full screen mode to true (removes os dock, explorer etc.)
full_screen = True
Expand Down
13 changes: 6 additions & 7 deletions bcipy/display/rsvp/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bcipy.acquisition.marker_writer import NullMarkerWriter, MarkerWriter
from bcipy.helpers.task import SPACE_CHAR
from bcipy.helpers.stimuli import resize_image
from bcipy.helpers.system_utils import get_system_info
from bcipy.helpers.system_utils import get_screen_resolution
from bcipy.helpers.triggers import TriggerCallback, _calibration_trigger


Expand Down Expand Up @@ -293,19 +293,18 @@ def _generate_sequence(self):
# test whether the word will be too big for the screen
text_width = current_stim['sti'].boundingBox[0]
if text_width > self.window.size[0]:
info = get_system_info()
monitor_width, monitor_height = get_screen_resolution()
text_height = current_stim['sti'].boundingBox[1]
# If we are in full-screen, text size in Psychopy norm units
# is monitor width/monitor height
if self.window.size[0] == info['RESOLUTION'][0]:
new_text_width = info['RESOLUTION'][0] / \
info['RESOLUTION'][1]
if self.window.size[0] == monitor_width:
new_text_width = monitor_width / monitor_height
else:
# If not, text width is calculated relative to both
# monitor size and window size
new_text_width = (
self.window.size[1] / info['RESOLUTION'][1]) * (
info['RESOLUTION'][0] / info['RESOLUTION'][1])
self.window.size[1] / monitor_height) * (
monitor_width / monitor_height)
new_text_height = (text_height * new_text_width) / text_width
current_stim['sti'].height = new_text_height
stim_info.append(current_stim)
Expand Down
49 changes: 38 additions & 11 deletions bcipy/helpers/system_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import sys
import os

from typing import Optional
from cpuinfo import get_cpu_info
from typing import Optional, Tuple
from pathlib import Path
import pkg_resources
import platform
import psutil
import pyglet
import importlib
Expand Down Expand Up @@ -70,22 +72,47 @@ def bcipy_version() -> str:
return f'{version} - {sha_hash}' if sha_hash else version


def get_system_info() -> dict:
"""Get System Information.
"""
def get_screen_resolution() -> Tuple[int, int]:
"""Gets the screen resolution.
Note: Use this method if only the screen resolution is needed; it is much more efficient
than extracting that information from the dict returned by the get_system_info method.
Returns
-------
(width, height)
"""
screen = pyglet.canvas.get_display().get_default_screen()
return (screen.width, screen.height)

# Three lines for getting screen resolution
display = pyglet.canvas.get_display()
screen = display.get_default_screen()

mem = psutil.virtual_memory()
def get_system_info() -> dict:
"""Get System Information.
See: https://stackoverflow.com/questions/3103178/how-to-get-the-system-info-with-python
Returns
-------
dict of system-related properties, including ['os', 'py_version', 'resolution',
'memory', 'bcipy_version', 'platform', 'platform-release', 'platform-version',
'architecture', 'processor', 'cpu_count', 'hz', 'ram']
"""
screen_width, screen_height = get_screen_resolution()
info = get_cpu_info()
return {
'os': sys.platform,
'py_version': sys.version,
'resolution': [screen.width, screen.height],
'memory': mem.available / 1024 / 1024,
'bcipy_version': bcipy_version()
'resolution': [screen_width, screen_height],
'memory': psutil.virtual_memory().available / 1024 / 1024,
'bcipy_version': bcipy_version(),
'platform': platform.system(),
'platform-release': platform.release(),
'platform-version': platform.version(),
'architecture': platform.machine(),
'processor': platform.processor(),
'cpu_count': os.cpu_count(),
'cpu_brand': info['brand_raw'],
'hz': info['hz_actual_friendly'],
'ram': str(round(psutil.virtual_memory().total / (1024.0**3))) + " GB"
}


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pylsl==1.13.1
pandas==1.1.3
psutil==5.7.2
Pillow==8.0.0
py-cpuinfo==7.0.0

0 comments on commit 991e398

Please sign in to comment.