Skip to content

Commit dd0bcde

Browse files
committed
BF: fix Python 2, old Sympy stuff in derivations
Python 2 prints, and older uses of Sympy.
1 parent 7bc31e5 commit dd0bcde

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
''' Just showing the mosaic simplification '''
2-
import sympy
3-
from sympy import Matrix, Symbol, symbols, zeros, ones, eye
2+
3+
from sympy import Matrix, Symbol, symbols, simplify
4+
45

56
def numbered_matrix(nrows, ncols, symbol_prefix):
67
return Matrix(nrows, ncols, lambda i, j: Symbol(
78
symbol_prefix + '_{%d%d}' % (i+1, j+1)))
89

10+
911
def numbered_vector(nrows, symbol_prefix):
1012
return Matrix(nrows, 1, lambda i, j: Symbol(
1113
symbol_prefix + '_{%d}' % (i+1)))
@@ -14,7 +16,7 @@ def numbered_vector(nrows, symbol_prefix):
1416
RS = numbered_matrix(3, 3, 'rs')
1517

1618
mdc, mdr, rdc, rdr = symbols(
17-
'md_{cols}', 'md_{rows}', 'rd_{cols}', 'rd_{rows}')
19+
'md_{cols} md_{rows} rd_{cols} rd_{rows}')
1820

1921
md_adj = Matrix((mdc - 1, mdr - 1, 0)) / -2
2022
rd_adj = Matrix((rdc - 1 , rdr - 1, 0)) / -2
@@ -25,6 +27,5 @@ def numbered_vector(nrows, symbol_prefix):
2527
Q = RS[:,:2] * Matrix((
2628
(mdc - rdc) / 2,
2729
(mdr - rdr) / 2))
28-
Q.simplify()
2930

30-
assert adj == Q
31+
assert simplify(adj - Q) == Matrix([0, 0, 0])

doc/source/dicom/derivations/spm_dicom_orient.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@
33
Notes on the SPM orientation machinery.
44
55
There are symbolic versions of the code in ``spm_dicom_convert``,
6-
``write_volume`` subfunction, around line 509 in the version I have
7-
(SPM8, late 2009 vintage).
6+
``write_volume`` subfunction, around line 509 in the version I have (SPM8, late
7+
2009 vintage).
88
'''
99

1010
import numpy as np
1111

1212
import sympy
1313
from sympy import Matrix, Symbol, symbols, zeros, ones, eye
1414

15+
1516
# The code below is general (independent of SPMs code)
1617
def numbered_matrix(nrows, ncols, symbol_prefix):
1718
return Matrix(nrows, ncols, lambda i, j: Symbol(
1819
symbol_prefix + '_{%d%d}' % (i+1, j+1)))
1920

21+
2022
def numbered_vector(nrows, symbol_prefix):
2123
return Matrix(nrows, 1, lambda i, j: Symbol(
2224
symbol_prefix + '_{%d}' % (i+1)))
2325

26+
2427
# premultiplication matrix to go from 0 based to 1 based indexing
2528
one_based = eye(4)
2629
one_based[:3,3] = (1,1,1)

0 commit comments

Comments
 (0)