Ignore:
Timestamp:
Jul 22, 2005, 5:59:19 PM (20 years ago)
Author:
ole
Message:

Interpolation work and some refactoring

Location:
inundation/ga/storm_surge/pyvolution
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/general_mesh.py

    r1587 r1632  
    173173
    174174
    175     def get_vertex_coordinates(self):
     175    def get_vertex_coordinates(self, obj = False):
    176176        """Return all vertex coordinates.
    177177        Return all vertex coordinates for all triangles as an Nx6 array
    178178        (ordered as x0, y0, x1, y1, x2, y2 for each triangle)
    179         """
    180         return self.vertex_coordinates
     179
     180        if obj is True, the x/y pairs are returned in a 3*N x 2 array.
     181        FIXME, we might make that the default.
     182
     183       
     184        """
     185
     186        if obj is True:
     187            from Numeric import concatenate, reshape
     188            V = self.vertex_coordinates
     189            #return concatenate( (V[:,0:2], V[:,2:4], V[:,4:6]), axis=0)
     190
     191            N = V.shape[0]
     192            return reshape(V, (3*N, 2))
     193        else:   
     194            return self.vertex_coordinates
    181195
    182196
     
    193207        """
    194208
    195         #FIXME: Perhaps they should be ordered as in obj files??
     209        #FIXME (Ole): Perhaps they should be ordered as in obj files??
    196210        #See quantity.get_vertex_values
     211        #FIXME (Ole) - oh yes they should
    197212
    198213        from Numeric import zeros, Float
     
    210225        return vertex_coordinates
    211226
    212     def get_vertices(self,  indexes=None):
     227    def get_vertices(self, indexes=None):
    213228        """Get connectivity
    214229        indexes is the set of element ids of interest
     
    221236
    222237        return  take(self.triangles, indexes)
     238
     239    #FIXME - merge these two
     240    def get_triangles(self, obj = False):
     241        """Get connetivity
     242        Return triangles (triplets of indices into point coordinates)
     243       
     244        """
     245
     246        if obj is True:
     247            from Numeric import array, reshape, Int       
     248            m = len(self)  #Number of triangles
     249            M = 3*m        #Total number of unique vertices
     250            T = reshape(array(range(M)).astype(Int), (m,3))
     251        else:
     252            T = self.triangles
     253
     254        return T     
     255
     256   
    223257
    224258    def get_unique_vertices(self,  indexes=None):
  • inundation/ga/storm_surge/pyvolution/interpolate_sww.py

    r1396 r1632  
    8484       
    8585           
    86     def read_sww(self,file_name, quantity_name):
     86    def read_sww(self, file_name, quantity_name):
    8787        """
    8888        Read in an sww file.
     
    136136        The time list is defined
    137137        """
    138         from load_mesh.loadASCII import  export_points_file
     138        from load_mesh.loadASCII import export_points_file
    139139
    140        
    141140        xya_dict = {}
    142141        xya_dict['pointlist'] = self.point_coordinates
    143142        xya_dict['attributelist'] = self.interpolated_quantity
    144143        export_points_file(point_file, xya_dict)
     144       
    145145       
    146146#-------------------------------------------------------------
  • inundation/ga/storm_surge/pyvolution/least_squares.py

    r1627 r1632  
    279279          vertex_coordinates: List of coordinate pairs [xi, eta] of
    280280          points constituting mesh (or a an m x 2 Numeric array)
     281          Points may appear multiple times
     282          (e.g. if vertices have discontinuities)
    281283
    282284          triangles: List of 3-tuples (or a Numeric array) of
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r1626 r1632  
    538538        else:
    539539            #Don't smooth
     540            #obj machinery moved to general_mesh
    540541
    541542            # Create a V like [[0 1 2], [3 4 5]....[3*m-2 3*m-1 3*m]]
    542543            # These vert_id's will relate to the verts created below
    543             m = len(self.domain)  #Number of volumes
    544             M = 3*m        #Total number of unique vertices
    545             V = reshape(array(range(M)).astype(Int), (m,3))
     544            #m = len(self.domain)  #Number of volumes
     545            #M = 3*m        #Total number of unique vertices
     546            #V = reshape(array(range(M)).astype(Int), (m,3))
     547           
     548            V = self.domain.get_triangles(obj=True)
     549            #FIXME use get_vertices, when ready
    546550
    547551            A = self.vertex_values.flat
  • inundation/ga/storm_surge/pyvolution/sparse.py

    r605 r1632  
    115115            B = array(other)
    116116        except:
    117             print 'FIXME: Only Numeric types implemented so far'
     117            msg = 'FIXME: Only Numeric types implemented so far'
     118            raise msg
     119           
    118120
    119121        #Assume numeric types from now on
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r1469 r1632  
    925925
    926926
     927    def test_interpolation_from_discontinuous_vertex_values(self):
     928        """test_interpolation_from_discontinuous_vertex_values.
     929        This will test the format used internally in pyvolution and also
     930        interpolation from sww files
     931        """
     932       
     933        from mesh import Mesh
     934
     935
     936        #Setup mesh used to represent discontinuous function
     937        a = [0.0, 0.0]
     938        b = [0.0, 2.0]
     939        c = [2.0, 0.0]
     940        d = [0.0, 4.0]
     941        e = [2.0, 2.0]
     942        f = [4.0, 0.0]
     943
     944        points = [b, a, c,
     945                  b, c, e,
     946                  e, c, f,
     947                  d, b, e]
     948       
     949        #bac, bce, ecf, dbe
     950        triangles = [[0,1,2], [3,4,5], [6,7,8], [9,10,11]]
     951
     952       
     953        vertex_values = [0.,0.,0.,1.,1.,1.,2.,2.,2.,7.,3.,3.]
     954                         
     955       
     956
     957        #New datapoints where interpolated values are sought
     958        data_points = [[0.0, 0.0],  #T0
     959                       [0.5, 0.5],  #T0
     960                       [1.5, 1.5],  #T1
     961                       [2.5, 0.5],  #T2
     962                       [0.0, 3.0],  #T3
     963                       [1.0, 2.0],  #In between T1 and T3 (T1 is used) FIXME?
     964                       [2.0, 1.0],  #In between T1 and T2 (T1 is used) FIXME?
     965                       [1.0, 1.0]]  #In between T1 and T0 (T0 is used) FIXME?
     966       
     967
     968
     969
     970        #Build interpolation matrix
     971        interp = Interpolation(points, triangles, data_points)
     972                               #, alpha=0.0, precrop = True)
     973
     974        #print interp.A.todense()
     975        #print vertex_values
     976
     977        #Interpolate using fitted surface
     978        z = interp.interpolate(vertex_values)
     979
     980        #print z
     981
     982        assert allclose(z, [0,0,1,2,5,1,1,0])
     983
     984
     985
     986
     987
     988
     989
    927990
    928991    def test_fit_and_interpolation_with_different_origins(self):
     
    11671230        mesh_dic = {}
    11681231        mesh_dic['vertices'] = [[0.0, 0.0],
    1169                                           [0.0, 5.0],
    1170                                           [5.0, 0.0]]
     1232                                [0.0, 5.0],
     1233                                [5.0, 0.0]]
    11711234        mesh_dic['triangles'] =  [[0, 2, 1]]
    11721235        mesh_dic['segments'] = [[0, 1], [2, 0], [1, 2]]
     
    12101273
    12111274    def test_fit_to_msh_netcdf_fileII(self):
    1212         from load_mesh.loadASCII import import_mesh_file,export_mesh_file
     1275        from load_mesh.loadASCII import import_mesh_file, export_mesh_file
    12131276        import tempfile
    12141277        import os
     
    12171280        mesh_dic = {}
    12181281        mesh_dic['vertices'] = [[0.0, 0.0],
    1219                                           [0.0, 5.0],
    1220                                           [5.0, 0.0]]
     1282                                [0.0, 5.0],
     1283                                [5.0, 0.0]]
    12211284        mesh_dic['triangles'] =  [[0, 2, 1]]
    12221285        mesh_dic['segments'] = [[0, 1], [2, 0], [1, 2]]
  • inundation/ga/storm_surge/pyvolution/test_mesh.py

    r1392 r1632  
    7070        V = mesh.get_vertex_coordinates()
    7171        assert allclose(V[0], [0.0, 0.0, 4.0, 0.0, 0.0, 3.0])
     72
     73        V = mesh.get_vertex_coordinates(obj=True)
     74        assert allclose(V, [ [0.0, 0.0],
     75                             [4.0, 0.0],
     76                             [0.0, 3.0] ])
    7277
    7378        V0 = mesh.get_vertex_coordinate(0, 0)
Note: See TracChangeset for help on using the changeset viewer.