Skip to content

Commit cc1452d

Browse files
committed
removed errant use of metadata.json file instead of import
1 parent 0f21e8b commit cc1452d

File tree

1 file changed

+9
-47
lines changed

1 file changed

+9
-47
lines changed

pypet2bids/pypet2bids/helper_functions.py

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,10 @@
5151
if "PET2BIDS" not in project_dir.parts:
5252
project_dir = parent_dir
5353

54-
metadata_dir = os.path.join(project_dir, "metadata")
55-
56-
# check to see where the schema is at
57-
pet_metadata_json = os.path.join(metadata_dir, "PET_metadata.json")
58-
permalink_pet_metadata_json = "https://github.com/openneuropet/PET2BIDS/blob/76d95cf65fa8a14f55a4405df3fdec705e2147cf/metadata/PET_metadata.json"
59-
pet_reconstruction_metadata_json = os.path.join(
60-
metadata_dir, "PET_reconstruction_methods.json"
61-
)
6254

6355
# load bids schema
6456
schema = metadata.schema
65-
57+
pet_metadata = metadata.PET_metadata
6658
# putting these paths here as they are reused in dcm2niix4pet.py, update_json_pet_file.py, and ecat.py
6759
module_folder = Path(__file__).parent.resolve()
6860
python_folder = module_folder.parent
@@ -95,19 +87,6 @@ def logger(name):
9587
return logger
9688

9789

98-
def load_pet_bids_requirements_json(
99-
pet_bids_req_json: Union[str, pathlib.Path] = pet_metadata_json
100-
) -> dict:
101-
if type(pet_bids_req_json) is str:
102-
pet_bids_req_json = pathlib.Path(pet_bids_req_json)
103-
if pet_bids_req_json.is_file():
104-
with open(pet_bids_req_json, "r") as infile:
105-
reqs = json.load(infile)
106-
return reqs
107-
else:
108-
raise FileNotFoundError(pet_bids_req_json)
109-
110-
11190
def flatten_series(series):
11291
"""
11392
This function retrieves either a list or a single value from a pandas series object thus converting a complex
@@ -150,12 +129,13 @@ def collect_spreadsheets(folder_path: pathlib.Path):
150129

151130
def single_spreadsheet_reader(
152131
path_to_spreadsheet: Union[str, pathlib.Path],
153-
pet2bids_metadata_json: Union[str, pathlib.Path] = pet_metadata_json,
132+
pet2bids_metadata: dict = metadata.PET_metadata,
154133
dicom_metadata={},
155134
**kwargs,
156135
) -> dict:
157136

158-
metadata = {}
137+
spreadsheet_metadata = {}
138+
metadata_fields = pet2bids_metadata.PET_metadata
159139

160140
if type(path_to_spreadsheet) is str:
161141
path_to_spreadsheet = pathlib.Path(path_to_spreadsheet)
@@ -165,24 +145,6 @@ def single_spreadsheet_reader(
165145
else:
166146
raise FileNotFoundError(f"{path_to_spreadsheet} does not exist.")
167147

168-
if pet2bids_metadata_json:
169-
if type(pet_metadata_json) is str:
170-
pet2bids_metadata_json = pathlib.Path(pet2bids_metadata_json)
171-
172-
if pet2bids_metadata_json.is_file():
173-
with open(pet_metadata_json, "r") as infile:
174-
metadata_fields = json.load(infile)
175-
else:
176-
raise FileNotFoundError(
177-
f"Required metadata file not found at {pet_metadata_json}, check to see if this file exists;"
178-
f"\nelse pass path to file formatted to this {permalink_pet_metadata_json} via "
179-
f"pet2bids_metadata_json argument in simplest_spreadsheet_reader call."
180-
)
181-
else:
182-
raise FileNotFoundError(
183-
f"pet2bids_metadata_json input required for function call, you provided {pet2bids_metadata_json}"
184-
)
185-
186148
spreadsheet_dataframe = open_meta_data(path_to_spreadsheet)
187149

188150
log = logging.getLogger("pypet2bids")
@@ -192,7 +154,7 @@ def single_spreadsheet_reader(
192154
for field in metadata_fields[field_level]:
193155
series = spreadsheet_dataframe.get(field, Series(dtype=numpy.float64))
194156
if not series.empty:
195-
metadata[field] = flatten_series(series)
157+
spreadsheet_metadata[field] = flatten_series(series)
196158
elif (
197159
series.empty
198160
and field_level == "mandatory"
@@ -204,10 +166,10 @@ def single_spreadsheet_reader(
204166
)
205167

206168
# lastly apply any kwargs to the metadata
207-
metadata.update(**kwargs)
169+
spreadsheet_metadata.update(**kwargs)
208170

209171
# more lastly, check to see if values are of the correct datatype (e.g. string, number, boolean)
210-
for field, value in metadata.items():
172+
for field, value in spreadsheet_metadata.items():
211173
# check schema for field
212174
field_schema_properties = schema["objects"]["metadata"].get(field, None)
213175
if field_schema_properties:
@@ -220,7 +182,7 @@ def single_spreadsheet_reader(
220182
try:
221183
check_bool = int(value) / 1
222184
if check_bool == 0 or check_bool == 1:
223-
metadata[field] = bool(value)
185+
spreadsheet_metadata[field] = bool(value)
224186
else:
225187
log.warning(
226188
f"{field} is not boolean, it's value is {value}"
@@ -232,7 +194,7 @@ def single_spreadsheet_reader(
232194
log.warning(f"{field} is not string, it's value is {value}")
233195
else:
234196
pass
235-
return metadata
197+
return spreadsheet_metadata
236198

237199

238200
def compress(file_like_object, output_path: str = None):

0 commit comments

Comments
 (0)