Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System info #98

Merged
merged 4 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 36 additions & 12 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,23 +72,45 @@ 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to change slightly to work with the updated dependencies

return (screen.width, screen.height)

# Three lines for getting screen resolution
platform = pyglet.window.get_platform()
display = platform.get_default_display()
screen = display.get_default_screen()

mem = psutil.virtual_memory()
def get_system_info() -> dict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome - this is exactly what Barry et al. asked for!

"""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()
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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we can get the CPU name in most cases. It would be worth adding! https://github.com/workhorsy/py-cpuinfo#raw-fields

'hz': get_cpu_info()['hz_actual_friendly'],
'ram': str(round(psutil.virtual_memory().total / (1024.0**3))) + " GB"
}


Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ SoundFile==0.10.1
PySoundCard==0.5.2
PySoundFile==0.9.0
Pillow==4.3.0
openpyxl==2.6.3
openpyxl==2.6.3
py-cpuinfo==7.0.0