Changeset 2447


Ignore:
Timestamp:
Feb 24, 2006, 6:21:06 PM (19 years ago)
Author:
ole
Message:

Build in caching into least squares + comments

Location:
inundation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inundation/load_mesh/loadASCII.py

    r2262 r2447  
    989989    Note: will throw an IOError if it can't load the file.
    990990    Catch these!
     991
     992    #FIXME (Ole): This function should really return a Geospatial_data object.   
    991993    """
    992994   
  • inundation/pyvolution/least_squares.py

    r2347 r2447  
    127127
    128128    if verbose: print "points file loaded"
    129     if verbose:print "fitting to mesh"
     129    if verbose: print "fitting to mesh"
    130130    f = fit_to_mesh(vertex_coordinates,
    131131                    triangles,
     
    156156
    157157    #FIXME (Ole): Remember to output mesh_origin as well
    158     if verbose: print "exporting to file ",mesh_output_file
     158    if verbose: print "exporting to file ", mesh_output_file
    159159
    160160    try:
     
    174174                data_origin = None,
    175175                mesh_origin = None,
    176                 precrop = False):
     176                precrop = False,
     177                use_cache = False):
    177178    """
    178179    Fit a smooth surface to a triangulation,
     
    202203    """
    203204
    204 
    205     interp = Interpolation(vertex_coordinates,
    206                            triangles,
    207                            point_coordinates,
    208                            alpha = alpha,
    209                            verbose = verbose,
    210                            expand_search = expand_search,
    211                            data_origin = data_origin,
    212                            mesh_origin = mesh_origin,
    213                            precrop = precrop)
     205    if use_cache is True:
     206        from caching.caching import cache
     207        interp = cache(_interpolation,
     208                       (vertex_coordinates,
     209                        triangles,
     210                        point_coordinates),
     211                       {'alpha': alpha,
     212                        'verbose': verbose,
     213                        'expand_search': expand_search,
     214                        'data_origin': data_origin,
     215                        'mesh_origin': mesh_origin,
     216                        'precrop': precrop},
     217                       verbose = verbose)       
     218       
     219    else:
     220        interp = Interpolation(vertex_coordinates,
     221                               triangles,
     222                               point_coordinates,
     223                               alpha = alpha,
     224                               verbose = verbose,
     225                               expand_search = expand_search,
     226                               data_origin = data_origin,
     227                               mesh_origin = mesh_origin,
     228                               precrop = precrop)
    214229
    215230    vertex_attributes = interp.fit_points(point_attributes, verbose = verbose)
     
    272287    return vertex_coordinates, triangles, boundary, vertex_attributes
    273288
     289
     290def _interpolation(*args, **kwargs):
     291    """Private function for use with caching. Reason is that classes
     292    may change their byte code between runs which is annoying.
     293    """
     294   
     295    return Interpolation(*args, **kwargs)
    274296
    275297
  • inundation/pyvolution/quantity.py

    r2366 r2447  
    690690
    691691        #Read from (NetCDF) file
     692        #FIXME (Ole): This function should really return a Geospatial_data object.
    692693        points_dict = import_points_file(filename)
    693694        points = points_dict['pointlist']
Note: See TracChangeset for help on using the changeset viewer.