Changeset 1891


Ignore:
Timestamp:
Oct 11, 2005, 1:52:46 PM (18 years ago)
Author:
duncan
Message:

checking in least squares changes, ticket 8

Location:
inundation/pyvolution
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/least_squares.py

    r1888 r1891  
    279279                 verbose = False,
    280280                 expand_search = True,
     281                 interp_only = False,
    281282                 max_points_per_cell = 30,
    282283                 mesh_origin = None,
     
    345346            self.alpha = alpha
    346347
     348
     349        if point_coordinates is not None:
     350            if verbose: print 'Building interpolation matrix'
     351            self.build_interpolation_matrix_A(point_coordinates,
     352                                              verbose = verbose,
     353                                              expand_search = expand_search,
     354                                              interp_only = interp_only,
     355                                              max_points_per_cell =\
     356                                              max_points_per_cell,
     357                                              data_origin = data_origin,
     358                                              precrop = precrop)
    347359        #Build coefficient matrices
    348         self.build_coefficient_matrix_B(point_coordinates,
     360        if interp_only == False:
     361            self.build_coefficient_matrix_B(point_coordinates,
    349362                                        verbose = verbose,
    350363                                        expand_search = expand_search,
     
    356369
    357370    def set_point_coordinates(self, point_coordinates,
    358                               data_origin = None):
     371                              data_origin = None,
     372                              verbose = False,
     373                              precrop = True):
    359374        """
    360375        A public interface to setting the point co-ordinates.
    361376        """
     377        if point_coordinates is not None:
     378            if verbose: print 'Building interpolation matrix'
     379            self.build_interpolation_matrix_A(point_coordinates,
     380                                              verbose = verbose,
     381                                              data_origin = data_origin,
     382                                              precrop = precrop)
    362383        self.build_coefficient_matrix_B(point_coordinates, data_origin)
    363384
     
    375396
    376397        if point_coordinates is not None:
    377 
    378             if verbose: print 'Building interpolation matrix'
    379             self.build_interpolation_matrix_A(point_coordinates,
    380                                               verbose = verbose,
    381                                               expand_search = expand_search,
    382                                               max_points_per_cell =\
    383                                               max_points_per_cell,
    384                                               data_origin = data_origin,
    385                                               precrop = precrop)
    386 
    387398            if self.alpha <> 0:
    388399                self.B = self.AtA + self.alpha*self.D
     
    397408                                     max_points_per_cell=30,
    398409                                     data_origin = None,
    399                                      precrop = False):
     410                                     precrop = False,
     411                                     interp_only = False):
    400412        """Build n x m interpolation matrix, where
    401413        n is the number of data points and
     
    556568                    self.A[i,j] = sigmas[j]
    557569                    for k in js:
    558                         self.AtA[j,k] += sigmas[j]*sigmas[k]
     570                        if interp_only == False:
     571                            self.AtA[j,k] += sigmas[j]*sigmas[k]
    559572            else:
    560573                pass
  • inundation/pyvolution/test_data_manager.py

    r1875 r1891  
    25142514        os.remove(root + '_100.dem')
    25152515
     2516    def xxxtestz_sww2ers_real(self):
     2517        """Test that sww information can be converted correctly to asc/prj
     2518        format readable by e.g. ArcView
     2519        """
     2520
     2521        import time, os
     2522        from Numeric import array, zeros, allclose, Float, concatenate
     2523        from Scientific.IO.NetCDF import NetCDFFile
     2524
     2525        # the memory optimised least squares
     2526        #  cellsize = 20,   # this one seems to hang
     2527        #  cellsize = 200000, # Ran 1 test in 269.703s
     2528                                #Ran 1 test in 267.344s
     2529        #  cellsize = 20000,  # Ran 1 test in 460.922s
     2530        #  cellsize = 2000   #Ran 1 test in 5340.250s
     2531        #  cellsize = 200   #Ran 1 test in
     2532
     2533        # not optimised
     2534        # seems to hang
     2535        #  cellsize = 2000   # Ran 1 test in 5334.563s
     2536        #Export to ascii/prj files
     2537        sww2dem('karratha_100m',
     2538                quantity = 'depth',
     2539                cellsize = 200000,
     2540                verbose = True)
     2541
    25162542
    25172543
     
    25202546if __name__ == "__main__":
    25212547    suite = unittest.makeSuite(Test_Data_Manager,'test')
     2548    #suite = unittest.makeSuite(Test_Data_Manager,'xxxtest')
    25222549    #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_boundingbox')   
    25232550    #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box')
  • inundation/pyvolution/test_least_squares.py

    r1890 r1891  
    490490
    491491
     492    def test_interpolate_attributes_to_points_interp_only(self):
     493        v0 = [0.0, 0.0]
     494        v1 = [0.0, 5.0]
     495        v2 = [5.0, 0.0]
     496
     497        vertices = [v0, v1, v2]
     498        triangles = [ [1,0,2] ]   #bac
     499
     500        d0 = [1.0, 1.0]
     501        d1 = [1.0, 2.0]
     502        d2 = [3.0, 1.0]
     503        point_coords = [ d0, d1, d2]
     504
     505        interp = Interpolation(vertices, triangles, point_coords,
     506                               interp_only = True)
     507       
     508        f = linear_function(vertices)
     509        z = interp.interpolate(f)
     510        answer = linear_function(point_coords)
     511        #print "answer", answer
     512        #print "z", z
     513
     514        assert allclose(z, answer)
     515
    492516    def test_interpolate_attributes_to_pointsII(self):
    493517        a = [-1.0, 0.0]
Note: See TracChangeset for help on using the changeset viewer.