Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated record_by metadata #102

Merged
merged 7 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions rsciio/blockfile/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def file_reader(filename, lazy=False, mmap_mode=None, endianess="<"):

units = ["nm", "nm", "cm", "cm"]
names = ["y", "x", "dy", "dx"]
navigate = [True, True, False, False]
scales = [header["SY"], header["SX"], SDP, SDP]
date, time, time_zone = serial_date_to_ISO_format(header["Acquisition_time"])
metadata = {
Expand All @@ -305,10 +306,7 @@ def file_reader(filename, lazy=False, mmap_mode=None, endianess="<"):
"time_zone": time_zone,
"notes": header["Note"],
},
"Signal": {
"signal_type": "diffraction",
"record_by": "image",
},
"Signal": {"signal_type": "diffraction"},
}
# Create the axis objects for each axis
dim = data.ndim
Expand All @@ -320,6 +318,7 @@ def file_reader(filename, lazy=False, mmap_mode=None, endianess="<"):
"scale": scales[i],
"offset": 0.0,
"units": units[i],
"navigate": navigate[i],
}
for i in range(dim)
]
Expand Down
8 changes: 5 additions & 3 deletions rsciio/bruker/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def _parse_image(self, xml_node, overview=False):
item["data"] = data
item["axes"][0]["size"] = image.height
item["axes"][1]["size"] = image.width
item["metadata"]["Signal"] = {"record_by": "image"}
item["metadata"]["Signal"] = {}
item["metadata"]["General"] = {}
if desc is not None:
item["metadata"]["General"]["title"] = str(desc.text)
Expand Down Expand Up @@ -1015,6 +1015,7 @@ def spx_reader(filename, lazy=False):
"offset": spectrum.offset,
"scale": spectrum.scale,
"units": "keV",
"navigate": False,
}
],
"metadata":
Expand All @@ -1036,7 +1037,6 @@ def spx_reader(filename, lazy=False):
"Sample": {"name": name},
"Signal": {
"signal_type": "EDS_%s" % mode,
"record_by": "spectrum",
"quantity": "X-rays (Counts)",
},
},
Expand Down Expand Up @@ -1427,20 +1427,23 @@ def bcf_hyperspectra(
"offset": 0,
"scale": obj_bcf.header.y_res * downsample,
"units": obj_bcf.header.units,
"navigate": True,
},
{
"name": "width",
"size": hypermap.shape[1],
"offset": 0,
"scale": obj_bcf.header.y_res * downsample,
"units": obj_bcf.header.units,
"navigate": True,
},
{
"name": "Energy",
"size": hypermap.shape[2],
"offset": eds_metadata.offset,
"scale": eds_metadata.scale,
"units": "keV",
"navigate": False,
},
],
"metadata":
Expand All @@ -1465,7 +1468,6 @@ def bcf_hyperspectra(
},
"Signal": {
"signal_type": "EDS_%s" % mode,
"record_by": "spectrum",
"quantity": "X-rays (Counts)",
},
},
Expand Down
26 changes: 16 additions & 10 deletions rsciio/digitalmicrograph/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ def __init__(self, imdict, file, order="C"):
self.imdict = Box(imdict, box_dots=True)
self.file = file
self._order = order if order else "C"
self._record_by = None

@property
def shape(self):
Expand Down Expand Up @@ -521,11 +520,10 @@ def title(self):
return title if title else ""

@property
def record_by(self):
if self._record_by is not None:
return self._record_by
def navigate(self):
result = [True] * len(self.shape)
if len(self.scales) == 1:
return "spectrum"
result[-1] = False
elif (
(
self.imdict.get("ImageTags.Meta Data.Format") is not None
Expand All @@ -534,9 +532,10 @@ def record_by(self):
)
or (self.imdict.get("ImageTags.spim") is not None)
) and len(self.scales) == 2:
return "spectrum"
result[-1] = False
else:
return "image"
result[-2:] = (False, False)
return result

@property
def to_spectrum(self):
Expand Down Expand Up @@ -733,9 +732,17 @@ def get_axes_dict(self):
"scale": scale,
"offset": offset,
"units": str(units),
"navigate": nav,
}
for i, (name, size, scale, offset, units) in enumerate(
zip(self.names, self.shape, self.scales, self.offsets, self.units)
for i, (name, size, scale, offset, units, nav) in enumerate(
zip(
self.names,
self.shape,
self.scales,
self.offsets,
self.units,
self.navigate,
)
)
]

Expand All @@ -747,7 +754,6 @@ def get_metadata(self, metadata=None):
if "Signal" not in metadata:
metadata["Signal"] = {}
metadata["General"]["title"] = self.title
metadata["Signal"]["record_by"] = self.record_by
metadata["Signal"]["signal_type"] = self.signal_type
return metadata

Expand Down
6 changes: 4 additions & 2 deletions rsciio/edax/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ def spc_reader(filename, lazy=False, endianess="<", load_all_spc=False, **kwargs
"scale": original_metadata["spc_header"]["evPerChan"] / 1000.0,
"offset": original_metadata["spc_header"]["startEnergy"],
"units": "keV",
"navigate": False,
}

# Assign metadata for spectrum:
Expand All @@ -742,7 +743,6 @@ def spc_reader(filename, lazy=False, endianess="<", load_all_spc=False, **kwargs
},
"Signal": {
"signal_type": "EDS_SEM",
"record_by": "spectrum",
},
}
metadata = _add_spc_metadata(metadata, spc_dict)
Expand Down Expand Up @@ -897,6 +897,7 @@ def spd_reader(
else 1,
"offset": original_metadata["spc_header"]["startEnergy"] if read_spc else 1,
"units": "keV" if read_spc else None,
"navigate": False,
}

nav_units = "µm"
Expand All @@ -908,6 +909,7 @@ def spd_reader(
"scale": original_metadata["ipr_header"]["mppX"] if read_ipr else 1,
"offset": 0,
"units": nav_units if read_ipr else None,
"navigate": True,
}

y_axis = {
Expand All @@ -917,6 +919,7 @@ def spd_reader(
"scale": original_metadata["ipr_header"]["mppY"] if read_ipr else 1,
"offset": 0,
"units": nav_units if read_ipr else None,
"navigate": True,
}

# Assign metadata for spectrum image:
Expand All @@ -927,7 +930,6 @@ def spd_reader(
},
"Signal": {
"signal_type": "EDS_SEM",
"record_by": "spectrum",
},
}

Expand Down
8 changes: 6 additions & 2 deletions rsciio/empad/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def _parse_xml(filename):
"width": 128,
"height": 128,
"raw_height": 130,
"record-by": "image",
}
if om.has_item("root.scan_parameters.series_count"):
# Stack of images
Expand Down Expand Up @@ -113,7 +112,7 @@ def file_reader(filename, lazy=False, **kwds):
"original_filename": fname,
"title": os.path.splitext(fname)[0],
},
"Signal": {"signal_type": "electron_diffraction", "record_by": "image"},
"Signal": {"signal_type": "electron_diffraction"},
}

if om.has_item("root.timestamp.isoformat"):
Expand All @@ -132,12 +131,14 @@ def file_reader(filename, lazy=False, **kwds):
axes = []
index_in_array = 0
names = ["height", "width"]
navigate = [False, False]

if "series_count" in info.keys():
names = ["series_count"] + names
units.insert(0, "ms")
scales.insert(0, 1)
origins.insert(0, 0)
navigate.insert(0, True)
else:
names = ["scan_x", "scan_y"] + names
units.insert(0, "")
Expand All @@ -146,6 +147,8 @@ def file_reader(filename, lazy=False, **kwds):
scales.insert(0, 1)
origins.insert(0, 0)
origins.insert(0, 0)
navigate.insert(0, True)
navigate.insert(0, True)

sizes = [info[name] for name in names]

Expand Down Expand Up @@ -178,6 +181,7 @@ def file_reader(filename, lazy=False, **kwds):
"scale": scales[i],
"offset": origins[i] * scales[i],
"units": units[i],
"navigate": navigate[i],
}
)
index_in_array += 1
Expand Down
5 changes: 1 addition & 4 deletions rsciio/image/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@ def file_reader(filename, **kwds):
"data": dc,
"metadata": {
"General": {"original_filename": os.path.split(filename)[1]},
"Signal": {
"signal_type": "",
"record_by": "image",
},
"Signal": {"signal_type": ""},
},
}
]
Expand Down
19 changes: 11 additions & 8 deletions rsciio/jeol/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ def _read_img(filename, **kwargs):
"offset": 0,
"scale": yscale,
"units": units,
"navigate": False,
},
{
"name": "x",
"size": width,
"offset": 0,
"scale": xscale,
"units": units,
"navigate": False,
},
]

