Skip to content

Commit

Permalink
Create memmapped files on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
HagaiHargil committed Aug 15, 2019
1 parent eb47bec commit 31b3359
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ nosetests.xml
coverage.xml
*,cover
.hypothesis/
!testdata/*.mmap

# Translations
*.mo
Expand Down
24 changes: 21 additions & 3 deletions caiman/tests/test_memmapping.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import pathlib

import numpy as np
import nose

from caiman import mmapping
from caiman.paths import caiman_datadir

twod_fname = pathlib.Path(caiman_datadir()) / 'testdata/memmap__d1_10_d2_11_d3_1_order_F_frames_12_.mmap'
threed_fname = pathlib.Path(caiman_datadir()) / 'testdata/memmap__d1_10_d2_11_d3_13_order_F_frames_12_.mmap'

def test_load_raises_wrong_ext():
fname = "a.mmapp"
Expand All @@ -26,15 +29,30 @@ def test_load_raises_multiple_ext():
assert False


def setup_2d_mmap():
np.memmap(twod_fname, mode='w+', dtype=np.float32, shape=(12, 10, 11, 13), order='F')

def teardown_2d_mmap():
twod_fname.unlink()

def setup_3d_mmap():
np.memmap(threed_fname, mode='w+', dtype=np.float32, shape=(12, 10, 11, 13), order='F')

def teardown_3d_mmap():
threed_fname.unlink()


@nose.with_setup(setup_2d_mmap, teardown_2d_mmap)
def test_load_successful_2d():
fname = pathlib.Path(caiman_datadir()) / 'testdata' / 'memmap__d1_10_d2_11_d3_1_order_F_frames_12_.mmap'
fname = pathlib.Path(caiman_datadir()) / 'testdata' / twod_fname
Yr, (d1, d2), T = mmapping.load_memmap(str(fname))
assert (d1, d2) == (10, 11)
assert T == 12
assert isinstance(Yr, np.memmap)


@nose.with_setup(setup_3d_mmap, teardown_3d_mmap)
def test_load_successful_3d():
fname = pathlib.Path(caiman_datadir()) / 'testdata' / 'memmap__d1_10_d2_11_d3_13_order_F_frames_12_.mmap'
fname = pathlib.Path(caiman_datadir()) / 'testdata' / threed_fname
Yr, (d1, d2, d3), T = mmapping.load_memmap(str(fname))
assert (d1, d2, d3) == (10, 11, 13)
assert T == 12
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 31b3359

Please sign in to comment.