Commit 70a084bc authored by Roque Porchetto's avatar Roque Porchetto

erp5_wendelin_telecom_ingestion: metadata for nifty images .nii

parent 3c85c817
...@@ -115,7 +115,7 @@ def processTextData(file_name, data_array, data_descriptor): ...@@ -115,7 +115,7 @@ def processTextData(file_name, data_array, data_descriptor):
try: try:
json_report = getJSONfromTextFile(file_name) json_report = getJSONfromTextFile(file_name)
data_descriptor.setTextContent(json_report) data_descriptor.setTextContent(json_report)
log("Data Descriptor content saved") log("Data Descriptor text content saved")
except Exception as e: except Exception as e:
log("Error handling Data Descriptor content: " + str(e)) log("Error handling Data Descriptor content: " + str(e))
...@@ -179,16 +179,43 @@ def processCsvData(file_name, data_array, data_descriptor, delimiter=","): ...@@ -179,16 +179,43 @@ def processCsvData(file_name, data_array, data_descriptor, delimiter=","):
def processTsvData(file_name, data_array, data_descriptor): def processTsvData(file_name, data_array, data_descriptor):
processCsvData(file_name, data_array, data_descriptor, delimiter="\t") processCsvData(file_name, data_array, data_descriptor, delimiter="\t")
def processNiiData(file_name, data_array, data_descriptor): def processNiiData(file_name, data_array, data_descriptor, gz=False):
old_file = file_name
file_name = file_name + ".nii.gz" if gz else file_name + ".nii"
os.rename(old_file, file_name)
try:
import nibabel as nib
img = nib.load(file_name)
data = {} data = {}
data["File content sample: "] = "nifti files data processing not available yet." for key in img.header:
try:
if type(img.header[key]) is np.ndarray:
content = img.header[key].tolist()
try:
if np.isnan(img.header[key]): content = "nan"
except:
pass
else:
content = img.header[key]
if content == 0: content = "0"
json.dumps(content)
if content != "":
data[key] = content
except Exception as e:
pass # ignore non serializable info
json_data = json.dumps(data) json_data = json.dumps(data)
data_descriptor.setTextContent(json_data) data_descriptor.setTextContent(json_data)
log("Data Descriptor nii content saved")
except Exception as e:
log("Error handling Data Descriptor nii content: " + str(e))
raise e
finally:
os.rename(file_name, old_file)
def processGZData(file_name, data_array, data_descriptor): def processGZData(file_name, data_array, data_descriptor):
if data_array.getReference().endswith(".nii/gz"): try:
processNiiData(file_name, data_array, data_descriptor) processNiiData(file_name, data_array, data_descriptor, gz=True)
else: except:
raise KeyError("gz") raise KeyError("gz")
def processRawData(data_stream, data_array, data_descriptor, reference_extension): def processRawData(data_stream, data_array, data_descriptor, reference_extension):
...@@ -219,7 +246,7 @@ def processRawData(data_stream, data_array, data_descriptor, reference_extension ...@@ -219,7 +246,7 @@ def processRawData(data_stream, data_array, data_descriptor, reference_extension
else: else:
options["default"](file_name, data_array, data_descriptor) options["default"](file_name, data_array, data_descriptor)
except KeyError, e: except KeyError, e:
return "Proccessing for %s data not implemented yet." % reference_extension return "Proccessing for data in this %s not implemented yet." % reference_extension
except Exception as e: except Exception as e:
return "Error while processing raw data: " + str(e) return "Error while processing raw data: " + str(e)
finally: finally:
......
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
<string>W:100, 8: Unused variable \'times\' (unused-variable)</string> <string>W:100, 8: Unused variable \'times\' (unused-variable)</string>
<string>W:137, 6: No exception type(s) specified (bare-except)</string> <string>W:137, 6: No exception type(s) specified (bare-except)</string>
<string>W:173, 8: Unreachable code (unreachable)</string> <string>W:173, 8: Unreachable code (unreachable)</string>
<string>W:192, 11: Using type() instead of isinstance() for a typecheck. (unidiomatic-typecheck)</string>
<string>W:196, 10: No exception type(s) specified (bare-except)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment