Skip to content
Snippets Groups Projects
Commit 047ab19a authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

More trying to reduce memory usage'

parent 0da742af
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -285,21 +285,15 @@ def make_random_mask(filename, shape, xform, premask=None): ...@@ -285,21 +285,15 @@ def make_random_mask(filename, shape, xform, premask=None):
mask = np.zeros(shape, dtype=np.uint8) mask = np.zeros(shape, dtype=np.uint8)
if premask is None: numones = np.random.randint(1, np.prod(shape) / 100)
numones = np.random.randint(1, np.prod(shape) / 100) xc = np.random.randint(0, shape[0], numones)
xc = np.random.randint(0, shape[0], numones) yc = np.random.randint(0, shape[1], numones)
yc = np.random.randint(0, shape[1], numones) zc = np.random.randint(0, shape[2], numones)
zc = np.random.randint(0, shape[2], numones)
mask[xc, yc, zc] = 1 mask[xc, yc, zc] = 1
else:
xc, yc, zc = np.where(premask) if premask is not None:
numones = np.random.randint(1, len(xc)) mask[premask == 0] = 0
idxs = np.random.randint(1, len(xc), numones)
xc = xc[idxs]
yc = yc[idxs]
zc = zc[idxs]
mask[xc, yc, zc] = 1
img = fslimage.Image(mask, xform=xform) img = fslimage.Image(mask, xform=xform)
img.save(filename) img.save(filename)
......
...@@ -20,7 +20,7 @@ import pytest ...@@ -20,7 +20,7 @@ import pytest
import tests import tests
import fsl.utils.transform as transform import fsl.utils.transform as transform
import fsl.data.atlases as atlases import fsl.data.atlases as atlases
import fsl.data.image as fslimage import fsl.data.image as fslimage
datadir = op.join(op.dirname(__file__), 'testdata') datadir = op.join(op.dirname(__file__), 'testdata')
...@@ -222,7 +222,8 @@ def test_load_atlas(): ...@@ -222,7 +222,8 @@ def test_load_atlas():
reg = atlases.registry reg = atlases.registry
reg.rescanAtlases() reg.rescanAtlases()
probatlas = reg.loadAtlas('harvardoxford-cortical') probatlas = reg.loadAtlas('harvardoxford-cortical',
indexed=True, calcRange=False, loadData=False)
probsumatlas = reg.loadAtlas('harvardoxford-cortical', loadSummary=True) probsumatlas = reg.loadAtlas('harvardoxford-cortical', loadSummary=True)
lblatlas = reg.loadAtlas('talairach') lblatlas = reg.loadAtlas('talairach')
...@@ -236,7 +237,8 @@ def test_find(): ...@@ -236,7 +237,8 @@ def test_find():
reg = atlases.registry reg = atlases.registry
reg.rescanAtlases() reg.rescanAtlases()
probatlas = reg.loadAtlas('harvardoxford-cortical') probatlas = reg.loadAtlas('harvardoxford-cortical',
indexed=True, calcRange=False, loadData=False)
probsumatlas = reg.loadAtlas('harvardoxford-cortical', loadSummary=True) probsumatlas = reg.loadAtlas('harvardoxford-cortical', loadSummary=True)
lblatlas = reg.loadAtlas('talairach') lblatlas = reg.loadAtlas('talairach')
...@@ -268,7 +270,8 @@ def test_prepareMask(): ...@@ -268,7 +270,8 @@ def test_prepareMask():
reg = atlases.registry reg = atlases.registry
reg.rescanAtlases() reg.rescanAtlases()
probatlas = reg.loadAtlas('harvardoxford-cortical') probatlas = reg.loadAtlas('harvardoxford-cortical',
indexed=True, loadData=False, calcRange=False)
probsumatlas = reg.loadAtlas('harvardoxford-cortical', loadSummary=True) probsumatlas = reg.loadAtlas('harvardoxford-cortical', loadSummary=True)
lblatlas = reg.loadAtlas('talairach') lblatlas = reg.loadAtlas('talairach')
...@@ -276,13 +279,16 @@ def test_prepareMask(): ...@@ -276,13 +279,16 @@ def test_prepareMask():
ashape = list(atlas.shape[:3]) ashape = list(atlas.shape[:3])
m2shape = [s * 1.5 for s in ashape] m2shape = [s * 1.5 for s in ashape]
goodmask1 = fslimage.Image(np.random.random(ashape),
xform=atlas.voxToWorldMat) goodmask1 = fslimage.Image(
np.array(np.random.random(ashape), dtype=np.float32),
xform=atlas.voxToWorldMat)
goodmask2, xf = goodmask1.resample(m2shape) goodmask2, xf = goodmask1.resample(m2shape)
goodmask2 = fslimage.Image(goodmask2, xform=xf) goodmask2 = fslimage.Image(goodmask2, xform=xf)
wrongdims = fslimage.Image( wrongdims = fslimage.Image(
np.random.random(list(ashape) + [10])) np.random.random(list(ashape) + [2]))
wrongspace = fslimage.Image( wrongspace = fslimage.Image(
np.random.random((20, 20, 20)), np.random.random((20, 20, 20)),
xform=transform.concat(atlas.voxToWorldMat, np.diag([2, 2, 2, 1]))) xform=transform.concat(atlas.voxToWorldMat, np.diag([2, 2, 2, 1])))
......
...@@ -34,11 +34,12 @@ def _repeat(iterator, n): ...@@ -34,11 +34,12 @@ def _repeat(iterator, n):
yield elem yield elem
_atlases = cache.Cache(maxsize=1) _atlases = cache.Cache()
def _get_atlas(atlasID, res, summary=False): def _get_atlas(atlasID, res, summary=False):
atlas = _atlases.get((atlasID, res, summary), default=None) atlas = _atlases.get((atlasID, res, summary), default=None)
if atlas is None: if atlas is None:
if summary or atlasID in ('talairach', 'striatum-structural', 'jhu-labels'): if summary or atlasID in ('talairach', 'striatum-structural',
'jhu-labels'):
kwargs = {} kwargs = {}
else: else:
kwargs = {'loadData' : False, kwargs = {'loadData' : False,
...@@ -66,7 +67,7 @@ def _random_atlas(atype, res, summary=False): ...@@ -66,7 +67,7 @@ def _random_atlas(atype, res, summary=False):
# Generate a mask which tells us which # Generate a mask which tells us which
# voxels in the atlas are all zeros # voxels in the atlas are all zeros
_zero_masks = {} _zero_masks = cache.Cache(maxsize=5)
def _get_zero_mask(aimg): def _get_zero_mask(aimg):
atlasID = aimg.desc.atlasID atlasID = aimg.desc.atlasID
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment