Cloud Surfaces

Cloud Plots

Point clouds are represented as a 3-dimensional grid of float values in the form of a Numpy array of shape (M,N,P). The (M,N,P) dimensions correspond to the x, y, and z locations along the Cartesian coordinates.

Given a point cloud array, cloud, values can be visualized using a Matplotlib scatter plot on a 3-D axes. First, generate the point coordinates within a domain, and value colors based on a colormap, as:

xyz, colors, sm = s3d.get_points_from_cloud(cloud, domain, cmap)

where cloud is the point cloud array, domain is a number or array indicating the x, y, and z coordinate domain, and cmap is a colormap.

The Matplotlib scatter plot is then generated on an Axes3D, ax, using the return values as:

ax.scatter( *xyz, c=colors )

Also, the return value of sm is the corresponding Matplotlib ScalarMappable object which can be used to show the cloud colorbar as:

plt.colorbar(sm, ax=ax)

The resulting visualization of the cloud plot will depend on:

  1. the density of the cloud array, controlled by (M,N,P).

  2. The distribution of the alpha values of the colormap.

  3. The additional parameters passed to the Axes3D scatter method:
    • s, the marker size (float or array-like).

    • depthshade, used to give the appearence of depth. (True or False)

  4. the axes view orientation, controlled by Axes3D view_init method.

Consider a spherical point cloud created using:

N,rng = 30, 3   # cloud divisions & the spherical function domain.
x,y,z = np.mgrid[ -rng:rng:N*1j,-rng:rng:N*1j,-rng:rng:N*1j ]
x,z = x+2, z-1   # offset spherical distribution
cloud = np.sqrt(x**2 + y**2 + z**2)

domain,cmap = [-10,20], 'jet_r'   # xyz domain to interpret the cloud

Using this cloud definition, the point cloud visualization is:

../../_images/sphere_cloud.png

Values within the cloud may be emphasized either by

  1. assigning the fade argument of the get_points_from_cloud method, or

  2. applying a custom colormap constructed from a function using the colormap utility op_alpha_cmap.

Examples of these two approaches, using the following code:

xyz, colors_1, scmp = s3d.get_points_from_cloud(cloud,domain,cmap,fade=-1.5 )
xyz, colors_2, scmp_2 = s3d.get_points_from_cloud(cloud,domain,'mapL')

When applied, the visualization is :

../../_images/sphere_cloud_alpha.png

The fade argument can be positive or negative, emphasizing either the high or low values of the cloud, as shown below for different assignments of fade:

../../_images/fade_spherical.png

The mapL custom colormap was used to emphasize two value regions by using varying alpha values within the assigned colormap:

../../_images/cmap_mapL.png

The detailed of this colormap is defined in the Transparent Cloud Sections example.

Note

The ScalarMappable object returned from the get_points_from_cloud method is generated from the colormap passed to the method. For colormaps having transparencies, Matplotlib colorbars will be rendered using white for the transparency.

Cloud Surfaces

Cloud surfaces are contour surfaces in 3D, which are analogous to contour lines in 2D. A surface of constant value within a cloud is constructed from the cloudsurf static method of the Surface3DCollection class. A surface is generated using:

surface = s3d.Surface3DCollection.cloudsurf(cloud, domain, val)

where val is a scalar value within the cloud. Using the previous cloud example, the surface of val=4.5 and color=’aqua’ is:

../../_images/sphere_cloud_surface.png

In a similar manner, a set of surfaces within a domain can be constructed as:

surface = s3d.Surface3DCollection.cloudsurfSet(cloud, domain, numb)

where the numb argument is the number of surfaces which have evenly spaced constant values within the domain. Again, using the example cloud, the set of 7 surfaces within the domain is:

../../_images/sphere_cloud_contours.png

In the above example, a colormap was passed to the method with assignment to the cmap argument.

Note

Surface colormapping is normalized to cloud values, not the range of the values in the composite surface set.

Example Python Scripts

Cloud visualization code:

import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d
import s3dlib.cmap_utilities as cmu

# 1. Generate a spherical cloud distribution to examine ............
N,rng = 30, 3   # cloud divisions & the spherical function domain.
x,y,z = np.mgrid[ -rng:rng:N*1j,-rng:rng:N*1j,-rng:rng:N*1j ]
x,z = x+2, z-1   # offset spherical distribution
cloud = np.sqrt(x**2 + y**2 + z**2)

domain,cmap = [-10,20], 'jet_r'   # xyz domain to interpret the cloud

alpha_list = [ [0.13,0.0],[1.0,0.0],[1.5,1.0],[2.0,0.0], 
               [3.5,0.0], [4.5,1.0], [5.5,0.0], [7.01,0.0] ]
op_list = lambda t : cmu.linsegfunc(t, alpha_list)
cmu.op_alpha_cmap(cmap,op_list, name='mapL')

# 2. Setup data ....................................................

xyz, colors_1, scmp = s3d.get_points_from_cloud(cloud,domain,cmap,fade=-1.5 )
xyz, colors_2, scmp_2 = s3d.get_points_from_cloud(cloud,domain,'mapL')

# 3. Construct figures, add points, and plot .......................
fig = plt.figure(figsize=(10,3.5))
mnx = domain
ax = fig.add_subplot(121, projection='3d', aspect='equal',proj_type='ortho')
ax.set(xlim=mnx,ylim=mnx,zlim=mnx,xlabel='x',ylabel='y',zlabel='z')
ax.scatter(*xyz, c=colors_1, marker='.', s=2)

ax = fig.add_subplot(122, projection='3d', aspect='equal')
ax.set(xlim=mnx,ylim=mnx,zlim=mnx,xlabel='x',ylabel='y',zlabel='z',proj_type='ortho')
ax.scatter(*xyz, c=colors_2, marker='.', s=2)

cbar = plt.colorbar(scmp, ax=ax,  shrink=0.8, pad=.15 )
cbar.set_label('cloud data values', rotation=270, labelpad = 20)

fig.tight_layout(pad=2)
plt.show()

Cloud surface visualization code:

import numpy as np
import matplotlib.pyplot as plt
import s3dlib.surface as s3d

# 1. Generate a spherical cloud distribution to examine ............
N,rng = 30, 3   # cloud divisions & the spherical function domain.
x,y,z = np.mgrid[ -rng:rng:N*1j,-rng:rng:N*1j,-rng:rng:N*1j ]
x,z = x+2, z-1   # offset spherical distribution
cloud = np.sqrt(x**2 + y**2 + z**2)

domain,cmap = [-10,20], 'jet_r'   # xyz domain to interpret the cloud

# 2. Setup data ....................................................
surface = s3d.Surface3DCollection.cloudsurfSet(cloud, domain, 7, cmap=cmap)

# 3. Construct figures, add points, and plot .......................
fig = plt.figure(figsize=(5,3.5))
mnx = domain
ax = fig.add_subplot(111, projection='3d', aspect='equal',proj_type='ortho')
ax.set(xlim=mnx,ylim=mnx,zlim=mnx,xlabel='x',ylabel='y',zlabel='z')

ax.add_collection3d(surface.shade( ))

cbar = plt.colorbar(surface.cBar_ScalarMappable, ax=ax,  shrink=0.8, pad=.15 )
cbar.set_label('cloud data values', rotation=270, labelpad = 20)

fig.tight_layout(pad=2)
plt.show()