[cig-commits] r5543 - in mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins: . plugins

luis at geodynamics.org luis at geodynamics.org
Fri Dec 8 09:44:47 PST 2006


Author: luis
Date: 2006-12-08 09:44:47 -0800 (Fri, 08 Dec 2006)
New Revision: 5543

Added:
   mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/custom_ui.py
   mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/utils.py
Modified:
   mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/Citcoms_HdfDisplay.py
   mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomSHDFUgrid.py
   mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomS_hdf_file_reader.py
   mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/OpenCitcomSFILES.py
Log:
Various patches.


Modified: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/Citcoms_HdfDisplay.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/Citcoms_HdfDisplay.py	2006-12-08 17:40:08 UTC (rev 5542)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/Citcoms_HdfDisplay.py	2006-12-08 17:44:47 UTC (rev 5543)
@@ -25,10 +25,10 @@
         from enthought.mayavi.modules import surface, glyph , axes, outline, orientation_axes, scalar_cut_plane  
         from enthought.mayavi.sources.vtk_data_source import VTKDataSource 
         from enthought.tvtk.api import tvtk
-        #citcomS Filter and Modules
-        from plugins.CitcomSHDFUgrid import CitcomSHDFUgrid
-        from plugins.filter.CitcomSshowCaps import CitcomSshowCaps
-        from plugins.filter.CitcomSreduce import CitcomSreduce
+        #CitcomS Filter and Modules
+        from citcoms_plugins.plugins.CitcomSHDFUgrid import CitcomSHDFUgrid
+        from citcoms_plugins.plugins.filter.CitcomSshowCaps import CitcomSshowCaps
+        from citcoms_plugins.plugins.filter.CitcomSreduce import CitcomSreduce
         
         import re
         
@@ -42,7 +42,7 @@
         
         #Read Hdf file
         src_hdf = CitcomSHDFUgrid()
-        hexgrid = src_hdf.initialize(self.filename,self.timestep,self.nx_redu,self.ny_redu,self.nz_redu)
+        hexgrid = src_hdf.initialize(self.filename, self.timestep, self.nx_redu, self.ny_redu, self.nz_redu)
         radius_inner = src_hdf._radius_inner
         data = VTKDataSource()
         data.data = hexgrid
@@ -56,15 +56,14 @@
         scap = CitcomSshowCaps()
         script.add_filter(scap)
         
-        
         #Show ScalarCutPlane
         scp = scalar_cut_plane.ScalarCutPlane()
         script.add_module(scp)
         
         #Add filter for a reduce grid
-        redu = CitcomSreduce()
-        #redu.setvalues(nx,ny,nz)
-        script.add_filter(redu)
+        #redu = CitcomSreduce()
+        ##redu.setvalues(nx,ny,nz)
+        #script.add_filter(redu)
        
         gly = glyph.Glyph()
         gly.glyph.glyph_source.scale = 0.082
@@ -72,8 +71,9 @@
         gly.glyph.color_mode = 'color_by_scalar'
         script.add_module(gly)
         mm = gly.module_manager
-        mm.scalar_lut_manager.use_default_range = False
-        mm.scalar_lut_manager.data_range = 0.0, 1.0
+        #mm.scalar_lut_manager.use_default_range = False
+        #mm.scalar_lut_manager.data_range = 0.0, 1.0
+
         ################### Create CORE ################################
         #Load VTK Data Sets
         sphere = tvtk.SphereSource()
@@ -91,26 +91,20 @@
         surf_module.actor.property.color = orange
         script.add_module(surf_module)
         
-        
          # to create the rendering scene
          ## your stuff here
 
 if __name__ == '__main__':
     mc = HdfDisplay()
-    if len(sys.argv)>=3:
+    if len(sys.argv) > 1:
         mc.filename = sys.argv[1]
-        try:
-            mc.timestep = int(sys.argv[2])
-        except ValueError:
-            print "Timestep is not a number."
-            sys.exit(1)
         if not isfile(mc.filename):
             print "File not found."
             sys.exit(1)
-            
     else:
-        print "[filename] [timestep] -x [Reduce Grid Size X] -y [Reduce Grid Size X] -z [Reduce Grid Size Z]"
+        print "Usage: %s [filename] -x [Reduced Grid Size X] -y [Reduced Grid Size X] -z [Reduced Grid Size Z]" % sys.argv[0]
         sys.exit(0)
+
    ##parse for reduction factors 
     try:
         opts, args = getopt(sys.argv[3:], "x:y:z:", ['x=','y=','z='])

Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/custom_ui.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/custom_ui.py	2006-12-08 17:40:08 UTC (rev 5542)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/custom_ui.py	2006-12-08 17:44:47 UTC (rev 5543)
@@ -0,0 +1,44 @@
+from enthought.envisage.workbench.action.action_plugin_definition import \
+     Action, Group, Location, Menu, WorkbenchActionSet
+
+ID = "citcoms_plugins"
+
+open_citcoms_hdf = Action(
+    id          = ID + ".plugins.OpenCitcomSFILES.OpenCitcomSHDFFILE",
+    class_name  = ID + ".plugins.OpenCitcomSFILES.OpenCitcomSHDFFILE",
+    name        = "CitcomS &HDF5 file",
+    tooltip     = "Open a CitcomS HDF5 data file",
+    description = "Open a CitcomS HDF5 data file",
+    locations   = [Location(path="MenuBar/FileMenu/OpenMenu/additions"),]
+)
+
+citcoms_cap_filter = Action(
+    id          = ID + ".plugins.filter.CitcomSFilterActions.CitcomSshowCaps",
+    class_name  = ID + ".plugins.filter.CitcomSFilterActions.CitcomSshowCaps",
+    name        = "CitcomS &ShowCaps",
+    tooltip     = "Display a specified range of caps",
+    description = "Display a specified range of caps",
+    locations   = [Location(path="MenuBar/VisualizeMenu/FiltersMenu/additions"),]
+)
+
+citcoms_reduce_filter = Action(
+    id          = ID + ".plugins.filter.CitcomSFilterActions.CitcomSreduce",
+    class_name  = ID + ".plugins.filter.CitcomSFilterActions.CitcomSreduce",
+    name        = "CitcomS &Reduce",
+    tooltip     = "Display a Reduce Grid for interpolation",
+    description = "Display a Reduce Grid for interpolation",
+    locations   = [Location(path="MenuBar/VisualizeMenu/FiltersMenu/additions"),]
+)
+
+action_set = WorkbenchActionSet(
+    id      = ID + '.action_set',
+    name    = 'CitcomsActionSet',
+    actions = [open_citcoms_hdf, citcoms_cap_filter, citcoms_reduce_filter,]
+)
+
+###############################################################################
+
+requires = []
+extensions = [action_set]
+
+

Modified: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomSHDFUgrid.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomSHDFUgrid.py	2006-12-08 17:40:08 UTC (rev 5542)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomSHDFUgrid.py	2006-12-08 17:44:47 UTC (rev 5543)
@@ -37,7 +37,7 @@
     _nz_redu = None
     _radius_inner = None
     _radius_outer = None
-    timesteps = None
+    #timesteps = None
     frequency = None
     
     progress = 0
@@ -86,7 +86,7 @@
     
     
     
-    def __citcom2vtk(self,t,f,nproc_surf,nx_redu,ny_redu,nz_redu):
+    def __citcom2vtk(self,f,ft,nproc_surf,nx_redu,ny_redu,nz_redu):
         """Method to convert one timestep from a hdf file to a Vtk file. This Method is used
         by the method initialize. Initialize reads the necessary meta information from the hdf file"""
         
@@ -111,7 +111,7 @@
         for capnr in xrange(nproc_surf):
           
            
-            cap = f.root._f_getChild("cap%02d" % capnr)
+            #cap = f.root._f_getChild("cap%02d" % capnr)
     
             temp_coords =  [] # reset Coordinates, Velocity, Temperature Sequence
             temp_vel = []     
@@ -119,10 +119,16 @@
             temp_visc = []
     
             #Information from hdf
-            hdf_coords = cap.coord[:]
-            hdf_velocity = cap.velocity[t]
-            hdf_temperature = cap.temperature[t]
-            hdf_viscosity = cap.viscosity[t]
+            #hdf_coords = cap.coord[:]
+            #hdf_velocity = cap.velocity[t]
+            #hdf_temperature = cap.temperature[t]
+            #hdf_viscosity = cap.viscosity[t]
+
+            hdf_coords = f.root.coord[capnr]
+            hdf_velocity = ft.root.velocity[capnr]
+            hdf_temperature = ft.root.temperature[capnr]
+            hdf_viscosity = ft.root.viscosity[capnr]
+
     
 
             #Create Iterator to change data representation
@@ -149,7 +155,6 @@
       
                         ordered_temperature.append(float(hdf_temperature[i_redu,j_redu,k_redu]))
                         ordered_viscosity.append(float(hdf_viscosity[i_redu,j_redu,k_redu]))
-                
                     
                         vel_colat, vel_lon , vel_r = map(float,hdf_velocity[i_redu,j_redu,k_redu])
                         x_velo, y_velo, z_velo = self.velocity2cart(vel_colat,vel_lon,vel_r, colat,lon , r)
@@ -214,12 +219,26 @@
     def initialize(self,filename,timestep,nx_redu,ny_redu,nz_redu):
         """Call this method to convert a Citcoms Hdf file to a Vtk file"""
         
+        from citcoms_plugins.utils import parsemodel
+        (step, modelname, metafile, fullpath) = parsemodel(filename)
+
+        if not fullpath:
+            # try to load step=0
+            import os.path
+            step = 0
+            pardir, mfilename = os.path.split(metafile)
+            fullpath = os.path.join(pardir, "%s.%d.h5" % (modelname, step))
+
+        
         #Read meta-inforamtion
-        hdf=tables.openFile(filename,'r')
+        hdf = tables.openFile(metafile, 'r')
+        hdf_t = tables.openFile(fullpath, 'r')
+
         self._nx = int(hdf.root.input._v_attrs.nodex)
         self._ny = int(hdf.root.input._v_attrs.nodey)
         self._nz = int(hdf.root.input._v_attrs.nodez)
         
+
         #Clip against boundaries
         if nx_redu>=0 or nx_redu>=self._nx:
             nx_redu = self._nx-1
@@ -234,13 +253,14 @@
         self._nz_redu = nz_redu
         
         #Number of Timesteps in scene   
-        self.timesteps = int(hdf.root.time.nrows)
+        #self.timesteps = int(hdf.root.time.nrows)
+
         #Number of caps
         nproc_surf = int(hdf.root.input._v_attrs.nproc_surf)
         #Store the Inner Radius. Import if we want to create a core
         self._radius_inner = self._radius_inner = float(hdf.root.input._v_attrs.radius_inner)
         #start computation
-        hexgrid = self.__citcom2vtk(timestep,hdf,nproc_surf,nx_redu,ny_redu,nz_redu)
+        hexgrid = self.__citcom2vtk(hdf, hdf_t, nproc_surf,nx_redu,ny_redu,nz_redu)
         
         hdf.close()
         self.progress = -1

Modified: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomS_hdf_file_reader.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomS_hdf_file_reader.py	2006-12-08 17:40:08 UTC (rev 5542)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/CitcomS_hdf_file_reader.py	2006-12-08 17:44:47 UTC (rev 5543)
@@ -11,21 +11,22 @@
 from enthought.persistence.state_pickler \
      import gzip_string, gunzip_string, set_state
 from enthought.tvtk.api import tvtk
-from enthought.mayavi.plugins.CitcomSHDFUgrid import CitcomSHDFUgrid
-from CitcomHDFThread import *
 
+from citcoms_plugins.utils import parsemodel
+from CitcomSHDFUgrid import CitcomSHDFUgrid
+
 # Local imports.
 from enthought.mayavi.core.source import Source
 from enthought.mayavi.core.common import handle_children_state
 from enthought.mayavi.sources.vtk_xml_file_reader import get_all_attributes
-from CitcomHDFThread import *
+from CitcomHDFThread import CitcomSHdf2UGridThread
 
 import tables
 import re
 
 
 ######################################################################
-# `CitcomSVTKDataSource` class
+# `CitcomSHDFFileReader` class
 ######################################################################
 class CitcomSHDFFileReader(Source):
 
@@ -38,7 +39,9 @@
     data = Instance(tvtk.DataSet)
     # Class to convert Hdf to Vtk Unstructured Grid Objects
     citcomshdftougrid = CitcomSHDFUgrid()
-    current_timestep = Int(0)
+
+    timestep = Int(0)
+
     #To support changing the Scalar values in Mayavi2
     temperature = Instance(tvtk.FloatArray())
     viscosity = Instance(tvtk.FloatArray())
@@ -54,10 +57,10 @@
     nz_redu = Int()
     
     #Number of timesteps in Hdf
