Spaces:
Sleeping
Sleeping
Commit
·
efa3bef
1
Parent(s):
4396283
update
Browse files- app.py +41 -41
- app_utils.py +3 -3
app.py
CHANGED
@@ -364,7 +364,7 @@ with gr.Blocks() as demo:
|
|
364 |
# +========================================================================================+
|
365 |
# | step transition |
|
366 |
# +========================================================================================+
|
367 |
-
def init_next_step(stage1_info, channel_info, fillmode,
|
368 |
|
369 |
# ========================================step0=========================================
|
370 |
# step0 to step1
|
@@ -477,16 +477,16 @@ with gr.Blocks() as demo:
|
|
477 |
elif stage1_info["state"] == "step2-selecting":
|
478 |
# --------------------------------store information---------------------------------
|
479 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
480 |
-
if
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
|
485 |
-
stage1_info["mappingResults"][0]["newOrder"][
|
486 |
-
stage1_info["mappingResults"][0]["isOriginalData"][
|
487 |
-
channel_info["templateDict"][
|
488 |
-
channel_info["inputDict"][
|
489 |
-
#print(
|
490 |
|
491 |
# --------------------------------update information--------------------------------
|
492 |
# exclude the selected in_channel of the previous round
|
@@ -566,11 +566,11 @@ with gr.Blocks() as demo:
|
|
566 |
"count" : 1,
|
567 |
"totalNum" : len(stage1_info["missingTemplates"])
|
568 |
}
|
569 |
-
|
570 |
-
chkbox_label = '{} (1/{})'.format(
|
571 |
|
572 |
-
|
573 |
-
chkbox_value = stage1_info["mappingResults"][0]["newOrder"][
|
574 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
575 |
|
576 |
stage1_info["state"] = "step3-2-selecting"
|
@@ -596,11 +596,11 @@ with gr.Blocks() as demo:
|
|
596 |
# step3-2 to step4
|
597 |
elif stage1_info["state"] == "step3-2-selecting":
|
598 |
# --------------------------------store information---------------------------------
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
stage1_info["mappingResults"][0]["newOrder"][
|
603 |
-
#print(
|
604 |
# ----------------------------------------------------------------------------------
|
605 |
md = """
|
606 |
### Mapping Results
|
@@ -668,20 +668,20 @@ with gr.Blocks() as demo:
|
|
668 |
else:
|
669 |
return {radio_group : gr.Radio(value=[])}
|
670 |
|
671 |
-
def update_radio(stage1_info, channel_info,
|
672 |
step2 = stage1_info["step2"]
|
673 |
# ----------------------------------store information-----------------------------------
|
674 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
675 |
-
if
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
|
680 |
-
stage1_info["mappingResults"][0]["newOrder"][
|
681 |
-
stage1_info["mappingResults"][0]["isOriginalData"][
|
682 |
-
channel_info["templateDict"][
|
683 |
-
channel_info["inputDict"][
|
684 |
-
#print(
|
685 |
|
686 |
# ---------------------------------update the new round---------------------------------
|
687 |
step2["count"] += 1
|
@@ -689,8 +689,8 @@ with gr.Blocks() as demo:
|
|
689 |
# exclude the selected in_channel of the previous round
|
690 |
stage1_info["unassignedInputs"] = app_utils.get_unassigned_inputs(channel_info["inputOrder"], channel_info["inputDict"])
|
691 |
|
692 |
-
|
693 |
-
radio_label = '{} ({}/{})'.format(
|
694 |
|
695 |
stage1_info["step2"] = step2
|
696 |
# determine which button to display
|
@@ -721,23 +721,23 @@ with gr.Blocks() as demo:
|
|
721 |
# +========================================================================================+
|
722 |
# | Stage1-step3 |
|
723 |
# +========================================================================================+
|
724 |
-
def update_chkbox(stage1_info, channel_info,
|
725 |
step3 = stage1_info["step3"]
|
726 |
# ----------------------------------store information-----------------------------------
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
stage1_info["mappingResults"][0]["newOrder"][
|
731 |
-
#print(
|
732 |
|
733 |
# ---------------------------------update the new round---------------------------------
|
734 |
step3["count"] += 1
|
735 |
|
736 |
-
|
737 |
-
chkbox_label = '{} ({}/{})'.format(
|
738 |
|
739 |
-
|
740 |
-
chkbox_value = stage1_info["mappingResults"][0]["newOrder"][
|
741 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
742 |
|
743 |
stage1_info["step3"] = step3
|
|
|
364 |
# +========================================================================================+
|
365 |
# | step transition |
|
366 |
# +========================================================================================+
|
367 |
+
def init_next_step(stage1_info, channel_info, fillmode, sel_radio, sel_chkbox):
|
368 |
|
369 |
# ========================================step0=========================================
|
370 |
# step0 to step1
|
|
|
477 |
elif stage1_info["state"] == "step2-selecting":
|
478 |
# --------------------------------store information---------------------------------
|
479 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
480 |
+
if sel_radio != []:
|
481 |
+
prev_tpl_name = stage1_info["missingTemplates"][stage1_info["step2"]["count"]-1]
|
482 |
+
prev_tpl_idx = channel_info["templateDict"][prev_tpl_name]["index"]
|
483 |
+
sel_idx = channel_info["inputDict"][sel_radio]["index"]
|
484 |
|
485 |
+
stage1_info["mappingResults"][0]["newOrder"][prev_tpl_idx] = [sel_idx]
|
486 |
+
stage1_info["mappingResults"][0]["isOriginalData"][prev_tpl_idx] = True
|
487 |
+
channel_info["templateDict"][prev_tpl_name]["matched"] = True
|
488 |
+
channel_info["inputDict"][sel_radio]["assigned"] = True
|
489 |
+
#print(prev_tpl_name, '<-', sel_radio)
|
490 |
|
491 |
# --------------------------------update information--------------------------------
|
492 |
# exclude the selected in_channel of the previous round
|
|
|
566 |
"count" : 1,
|
567 |
"totalNum" : len(stage1_info["missingTemplates"])
|
568 |
}
|
569 |
+
tpl_name = stage1_info["missingTemplates"][0]
|
570 |
+
chkbox_label = '{} (1/{})'.format(tpl_name, stage1_info["step3"]["totalNum"])
|
571 |
|
572 |
+
tpl_idx = channel_info["templateDict"][tpl_name]["index"]
|
573 |
+
chkbox_value = stage1_info["mappingResults"][0]["newOrder"][tpl_idx]
|
574 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
575 |
|
576 |
stage1_info["state"] = "step3-2-selecting"
|
|
|
596 |
# step3-2 to step4
|
597 |
elif stage1_info["state"] == "step3-2-selecting":
|
598 |
# --------------------------------store information---------------------------------
|
599 |
+
prev_tpl_name = stage1_info["missingTemplates"][stage1_info["step3"]["count"]-1]
|
600 |
+
prev_tpl_idx = channel_info["templateDict"][prev_tpl_name]["index"]
|
601 |
+
sel_idx = [channel_info["inputDict"][channel]["index"] for channel in sel_chkbox]
|
602 |
+
stage1_info["mappingResults"][0]["newOrder"][prev_tpl_idx] = sel_idx if sel_idx!=[] else [None]
|
603 |
+
#print(prev_tpl_name, '<-', sel_chkbox)
|
604 |
# ----------------------------------------------------------------------------------
|
605 |
md = """
|
606 |
### Mapping Results
|
|
|
668 |
else:
|
669 |
return {radio_group : gr.Radio(value=[])}
|
670 |
|
671 |
+
def update_radio(stage1_info, channel_info, sel_name):
|
672 |
step2 = stage1_info["step2"]
|
673 |
# ----------------------------------store information-----------------------------------
|
674 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
675 |
+
if sel_name != []:
|
676 |
+
prev_tpl_name = stage1_info["missingTemplates"][step2["count"]-1]
|
677 |
+
prev_tpl_idx = channel_info["templateDict"][prev_tpl_name]["index"]
|
678 |
+
sel_idx = channel_info["inputDict"][sel_name]["index"]
|
679 |
|
680 |
+
stage1_info["mappingResults"][0]["newOrder"][prev_tpl_idx] = [sel_idx]
|
681 |
+
stage1_info["mappingResults"][0]["isOriginalData"][prev_tpl_idx] = True
|
682 |
+
channel_info["templateDict"][prev_tpl_name]["matched"] = True
|
683 |
+
channel_info["inputDict"][sel_name]["assigned"] = True
|
684 |
+
#print(prev_tpl_name, '<-', sel_name)
|
685 |
|
686 |
# ---------------------------------update the new round---------------------------------
|
687 |
step2["count"] += 1
|
|
|
689 |
# exclude the selected in_channel of the previous round
|
690 |
stage1_info["unassignedInputs"] = app_utils.get_unassigned_inputs(channel_info["inputOrder"], channel_info["inputDict"])
|
691 |
|
692 |
+
tpl_name = stage1_info["missingTemplates"][step2["count"]-1]
|
693 |
+
radio_label = '{} ({}/{})'.format(tpl_name, step2["count"], step2["totalNum"])
|
694 |
|
695 |
stage1_info["step2"] = step2
|
696 |
# determine which button to display
|
|
|
721 |
# +========================================================================================+
|
722 |
# | Stage1-step3 |
|
723 |
# +========================================================================================+
|
724 |
+
def update_chkbox(stage1_info, channel_info, sel_name):
|
725 |
step3 = stage1_info["step3"]
|
726 |
# ----------------------------------store information-----------------------------------
|
727 |
+
prev_tpl_name = stage1_info["missingTemplates"][step3["count"]-1]
|
728 |
+
prev_tpl_idx = channel_info["templateDict"][prev_tpl_name]["index"]
|
729 |
+
sel_idx = [channel_info["inputDict"][channel]["index"] for channel in sel_name]
|
730 |
+
stage1_info["mappingResults"][0]["newOrder"][prev_tpl_idx] = sel_idx if sel_idx!=[] else [None]
|
731 |
+
#print(prev_tpl_name, '<-', sel_name)
|
732 |
|
733 |
# ---------------------------------update the new round---------------------------------
|
734 |
step3["count"] += 1
|
735 |
|
736 |
+
tpl_name = stage1_info["missingTemplates"][step3["count"]-1]
|
737 |
+
chkbox_label = '{} ({}/{})'.format(tpl_name, step3["count"], step3["totalNum"])
|
738 |
|
739 |
+
tpl_idx = channel_info["templateDict"][tpl_name]["index"]
|
740 |
+
chkbox_value = stage1_info["mappingResults"][0]["newOrder"][tpl_idx]
|
741 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
742 |
|
743 |
stage1_info["step3"] = step3
|
app_utils.py
CHANGED
@@ -21,7 +21,7 @@ def reorder_data(idx_order, orig_flags, inputname, filename):
|
|
21 |
for i, (idx_set, flag) in enumerate(zip(idx_order, orig_flags)):
|
22 |
if flag == True:
|
23 |
new_data[i, :] = raw_data[idx_set[0], :]
|
24 |
-
elif idx_set == []:
|
25 |
new_data[i, :] = zero_arr
|
26 |
else:
|
27 |
tmp_data = [raw_data[j, :] for j in idx_set]
|
@@ -234,7 +234,7 @@ def match_names(stage1_info):
|
|
234 |
tpl_montage, in_montage, tpl_dict, in_dict = read_montage_data(loc_file)
|
235 |
tpl_order = tpl_montage.ch_names
|
236 |
in_order = in_montage.ch_names
|
237 |
-
new_idx = [[]]*30 # store the indices of the in_channels in the order of tpl_channels
|
238 |
orig_flags = [False]*30
|
239 |
|
240 |
alias_dict = {
|
@@ -304,7 +304,7 @@ def optimal_mapping(channel_info):
|
|
304 |
row_idx, col_idx = linear_sum_assignment(cost_matrix)
|
305 |
|
306 |
# store the mapping results
|
307 |
-
new_idx = [[]]*30
|
308 |
orig_flags = [False]*30
|
309 |
for i, j in zip(row_idx, col_idx):
|
310 |
if j < len(unassigned): # filter out dummy channels
|
|
|
21 |
for i, (idx_set, flag) in enumerate(zip(idx_order, orig_flags)):
|
22 |
if flag == True:
|
23 |
new_data[i, :] = raw_data[idx_set[0], :]
|
24 |
+
elif idx_set == [None]:
|
25 |
new_data[i, :] = zero_arr
|
26 |
else:
|
27 |
tmp_data = [raw_data[j, :] for j in idx_set]
|
|
|
234 |
tpl_montage, in_montage, tpl_dict, in_dict = read_montage_data(loc_file)
|
235 |
tpl_order = tpl_montage.ch_names
|
236 |
in_order = in_montage.ch_names
|
237 |
+
new_idx = [[None]]*30 # store the indices of the in_channels in the order of tpl_channels
|
238 |
orig_flags = [False]*30
|
239 |
|
240 |
alias_dict = {
|
|
|
304 |
row_idx, col_idx = linear_sum_assignment(cost_matrix)
|
305 |
|
306 |
# store the mapping results
|
307 |
+
new_idx = [[None]]*30
|
308 |
orig_flags = [False]*30
|
309 |
for i, j in zip(row_idx, col_idx):
|
310 |
if j < len(unassigned): # filter out dummy channels
|