How can I store data in a file and extract in a matrix form later? #39
-
Thank you for the magnificent work in py-pde! I'm simulating the 1D wave equation (with a time function source) in py-pde, and I want to compare the results to another results I got from another python code output.
In my other code, I'm saving my data in an npz file:
and then loading them to check/plot the values:
How can I do something similar in py-pde? Thanks in advance! This my code:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If you want to store the results on the hard drive, it might be best to use a |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for this information. The FileStorage class seems to be very useful for data storage in an external file. The above code worked for me when I added name of the file inside the brackets of pde.FileStorage()
|
Beta Was this translation helpful? Give feedback.
If you want to store the results on the hard drive, it might be best to use a
FileStorage
instead of theMemoryStorage
in your code. py-pde will then store the results in an hdf5 file which you can read either by initializing apde.FileStorage
with it or by just reading it usingh5py
. Note that the information about the grid (and thus the discretization) is stored in a hdf attribute and might be difficult to reconstruct manually. I thus suggest initializing the storage usingpy-pde
again and then access the data using thedata
attribute. The underlying grid can be accessed using thegrid
attribute. In particular, you get information about the discretization using theaxes_coords
orcell_c…