3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-02 04:03:49 +01:00
dft_tools/doc/reference/python/data_analysis/hdf5/tut_ex3.rst
tayral 880f30b086 Changed all literalincludes --> runblock / triqs_example
This is to avoid keeping code snippets that do not work in the doc. At least there will be an error message.
2014-10-17 16:50:46 +01:00

54 lines
1.6 KiB
ReStructuredText

.. _hdf5_tut_ex3:
Example 3 : Use the dictionary interface of the archive
--------------------------------------------------------------------
The archive is like a dictionary, persistent on disk.
`[for Python afficionados, it is similar to a shelve, but in a portable format]`.
Therefore, one can iterate on its elements.
Let us imagine that you have stored 5 Green functions in an hdf5 file.
For example, we can create such a file as :download:`[file] <./tut_ex3.py>`:
.. runblock:: python
from pytriqs.gf.local import GfReFreq
from pytriqs.gf.local.descriptors import SemiCircular
from pytriqs.archive import HDFArchive
import numpy
R = HDFArchive('myfile.h5', 'w')
for D in range(1,10,2) :
g = GfReFreq(indices = [0], window = (-2.00,2.00), name = "D=%s"%D)
g <<= SemiCircular(half_bandwidth = 0.1*D)
R[g.name]= g
Imagine that we want to plot those functions :download:`[file] <./tut_ex3b.py>`:
.. literalinclude:: tut_ex3b.py
:lines: 1-13
This produces the following plot (scaled semi-circular density of states).
.. image:: tut_ex3b.png
:width: 750
:align: center
Various pythonic constructs can be used in combinaison with HDFArchive, e.g.
in order to plot only a few curves from a list ::
keylist = ['D=1', 'D=3']
for g in ( R[x] for x in keylist) : # use an iterator
oplot( (- 1/pi * g).imag, "-o", name = 'g' )
or if we want to add the names ::
for n,g in ( (x,R[x]) for x in keylist) : # use an iterator
oplot( (- 1/pi * g).imag, "-o", name = n )
The advantage of using an iterator is that the object is only retrieved from disk when needed.