Ignore:
Timestamp:
Sep 21, 2004, 5:12:15 PM (20 years ago)
Author:
duncan
Message:

testing fit_to_mesh

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

Legend:

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

    r330 r333  
    1212from LinearAlgebra import solve_linear_equations
    1313
    14 def smooth_attributes_to_mesh(vertex_coordinates,
     14def fit_to_mesh(vertex_coordinates,
    1515                              triangles,
    1616                              point_coordinates,
    17                               point_attributes):
     17                              point_attributes,
     18                              alpha = 0.0):
    1819    """
    1920    """
    2021    interp = Interpolation(vertex_coordinates,
    21                               triangles,
    22                               point_coordinates)
    23     vertex_attributes = interp.smooth_attributes_to_mesh(point_attributes)
     22                           triangles,
     23                           point_coordinates,
     24                           alpha = alpha)
     25   
     26    vertex_attributes = interp.fit(point_attributes)
    2427    return vertex_attributes
    2528
  • inundation/ga/storm_surge/pyvolution/load_mesh/loadASCII.py

    r328 r333  
    258258    return meshDict
    259259
     260###
     261#  LOADING XYA FILES
     262###
     263 
     264           
     265def load_xya_file(ofile,delimiter):
     266    """
     267    load a file, ofile, with the format
     268    x,y, [attributes]
     269    """
     270    try:
     271        fd = open(ofile)
     272        xya_dic = read_xya_file(fd, delimiter)
     273        fd.close()
     274    except IOError, e:       
     275        msg = 'Could not open file %s ' %fileName
     276        raise IOError, msg
     277    return xya_dic
     278
     279def read_xya_file(fd, delimiter):
     280    lines = fd.readlines()
     281    points = []
     282    pointattributes = []
     283    if len(lines) <= 1:
     284        raise SyntaxError
     285    lines.pop(0) #remove the first (title) line
     286    attLength = len(clean_line(lines[0],delimiter))-2
     287   
     288    #print "initlegth"
     289    #print attLength
     290    for line in lines:
     291        #print "line >%s" %line
     292        numbers = clean_line(line,delimiter)
     293        #print "numbers >%s<" %numbers
     294        if len(numbers) < 2 and numbers != []:
     295            raise SyntaxError
     296        if numbers != []:
     297            try:
     298                x = float(numbers[0])
     299                y = float(numbers[1])
     300                points.append([x,y])
     301                numbers.pop(0)
     302                numbers.pop(0)
     303                attributes = []
     304                if attLength != len(numbers):
     305                    raise SyntaxError
     306                   
     307                attLength = len(numbers)
     308
     309                for num in numbers:
     310                    num.strip()
     311                    if num != '\n' and num != '':
     312                        attributes.append(float(num))
     313            except ValueError:
     314                raise SyntaxError
     315            pointattributes.append(attributes)
     316    xya_dict = {}
     317    xya_dict['pointlist'] = points
     318    xya_dict['pointattributelist'] = pointattributes
     319    xya_dict['segmentlist'] = []
     320    xya_dict['segmentmarkerlist'] = []
     321    xya_dict['regionlist'] = []
     322    xya_dict['regionattributelist'] = []
     323    xya_dict['regionmaxarealist'] = []
     324    xya_dict['holelist'] = []
     325   
     326    return xya_dict
     327
     328def clean_line(line,delimiter):     
     329    """Remove whitespace
     330    """
     331    #print ">%s" %line
     332    line = line.strip()
     333    #print "stripped>%s" %line
     334    numbers = line.split(delimiter)
     335    i = len(numbers) - 1
     336    while i >= 0:
     337        if numbers[i] == '':
     338            numbers.pop(i)
     339        i += -1
     340    #for num in numbers:
     341    #    print "num>%s<" %num
     342    return numbers
     343
    260344if __name__ == "__main__":
    261345    m = import_mesh("tee.txt")
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r331 r333  
    314314        z3 = [4,8]
    315315        data_coords = [ d1, d2, d3]
    316        
    317         interp = Interpolation(points, triangles, data_coords, alpha=0.0)
    318316        z = [z1, z2, z3]
    319         f = interp.fit(z)
     317       
     318        f = fit_to_mesh(points, triangles, data_coords, z, alpha=0.0)
    320319        answer = [[0, 0], [5., 10.], [5., 10.]]
    321320       
Note: See TracChangeset for help on using the changeset viewer.