Ignore:
Timestamp:
Jun 8, 2010, 2:31:04 PM (14 years ago)
Author:
hudson
Message:

Added aggressive psyco optimisation, fixed benchmark app to work with new API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/file_function.py

    r7690 r7810  
    22"""File function
    33Takes a file as input, and returns it as a mathematical function.
    4 For example, you can load an arbitrary 2D heightfield mesh, and treat it as a function as so:
     4For example, you can load an arbitrary 2D heightfield mesh, and treat it as a
     5function like so:
    56
    67F = file_function('my_mesh.sww', ...)
    78evaluated_point = F(x, y)
    89
    9 Values will be interpolated across the surface of the mesh. Holes in the mesh have an undefined value.
     10Values will be interpolated across the surface of the mesh. Holes in the mesh
     11have an undefined value.
    1012
    1113"""
     
    2123
    2224
    23 
    24 ##
    25 # @brief Read time history of data from NetCDF file, return callable object.
    26 # @param filename  Name of .sww or .tms file.
    27 # @param domain Associated domain object.
    28 # @param quantities Name of quantity to be interpolated or a list of names.
    29 # @param interpolation_points List of absolute UTM coordinates for points
    30 #                             (N x 2) or geospatial object or
    31 #                             points file name at which values are sought.
    32 # @param time_thinning
    33 # @param verbose True if this function is to be verbose.
    34 # @param use_cache True means that caching of intermediate result is attempted.
    35 # @param boundary_polygon
    36 # @param output_centroids if True, data for the centroid of the triangle will be output
    37 # @return A callable object.
    3825def file_function(filename,
    3926                  domain=None,
     
    10794        if verbose:
    10895            msg = 'Quantities specified in file_function are None,'
    109             msg += ' so I will use stage, xmomentum, and ymomentum in that order'
     96            msg += ' so using stage, xmomentum, and ymomentum in that order'
    11097            log.critical(msg)
    11198        quantities = ['stage', 'xmomentum', 'ymomentum']
     
    140127            msg = 'Caching was requested, but caching module'+\
    141128                  'could not be imported'
    142             raise msg
     129            raise Exception(msg)
    143130
    144131        f, starttime = cache(_file_function,
     
    160147        #Update domain.startime if it is *earlier* than starttime from file
    161148        if starttime > domain.starttime:
    162             msg = 'WARNING: Start time as specified in domain (%f)'\
    163                   %domain.starttime
    164             msg += ' is earlier than the starttime of file %s (%f).'\
    165                      %(filename, starttime)
     149            msg = 'WARNING: Start time as specified in domain (%f)' \
     150                  % domain.starttime
     151            msg += ' is earlier than the starttime of file %s (%f).' \
     152                     % (filename, starttime)
    166153            msg += ' Modifying domain starttime accordingly.'
    167154           
     
    206193    try:
    207194        fid = open(filename)
    208     except Exception, e:
     195    except IOError, e:
    209196        msg = 'File "%s" could not be opened: Error="%s"' % (filename, e)
    210         raise msg
     197        raise IOError(msg)
    211198
    212199    # read first line of file, guess file type
     
    312299    if filename[-3:] == 'tms' and spatial is True:
    313300        msg = 'Files of type tms must not contain spatial  information'
    314         raise msg
     301        raise Exception(msg)
    315302
    316303    if filename[-3:] == 'sww' and spatial is False:
    317304        msg = 'Files of type sww must contain spatial information'       
    318         raise msg
     305        raise Exception(msg)
    319306
    320307    if filename[-3:] == 'sts' and spatial is False:
    321308        #What if mux file only contains one point
    322309        msg = 'Files of type sts must contain spatial information'       
    323         raise msg
     310        raise Exception(msg)
    324311
    325312    if filename[-3:] == 'sts' and boundary_polygon is None:
    326313        #What if mux file only contains one point
    327314        msg = 'Files of type sts require boundary polygon'       
    328         raise msg
     315        raise Exception(msg)
    329316
    330317    # Get first timestep
     
    333320    except ValueError:
    334321        msg = 'Could not read starttime from file %s' % filename
    335         raise msg
     322        raise Exception(msg)
    336323
    337324    # Get variables
     
    380367            triangles = fid.variables['volumes'][:]
    381368
    382         x = num.reshape(x, (len(x),1))
    383         y = num.reshape(y, (len(y),1))
    384         vertex_coordinates = num.concatenate((x,y), axis=1) #m x 2 array
     369        x = num.reshape(x, (len(x), 1))
     370        y = num.reshape(y, (len(y), 1))
     371        vertex_coordinates = num.concatenate((x, y), axis=1) #m x 2 array
    385372
    386373        if boundary_polygon is not None:
    387374            # Remove sts points that do not lie on boundary
    388             # FIXME(Ole): Why don't we just remove such points from the list of points and associated data?
    389             # I am actually convinced we can get rid of neighbour_gauge_id altogether as the sts file is produced using the ordering file.
    390             # All sts points are therefore always present in the boundary. In fact, they *define* parts of the boundary.
     375            # FIXME(Ole): Why don't we just remove such points from the list of
     376            # points and associated data?
     377            # I am actually convinced we can get rid of neighbour_gauge_id
     378            # altogether as the sts file is produced using the ordering file.
     379            # All sts points are therefore always present in the boundary.
     380            # In fact, they *define* parts of the boundary.
    391381            boundary_polygon=ensure_numeric(boundary_polygon)
    392             boundary_polygon[:,0] -= xllcorner
    393             boundary_polygon[:,1] -= yllcorner
     382            boundary_polygon[:, 0] -= xllcorner
     383            boundary_polygon[:, 1] -= yllcorner
    394384            temp=[]
    395385            boundary_id=[]
     
    420410            gauge_neighbour_id=ensure_numeric(gauge_neighbour_id)
    421411
    422             if len(num.compress(gauge_neighbour_id>=0,gauge_neighbour_id)) \
     412            if len(num.compress(gauge_neighbour_id>=0, gauge_neighbour_id)) \
    423413               != len(temp)-1:
    424414                msg='incorrect number of segments'
     
    433423        if interpolation_points is not None:
    434424            # Adjust for georef
    435             interpolation_points[:,0] -= xllcorner
    436             interpolation_points[:,1] -= yllcorner       
     425            interpolation_points[:, 0] -= xllcorner
     426            interpolation_points[:, 1] -= yllcorner       
    437427    else:
    438428        gauge_neighbour_id=None
Note: See TracChangeset for help on using the changeset viewer.