Commit 98ec0de1 authored by inhuszar's avatar inhuszar
Browse files

Partial fix for Loader serialisability bug. Full fix in v1.1

parent f7495052
......@@ -1527,6 +1527,23 @@ class TImage(TField):
# Create TImage from TField
mask = dump.get("mask")
hdr = dill.loads(dump.get("header"))
# Load original header object
input_file = hdr.get("input_file", "")
if os.path.isfile(input_file):
from tirl.loader import LOADER_PREFERENCES
for key in LOADER_PREFERENCES.keys():
if input_file.endswith(key):
loader = LOADER_PREFERENCES[key]()
break
else:
raise TypeError(f"None of the loaders support the file type: "
f"{input_file}")
# TODO: Unnecessary to load original data.
# TODO: Loader kwargs are not saved. Reloaded hdr can be different.
arr, original_hdr = loader(input_file)
hdr.update(meta=original_hdr.get("meta", {}))
obj = TImage.fromTField(tfield, copy=False, mask=mask,
storage=tfield.storage, header=hdr)
......@@ -1543,7 +1560,7 @@ class TImage(TField):
# Save TImage-specific properties: mask, header and ResMgr
objdump.update({
"mask": self.mask,
"header": dill.dumps(self.header)
"header": self._dump_header()
})
if resmgr and (self.resmgr.data.base is not self.data.base):
objdump.update({"resmgr": self.resmgr.dump()})
......@@ -1552,6 +1569,11 @@ class TImage(TField):
return objdump
def _dump_header(self):
hdr = self.header.copy()
hdr.pop("meta", None)
return dill.dumps(hdr)
@property
def asTField(self):
return self.__tfield__()
......
Supports Markdown
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