Changeset 4252


Ignore:
Timestamp:
Feb 9, 2007, 4:49:27 PM (17 years ago)
Author:
duncan
Message:

working on the verbose when using blocking

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py

    r4220 r4252  
    717717                             location, indices,
    718718                             verbose = False,
    719                              use_cache = False):
     719                             use_cache = False,
     720                             max_read_lines=None):
    720721        """Set quantity based on arbitrary points in a points file
    721722        using attribute_name selects name of attribute
     
    747748                                       'attribute_name': attribute_name,
    748749                                       'use_cache': False,
    749                                        'verbose': verbose},
     750                                       'verbose': verbose,
     751                                       'max_read_lines':max_read_lines},
    750752                                      verbose=verbose)
    751753        else:
     
    754756                                            attribute_name=attribute_name,
    755757                                            use_cache=use_cache,
    756                                             verbose=verbose)
     758                                            verbose=verbose,
     759                                             max_read_lines=max_read_lines)
    757760           
    758761                               
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r4203 r4252  
    652652        import os
    653653        os.remove(txt_file)
    654          
    655     def test_set_values_from_UTM(self):
     654         
     655    def test_set_values_from_lat_long(self):
     656        quantity = Quantity(self.mesh_onslow)
     657
     658        #Get (enough) datapoints
     659        data_points = [[-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     660                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6]]
     661
     662        data_geo_spatial = Geospatial_data(data_points,
     663                                           points_are_lats_longs=True)
     664        points_UTM = data_geo_spatial.get_data_points(absolute=True)
     665        attributes = linear_function(points_UTM)
     666        att = 'elevation'
     667       
     668        #Create .txt file
     669        txt_file = tempfile.mktemp(".txt")
     670        file = open(txt_file,"w")
     671        file.write(" lat,long," + att + " \n")
     672        for data_point, attribute in map(None, data_points, attributes):
     673            row = str(data_point[0]) + ',' + str(data_point[1]) \
     674                  + ',' + str(attribute)
     675            #print "row", row
     676            file.write(row + "\n")
     677        file.close()
     678
     679
     680        #Check that values can be set from file
     681        quantity.set_values(filename = txt_file,
     682                            attribute_name = att, alpha = 0)
     683        answer = linear_function(quantity.domain.get_vertex_coordinates())
     684
     685        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
     686        #print "answer",answer
     687
     688        assert allclose(quantity.vertex_values.flat, answer)
     689
     690
     691        #Check that values can be set from file using default attribute
     692        quantity.set_values(filename = txt_file, alpha = 0)
     693        assert allclose(quantity.vertex_values.flat, answer)
     694
     695        #Cleanup
     696        import os
     697        os.remove(txt_file)
     698       
     699    def test_set_values_from_UTM_pts(self):
    656700        quantity = Quantity(self.mesh_onslow)
    657701
     
    678722
    679723
     724        pts_file = tempfile.mktemp(".pts")       
     725        convert = Geospatial_data(txt_file)
     726        convert.export_points_file(pts_file)
     727
    680728        #Check that values can be set from file
    681         quantity.set_values_from_file(txt_file, att, 0,
     729        quantity.set_values_from_file(pts_file, att, 0,
    682730                                      'vertices', None)
    683731        answer = linear_function(quantity.domain.get_vertex_coordinates())
     
    687735
    688736        #Check that values can be set from file
    689         quantity.set_values(filename = txt_file,
     737        quantity.set_values(filename = pts_file,
    690738                            attribute_name = att, alpha = 0)
    691739        answer = linear_function(quantity.domain.get_vertex_coordinates())
     
    702750        import os
    703751        os.remove(txt_file)
     752        os.remove(pts_file)
     753       
     754    def verbose_test_set_values_from_UTM_pts(self):
     755        quantity = Quantity(self.mesh_onslow)
     756
     757        #Get (enough) datapoints
     758        data_points = [[-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     759                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     760                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     761                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     762                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     763                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     764                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     765                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     766                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     767                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     768                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     769                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     770                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     771                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     772                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     773                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     774                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     775                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     776                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     777                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     778                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     779                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     780                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     781                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     782                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     783                       [-21.5, 114.5],[-21.4, 114.6],[-21.45,114.65],
     784                       [-21.35, 114.65],[-21.45, 114.55],[-21.45,114.6],
     785                       ]
     786
     787        data_geo_spatial = Geospatial_data(data_points,
     788                                           points_are_lats_longs=True)
     789        points_UTM = data_geo_spatial.get_data_points(absolute=True)
     790        attributes = linear_function(points_UTM)
     791        att = 'elevation'
     792       
     793        #Create .txt file
     794        txt_file = tempfile.mktemp(".txt")
     795        file = open(txt_file,"w")
     796        file.write(" x,y," + att + " \n")
     797        for data_point, attribute in map(None, points_UTM, attributes):
     798            row = str(data_point[0]) + ',' + str(data_point[1]) \
     799                  + ',' + str(attribute)
     800            #print "row", row
     801            file.write(row + "\n")
     802        file.close()
     803
     804
     805        pts_file = tempfile.mktemp(".pts")       
     806        convert = Geospatial_data(txt_file)
     807        convert.export_points_file(pts_file)
     808
     809        #Check that values can be set from file
     810        quantity.set_values_from_file(pts_file, att, 0,
     811                                      'vertices', None, verbose = True,
     812                                      max_read_lines=2)
     813        answer = linear_function(quantity.domain.get_vertex_coordinates())
     814        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
     815        #print "answer",answer
     816        assert allclose(quantity.vertex_values.flat, answer)
     817
     818        #Check that values can be set from file
     819        quantity.set_values(filename = pts_file,
     820                            attribute_name = att, alpha = 0)
     821        answer = linear_function(quantity.domain.get_vertex_coordinates())
     822        #print "quantity.vertex_values.flat", quantity.vertex_values.flat
     823        #print "answer",answer
     824        assert allclose(quantity.vertex_values.flat, answer)
     825
     826
     827        #Check that values can be set from file using default attribute
     828        quantity.set_values(filename = txt_file, alpha = 0)
     829        assert allclose(quantity.vertex_values.flat, answer)
     830
     831        #Cleanup
     832        import os
     833        os.remove(txt_file)
     834        os.remove(pts_file)
    704835       
    705836    def test_set_values_from_file_with_georef1(self):
     
    18702001    #suite = unittest.makeSuite(Test_Quantity, 'test_set_values_from_UTM')
    18712002    #print "restricted test"
    1872     #suite = unittest.makeSuite(Test_Quantity,'test_set_values_from_file_with_georef2')
     2003    #suite = unittest.makeSuite(Test_Quantity,'verbose_test_set_values_from_UTM_pts')
    18732004    runner = unittest.TextTestRunner()
    18742005    runner.run(suite)
  • anuga_core/source/anuga/fit_interpolate/fit.py

    r4214 r4252  
    329329                                              verbose=verbose)):
    330330                if verbose is True and 0 == i%200: # round every 5 minutes
     331                    # But this is dependant on the # of Triangles, so it
     332                    #isn't every 5 minutes.
    331333                    print 'Block %i' %i
    332334                # build the array
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r4245 r4252  
    724724                     _read_pts_file_header(self.fid, self.verbose)
    725725            self.start_row=0
     726            self.show_verbose = 0
     727            self.verbose_block_size =  (self.last_row +10) /10
    726728        else:
    727729            file_pointer = open(self.file_name)
     
    761763                fin_row = self.last_row
    762764
    763             if self.verbose is True and \
    764                    0==self.start_row%(( self.last_row+10)/10)==0:
     765               
     766           
     767            if self.verbose is True:
     768                if self.show_verbose >= self.start_row and \
     769                                       self.show_verbose < fin_row:
    765770                 print 'Doing %d of %d' %(self.start_row, self.last_row+10)
     771                 self.show_verbose += max(self.max_read_lines,
     772                                          self.verbose_block_size)
    766773            #call stuff
    767774            pointlist, att_dict, = \
  • anuga_core/source/anuga/geospatial_data/test_geospatial_data.py

    r4238 r4252  
    10501050       
    10511051    def test_load_pts_blocking(self):
    1052         """ test_load_csv(self):
    1053         space delimited
    1054         """
     1052        #This is pts!
     1053       
    10551054        import os
    10561055       
  • anuga_validation/automated_validation_tests/okushiri_tank_validation/loading_pts_test.py

    r4237 r4252  
    4848t0 = time.time()
    4949bathymetry_filename=project.bathymetry_filename
     50bathymetry_filename='Benchmark_2_Bathymetry_very_thin.pts'
    5051print 'Starting domain.set_quantity.  Loading ', bathymetry_filename
    5152s = "domain.set_quantity('elevation',filename=bathymetry_filename,alpha=0.02,verbose=True,use_cache=False)"
Note: See TracChangeset for help on using the changeset viewer.