Skip to content

Commit 9dee35c

Browse files
FEAT: centaurz derivatives (pyxnat#206)
* FEAT: centaurz derivatives * REF: Remove legacy Python 2 import * REF: refine centaurz() to filter by region and optimization level * REF: set default optimization to "harmonized" * FEAT: CI test_centaurz * REF: simplify and generalize centaurz quantification test --------- Co-authored-by: anaharrismatnez <anaharrismar@gmail.com>
1 parent 9cec2d0 commit 9dee35c

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
XNAT_RESOURCE_NAMES = ['CENTAURZ']
2+
3+
4+
def quantification_results(self):
5+
import pandas as pd
6+
from io import StringIO
7+
8+
f = self.file('centaurz_quantification_results.csv')
9+
uri = f._uri
10+
res = self._intf.get(uri).text
11+
text = StringIO(res)
12+
df = pd.read_csv(text)
13+
return df
14+
15+
16+
def centaurz(self, optimization='harmonized'):
17+
"""Return the CenTauRz metric for the "Universal" region and given
18+
optimization type. The default optimization ("harmonized") ensures
19+
generalizability and robustness across tracers, scanners and projects."""
20+
df = self.quantification_results()
21+
q = 'region == "Universal" and measurement == "centaurz"'
22+
q += f' and smoothing_type == "{optimization}"'
23+
return float(df.query(q)['value'].iloc[0])

pyxnat/core/derivatives/pet_fdg.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33

44
def quantification_results(self):
55
import pandas as pd
6-
import sys
7-
if sys.version_info[0] < 3:
8-
from StringIO import StringIO
9-
else:
10-
from io import StringIO
6+
from io import StringIO
117

128
f = self.file('quantification_results.csv')
139
uri = f._uri

pyxnat/tests/test_resource_functions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,16 @@ def test_bamos_arterial_stats():
323323
r = e1.resource('BAMOS_ARTERIAL')
324324
v = r.stats()
325325
assert isclose(sum(v['volume']), 32995.6548)
326+
327+
328+
def test_centaurz_quantification():
329+
r = e1.resource('CENTAURZ')
330+
c1 = r.centaurz()
331+
c2 = r.centaurz(optimization='original')
332+
q = 'region == "MesialTemporal" and smoothing_type == "{s_type}"'
333+
rq1 = r.quantification_results().query(q.format(s_type="original"))
334+
rq2 = r.quantification_results().query(q.format(s_type="harmonized"))
335+
assert c1 > c2
336+
assert not rq1.empty and not rq2.empty
337+
assert rq1[rq1['measurement'] == 'suvr'].value.iloc[0] > 0.8
338+
assert rq2[rq2['measurement'] == 'suvr_spm8'].value.iloc[0] < 0.8

0 commit comments

Comments
 (0)