Skip to content

Commit

Permalink
Merge pull request #27 from Macquarie-MEG-Research/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
monkeyman192 authored Feb 8, 2019
2 parents 4c7599f + 363ab26 commit be2b1ed
Show file tree
Hide file tree
Showing 39 changed files with 470 additions and 56 deletions.
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,3 @@ venv.bak/
#vscode directory
.vscode/
.DS_Store

settings.pkl
ListVar.py
thread_test.py
mne_bids/MNEExceptions.py
proj_settings.pkl
savedata.save
19 changes: 8 additions & 11 deletions Biscuit/CustomWidgets/FileTreeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def generate(self, parent, directory=""):
curr_children], curr_children))

# we want to put folders above files (it looks nicer!!)
try:
for file in os.listdir(dir_):
for file in os.listdir(dir_):
try:
fullpath = op.normpath(op.join(dir_, file))

# need to check to see whether or not the file/folder already
Expand All @@ -64,10 +64,10 @@ def generate(self, parent, directory=""):
values=[ext, fullpath],
text=fname, open=False,
tags=(ext))
except PermissionError:
# user doesn't have sufficient permissions to open folder so it
# won't be included
pass
except PermissionError:
# user doesn't have sufficient permissions to open folder so it
# won't be included
pass

def get_filepath(self, sid):
""" Return the file path corresponding to the provided sid """
Expand Down Expand Up @@ -148,12 +148,9 @@ def sid_from_filepath(self, fpath):
# found then follow it back down.
temp_fpath = op.dirname(fpath)
while True:
print(temp_fpath)
if temp_fpath in self.index_cache:
print('found in cache')
sid = self.index_cache[temp_fpath]
for child in self.all_children(item=sid):
print(self.item(child)['values'][1])
if child['values'][1] == fpath:
return child
_temp_fpath = op.dirname(temp_fpath)
Expand Down Expand Up @@ -198,7 +195,7 @@ def _find_added_files(self):
new_files.append(fpath)
# add all the new folders
for dir_ in dirs:
fpath = op.join(root, dir_)
fpath = op.normpath(op.join(root, dir_))
if self.index_cache.get(fpath, None) is None:
new_files.append(fpath)
return new_files
Expand All @@ -218,7 +215,7 @@ def _find_folder_diff(self):
contained_files.add(fpath)
# add all the new folders
for dir_ in dirs:
fpath = op.join(root, dir_)
fpath = op.normpath(op.join(root, dir_))
contained_files.add(fpath)
prev_files = set(self.index_cache.keys())
removed_files = (prev_files - contained_files) - set([self.root_path])
Expand Down
18 changes: 11 additions & 7 deletions Biscuit/FileTypes/KITData.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,20 @@ def load_data(self):
# apply some values
# TODO: clean this up a bit...
""" Project settings """
try:
if self.proj_name.get() == '':
# only set the name from the folder name if we don't
# already have one (eg from a save)
if self.proj_name.get() == '':
# only set the name from the folder name if we don't
# already have one (eg from a save)
try:
proj_name = self.parent.file_treeview.item(
self._id)['text'].split('_')[2]
self.proj_name.set(proj_name)
except IndexError:
# the proj_name will already be an empty string by default
pass
except IndexError:
# Look at the parent folder name instead.
parent_folder = self.parent.file_treeview.parent(
self._id)
proj_name = self.parent.file_treeview.item(
parent_folder)['text']
self.proj_name.set(proj_name)
# set the settings via the setter.
try:
self.settings = self.proj_settings
Expand Down
2 changes: 1 addition & 1 deletion Biscuit/InfoTabs/BIDSSearchFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from Biscuit.Management.CustomVars import OptionsVar
from Biscuit.Management.tkHyperlinkManager import HyperlinkManager

HELP_LINK = "https://github.com/Macquarie-MEG-Research/BIDSHandler/blob/master/README.md#querying-bids-data" # noqa
HELP_LINK = "https://macquarie-meg-research.github.io/BIDSHandler/usage_docs/querying_data.html" # noqa


class BIDSSearchFrame(Frame):
Expand Down
18 changes: 14 additions & 4 deletions Biscuit/Windows/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import webbrowser

from bidshandler import BIDSTree, MappingError

from Biscuit.FileTypes import (generic_file, Folder, KITData, BIDSFile,
BIDSContainer)

Expand Down Expand Up @@ -528,12 +530,20 @@ def _display_defaults_popup(self):

def _import_bids_data(self):
"""Allow BIDS data to be imported into Biscuit."""
# TODO: only works to import an entire BIDS folder currently...
src_dir = filedialog.askdirectory(
title="Select the BIDS folder to import")
dst_dir = filedialog.askdirectory(
title="Select the BIDS folder to import into")
SendFilesWindow(self, src_dir, dst_dir, opt_verify=True)
if src_dir != '':
try:
bt = BIDSTree(src_dir)
except MappingError:
messagebox.showerror('Invalid folder',
'Can only import entire BIDS folders '
'currently.')
return
dst_dir = filedialog.askdirectory(
title="Select the BIDS folder to import into")
if dst_dir != '':
SendFilesWindow(self, bt, dst_dir, opt_verify=True)

def _display_credits_popup(self):
CreditsPopup(self)
Expand Down
4 changes: 2 additions & 2 deletions Biscuit/Windows/SendFilesWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ def _check_write_access(self):
"""
# TODO: make more generic? (and check if this even works???)
auth = dict()
if not os.access(OSCONST.MEG_RAW_PATH, os.W_OK):
if not os.access(OSCONST.SVR_PATH, os.W_OK):
# create a popup to get the username and password
AuthPopup(self, auth)

if auth.get('uname', None) and auth.get('pword', None):
auth_cmd = OSCONST.ACCESS_CMD.format(
unc_path=OSCONST.MEG_RAW_PATH,
unc_path=OSCONST.SVR_PATH,
uname=auth.get('uname', ''),
pword=auth.get('pword', ''))
del auth
Expand Down
15 changes: 15 additions & 0 deletions Biscuit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
__version__ = '0.9.7'
name = "Biscuit" # noqa


def run():
# main entry point to run the Biscuit GUI
from tkinter import Tk
import os
from os.path import dirname
os.chdir(dirname(__file__))

from .Windows import MainWindow

root = Tk()

m = MainWindow(master=root)
m.mainloop()
17 changes: 0 additions & 17 deletions Biscuit/__main__.py

This file was deleted.

8 changes: 2 additions & 6 deletions Biscuit/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,8 @@ def __getattr__(self, name):
OSCONST.TREEVIEW_TEXT_SIZE_MAC = 13
OSCONST.TREEVIEW_TEXT_SIZE_LNX = 12

# server file paths (!TEMPORARY!)
# TODO: rename the SVR_PATH with the value in MEG_RAW_PATH.
# (current value is for testing purposes)
# TODO: add 'BIDS' folder to server and change path to point to it
OSCONST.MEG_RAW_PATH = "\\\\file.cogsci.mq.edu.au\\MEG_RAW"
OSCONST.SVR_PATH = "\\\\file.cogsci.mq.edu.au\\Homes\\mq20184158\\BIDS"
# server file paths
OSCONST.SVR_PATH = "\\\\file.cogsci.mq.edu.au\\MEG_RAW\\BIDS"

# TODO: Not needed/won't work on a mac...
OSCONST.ACCESS_CMD = 'NET USE "{unc_path}" "{pword}" /USER:"MQAUTH\\{uname}"'
12 changes: 12 additions & 0 deletions custom_theme/js/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function GetReleases()
{
$.getJSON("https://api.github.com/repos/Macquarie-MEG-Research/Biscuit/releases").done(function (json){
// most recent release will be first entry in list
var release = json[0];
if (release.assets.length === 0){
alert('Something went wrong! Please raise an issue on GitHub!');
}
var asset = release.assets[0];
window.location.href = asset.browser_download_url;
});
}
14 changes: 14 additions & 0 deletions custom_theme/js/get_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function GetVersion()
{
$.getJSON("https://api.github.com/repos/Macquarie-MEG-Research/Biscuit/releases").done(function (json){
// most recent release will be first entry in list
var release = json[0];
if (release.assets.length === 0){
alert('Something went wrong! Please raise an issue on GitHub!');
}
var version = release.tag_name;

document.getElementById("complete_link").innerText = "Complete install (" + version + ")";
document.getElementById("standard_link").innerText = "Standard install (" + version + ")";
});
}
40 changes: 40 additions & 0 deletions custom_theme/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "base.html" %}

{% block libs %}
{{ super() }}
<script type='text/javascript' src="{{ base_url }}/js/get_version.js"></script>
<script type='text/javascript' src="{{ base_url }}/js/jquery-1.10.2.min.js"></script>
<script type='text/javascript'>
GetVersion();
</script>
<script type="text/javascript" src="{{ base_url }}/js/download.js"></script>
{% endblock %}

{% block site_nav %}
{{ super() }}
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Downloads <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a onclick="GetReleases()" href="#" id="complete_link">Complete install</a>
</li>
<li>
<a onclick="GetReleases()" href="#" id="standard_link">Standard install</a>
</li>
<li>
<a href="https://github.com/Macquarie-MEG-Research/Biscuit">Source code (GitHub)</a>
</li>
{% if page.is_homepage %}
<li>
<a href="installation#complete-install">Not sure which version?</a>
</li>
{% else %}
<li>
<a href="../installation#complete-install">Not sure which version?</a>
</li>
{% endif %}
</ul>
</li>
</ul>
{% endblock %}
40 changes: 40 additions & 0 deletions docs/guide_elekta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Converting Elekta data

Data exported from Elekta MEG machines is stored entirely in a single `.fif` file per run. Because of this all the information required to be added can be entered on one single file.

## FIF file window

![fif_initial](images/screenshots/FIF_main_initial.PNG)

There are a number of fields that need to be completed before the `.fif` file is ready for conversion.

### Experimental information

#### Required information
- **Project Name**: ID of the project. This should match the project ID specified in the project settings so that any default values can be applied automatically.
- **Session ID**: Session number with the particular participant.
- **Task**: A shorthand identifier for the task performed.
- **Run**: An integer identifier for the run or block number (often just `1`, `2` etc.).

#### Subject information
- **Subject ID**: The ID used to identify the participant in a confidential manner.
- **Subject DOB**: The date of birth of the participant. This is entered in *dd/mm/yyy* format (sorry America!).
- **Subject Gender**: One of M (Male), F (Female), U (Unknown).
- **Subject Group**: The group within the study the participant belongs to. THe default values are `Participant` and `Control`, however these can be set in the [project default settings](guide_general.md#settings_window).

#### Optional information
- **Is empty room**: If this is selected the file is specified as the empty room data. Empty room data is copied to a different location and named based on the date of the recording. You should only select one empty room recoring per day otherwise any other existing empty room recording will be overwritten by the new one.
- **Has empty room**: If this is selected the BIDS data will contain a path pointing to the location of empty room file from the same recording day. Note that there is not check on whether or not this empty room file actually exists as this data can be produced after the BIDS conversion occurs for this file. If you do not have any empty room data that was taken on the same day as this con file, **do not** check this box as the data will not be correct.

#### Channel name overrides
As Elekta data can contain `BIO` channels which can contain data from `EMG`, `ECG` or `EOG` sources we need some way to specify the data on these channels.
Currently the channel names section will display all channels that have the `BIO` type.
You can rename the channel if you wish, and also specify the type of data on the channel so that the BIDS conversion process can correctly output the right channel type.

## Exporting the data
When all the required information has been entered, the `Generate BIDS` button will become active.

![fif_complete](images/screenshots/FIF_main_complete.PNG)

To export you simply press this button once and a popup will appear which gives the current progress of the export process.
Once the conversion is done the popup will close and the data will available in the `BIDS` folder that will be in the file view.
35 changes: 35 additions & 0 deletions docs/guide_first_time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# First-time use guide

At first glance Biscuit may look a little bit daunting to use, but once you are familiar with how it works it is very simple and fast to use.

### Add new project settings

If it is your first time using Biscuit to convert some MEG data, you must ensure that the first thing you do before trying to convert any data is to enter the default project settings for your project.
This will allow Biscuit to automatically assign a number of values which saves a lot of time for yourself and can lead to almost automatic exporting, requiring only a few values to be selected.

To add new project settings you can follow the guide [here](guide_new_proj_settings.md).
It is recommended that you add these settings as soon as you know what they are so that when you take some measurements and open Biscuit for file conversion the data is already added and you do not need to worry about adding them then.
Don't worry if you mess up the settings, they can be changed later and the old file will be overwritten with the new settings.

### Exporting data to a BIDS compliant folder

Next, select the folder on the left-hand side that contains the newly acquired data.

If you have acquired data using a Yokogawa/KIT system, you can proceed to follow the guide specifically for this data [here](guide_kit.md).
If you have acquired data using an Elekta system, the specific guide can be found [here](guide_elekta.md).

### Copying data off computer (if required)

The BIDS-compliant data exported by Biscuit will be placed in a sub-folder of a folder named `BIDS`. Depending on your settings it will most likely be placed in a folder named `BIDS-XX` where `XX` is a number. This is to chunk the data so if Biscuit is used on a computer where large amounts of data is being generated, finding the most recent data is easy for those who may need to back up the data.

To transfer the data off one computer and onto another the easiest way is to use Biscuit's built in file-transfer abilities. This is recommended because it is able to transfer the data in a way that is 'BIDS-safe'. This means that you can transfer the data to another folder containing BIDS-compliant data and the new data will be merged automatically into the file hierarchy.

Transferring your BIDS-compliant data is as easy as selecting the folder you want to transfer, right-click the folder name in the built-in file browser, then selecting 'Send to...'.
This will display a pop-up which will let you select the location to transfer your files. It is **highly recommnded** that you select the same folder every time you do this. This is most easily achieved by using an external HDD and having a folder on it called `BIDS` (for example). Every time you transfer data off the computer using Biscuit, transfer to this BIDS folder and it will always contain the entire BIDS folder structure of your data.

*Note*: If you do not see the 'Send to...' option the folder hasn't been specified as a folder containing BIDS formatted data. You can fix this by right-clicking the `BIDS_XX` folder and selecting 'Assign as BIDS folder'.

### Finishing up

Now that your data has been "BIDSified", you have an easy to search folder containing all the data from your various experiments.
In the future Biscuit will be able to be used to search this data so that specific tests or recordings can be found easily to allow for easy identification for analysis purposes.
Loading

0 comments on commit be2b1ed

Please sign in to comment.