-    timesteps = Int()
+    #timesteps = Int()
     
     #Button to trigger the process of reading a timestep
-    read_timestep = Button('Read timestep')
+    read_data = Button('Read data')
     filename = Str()
     
     ########################################
@@ -80,21 +83,19 @@
     ########################################
 
     # Our view.
-    view = View(Group(Item(name='current_timestep'),
-                      Item(name='nx_redu'),
-                      Item(name='ny_redu'),
-                      Item(name='nz_redu'),
-                      Item(name='read_timestep', style='simple', label='Simple'),
+    view = View(Group(#Item(name='current_timestep'),
+                      Item(name='nx_redu', label='Grid Size in X'),
+                      Item(name='ny_redu', label='Grid Size in Y'),
+                      Item(name='nz_redu', label='Grid Size in Z'),
+                      Item(name='read_data', style='simple', label='Simple'),
                       Item(name='point_scalars_name'),
                       Item(name='point_vectors_name'),
                       Item(name='point_tensors_name'),
-                      Item(name='cell_scalars_name'),
-                      Item(name='cell_vectors_name'),
-                      Item(name='cell_tensors_name'),
-                      
-                      ),
-                      
-                     )
+                      #Item(name='cell_scalars_name'),
+                      #Item(name='cell_vectors_name'),
+                      #Item(name='cell_tensors_name'),
+                     ),
+               )
     
     ######################################################################
     # `object` interface
@@ -125,7 +126,10 @@
                 msg = 'Could not find file at %s\n'%file_name
                 msg += 'Please move the file there and try again.'
                 raise IOError, msg
-        
+            
+            (step, modelname, metafilepath, filepath) = parsemodel(file_name)
+            file_name = metafilepath
+            
             self.filename = file_name
         
             #self.data = self.citcomshdftougrid.initialize(self.filename,0,0,0,0,False,False)
@@ -134,7 +138,8 @@
             self.ny = int(f.root.input._v_attrs.nodey)
             self.nz = int(f.root.input._v_attrs.nodez)
         
-            self.timesteps = int(f.root.time.nrows)
+            #self.timesteps = int(f.root.time.nrows)
+
             f.close()
             self.data = self.citcomshdftougrid.initialize(self.filename,self.current_timestep,self.nx_redu,self.ny_redu,self.nz_redu)
             self.data_changed = True
@@ -174,7 +179,13 @@
         self.filename = file_name
         
         #self.data = self.citcomshdftougrid.initialize(self.filename,0,0,0,0,False,False)
-        f = tables.openFile(file_name,'r')
+        from citcoms_plugins.utils import parsemodel
+
+        (step, modelname, coordpath, filepath) = parsemodel(file_name)
+        if step is None:
+            step = 0
+
+        f = tables.openFile(coordpath,'r')
         self.nx = int(f.root.input._v_attrs.nodex)
         self.ny = int(f.root.input._v_attrs.nodey)
         self.nz = int(f.root.input._v_attrs.nodez)
@@ -183,7 +194,8 @@
         self.ny_redu = self.ny
         self.nz_redu = self.nz
         
-        self.timesteps = int(f.root.time.nrows)
+        self.timestep = step
+        #self.timesteps = int(f.root.time.nrows)
         f.close()
         
         
@@ -193,10 +205,10 @@
     def tno_get_label(self, node):
         """ Gets the label to display for a specified object.
         """
-        ret = "CitcomS HDF Data (uninitialized)"
+        ret = "CitcomS HDF5 Data (not initialized)"
         if self.data:
             typ = self.data.__class__.__name__
-            ret = "CitcomS HDF Data (%d)"%self.current_timestep
+            ret = "CitcomS HDF5 Data (step %d)" % self.timestep
         return ret
 
     ######################################################################
@@ -216,14 +228,14 @@
         """Callback for the current timestep input box"""
         if new_value < 0:
             self.current_timestep = 0
-        if new_value > self.timesteps:
-            self.current_timestep = self.timesteps-1
+        #if new_value > self.timesteps:
+        #    self.current_timestep = self.timesteps-1
     
