Beispiel #1
0
def test_non_square():
    signal = hs.signals.Signal2D((255 * np.random.rand(10, 3, 5, 6)
                                  ).astype(np.uint8))
    try:
        with nt.assert_raises(ValueError):
            signal.save(save_path, overwrite=True)
    finally:
        remove_file(save_path)
Beispiel #2
0
def test_write_data_am_mismatch():
    signal = hs.signals.Signal2D((255 * np.random.rand(10, 3, 5, 5)
                                  ).astype(np.uint8))
    signal.axes_manager.navigation_axes[1].size = 4
    try:
        with nt.assert_raises(ValueError):
            signal.save(save_path, overwrite=True)
    finally:
        remove_file(save_path)
Beispiel #3
0
def test_write_data_single():
    signal = hs.signals.Signal2D((255 * np.random.rand(5, 5)
                                  ).astype(np.uint8))
    try:
        signal.save(save_path, overwrite=True)
        sig_reload = hs.load(save_path)
        np.testing.assert_equal(signal.data, sig_reload.data)
    finally:
        remove_file(save_path)
Beispiel #4
0
def test_crop_notes():
    note_len = 0x1000 - 0xF0
    note = 'test123' * 1000     # > note_len
    signal = hs.signals.Signal2D((255 * np.random.rand(2, 3, 2, 2)
                                  ).astype(np.uint8))
    signal.original_metadata.add_node('blockfile_header.Note')
    signal.original_metadata.blockfile_header.Note = note
    try:
        signal.save(save_path, overwrite=True)
        sig_reload = hs.load(save_path)
        nt.assert_equal(sig_reload.original_metadata.blockfile_header.Note,
                        note[:note_len])
    finally:
        remove_file(save_path)
Beispiel #5
0
def test_save_load_cycle():
    sig_reload = None
    signal = hs.load(file2)
    try:
        signal.save(save_path, overwrite=True)
        sig_reload = hs.load(save_path)
        np.testing.assert_equal(signal.data, sig_reload.data)
        assert_deep_almost_equal(signal.axes_manager.as_dictionary(), axes3,
                                 places=8)
        assert_deep_almost_equal(signal.original_metadata.as_dictionary(),
                                 sig_reload.original_metadata.as_dictionary(),
                                 places=8)
        nt.assert_is_instance(signal, hs.signals.Signal2D)
    finally:
        # Delete reference to close memmap file!
        del sig_reload
        gc.collect()
        remove_file(save_path)
Beispiel #6
0
def test_write_cutoff():
    signal = hs.signals.Signal2D((255 * np.random.rand(10, 3, 5, 5)
                                  ).astype(np.uint8))
    signal.axes_manager.navigation_axes[0].size = 20
    try:
        signal.save(save_path, overwrite=True)
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            sig_reload = hs.load(save_path)
            assert len(w) == 1
            assert issubclass(w[-1].category, UserWarning)
            assert "Blockfile header" in str(w[-1].message)
        cut_data = signal.data.flatten()
        pw = [(0, 17 * 10 * 5 * 5)]
        cut_data = np.pad(cut_data, pw, mode='constant')
        cut_data = cut_data.reshape((10, 20, 5, 5))
        np.testing.assert_equal(cut_data, sig_reload.data)
    finally:
        remove_file(save_path)
Beispiel #7
0
def test_load_inplace():
    sig_reload = None
    signal = hs.signals.Signal2D((255 * np.random.rand(2, 3, 2, 2)
                                  ).astype(np.uint8))
    try:
        signal.save(save_path, overwrite=True)
        del signal
        sig_reload = hs.load(save_path, load_to_memory=False, mmap_mode='r+')
        sig_reload.data[:] = 23
        # Flush and close memmap:
        del sig_reload
        gc.collect()
        # Check if values were written to disk
        sig_reload = hs.load(save_path, load_to_memory=False, mmap_mode='r')
        nt.assert_true(np.all(sig_reload.data == 23))
    finally:
        # Delete reference to close memmap file!
        del sig_reload
        gc.collect()
        remove_file(save_path)
Beispiel #8
0
def test_write_fresh():
    signal = hs.signals.Signal2D((255 * np.random.rand(10, 3, 5, 5)
                                  ).astype(np.uint8))
    try:
        signal.save(save_path, overwrite=True)
        sig_reload = hs.load(save_path)
        np.testing.assert_equal(signal.data, sig_reload.data)
        header = sarray2dict(get_default_header())
        header.update({
            'NX': 3, 'NY': 10,
            'DP_SZ': 5,
            'SX': 1, 'SY': 1,
            'SDP': 100,
            'Data_offset_2': 10 * 3 + header['Data_offset_1'],
            'Note': '',
        })
        header['Data_offset_2'] += header['Data_offset_2'] % 16
        nt.assert_equal(
            sig_reload.original_metadata.blockfile_header.as_dictionary(),
            header)
    finally:
        remove_file(save_path)