Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
finished read_quicknii_xml
Browse files Browse the repository at this point in the history
Co-authored-by: Estelle Nassar <estelle.nassar@crick.ac.uk>
  • Loading branch information
nickdelgrosso and Estelle Nassar committed Jun 1, 2021
1 parent efeb342 commit d4f9afa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
28 changes: 19 additions & 9 deletions slicereg/io/xml/reader.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
from dataclasses import dataclass
from _pytest.monkeypatch import V
import xmltodict


@dataclass
class QuickNiiResult:
ox: float
# oy: float
# oz: float
# ux: float
# uy: float
# uz: float
# vx: float
# vy: float
# vz: float
oy: float
oz: float
ux: float
uy: float
uz: float
vx: float
vy: float
vz: float


def read_quicknii_xml(filename: str):
data = QuickNiiResult(ox=475.8982543945312)
with open(filename, mode='rb') as f:
metadata = xmltodict.parse(f)
anchoring = metadata['series']['slice']['@anchoring']
coords = {(kv := pair.split('='))[0]: float(kv[1]) for pair in anchoring.split('&')}
data = QuickNiiResult(
ox=coords['ox'], oy=coords['oy'], oz=coords['oz'],
ux=coords['ux'], uy=coords['uy'], uz=coords['uz'],
vx=coords['vx'], vy=coords['vy'], vz=coords['vz'],
)
return data
20 changes: 10 additions & 10 deletions slicereg/io/xml/tests/test_xml.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from slicereg.io.xml.reader import read_quicknii_xml

from pytest import approx

def test_xml_read_function_gets_transformation_properties_from_example_quicknii_file():
output = read_quicknii_xml(filename='data/deepslice_output/results.xml')
assert output.ox == 475.8982543945312
# assert output.oy == 260.47747802734375
# assert output.oz == 346.73419189453125
# assert output.ux == -481.19720458984375
# assert output.uy == 5.9310126304626465
# assert output.uz == 8.603763580322266
# assert output.vx == -21.585269927978516
# assert output.vy == -4.721147060394287
# assert output.vz == -389.2110595703125
assert output.ox == approx(475.8982543945312)
assert output.oy == approx(260.47747802734375)
assert output.oz == approx(346.73419189453125)
assert output.ux == approx(-481.19720458984375)
assert output.uy == approx(5.9310126304626465)
assert output.uz == approx(8.603763580322266)
assert output.vx == approx(-21.585269927978516)
assert output.vy == approx(-4.721147060394287)
assert output.vz == approx(-389.2110595703125)

0 comments on commit d4f9afa

Please sign in to comment.