Modify some EDF metadata#
If a value is wrong on a .info file and if you need it for running a reconstruction you will need to modify the .info file in order to share this information with nabu. On this example:
copy the original file to a ‘*_raw.info’ file (to be safer)
modify the “Distance” metadata
reset tomwer object “distance” to ensure coherence
set the output scan to continue processing
import os
import shutil
from tomwer.core.scan.edfscan import EDFTomoScan
from silx.io.dictdump import dicttoini, load as load_ini
def get_key(line):
""""return key name of a .info file"""
return line.split("=")[0].replace(" ", "")
def get_raw_dict(file_path):
"""return the info file metadata as a dictionary with metadata name as key and raw line as value"""
metadata = {}
with open(file_path, mode="r") as f:
line = f.readline()
while line:
key = get_key(line)
metadata[key] = line
line = f.readline()
return metadata
scan = in_data
if isinstance(scan, EDFTomoScan):
# copy the .info file
info_file = scan.get_info_file(scan.path)
raw_info_file = info_file[:-5] + "_raw.info"
if not os.path.exists(raw_info_file):
# copy the original file only the first time. Otherwise we will overwrite with an updated file.
shutil.copyfile(
info_file,
raw_info_file,
)
metadata = get_raw_dict(info_file)
# overwrite distance key
new_distance = 0.02598
metadata["Distance"] = "Distance= \t\t" + str(new_distance) + "\n"
with open(info_file, mode="w") as f:
for _, line in metadata.items():
f.write(line)
# reset key for coherence
scan._distance = None
out_data = scan