Skip to content

Commit

Permalink
[MAINT] convert setVolumeThreshold to JS and minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Levitas committed Aug 14, 2023
1 parent eaf24fc commit fc0ec0c
Show file tree
Hide file tree
Showing 4 changed files with 707 additions and 658 deletions.
114 changes: 57 additions & 57 deletions handler/ezBIDS_core/ezBIDS_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2105,61 +2105,61 @@ def extract_series_info(dataset_list_unique_series):
return ui_series_info_list


def setVolumeThreshold(dataset_list_unique_series, objects_list):
"""
Determine a volume threshold for all func/bold acquisitions in dataset,
using the following heuristic:
Parameters
----------
dataset_list_unique_series : list
List of dictionaries of unique series
objects_list: list
List of dictionaries of all dataset objects
"""

func_series = [
x for x in dataset_list_unique_series
if "func" in x["type"]
and x["type"] != "func/sbref"
and x["RepetitionTime"] > 0
]

if len(func_series):
for func in func_series:
series_idx = func["series_idx"]
tr = func["RepetitionTime"]
corresponding_objects_volumes = [
x["analysisResults"]["NumVolumes"] for x in objects_list if x["series_idx"] == series_idx
]
minNumVolumes = min(corresponding_objects_volumes)
maxNumVolumes = max(corresponding_objects_volumes)
numVolumes1min = floor(60 / tr)

if maxNumVolumes <= numVolumes1min: # set default as # volumes after 1 minute
volumeThreshold = numVolumes1min
else:
if minNumVolumes == maxNumVolumes: # set threshold at max NumVolumes
volumeThreshold = maxNumVolumes
else: # set threshold at 50% of max NumVolumes, or min NumVolumes if it's greater than half
half = floor(maxNumVolumes / 2)
if minNumVolumes > half:
volumeThreshold = minNumVolumes
else:
volumeThreshold = half

volumeThreshold = 9 # temporary, but setting threshold low for debugging purposes

# With volume threshold, exclude objects that don't pass it
corresponding_objects = [x for x in objects_list if x["series_idx"] == series_idx]
for obj in corresponding_objects:
if obj["analysisResults"]["NumVolumes"] < volumeThreshold:
obj["exclude"] = True
obj["analysisResults"]["errors"] = ["Acquisition is believed to be func/bold and contains "
f"{obj['analysisResults']['NumVolumes']} volumes, which "
f"is less than the threshold value of {volumeThreshold} "
"this acquisition will be excluded from BIDS conversion. "
"Please modify if incorrect"]
# def setVolumeThreshold(dataset_list_unique_series, objects_list):
# """
# Determine a volume threshold for all func/bold acquisitions in dataset,
# using the following heuristic:

# Parameters
# ----------
# dataset_list_unique_series : list
# List of dictionaries of unique series
# objects_list: list
# List of dictionaries of all dataset objects
# """

# func_series = [
# x for x in dataset_list_unique_series
# if "func" in x["type"]
# and x["type"] != "func/sbref"
# and x["RepetitionTime"] > 0
# ]

# if len(func_series):
# for func in func_series:
# series_idx = func["series_idx"]
# tr = func["RepetitionTime"]
# corresponding_objects_volumes = [
# x["analysisResults"]["NumVolumes"] for x in objects_list if x["series_idx"] == series_idx
# ]
# minNumVolumes = min(corresponding_objects_volumes)
# maxNumVolumes = max(corresponding_objects_volumes)
# numVolumes1min = floor(60 / tr)

# if maxNumVolumes <= numVolumes1min: # set default as # volumes after 1 minute
# volumeThreshold = numVolumes1min
# else:
# if minNumVolumes == maxNumVolumes: # set threshold at max NumVolumes
# volumeThreshold = maxNumVolumes
# else: # set threshold at 50% of max NumVolumes, or min NumVolumes if it's greater than half
# half = floor(maxNumVolumes / 2)
# if minNumVolumes > half:
# volumeThreshold = minNumVolumes
# else:
# volumeThreshold = half

# volumeThreshold = 9 # temporary, but setting threshold low for debugging purposes

# # With volume threshold, exclude objects that don't pass it
# corresponding_objects = [x for x in objects_list if x["series_idx"] == series_idx]
# for obj in corresponding_objects:
# if obj["analysisResults"]["NumVolumes"] < volumeThreshold:
# obj["exclude"] = True
# obj["analysisResults"]["errors"] = ["Acquisition is believed to be func/bold and contains "
# f"{obj['analysisResults']['NumVolumes']} volumes, which "
# f"is less than the threshold value of {volumeThreshold} "
# "this acquisition will be excluded from BIDS conversion. "
# "Please modify if incorrect"]

# Begin (Apply functions)

Expand Down Expand Up @@ -2241,8 +2241,8 @@ def setVolumeThreshold(dataset_list_unique_series, objects_list):
print("")
print("")

# Set volume threshold for func/bold acquisitions
setVolumeThreshold(dataset_list_unique_series, objects_list)
# # Set volume threshold for func/bold acquisitions
# setVolumeThreshold(dataset_list_unique_series, objects_list)

# Extract important series information to display in ezBIDS UI
ui_series_info_list = extract_series_info(dataset_list_unique_series)
Expand Down
3 changes: 2 additions & 1 deletion ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { IObject } from './store'
import { ElNotification } from 'element-plus'
//import 'element-plus/es/components/notification/style/css'
import { setSectionIDs, funcQA, fmapQA, dwiQA, setRun, setIntendedFor } from './libUnsafe'
import { setSectionIDs, funcQA, fmapQA, dwiQA, setRun, setIntendedFor, setVolumeThreshold } from './libUnsafe'
//import { IObjectItem } from './store'
import { createEventsTSV } from './lib'
Expand Down Expand Up @@ -149,6 +149,7 @@ export default defineComponent({
this.$store.commit("setPage", this.pages[idx+1]);
switch(this.page) {
case "event":
setVolumeThreshold(this.ezbids);
setSectionIDs(this.ezbids);
funcQA(this.ezbids);
fmapQA(this.ezbids);
Expand Down
Loading

0 comments on commit fc0ec0c

Please sign in to comment.