Changeset 2665


Ignore:
Timestamp:
Apr 6, 2006, 9:47:08 AM (18 years ago)
Author:
ole
Message:

Attempted to fix bug

Location:
inundation/pyvolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/least_squares.py

    r2663 r2665  
    226226    X = point_coordinates[:,0]
    227227    Y = point_coordinates[:,1] 
    228     Z = point_attributes       
     228    Z = ensure_numeric(point_attributes)
     229    if len(Z.shape) == 1:
     230        Z = Z[:, NewAxis]
     231       
    229232
    230233    #Data points inside mesh boundary
     
    242245    Xi = vertex_coordinates[:,0]
    243246    Eta = vertex_coordinates[:,1]       
    244     Zeta = vertex_attributes           
    245 
    246 
    247 
    248     if max(Zeta) > max(Zc)*acceptable_fit_overshoot or\
    249        min(Zeta) < min(Zc)/acceptable_fit_overshoot:
    250         msg = 'Least sqares produced values outside the range of the input '
    251         msg += 'data by a factor greater than %.2f. ' %acceptable_fit_overshoot
    252         msg += 'Z in [%f, %f], Zeta in [%f, %f].\n' %(min(Zc), max(Zc),
    253                                                       min(Zeta), max(Zeta))
    254 
    255         offending_vertices = (Zeta > max(Zc)*acceptable_fit_overshoot) or\
    256                              (Zeta < min(Zc)/acceptable_fit_overshoot)
    257 
    258         Xi_c = compress(offending_vertices, Xi)
    259         Eta_c = compress(offending_vertices, Eta)
    260         offending_coordinates = concatenate((Xi_c[:, NewAxis],
    261                                              Eta_c[:, NewAxis]),
    262                                             axis=1)
    263 
    264         msg += 'Offending locations:\n %s' %(offending_coordinates)
     247    Zeta = ensure_numeric(vertex_attributes)
     248    if len(Zeta.shape) == 1:
     249        Zeta = Zeta[:, NewAxis]   
     250
     251    for i in range(Zeta.shape[1]): #For each attribute
     252        zeta = Zeta[:,i]
     253        z = Z[:,i]               
     254        zc = Zc[:,i]       
    265255       
    266         raise FittingError, msg
     256        if max(zeta) > max(zc)*acceptable_fit_overshoot or\
     257           min(zeta) < min(zc)/acceptable_fit_overshoot:
     258            msg = 'Least sqares produced values outside the range of the input '
     259            msg += 'data by a factor greater than %.2f. ' %acceptable_fit_overshoot
     260            msg += 'z in [%f, %f], zeta in [%f, %f].\n' %(min(zc), max(zc),
     261                                                          min(zeta), max(zeta))
     262
     263            offending_vertices = (zeta > max(zc)*acceptable_fit_overshoot) or\
     264                                 (zeta < min(zc)/acceptable_fit_overshoot)
     265
     266            Xi_c = compress(offending_vertices, Xi)
     267            Eta_c = compress(offending_vertices, Eta)
     268            offending_coordinates = concatenate((Xi_c[:, NewAxis],
     269                                                 Eta_c[:, NewAxis]),
     270                                                axis=1)
     271
     272            msg += 'Offending locations:\n %s' %(offending_coordinates)
     273           
     274            raise FittingError, msg
    267275
    268276
    269277   
    270     if verbose:
    271         print '+------------------------------------------------'
    272         print 'Least squares statistics'
    273         print '+------------------------------------------------'       
    274         print 'points: %d points' %(len(Z))
    275         print '    x in [%f, %f]'%(min(X), max(X))
    276         print '    y in [%f, %f]'%(min(Y), max(Y))
    277         print '    z in [%f, %f]'%(min(Z), max(Z))
    278         print
    279 
    280         if indices is not None:
    281             print 'Cropped points: %d points' %(len(Zc))
    282             print '    x in [%f, %f]'%(min(Xc), max(Xc))
    283             print '    y in [%f, %f]'%(min(Yc), max(Yc))
    284             print '    z in [%f, %f]'%(min(Zc), max(Zc))
     278        if verbose:
     279            print '+------------------------------------------------'
     280            print 'Least squares statistics'
     281            print '+------------------------------------------------'   
     282            print 'points: %d points' %(len(z))
     283            print '    x in [%f, %f]'%(min(X), max(X))
     284            print '    y in [%f, %f]'%(min(Y), max(Y))
     285            print '    z in [%f, %f]'%(min(z), max(z))
    285286            print
    286        
    287 
    288         print 'Mesh: %d vertices' %(len(Zeta))
    289         print '    xi in [%f, %f]'%(min(Xi), max(Xi))
    290         print '    eta in [%f, %f]'%(min(Eta), max(Eta))
    291         print '    zeta in [%f, %f]'%(min(Zeta), max(Zeta))
    292         print '+------------------------------------------------'
     287
     288            if indices is not None:
     289                print 'Cropped points: %d points' %(len(zc))
     290                print '    x in [%f, %f]'%(min(Xc), max(Xc))
     291                print '    y in [%f, %f]'%(min(Yc), max(Yc))
     292                print '    z in [%f, %f]'%(min(zc), max(zc))
     293                print
     294           
     295
     296            print 'Mesh: %d vertices' %(len(zeta))
     297            print '    xi in [%f, %f]'%(min(Xi), max(Xi))
     298            print '    eta in [%f, %f]'%(min(Eta), max(Eta))
     299            print '    zeta in [%f, %f]'%(min(zeta), max(zeta))
     300            print '+------------------------------------------------'
    293301
    294302    return vertex_attributes
  • inundation/pyvolution/test_least_squares.py

    r2663 r2665  
    18631863#-------------------------------------------------------------
    18641864if __name__ == "__main__":
    1865     suite = unittest.makeSuite(Test_Least_Squares,'test_pts')
     1865    #suite = unittest.makeSuite(Test_Least_Squares,'test_smooth_attributes_to_mesh_function')
     1866    suite = unittest.makeSuite(Test_Least_Squares,'test_fit_using_fit_to_mesh')
    18661867
    18671868    #suite = unittest.makeSuite(Test_Least_Squares,'test_fit_to_msh_netcdf_fileII')
Note: See TracChangeset for help on using the changeset viewer.