Skip to content

Commit

Permalink
Merge pull request #564 from Sjoerd1993/parse-xry-progressively
Browse files Browse the repository at this point in the history
parse xry progressively
  • Loading branch information
cmkohnen authored Nov 9, 2023
2 parents e26affe + cba12ac commit 833e114
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions src/parse_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,43 @@ def import_from_xrdml(self, file):
def import_from_xry(self, file):
"""Import data from .xry files used by Leybold X-ray apparatus."""
with file_io.open_wrapped(file, "rt", encoding="ISO-8859-1") as wrapper:
lines = wrapper.readlines()
if lines[0].strip() != "XR01":
raise ParseError(_("Invalid .xry format"))

b_params = lines[4].strip().split()

info = lines[17].strip().split()
value_count = int(info[1])
item_count = int(info[0])

name = utilities.get_filename(file)
style = self.get_figure_style_manager().get_selected_style_params()
items = [
item.DataItem.new(
style, name=f"{name} - {i + 1}" if item_count > 1 else name,
xlabel=_("β (°)"), ylabel=_("R (1/s)"),
) for i in range(item_count)
]
x_step = float(b_params[3])
x_value = float(b_params[0])
for row in lines[18:18 + value_count]:
for value, item_ in zip(row.strip().split(), items):
if value != "NaN":
item_.xdata.append(x_value)
item_.ydata.append(float(value))
x_value += x_step
for row in lines[28 + value_count + item_count:]:
values = row.strip().split()
text = " ".join(values[7:])
items.append(item.TextItem.new(
style, float(values[5]), float(values[6]), text, name=text,
))
return items
def skip(lines: int):
for _count in range(lines):
next(wrapper)

if wrapper.readline().strip() != "XR01":
raise ParseError(_("Invalid .xry format"))
skip(3)
b_params = wrapper.readline().strip().split()
x_step = float(b_params[3])
x_value = float(b_params[0])

skip(12)
info = wrapper.readline().strip().split()
item_count = int(info[0])

name = utilities.get_filename(file)
style = self.get_figure_style_manager().get_selected_style_params()
items = [
item.DataItem.new(
style, name=f"{name} - {i + 1}" if item_count > 1 else name,
xlabel=_("β (°)"), ylabel=_("R (1/s)"),
) for i in range(item_count)
]
for _count in range(int(info[1])):
for value, item_ in zip(wrapper.readline().strip().split(), items):
if value != "NaN":
item_.xdata.append(x_value)
item_.ydata.append(float(value))
x_value += x_step
skip(9 + item_count)
for _count in range(int(wrapper.readline().strip())):
values = wrapper.readline().strip().split()
text = " ".join(values[7:])
items.append(item.TextItem.new(
style, float(values[5]), float(values[6]), text, name=text,
))
return items


def _swap(string):
Expand Down

0 comments on commit 833e114

Please sign in to comment.