forked from py4dstem/py4DSTEM
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request py4dstem#503 from bsavitzky/listwrite_patch
Listwrite patch
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import py4DSTEM | ||
import numpy as np | ||
|
||
# filepath | ||
from os import getcwd, remove | ||
from os.path import join, exists | ||
path = join(getcwd(),"test.h5") | ||
|
||
|
||
def test_listwrite(): | ||
|
||
# make two arrays | ||
ar1 = py4DSTEM.RealSlice( | ||
data = np.arange(24).reshape((2,3,4)), | ||
name = 'array1' | ||
) | ||
ar2 = py4DSTEM.RealSlice( | ||
data = np.arange(48).reshape((4,3,4)), | ||
name = 'array2' | ||
) | ||
|
||
# save them | ||
py4DSTEM.save( | ||
filepath = path, | ||
data = [ar1,ar2], | ||
mode = 'o' | ||
) | ||
|
||
# read them | ||
data1 = py4DSTEM.read( | ||
path, | ||
datapath = 'array1_root' | ||
) | ||
data2 = py4DSTEM.read( | ||
path, | ||
datapath = 'array2_root' | ||
) | ||
|
||
# check | ||
assert(np.array_equal(data1.data, ar1.data)) | ||
assert(np.array_equal(data2.data, ar2.data)) | ||
|
||
# delete the file | ||
if exists(path): | ||
remove(path) | ||
|
||
|