Ignore:
Timestamp:
Jan 5, 2007, 4:03:44 PM (18 years ago)
Author:
duncan
Message:

added handling of attributes to blocking

Location:
anuga_core/source/anuga
Files:
5 edited

Legend:

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

    r4130 r4135  
    741741        triangles = self.domain.triangles      #FIXME
    742742
    743        
    744         # FIXME handle attribute name
    745743        vertex_attributes = fit_to_mesh(coordinates, triangles,filename,
    746                                 alpha=alpha) #, max_read_lines=max_read_lines)
     744                                        alpha=alpha,
     745                                        attribute_name = attribute_name,
     746                                        use_cache = use_cache)
     747                                #, max_read_lines=max_read_lines)
    747748       
    748749        #Call underlying method using array values
  • anuga_core/source/anuga/fit_interpolate/fit.py

    r4130 r4135  
    304304            verbose=False,
    305305            point_origin=None,
     306            attribute_name=None,
    306307            max_read_lines=500):
    307308        """Fit a smooth surface to given 1d array of data points z.
     
    320321        # use blocking to load in the point info
    321322        if type(point_coordinates_or_filename) == types.StringType:
     323            msg = "Don't set a point origin when reading from a file"
     324            assert point_origin is None, msg
    322325            filename = point_coordinates_or_filename
    323326            for geo_block in  Geospatial_data(filename,
     
    326329                # build the array
    327330                points = geo_block.get_data_points(absolute=True)
    328                 z = geo_block.get_attributes()
     331                z = geo_block.get_attributes(attribute_name=attribute_name)
    329332                self.build_fit_subset(points, z)
    330333            point_coordinates = None
     
    423426                data_origin=None,
    424427                max_read_lines=None,
     428                attribute_name=None,
    425429                use_cache = False):
    426430    """
     
    472476        interp = Fit(vertex_coordinates,
    473477                     triangles,
    474                      verbose = verbose,
    475                      mesh_origin = mesh_origin,
     478                     verbose=verbose,
     479                     mesh_origin=mesh_origin,
    476480                     alpha=alpha)
    477481       
     
    480484                                   point_origin=data_origin,
    481485                                   max_read_lines=max_read_lines,
     486                                   attribute_name=attribute_name,
    482487                                   verbose=verbose)
    483488
  • anuga_core/source/anuga/fit_interpolate/test_fit.py

    r4130 r4135  
    240240        assert allclose(f, answer)
    241241
    242     def test_fit_2_mesh(self):
     242    def test_fit_to_mesh(self):
    243243
    244244        a = [-1.0, 0.0]
     
    272272        f = fit_to_mesh(vertices, triangles,fileName,
    273273                                alpha=0.0, max_read_lines=2)
     274        answer = linear_function(vertices)
     275        #print "f\n",f
     276        #print "answer\n",answer
     277        assert allclose(f, answer)
     278       
     279    def test_fit_to_mesh_2_atts(self):
     280
     281        a = [-1.0, 0.0]
     282        b = [3.0, 4.0]
     283        c = [4.0,1.0]
     284        d = [-3.0, 2.0] #3
     285        e = [-1.0,-2.0]
     286        f = [1.0, -2.0] #5
     287
     288        vertices = [a, b, c, d,e,f]
     289        triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc
     290
     291
     292        fileName = tempfile.mktemp(".ddd")
     293        file = open(fileName,"w")
     294        # the 2nd att name is wacky so it's the first key off a hash table
     295        file.write(" x,y, elevation, afriqction \n\
     296-2.0, 2.0, 0., 0.\n\
     297-1.0, 1.0, 0., 0.\n\
     2980.0, 2.0 , 2., 20.\n\
     2991.0, 1.0 , 2., 20.\n\
     300 2.0,  1.0 ,3., 30. \n\
     301 0.0,  0.0 , 0., 0.\n\
     302 1.0,  0.0 , 1., 10.\n\
     303 0.0,  -1.0, -1., -10.\n\
     304 -0.2, -0.5, -0.7, -7.\n\
     305 -0.9, -1.5, -2.4, -24. \n\
     306 0.5,  -1.9, -1.4, -14. \n\
     307 3.0,  1.0 , 4., 40. \n")
     308        file.close()
     309       
     310        f = fit_to_mesh(vertices, triangles,fileName,
     311                        alpha=0.0,
     312                        attribute_name='elevation', max_read_lines=2)
    274313        answer = linear_function(vertices)
    275314        #print "f\n",f
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r4129 r4135  
    838838                    # It might not be a problem with the header
    839839                    #raise TitleAmountError
    840                     raise IOError
     840                    msg = "File load error.  There might be a problem with the file header"
     841                    raise IOError, msg
    841842                for i,num in enumerate(numbers):
    842843                    num.strip()
     
    844845                        #attributes.append(float(num))
    845846                        att_dict.setdefault(header[i],[]).append(float(num))
     847            #except IOError:           
    846848            except ValueError:
    847849                raise SyntaxError
  • anuga_core/source/anuga/geospatial_data/test_geospatial_data.py

    r4129 r4135  
    943943           
    944944        os.remove(fileName)             
     945       
     946    def test_load_csv_bad(self):
     947        """
     948        space delimited
     949        """
     950        import os
     951       
     952        fileName = tempfile.mktemp(".txt")
     953        file = open(fileName,"w")
     954        file.write(" elevation ,  speed \n\
     9551.0, 0.0, 10.0, 0.0\n\
     9560.0, 1.0, 0.0, 10.0\n\
     9571.0, 0.0 ,10.4, 40.0\n")
     958        file.close()
     959
     960        results = Geospatial_data(fileName, max_read_lines=2,
     961                                  load_file_now=False)
     962
     963        # Blocking
     964        geo_list = []
     965        try:
     966            for i in results:
     967                geo_list.append(i)
     968        except IOError:
     969            pass
     970        else:
     971            msg = 'bad file did not raise error!'
     972            raise msg
     973        os.remove(fileName)
    945974       
    946975    def test_export_xya_file(self):
Note: See TracChangeset for help on using the changeset viewer.