Commit 6bcc089a authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

More trying to reduce memory usage'

parent 0d569569
Pipeline #1288 failed with stages
in 61 minutes and 8 seconds
......@@ -285,21 +285,15 @@ def make_random_mask(filename, shape, xform, premask=None):
mask = np.zeros(shape, dtype=np.uint8)
if premask is None:
numones = np.random.randint(1, np.prod(shape) / 100)
xc = np.random.randint(0, shape[0], numones)
yc = np.random.randint(0, shape[1], numones)
zc = np.random.randint(0, shape[2], numones)
mask[xc, yc, zc] = 1
else:
xc, yc, zc = np.where(premask)
numones = np.random.randint(1, len(xc))
idxs = np.random.randint(1, len(xc), numones)
xc = xc[idxs]
yc = yc[idxs]
zc = zc[idxs]
mask[xc, yc, zc] = 1
numones = np.random.randint(1, np.prod(shape) / 100)
xc = np.random.randint(0, shape[0], numones)
yc = np.random.randint(0, shape[1], numones)
zc = np.random.randint(0, shape[2], numones)
mask[xc, yc, zc] = 1
if premask is not None:
mask[premask == 0] = 0
img = fslimage.Image(mask, xform=xform)
img.save(filename)
......
......@@ -20,7 +20,7 @@ import pytest
import tests
import fsl.utils.transform as transform
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')
......@@ -222,7 +222,8 @@ def test_load_atlas():
reg = atlases.registry
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)
lblatlas = reg.loadAtlas('talairach')
......@@ -236,7 +237,8 @@ def test_find():
reg = atlases.registry
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)
lblatlas = reg.loadAtlas('talairach')
......@@ -268,7 +270,8 @@ def test_prepareMask():
reg = atlases.registry
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)
lblatlas = reg.loadAtlas('talairach')
......@@ -276,13 +279,16 @@ def test_prepareMask():
ashape = list(atlas.shape[:3])
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 = fslimage.Image(goodmask2, xform=xf)
wrongdims = fslimage.Image(
np.random.random(list(ashape) + [10]))
np.random.random(list(ashape) + [2]))
wrongspace = fslimage.Image(
np.random.random((20, 20, 20)),
xform=transform.concat(atlas.voxToWorldMat, np.diag([2, 2, 2, 1])))
......
......@@ -34,11 +34,12 @@ def _repeat(iterator, n):
yield elem
_atlases = cache.Cache(maxsize=1)
_atlases = cache.Cache()
def _get_atlas(atlasID, res, summary=False):
atlas = _atlases.get((atlasID, res, summary), default=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 = {}
else:
kwargs = {'loadData' : False,
......@@ -66,7 +67,7 @@ def _random_atlas(atype, res, summary=False):
# Generate a mask which tells us which
# voxels in the atlas are all zeros
_zero_masks = {}
_zero_masks = cache.Cache(maxsize=5)
def _get_zero_mask(aimg):
atlasID = aimg.desc.atlasID
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment