/
doc2.txt
61 lines (44 loc) · 2.84 KB
/
doc2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
.. _example post processing of saved field data:
Example: post processing of saved field data
--------------------------------------------
Suppose we have saved spatially resolved fields (as, for example, in
:ref:`example 2`), and we would like to read those from the data file to
process the data further.
We can use the :ref:`nmagpp` tool if it provides the required functionality.
Alternatively, we can write a Python script that:
1. reads the data from the ``_dat.h5`` file
2. carries out the required post processing and/or saves the data in
(another) format.
The program :download:`read_h5.py </example2/read_h5.py>`
demonstrates how to read the saved configuration with id=0 of the ``m_Py``
subfield, and to print this to the screen.
.. include:: read_h5.py
:literal:
The functions :ref:`get_subfield_from_h5file`,
:ref:`get_subfield_positions_from_h5file` and
:ref:`get_subfield_sites_from_h5file` allow in principle to retrieve all the
field data from the h5 files and stores this in the variables ``m``,
``pos``, and ``site``, respectively.
The program, when run like this::
$ nsim read_h5.py
in the :ref:`example 2` directory, produces output starting as follows (assuming the ``bar_dat.h5`` file exists)::
[0] [ 0. 0. 0.] [ 0.70710677 0. 0.70710677]
[1] [ 3.00000000e-09 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[2] [ 6.00000000e-09 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[3] [ 9.00000000e-09 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[4] [ 1.20000000e-08 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[5] [ 1.50000000e-08 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[6] [ 1.80000000e-08 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[7] [ 2.10000000e-08 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[8] [ 2.40000000e-08 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[9] [ 2.70000000e-08 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[10] [ 3.00000000e-08 0.00000000e+00 0.00000000e+00] [ 0.70710677 0. 0.70710677]
[11] [ 3.00000000e-08 3.00000000e-08 1.00000000e-07] [ 0.70710677 0. 0.70710677]
[12] [ 3.00000000e-08 2.70000000e-08 1.00000000e-07] [ 0.70710677 0. 0.70710677]
We can see that the :ref:`site` index is (here) just an integer, the position
(in nanometre) is shown as a triplet of three scalars, and the normalised
magnetisation is also a vector with three components.
The data (in the arrays ``m``, ``site`` and ``position`` in this
example) can be manipulated as explained in the :ref:`numpy` documentation,
because it is of type ``numpy array``. Numpy provides a powerful matrix
processing environment.