Expand All @@ -228,9 +230,7 @@ def _read_img(filename, **kwargs):
"time": datefile.time().isoformat(),
"title": header_long["Image"]["Title"],
},
"Signal": {
"record_by": "image",
},
"Signal": {},
}

dictionary = {
Expand Down Expand Up @@ -494,6 +494,7 @@ def _check_divisor(factor, number, string):
"offset": 0,
"scale": pixel_time * height * width / 1e3,
"units": "s",
"navigate": True,
}
]
width = data.shape[2]
Expand All @@ -506,24 +507,29 @@ def _check_divisor(factor, number, string):
"offset": origin[1],
"scale": yscale,
"units": units,
"navigate": False,
},
{
"name": "x",
"size": width,
"offset": origin[0],
"scale": xscale,
"units": units,
"navigate": False,
},
]
)
axes = axes_em.copy()
for ax in axes:
ax["navigate"] = True
axes.append(
{
"name": "Energy",
"size": channel_number,
"offset": energy_offset,
"scale": energy_scale,
"units": "keV",
"navigate": False,
},
)
if (not last_valid) and only_valid_data:
Expand Down Expand Up @@ -561,7 +567,6 @@ def _check_divisor(factor, number, string):
"title": "EDS extracted from " + os.path.basename(filename),
},
"Signal": {
"record_by": "spectrum",
"quantity": "X-rays (Counts)",
"signal_type": "EDS_" + mode,
},
Expand All @@ -579,9 +584,7 @@ def _check_divisor(factor, number, string):
"time": datefile.time().isoformat(),
"title": "S(T)EM Image extracted from " + os.path.basename(filename),
},
"Signal": {
"record_by": "image",
},
"Signal": {},
}

image_list = [
Expand Down Expand Up @@ -1391,6 +1394,7 @@ def _read_eds(filename, **kwargs):
"offset": header["CoefB"],
"scale": header["CoefA"],
"units": "keV",
"navigate": False,
}
]

Expand All @@ -1416,7 +1420,6 @@ def _read_eds(filename, **kwargs):
"title": "EDX",
},
"Signal": {
"record_by": "spectrum",
"quantity": "X-rays (Counts)",
"signal_type": "EDS_" + mode,
},
Expand Down
7 changes: 3 additions & 4 deletions rsciio/mrc/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@ def file_reader(filename, lazy=False, mmap_mode=None, endianess="<", **kwds):

units = [None, "nm", "nm"]
names = ["z", "y", "x"]
navigate = [True, False, False]
metadata = {
"General": {"original_filename": os.path.split(filename)[1]},
"Signal": {
"signal_type": "",
"record_by": "image",
},
"Signal": {"signal_type": ""},
}
# create the axis objects for each axis
axes = [
Expand All @@ -235,6 +233,7 @@ def file_reader(filename, lazy=False, mmap_mode=None, endianess="<", **kwds):
"scale": scales[i + 3 - dim],
"offset": offsets[i + 3 - dim],
"units": units[i + 3 - dim],
"navigate": navigate[i + 3 - dim],
}
for i in range(dim)
]
Expand Down
2 changes: 1 addition & 1 deletion rsciio/msa/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ def parse_msa_string(string, filename=None):
"scale": parameters["XPERCHAN"] if "XPERCHAN" in parameters else 1,
"offset": parameters["OFFSET"] if "OFFSET" in parameters else 0,
"units": parameters["XUNITS"] if "XUNITS" in parameters else "",
"navigate": False,
}
]
if filename is not None:
mapped.set_item("General.original_filename", os.path.split(filename)[1])
mapped.set_item("Signal.record_by", "spectrum")
if "SIGNALTYPE" in parameters and parameters["SIGNALTYPE"]:
if parameters["SIGNALTYPE"] == "ELS":
mapped.set_item("Signal.signal_type", "EELS")
Expand Down
Loading