Ignore:
Timestamp:
Jan 12, 2007, 3:54:31 PM (18 years ago)
Author:
duncan
Message:

working on fit_to_mesh when .pts and .xya files are passed in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/fit_interpolate/fit.py

    r4165 r4174  
    3030
    3131from anuga.caching import cache           
    32 from anuga.geospatial_data.geospatial_data import Geospatial_data, ensure_absolute
     32from anuga.geospatial_data.geospatial_data import Geospatial_data, \
     33     ensure_absolute
    3334from anuga.fit_interpolate.general_fit_interpolate import FitInterpolate
    3435from anuga.utilities.sparse import Sparse, Sparse_CSR
     
    499500    return vertex_attributes
    500501
    501 
    502 def obsolete_fit_to_mesh_file(mesh_file, point_file, mesh_output_file,
    503                      alpha=DEFAULT_ALPHA, verbose= False,
    504                      display_errors = True):
    505     """
    506     Given a mesh file (tsh) and a point attribute file (xya), fit
    507     point attributes to the mesh and write a mesh file with the
    508     results.
    509 
    510 
    511     If data_origin is not None it is assumed to be
    512     a 3-tuple with geo referenced
    513     UTM coordinates (zone, easting, northing)
    514 
    515     NOTE: Throws IOErrors, for a variety of file problems.
    516    
    517     """
    518     #OBSOLETE
    519     #Problems with using blocking and knowing the attribute title..
    520 
    521 
    522     # Question
    523     # should data_origin and mesh_origin be passed in?
    524     # No they should be in the data structure
    525     #
    526     #Should the origin of the mesh be changed using this function?
    527     # That is overloading this function.  Have it as a seperate
    528     # method, at least initially.
    529    
    530     from load_mesh.loadASCII import import_mesh_file, \
    531                  import_points_file, export_mesh_file, \
    532                  concatinate_attributelist
    533 
    534     # FIXME: Use geospatial instead of import_points_file
    535     try:
    536         mesh_dict = import_mesh_file(mesh_file)
    537     except IOError,e:
    538         if display_errors:
    539             print "Could not load bad file. ", e
    540         raise IOError  #Re-raise exception
    541        
    542     vertex_coordinates = mesh_dict['vertices']
    543     triangles = mesh_dict['triangles']
    544     if type(mesh_dict['vertex_attributes']) == ArrayType:
    545         old_point_attributes = mesh_dict['vertex_attributes'].tolist()
    546     else:
    547         old_point_attributes = mesh_dict['vertex_attributes']
    548 
    549     if type(mesh_dict['vertex_attribute_titles']) == ArrayType:
    550         old_title_list = mesh_dict['vertex_attribute_titles'].tolist()
    551     else:
    552         old_title_list = mesh_dict['vertex_attribute_titles']
    553 
    554     if verbose: print 'tsh file %s loaded' %mesh_file
    555 
    556     # load in the .pts file
    557     try:
    558         #point_dict = import_points_file(point_file, verbose=verbose)
    559        
    560         geospatial = Geospatial_data(point_file)
    561         point_coordinates = geospatial.get_data_points(absolute=False)
    562     except IOError,e:
    563         if display_errors:
    564             print "Could not load bad file. ", e
    565         raise IOError  #Re-raise exception 
    566 
    567     #point_coordinates = point_dict['pointlist']
    568     #get_all_attributes
    569     #title_list,point_attributes = concatinate_attributelist(point_dict['attributelist'])
    570     title_list,point_attributes = concatinate_attributelist( \
    571         geospatial.get_all_attributes())
    572 
    573 
    574     if mesh_dict.has_key('geo_reference') and not mesh_dict['geo_reference'] is None:
    575         mesh_origin = mesh_dict['geo_reference'].get_origin()
    576     else:
    577         mesh_origin = (56, 0, 0) #FIXME(DSG-DSG)
    578 
    579     if verbose: print "points file loaded"
    580     if verbose: print "fitting to mesh"
    581     f = fit_to_mesh(vertex_coordinates,
    582                     triangles,
    583                     point_file,
    584                     alpha = alpha,
    585                     verbose = verbose,
    586                     data_origin = data_origin,
    587                     mesh_origin = mesh_origin)
    588     if verbose: print "finished fitting to mesh"
    589 
    590     # convert array to list of lists
    591     new_point_attributes = f.tolist()
    592     #FIXME have this overwrite attributes with the same title - DSG
    593     #Put the newer attributes last
    594     if old_title_list <> []:
    595         old_title_list.extend(title_list)
    596         #FIXME can this be done a faster way? - DSG
    597         for i in range(len(old_point_attributes)):
    598             old_point_attributes[i].extend(new_point_attributes[i])
    599         mesh_dict['vertex_attributes'] = old_point_attributes
    600         mesh_dict['vertex_attribute_titles'] = old_title_list
    601     else:
    602         mesh_dict['vertex_attributes'] = new_point_attributes
    603         mesh_dict['vertex_attribute_titles'] = title_list
    604 
    605     if verbose: print "exporting to file ", mesh_output_file
    606 
    607     try:
    608         export_mesh_file(mesh_output_file, mesh_dict)
    609     except IOError,e:
    610         if display_errors:
    611             print "Could not write file. ", e
    612         raise IOError
    613 
    614 
    615502def _fit(*args, **kwargs):
    616503    """Private function for use with caching. Reason is that classes
Note: See TracChangeset for help on using the changeset viewer.