This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Estelle Nassar <estelle.nassar@crick.ac.uk>
- Loading branch information
1 parent
efeb342
commit d4f9afa
Showing
2 changed files
with
29 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |