Skip to content

Commit

Permalink
fixes in schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
denisri committed Dec 8, 2023
1 parent d084072 commit 36edb64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
13 changes: 3 additions & 10 deletions capsul/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ def _path_list(self, unused_meta=None):
"process",
"acquisition",
"preprocessings",
"longitudinal",
"analysis",
):
if key not in unused_meta:
Expand Down Expand Up @@ -465,7 +464,7 @@ def _path_list(self, unused_meta=None):
if "subject_in_filename" not in unused_meta and self.subject_in_filename:
filename.append(str(self.subject))
if "longitudinal" not in unused_meta and self.longitudinal:
filename.append(f"_to_avg_{self.longitudinal}")
filename.append(f"_to_avg_{'_'.join(self.longitudinal)}")
if ("suffix" not in unused_meta and self.suffix) or (
"sidebis" not in unused_meta and self.sidebis
):
Expand All @@ -487,16 +486,11 @@ class MorphologistBIDSSchema(BrainVISASchema):
schema_name = "morphologist_bids"

folder: Literal["sourcedata", "rawdata", "derivative"]
subject_only: field(type_=bool, default=False, used=False)

def _path_list(self, unused_meta=None):
if unused_meta is None:
unused_meta = set()
if "subject_only" not in unused_meta and self.subject_only:
return [self.subject]

if unused_meta is None:
unused_meta = set()
path_list = super()._path_list(unused_meta=unused_meta)
pre_path = [f"sub-{self.subject}", f"ses-{self.acquisition}", "anat"]
if "folder" not in unused_meta and self.folder not in (undefined, None, ""):
Expand Down Expand Up @@ -1250,7 +1244,7 @@ def path_for_parameters(self, executable, parameters=None):

if parameters is None:
parameters = [
field.name for field in executable.user_fields() if field.path_type
field.name for field in executable.user_fields() # if field.path_type
]
if self.debug:
if self._current_iteration is not None:
Expand Down Expand Up @@ -1332,8 +1326,6 @@ def path_for_parameters(self, executable, parameters=None):
mapping.map_schemas(source, dest)

resolved_process_schemas = {}
if parameters is None:
parameters = (i.name for i in executable.user_fields())
# print("!-" * 40)
parameters_equivalence = find_parameters_equivalence(executable)
for parameter in parameters:
Expand Down Expand Up @@ -1364,6 +1356,7 @@ def path_for_parameters(self, executable, parameters=None):
resolved_process_schema = resolved_process_schemas.get(
(schema, executable)
)
# print('param:', parameter)
if resolved_process_schema is None:
unused = {}
schema_metadata = defaultdict(lambda: metadata.asdict())
Expand Down
31 changes: 12 additions & 19 deletions capsul/schemas/brainvisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BrainVISASharedSchema(MetadataSchema):
schema_name = "brainvisa_shared"
data_id: str = ""
side: str = None
graph_version: str = None
sulci_graph_version: str = None
model_version: str = None

def _path_list(self, unused_meta=None):
Expand Down Expand Up @@ -54,7 +54,7 @@ def _path_list(self, unused_meta=None):
"models",
f"models_20{self.model_version}",
"discriminative_models",
self.graph_version,
self.sulci_graph_version,
f"{self.side}folds_noroots",
]
filename = f"{self.side}folds_noroots.arg"
Expand Down Expand Up @@ -150,7 +150,7 @@ class BrainVISAToShared(SchemaMapping):
@staticmethod
def map_schemas(source, dest):
dest.side = source.side
dest.graph_version = source.sulci_graph_version
dest.sulci_graph_version = source.sulci_graph_version


class MorphoBIDSToShared(SchemaMapping):
Expand Down Expand Up @@ -268,7 +268,6 @@ def declare_morpho_schemas(morpho_module):
)

bv_acq_unused = [
"subject_only",
"analysis",
"seg_directory",
"side",
Expand Down Expand Up @@ -306,8 +305,7 @@ def brainvisa_Morphologist(metadata):
"Talairach_transform",
"MNI_transform",
][bv_ref_unused].unused()
metadata["subject"]["subject_only", "subject"].used()
metadata["sulcal_morpho_measures"]["subject_only"].unused()
metadata.subject.subject.used()

metadata.normalization_spm_native_transformation.prefix = None
metadata.commissure_coordinates.extension = "APC"
Expand Down Expand Up @@ -335,11 +333,9 @@ def brainvisa_Morphologist(metadata):
)
metadata.MNI_transform.extension = "trm"

metadata["left_graph", "right_graph"].prefix = None
metadata["left_graph", "right_graph"].suffix = None

metadata.subject.subject_only = True
metadata.sulcal_morpho_measures.subject_only = False
metadata["left_graph", "right_graph"].sulci_recognition_session.unused()
# metadata["left_graph", "right_graph"].prefix = None
# metadata["left_graph", "right_graph"].suffix = None

@process_schema("bids", Morphologist)
def bids_Morphologist(metadata):
Expand Down Expand Up @@ -437,7 +433,7 @@ def brainvisa_T1BiasCorrection(metadata):
metadata.white_ridges.prefix = "whiteridge"
metadata.variance.prefix = "variance"
metadata.edges.prefix = "edges"
metadata.meancurvature.prefix = "meancurvature"
metadata.meancurvature.prefix = "mean_curvature"

@process_schema("morphologist_bids", T1BiasCorrection)
def morphologist_bids_T1BiasCorrection(metadata):
Expand Down Expand Up @@ -579,6 +575,8 @@ def brainvisa_SulciGraph(metadata):
metadata.sulci_voronoi.sulci_graph_version = (
metadata.executable.pipeline.CorticalFoldsGraph_graph_version
)
metadata.sulci_voronoi.sulci_graph_version.used()
metadata.sulci_voronoi.sulci_recognition_session.unused()
metadata.cortex_mid_interface.seg_directory = "segmentation"
metadata.cortex_mid_interface.prefix = "gw_interface"
# TODO: check conversion of the following code:
Expand Down Expand Up @@ -738,7 +736,7 @@ def brainvisa_brainvolumes(metadata):
"sulci_graph_version", "sulci_recognition_session"
].used()
metadata.subject["*"].unused()
metadata.subject["subject_only", "subject"].used()
metadata.subject["subject"].used()

metadata.left_csf.prefix = "csf"
metadata.left_csf.side = "L"
Expand All @@ -758,11 +756,6 @@ def brainvisa_brainvolumes(metadata):
metadata.brain_volumes_file.suffix = None
metadata.brain_volumes_file.extension = "csv"

metadata.subject.seg_directory = None
metadata.subject.prefix = None
metadata.subject.side = None
metadata.subject.subject_in_filename = False

metadata["output:*"] = metadata.left_labelled_graph
metadata.left_csf.extension = metadata.left_grey_white.extension

Expand All @@ -778,7 +771,7 @@ def brainvisa_morpho_report(metadata):
"sulci_graph_version", "sulci_recognition_session"
].used()
metadata.subject["*"].unused()
metadata.subject["subject_only", "subject"].used()
metadata.subject["subject"].used()
metadata.report.prefix = None
metadata.report.side = None
metadata.report.sidebis = None
Expand Down

0 comments on commit 36edb64

Please sign in to comment.