Skip to content

Commit

Permalink
Added function to plot the core in mayavi
Browse files Browse the repository at this point in the history
  • Loading branch information
leouieda committed Mar 5, 2013
1 parent 3e97bd9 commit 09122c2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions cookbook/vis_myv_earth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
Vis: Plot the Earth, continents, inner and outer core in 3D with Mayavi2
"""
from fatiando.vis import myv

myv.figure(zdown=False)
myv.continents(linewidth=2)
myv.earth(opacity=0.5)
myv.core(opacity=0.7)
myv.core(inner=True)
myv.show()
45 changes: 40 additions & 5 deletions fatiando/vis/myv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* :func:`~fatiando.vis.myv.wall_top`
* :func:`~fatiando.vis.myv.wall_bottom`
* :func:`~fatiando.vis.myv.earth`
* :func:`~fatiando.vis.myv.core`
* :func:`~fatiando.vis.myv.continents`
* :func:`~fatiando.vis.myv.meridians`
* :func:`~fatiando.vis.myv.parallels`
Expand Down Expand Up @@ -796,6 +797,40 @@ def earth(color=(0.4, 0.5, 1.0), opacity=1):
sphere.actor.property.backface_culling = True
return sphere

def core(inner=False, color=(1, 0, 0), opacity=1):
"""
Draw a sphere representing the Earth's core.
Parameters:
* inner : True or False
If True, will use the radius of the inner core, else the outer core.
* color : tuple
RGB color of the sphere. Defaults to red.
* opacity : float
The opacity of the sphere. Must be between 0 and 1
Returns:
* sphere : Mayavi surface
The Mayavi surface element of the sphere
"""
_lazy_import_mlab()
if inner:
radius = 1216000.
name = 'Inner core'
else:
radius = 3486000.
name = 'Core'
sphere = mlab.points3d(0, 0, 0, scale_mode='none',
scale_factor=2.*radius, color=color, resolution=50,
opacity=opacity, name=name)
sphere.actor.property.specular = 0.45
sphere.actor.property.specular_power = 5
sphere.actor.property.backface_culling = True
return sphere

def meridians(longitudes, color=(0, 0, 0), linewidth=1, opacity=1):
"""
Draw meridians on the Earth.
Expand All @@ -810,7 +845,7 @@ def meridians(longitudes, color=(0, 0, 0), linewidth=1, opacity=1):
The width of the lines
* opacity : float
The opacity of the lines. Must be between 0 and 1
Returns:
* lines : Mayavi surface
Expand All @@ -825,7 +860,7 @@ def meridians(longitudes, color=(0, 0, 0), linewidth=1, opacity=1):
y.extend(coords[1].tolist())
z.extend(coords[2].tolist())
x, y, z = numpy.array(x), numpy.array(y), numpy.array(z)
lines = mlab.plot3d(x, y, z, color=color, opacity=opacity,
lines = mlab.plot3d(x, y, z, color=color, opacity=opacity,
tube_radius=None)
lines.actor.property.line_width = linewidth
return lines
Expand All @@ -844,18 +879,18 @@ def parallels(latitudes, color=(0, 0, 0), linewidth=1, opacity=1):
The width of the lines
* opacity : float
The opacity of the lines. Must be between 0 and 1
Returns:
* lines : list
* lines : list
List of the Mayavi surface elements of each line
"""
lons = numpy.linspace(0, 360., 100)
parallels = []
for lat in latitudes:
x, y, z = utils.sph2cart(lons, numpy.ones_like(lons)*lat, 0)
lines = mlab.plot3d(x, y, z, color=color, opacity=opacity,
lines = mlab.plot3d(x, y, z, color=color, opacity=opacity,
tube_radius=None)
lines.actor.property.line_width = linewidth
parallels.append(lines)
Expand Down

0 comments on commit 09122c2

Please sign in to comment.