# complex valued function with "QM-standard" color convention?

7 messages
Open this post in threaded view
|

## complex valued function with "QM-standard" color convention?

 This post was updated on . CONTENTS DELETED The author has deleted this message.
Open this post in threaded view
|

## complex valued function with "QM-standard" color convention?

 Dear All, I want to visualize a function of two real variables with complex values, i.e. z = f(x,y) is complex with x, y real. Quite similar to the example on the  atomic orbital  http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_atomic_orbital.htmlI want to plot a surface with height abs(z)**2; the color of the points on the surface should depend on the angle(z). In the example of the atomic orbital, the colormap='hsv' is used. I wasn't able to find out how the colormaps (particularly hsv), is defined. However, in the standard book of visualization in quantum mechanics (Bernd Thaller), the convention is that a map is defined with the help of the HLS color system (hue-lightness-saturation): - the hue of the color is given by angle(z) - the lightness is given by absolute value of z (0 is white) - the saturation is always maximal. In case of complex functions depending on only one variable, I was able to implement the same idea: just define the hsv_colors with this convention (well, in 1D is the lightness also maximal) and convert them to rgb_colors that we feed to the matplotlib routines, see below. How should I implement this with mayavi2? Examples to try: g(x) = x*exp(-x**2) for x in [-1,1] should show two colors f(x,y) = g(x)*g(y) for x,y in [-1,1] should show two colors and no jumps, since white appears at x=0 or y=0 and the lightness vary smoothly (the RGBA has jumps...) Thank  you, Vasile from numpy import pi, empty, array from matplotlib.colors import hsv_to_rgb from matplotlib.collections import LineCollection from matplotlib.pyplot import gca, plot def phaseplot(grid, phase, modulus, ax=None, label="", color="k", alpha=1.0, linestylep="solid", linestyle="solid", linewidthp=1, linewidth=1, marker="None"):     """Plot the modulus complex valued function \$f:R -> C\$ together with its phase in a color coded fashion.     @param grid: The grid nodes of the real domain R     @param phase: The phase of the complex domain result f(grid)     @param modulus: The modulus of the complex domain result f(grid)     """     # Color mapping     hsv_colors = empty((1, len(grid), 3))     hsv_colors[:, :, 0] = 0.5*(pi+phase)/pi     hsv_colors[:, :, 1] = 1.0     hsv_colors[:, :, 2] = 1.0     rgb_colors = hsv_to_rgb(hsv_colors)     # Put all the vertical line into a collection     segments = [ array([[node,0], [node,value]]) for node, value in zip(grid, modulus) ]     line_segments = LineCollection(segments)     # Set some properties of the lines     rgb_colors = line_segments.to_rgba(rgb_colors)     line_segments.set_color(rgb_colors[0])     line_segments.set_linestyle(linestylep)     line_segments.set_linewidth(linewidthp) -- View this message in context: http://enthought-dev.117412.n3.nabble.com/complex-valued-function-with-QM-standard-color-convention-tp3038765p3038765.htmlSent from the Enthought Dev mailing list archive at Nabble.com. _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: complex valued function with "QM-standard" color convention?

 On Wed, Jun 08, 2011 at 12:04:38PM +0000, Gradinaru  Vasile Catrinel wrote: > is that a map is defined with the help of the HLS color system (hue-lightness-saturation): > - the hue of the color is given by angle(z) > - the lightness is given by absolute value of z (0 is white) > - the saturation is always maximal. > In case of complex functions depending on only one variable, I was able > to implement the same idea: just define the hsv_colors with this > convention (well, in 1D is the lightness also maximal) and convert them > to rgb_colors that we feed to the matplotlib routines, see below. > How should I implement this with mayavi2? Having a 2D colormap is not currently supported in Mayavi. If you want to define your own 1D colormap (that can then be called 'LUT' for Look Up Table), you can insert a pre-computed table, as can be seen in the following example: http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_custom_colormap.htmlHope this helps, Gaël _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: [MayaVi-users] complex valued function with "QM-standard" color convention?

 Dear Gael, thank you for your fast answer. I manipulated the colormap, as you see below, but I am not sure it does what I wanted, because I do not understand exactly how the LUT works. I expected a smoother transition in the example below. This does not happens, since the value v in hsv is constant 1. We can also compute the color of each computed point. Is there an efficient way to plot only the points with their associated colors? This will not look as good as mesh or surf, but it could be a start.   Another approach would be if lut: [0,1] x [0,1] x [0,1] x [0,1] -> R x G x B x A instead of lut: [0,1]  -> R x G x B x A     scalar |-> (r,b,g,alpha) would be available, or even better, mesh(..., scalar1=?, scalar2=?, scalar3=?, scalar4=?) Any further ideas? Thanks, Vasile from numpy import linspace, pi, exp, angle, squeeze, zeros from matplotlib.colors import hsv_to_rgb from enthought.mayavi import mlab # 1) create a colormap which do what I think it should do: def compute_color_map(): # B. Thaller like convention     k = linspace(-pi, pi, 256, endpoint=True)     #unitcircle = exp(1.0j*k)     #hsv_colors = zeros((1, unitcircle.shape[0], 3))     #hsv_colors[:,:, 0] = 0.5*(pi+angle(unitcircle))/pi     hsv_colors = zeros((1, k.shape[0], 3))     hsv_colors[:,:, 0] = 0.5*(pi+k)/pi     hsv_colors[:,:, 1] = 1.0     hsv_colors[:,:, 2] = 1.0     rgb_colors = hsv_to_rgb(hsv_colors)     color_map = 255*squeeze(rgb_colors)     return color_map # 2) define the ploting function def surfCF(gridx, gridy, phase, modulus, colormap=None):     """Plot the modulus of a complex valued function \$f:R^2 -> C\$ together with its phase in a color coded fashion.     @param grid: The grid nodes of the real domain R     @param phase: The phase of the complex domain result f(grid)     @param modulus: The modulus of the complex domain result f(grid)     @keyword colormap: The colormap to use, if none is given, compute the 'default' QM colormap.     """     if colormap is None:         colormap = compute_color_map()     mesh = mlab.mesh(gridx, gridy, modulus, scalars=phase, vmin=-pi, vmax=pi)     # Set the custom color map     lut = mesh.module_manager.scalar_lut_manager.lut.table.to_array()     lut[:,0] = colormap[:,0]     lut[:,1] = colormap[:,1]     lut[:,2] = colormap[:,2]     mesh.module_manager.scalar_lut_manager.lut.table = lut     mlab.draw()     return mesh # 3) then test it if __name__ == "__main__":     from numpy import real, imag, conj, abs, mgrid     x, y = mgrid[-2:2:0.05, -2:2:0.05]     u = x*exp(-0.25*x**2)     v = y*exp(-0.25*y**2)     z = u*v     surfCF(x, y, angle(z), abs(z)**2) ________________________________________ From: Gael Varoquaux [[hidden email]] Sent: Thursday, June 09, 2011 7:43 AM To: [hidden email] Cc: [hidden email] Subject: Re: [MayaVi-users] [Enthought-Dev] complex valued function with "QM-standard" color convention? On Wed, Jun 08, 2011 at 12:04:38PM +0000, Gradinaru  Vasile Catrinel wrote: > is that a map is defined with the help of the HLS color system (hue-lightness-saturation): > - the hue of the color is given by angle(z) > - the lightness is given by absolute value of z (0 is white) > - the saturation is always maximal. > In case of complex functions depending on only one variable, I was able > to implement the same idea: just define the hsv_colors with this > convention (well, in 1D is the lightness also maximal) and convert them > to rgb_colors that we feed to the matplotlib routines, see below. > How should I implement this with mayavi2? Having a 2D colormap is not currently supported in Mayavi. If you want to define your own 1D colormap (that can then be called 'LUT' for Look Up Table), you can insert a pre-computed table, as can be seen in the following example: http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_custom_colormap.htmlHope this helps, Gaël ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev_______________________________________________ MayaVi-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/mayavi-users_______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev
Open this post in threaded view
|

## Re: [MayaVi-users] complex valued function with "QM-standard" color convention?

 Hi, I had a quick look at your code, and it seems jst fine. It even seems to run fine, at least the Mayavi part. The 'angle(z)' variable that you are passing in is only made of 0 and pi values, thus I am not surprised that the mesh shows only two colors. Maybe that's where the problem lies? Cheers, Gael On Thu, Jun 09, 2011 at 03:00:36PM +0000, Gradinaru  Vasile Catrinel wrote: >     from numpy import real, imag, conj, abs, mgrid >     x, y = mgrid[-2:2:0.05, -2:2:0.05] >     u = x*exp(-0.25*x**2) >     v = y*exp(-0.25*y**2) >     z = u*v >     surfCF(x, y, angle(z), abs(z)**2) _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev