Skip to content

Commit f34d609

Browse files
committed
PL: fix long lines
1 parent bf80e71 commit f34d609

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

nitransforms/surface.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def __add__(self, other):
113113
return self.__class__(self.reference, other.moving)
114114
raise NotImplementedError
115115

116-
117116
def _to_hdf5(self, x5_root):
118117
"""Write transform to HDF5 file."""
119118
triangles = x5_root.create_group("Triangles")
@@ -186,9 +185,11 @@ def from_filename(cls, filename=None, reference_path=None, moving_path=None,
186185
)
187186
return cls(reference, moving)
188187

188+
189189
class SurfaceResampler(SurfaceTransformBase):
190190
"""
191-
Represents transformations in which the coordinate space remains the same and the indices change.
191+
Represents transformations in which the coordinate space remains the same
192+
and the indices change.
192193
To achieve surface project-unproject functionality:
193194
sphere_in as the reference
194195
sphere_project_to as the moving
@@ -235,7 +236,7 @@ def __init__(self, reference, moving, interpolation_method='barycentric', mat=No
235236
tri_lut = {}
236237
for i, idxs in enumerate(self.moving._triangles):
237238
for x in idxs:
238-
if not x in tri_lut:
239+
if x not in tri_lut:
239240
tri_lut[x] = [i]
240241
else:
241242
tri_lut[x].append(i)
@@ -251,7 +252,7 @@ def __init__(self, reference, moving, interpolation_method='barycentric', mat=No
251252

252253
# build sparse matrix
253254
# commenting out code for barycentric nearest neighbor
254-
#bary_nearest = []
255+
# bary_nearest = []
255256
mat = sparse.lil_array((self.reference._npoints, self.moving._npoints))
256257
for s_ix, dd in enumerate(bc_weights):
257258
for k, v in dd.items():
@@ -473,7 +474,7 @@ def from_filename(cls, filename=None, reference_path=None, moving_path=None,
473474
shape=iws["Shape"][()],
474475
)
475476
except KeyError:
476-
mat=None
477+
mat = None
477478
reference = SurfaceMesh.from_arrays(
478479
xform['Reference']['Coordinates'],
479480
xform['Reference']['Triangles']

nitransforms/tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,4 @@ def test_SurfaceMesh(testdata_path):
188188
SurfaceMesh(nb.load(img_path))
189189

190190
with pytest.raises(TypeError):
191-
SurfaceMesh(nb.load(shape_path))
191+
SurfaceMesh(nb.load(shape_path))

nitransforms/tests/test_surface.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
def test_SurfaceTransformBase(testdata_path):
4646
# note these transformations are a bit of a weird use of surface transformation, but I'm
4747
# just testing the base class and the io
48-
sphere_reg_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
48+
sphere_reg_path = (
49+
testdata_path
50+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
51+
)
4952
pial_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_pial.surf.gii"
5053

5154
sphere_reg = SurfaceMesh(nb.load(sphere_reg_path))
@@ -71,7 +74,10 @@ def test_SurfaceTransformBase(testdata_path):
7174
def test_SurfaceCoordinateTransform(testdata_path):
7275
# note these transformations are a bit of a weird use of surface transformation, but I'm
7376
# just testing the class and the io
74-
sphere_reg_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
77+
sphere_reg_path = (
78+
testdata_path
79+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
80+
)
7581
pial_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_pial.surf.gii"
7682
fslr_sphere_path = testdata_path / "tpl-fsLR_hemi-R_den-32k_sphere.surf.gii"
7783

@@ -107,8 +113,12 @@ def test_SurfaceCoordinateTransform(testdata_path):
107113
assert np.all(scti.reference._triangles == sct.reference._triangles)
108114
assert scti == sct
109115

116+
110117
def test_SurfaceCoordinateTransformIO(testdata_path, tmpdir):
111-
sphere_reg_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
118+
sphere_reg_path = (
119+
testdata_path
120+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
121+
)
112122
pial_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_pial.surf.gii"
113123

114124
sct = SurfaceCoordinateTransform(pial_path, sphere_reg_path)
@@ -117,12 +127,22 @@ def test_SurfaceCoordinateTransformIO(testdata_path, tmpdir):
117127
sct2 = SurfaceCoordinateTransform.from_filename(fn)
118128
assert sct == sct2
119129

130+
120131
def test_ProjectUnproject(testdata_path):
121132

122-
sphere_reg_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
133+
sphere_reg_path = (
134+
testdata_path
135+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
136+
)
123137
fslr_sphere_path = testdata_path / "tpl-fsLR_hemi-R_den-32k_sphere.surf.gii"
124-
subj_fsaverage_sphere_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsaverage_desc-reg_sphere.surf.gii"
125-
fslr_fsaverage_sphere_path = testdata_path / "tpl-fsLR_space-fsaverage_hemi-R_den-32k_sphere.surf.gii"
138+
subj_fsaverage_sphere_path = (
139+
testdata_path
140+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsaverage_desc-reg_sphere.surf.gii"
141+
)
142+
fslr_fsaverage_sphere_path = (
143+
testdata_path
144+
/ "tpl-fsLR_space-fsaverage_hemi-R_den-32k_sphere.surf.gii"
145+
)
126146
pial_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_pial.surf.gii"
127147

128148
# test project-unproject funcitonality
@@ -134,13 +154,28 @@ def test_ProjectUnproject(testdata_path):
134154
assert (projunproj_ref.agg_data()[0] - transformed._coords).max() < 0.0005
135155
assert np.all(transformed._triangles == projunproj_ref.agg_data()[1])
136156

157+
137158
def test_SurfaceResampler(testdata_path, tmpdir):
138159
dif_tol = 0.001
139-
fslr_sphere_path = testdata_path / "tpl-fsLR_hemi-R_den-32k_sphere.surf.gii"
140-
shape_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_thickness.shape.gii"
141-
ref_resampled_thickness_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_thickness.shape.gii"
142-
pial_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_pial.surf.gii"
143-
sphere_reg_path = testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
160+
fslr_sphere_path = (
161+
testdata_path
162+
/ "tpl-fsLR_hemi-R_den-32k_sphere.surf.gii"
163+
)
164+
shape_path = (
165+
testdata_path
166+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_thickness.shape.gii"
167+
)
168+
ref_resampled_thickness_path = (
169+
testdata_path
170+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_thickness.shape.gii"
171+
)
172+
pial_path = (
173+
testdata_path / "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_pial.surf.gii"
174+
)
175+
sphere_reg_path = (
176+
testdata_path
177+
/ "sub-sid000005_ses-budapest_acq-MPRAGE_hemi-R_space-fsLR_desc-reg_sphere.surf.gii"
178+
)
144179

145180
fslr_sphere = SurfaceMesh(nb.load(fslr_sphere_path))
146181
sphere_reg = SurfaceMesh(nb.load(sphere_reg_path))
@@ -177,7 +212,7 @@ def test_SurfaceResampler(testdata_path, tmpdir):
177212
resampling.to_filename(fn)
178213
resampling2 = SurfaceResampler.from_filename(fn)
179214

180-
#assert resampling2 == resampling
215+
# assert resampling2 == resampling
181216
assert np.allclose(resampling2.reference._coords, resampling.reference._coords)
182217
assert np.all(resampling2.reference._triangles == resampling.reference._triangles)
183218
assert np.allclose(resampling2.reference._coords, resampling.reference._coords)

0 commit comments

Comments
 (0)