
Joe, Thank you very much, that was exactly what I needed. Interestingly enough, when kwant.plotter.map(sys, ldos_array) is called again, AFTER dictionary creation, the resulting picture is changed to a random patchwork of colourful rectangles. Regards, Jerzy
On 30/06/14 08:55, Jerzy Wrobel wrote:
Dear All, How to retrieve the actual grid position from a given site index? For example, how to get local_dos at (i,j) space position from 1d Numpy array, on a simple rectangular grid? I assume that it has something to do with pos method, but an simple example will be appreciated. Thanks in advance, Jerzy
Hi,
The ordering of the elements of the output from `local_dos` (as well as `wave_function`) is the same as the ordering of the sites in your finalized system. You can say
ldos_dict = {tuple(site.tag): ldos for site, ldos in zip(fsys.sites, ldos_array)}
where `fsys` is your finalized system and `ldos` is the numpy array returned by `local_dos`. You can then get the value for site `(i,j)` by saying
ldos_dict[i, j]
Note that this will only work in the case where you have 1 orbital per site (i.e. scalar values for your onsite matrix elements).
Hope that helps,
Joe

"Jerzy Wrobel" wrobel@ifpan.edu.pl writes:
Interestingly enough, when kwant.plotter.map(sys, ldos_array) is called again, AFTER dictionary creation, the resulting picture is changed to a random patchwork of colourful rectangles.
The creation of ldos_dict should not have any side-effects. Can you show us a script that demonstrates the problem?
Best, Christoph

Dear Joe, Dear Christoph, For testing I have adopted quantum_wire.py. The "critical" part looks like this:
local_dos = kwant.ldos(sys, energy) # check size print local_dos.shape D2D = local_dos.reshape(NL,NW) kwant.plotter.map(sys, local_dos) # create dictionary to localize [i,j] ldos_dict = {tuple(site.tag): ldos for site, ldos in zip(sys.sites, local_dos)} for i in xrange(NL): for j in xrange(NW): D2D[i,j] = ldos_dict[i,j] pyplot.imshow(D2D.T, cmap=pyplot.cm.hot) pyplot.colorbar() kwant.plotter.map(sys, local_dos)
I am using 64 bit Python2.7 windows version. Jerzy
"Jerzy Wrobel" wrobel@ifpan.edu.pl writes:
Interestingly enough, when kwant.plotter.map(sys, ldos_array) is called again, AFTER dictionary creation, the resulting picture is changed to a random patchwork of colourful rectangles.
The creation of ldos_dict should not have any side-effects. Can you show us a script that demonstrates the problem?
Best, Christoph

Dear Joe, Christoph, Now I have realized that it is of course my python mistake: command D2D = local_dos.reshape(NL,NW) means probably that D2D is not a new matrix by a new name for the same thing. Thanks again for help, Jerzy

On 30/06/14 13:37, Jerzy Wrobel wrote:
means probably that D2D is not a new matrix by a new name for the same thing.
Actually, `reshape` creates a new *view* into the `local_dos` array. The `D2D` and `local_dos` arrays are not the same Python object; you can verify that
id(D2D) != id(local_dos)
The `D2D` array (view), however, *does* reference the same memory as the local_dos array, as can be verified by checking that
D2D.base is local_dos
Joe
participants (3)
-
christoph.groth@cea.fr
-
Jerzy Wrobel
-
Joseph Weston