-    def _read_timestep_fired(self):
-        """Callback for the Button to read one timestep"""
+    def _read_data_fired(self):
+        """Callback for the Button to read the data"""
         
         
-        self.data = self.citcomshdftougrid.initialize(self.filename,self.current_timestep,self.nx_redu,self.ny_redu,self.nz_redu)
+        self.data = self.citcomshdftougrid.initialize(self.filename,self.timestep,self.nx_redu,self.ny_redu,self.nz_redu)
         self.temperature = self.citcomshdftougrid.get_vtk_temperature()
         self.viscosity = self.citcomshdftougrid.get_vtk_viscosity()
         

Modified: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/OpenCitcomSFILES.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/OpenCitcomSFILES.py	2006-12-08 17:40:08 UTC (rev 5542)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/plugins/OpenCitcomSFILES.py	2006-12-08 17:44:47 UTC (rev 5543)
@@ -10,38 +10,10 @@
 from enthought.mayavi.action.common import WorkbenchAction, get_imayavi
 
 ######################################################################
-# `OpenCitcomSVtkFile` class.
+# `OpenCitcomSHDFFile` class.
 ######################################################################
-class OpenCitcomSVTKFILE(WorkbenchAction):
-    """ An action that opens a new VTK file. """
-
-    ###########################################################################
-    # 'Action' interface.
-    ###########################################################################
-
-    def perform(self):
-        """ Performs the action. """
-        wildcard = 'VTK files (*.vtk)|*.vtk|' + FileDialog.WILDCARD_ALL
-        parent = self.window.control
-        dialog = FileDialog(parent=parent,
-                            title='Open CitcomS VTK file',
-                            action='open', wildcard=wildcard
-                            )
-        if dialog.open() == OK:
-            if not isfile(dialog.path):
-                error("File '%s' does not exist!"%dialog.path, parent)
-                return
-            from enthought.mayavi.plugins.CitcomS_vtk_file_reader import CitcomSVTKFileReader
-            r = CitcomSVTKFileReader()
-            r.initialize(dialog.path)
-            mv = get_imayavi(self.window)
-            mv.add_source(r)
-
-######################################################################
-# `OpenCitcomSVtkFile` class.
-######################################################################
 class OpenCitcomSHDFFILE(WorkbenchAction):
-    """ An action that opens a new VTK file. """
+    """ An action that opens a new HDF5 file. """
 
     ###########################################################################
     # 'Action' interface.
@@ -52,15 +24,16 @@
         wildcard = 'HDF files (*.h5)|*.h5|' + FileDialog.WILDCARD_ALL
         parent = self.window.control
         dialog = FileDialog(parent=parent,
-                            title='Open CitcomS H5 file',
+                            title='Open CitcomS HDF5 file',
                             action='open', wildcard=wildcard
                             )
         if dialog.open() == OK:
             if not isfile(dialog.path):
                 error("File '%s' does not exist!"%dialog.path, parent)
                 return
-            from enthought.mayavi.plugins.CitcomS_hdf_file_reader import CitcomSHDFFileReader
+            from citcoms_plugins.plugins.CitcomS_hdf_file_reader import CitcomSHDFFileReader
             r = CitcomSHDFFileReader()
             r.initialize(dialog.path)
             mv = get_imayavi(self.window)
             mv.add_source(r)
+

Added: mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/utils.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/utils.py	2006-12-08 17:40:08 UTC (rev 5542)
+++ mc/3D/CitcomS/trunk/visual/Mayavi2/citcoms_plugins/utils.py	2006-12-08 17:44:47 UTC (rev 5543)
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+import os.path
+
+def parsemodel(somepath):
+    
+    nothing = (None, None, None, None)
+
+    # prepare...
+    filepath = os.path.abspath(somepath)
+
+    # first round
+    pardir, filename = os.path.split(filepath)
+    if not filename:
+        return nothing
+
+    # second round
+    rootname, h5 = os.path.splitext(filename)
+    if not rootname:
+        return nothing
+    if h5 != '.h5':
+        return nothing
+
+    # third round
+    modelname, dotstep = os.path.splitext(rootname)
+    if not modelname:
+        return nothing
+
+    coordfile = '%s.h5' % modelname
+    coordpath = os.path.join(pardir, coordfile)
+
+    # fourth round
+    try:
+        step = int(dotstep[1:])
+    except ValueError:
+        return (None, modelname, coordpath, None)
+
+    return (step, modelname, coordpath, filepath)
+
+
+if __name__ == '__main__':
+    import sys
+    if len(sys.argv) > 1:
+        print parsemodel(sys.argv[1])
+



More information about the cig-commits mailing list