Ignore:
Timestamp:
Jun 30, 2009, 2:07:41 PM (15 years ago)
Author:
ole
Message:

Merged numpy branch back into the trunk.

In ~/sandpit/anuga/anuga_core/source
svn merge -r 6246:HEAD ../../branches/numpy .

In ~/sandpit/anuga/anuga_validation
svn merge -r 6417:HEAD ../branches/numpy_anuga_validation .

In ~/sandpit/anuga/misc
svn merge -r 6809:HEAD ../branches/numpy_misc .

For all merges, I used numpy version where conflicts existed

The suites test_all.py (in source/anuga) and validate_all.py passed using Python2.5 with numpy on my Ubuntu Linux box.

File:
1 edited

Legend:

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

    r6621 r7276  
    4141
    4242
    43 import Numeric as num
     43import numpy as num
    4444
    4545
     
    6868                max_vertices_per_cell=None,
    6969                start_blocking_len=500000,
    70                 use_cache=False,             
    71                 verbose=False):                 
     70                use_cache=False,
     71                verbose=False):
    7272    """Interpolate vertex_values to interpolation points.
    73    
     73
    7474    Inputs (mandatory):
    7575
    76    
     76
    7777    vertex_coordinates: List of coordinate pairs [xi, eta] of
    78                         points constituting a mesh 
    79                         (or an m x 2 Numeric array or
     78                        points constituting a mesh
     79                        (or an m x 2 numeric array or
    8080                        a geospatial object)
    8181                        Points may appear multiple times
    8282                        (e.g. if vertices have discontinuities)
    8383
    84     triangles: List of 3-tuples (or a Numeric array) of
    85                integers representing indices of all vertices 
     84    triangles: List of 3-tuples (or a numeric array) of
     85               integers representing indices of all vertices
    8686               in the mesh.
    87                
     87
    8888    vertex_values: Vector or array of data at the mesh vertices.
    8989                   If array, interpolation will be done for each column as
    9090                   per underlying matrix-matrix multiplication
    91              
     91
    9292    interpolation_points: Interpolate mesh data to these positions.
    9393                          List of coordinate pairs [x, y] of
    94                           data points or an nx2 Numeric array or a
     94                          data points or an nx2 numeric array or a
    9595                          Geospatial_data object
    96                
     96
    9797    Inputs (optional)
    98                
     98
    9999    mesh_origin: A geo_reference object or 3-tuples consisting of
    100100                 UTM zone, easting and northing.
     
    108108                           object and a mesh origin, since geospatial has its
    109109                           own mesh origin.
    110                            
     110
    111111    start_blocking_len: If the # of points is more or greater than this,
    112                         start blocking 
    113                        
     112                        start blocking
     113
    114114    use_cache: True or False
    115                            
     115
    116116
    117117    Output:
    118    
     118
    119119    Interpolated values at specified point_coordinates
    120120
    121     Note: This function is a simple shortcut for case where 
     121    Note: This function is a simple shortcut for case where
    122122    interpolation matrix is unnecessary
    123     Note: This function does not take blocking into account, 
     123    Note: This function does not take blocking into account,
    124124    but allows caching.
    125    
     125
    126126    """
    127127
    128128    # FIXME(Ole): Probably obsolete since I is precomputed and
    129129    #             interpolate_block caches
    130        
     130
    131131    from anuga.caching import cache
    132132
    133133    # Create interpolation object with matrix
    134     args = (ensure_numeric(vertex_coordinates, num.Float),
     134    args = (ensure_numeric(vertex_coordinates, num.float),
    135135            ensure_numeric(triangles))
    136136    kwargs = {'mesh_origin': mesh_origin,
    137137              'max_vertices_per_cell': max_vertices_per_cell,
    138138              'verbose': verbose}
    139    
     139
    140140    if use_cache is True:
    141141        if sys.platform != 'win32':
     
    149149    else:
    150150        I = apply(Interpolate, args, kwargs)
    151    
     151
    152152    # Call interpolate method with interpolation points
    153153    result = I.interpolate_block(vertex_values, interpolation_points,
    154154                                 use_cache=use_cache,
    155155                                 verbose=verbose)
    156                            
     156
    157157    return result
    158158
    159159
    160160##
    161 # @brief 
     161# @brief
    162162class Interpolate (FitInterpolate):
    163163
     
    181181        Inputs:
    182182          vertex_coordinates: List of coordinate pairs [xi, eta] of
    183               points constituting a mesh (or an m x 2 Numeric array or
     183              points constituting a mesh (or an m x 2 numeric array or
    184184              a geospatial object)
    185185              Points may appear multiple times
    186186              (e.g. if vertices have discontinuities)
    187187
    188           triangles: List of 3-tuples (or a Numeric array) of
     188          triangles: List of 3-tuples (or a numeric array) of
    189189              integers representing indices of all vertices in the mesh.
    190190
     
    202202
    203203        # FIXME (Ole): Need an input check
    204        
     204
    205205        FitInterpolate.__init__(self,
    206206                                vertex_coordinates=vertex_coordinates,
     
    209209                                verbose=verbose,
    210210                                max_vertices_per_cell=max_vertices_per_cell)
    211                                
     211
    212212        # Initialise variables
    213213        self._A_can_be_reused = False  # FIXME (Ole): Probably obsolete
     
    215215        self.interpolation_matrices = {} # Store precomputed matrices
    216216
    217    
     217
    218218
    219219    ##
     
    243243          point_coordinates: Interpolate mesh data to these positions.
    244244              List of coordinate pairs [x, y] of
    245               data points or an nx2 Numeric array or a Geospatial_data object
    246              
    247               If point_coordinates is absent, the points inputted last time
     245              data points or an nx2 numeric array or a Geospatial_data object
     246
     247              If point_coordinates is absent, the points inputted last time
    248248              this method was called are used, if possible.
    249249
    250250          start_blocking_len: If the # of points is more or greater than this,
    251               start blocking 
    252 
    253         Output:
    254           Interpolated values at inputted points (z).
     251              start blocking
     252
     253        Output:
     254          Interpolated values at inputted points (z).
    255255        """
    256256
     
    262262        # This has now been addressed through an attempt in interpolate_block
    263263
    264         if verbose: print 'Build intepolation object' 
     264        if verbose: print 'Build intepolation object'
    265265        if isinstance(point_coordinates, Geospatial_data):
    266266            point_coordinates = point_coordinates.get_data_points(absolute=True)
     
    280280                msg = 'ERROR (interpolate.py): No point_coordinates inputted'
    281281                raise Exception(msg)
    282            
     282
    283283        if point_coordinates is not None:
    284284            self._point_coordinates = point_coordinates
     
    293293                start = 0
    294294                # creating a dummy array to concatenate to.
    295                
    296                 f = ensure_numeric(f, num.Float)
     295
     296                f = ensure_numeric(f, num.float)
    297297                if len(f.shape) > 1:
    298                     z = num.zeros((0, f.shape[1]))
     298                    z = num.zeros((0, f.shape[1]), num.int)     #array default#
    299299                else:
    300                     z = num.zeros((0,))
    301                    
     300                    z = num.zeros((0,), num.int)        #array default#
     301
    302302                for end in range(start_blocking_len,
    303303                                 len(point_coordinates),
     
    305305                    t = self.interpolate_block(f, point_coordinates[start:end],
    306306                                               verbose=verbose)
    307                     z = num.concatenate((z, t))
     307                    z = num.concatenate((z, t), axis=0)    #??default#
    308308                    start = end
    309309
     
    311311                t = self.interpolate_block(f, point_coordinates[start:end],
    312312                                           verbose=verbose)
    313                 z = num.concatenate((z, t))
     313                z = num.concatenate((z, t), axis=0)    #??default#
    314314        return z
    315    
     315
    316316
    317317    ##
     
    322322    # @param verbose True if this function is verbose.
    323323    # @return ??
    324     def interpolate_block(self, f, point_coordinates, 
     324    def interpolate_block(self, f, point_coordinates,
    325325                          use_cache=False, verbose=False):
    326326        """
     
    329329
    330330        Return the point data, z.
    331        
     331
    332332        See interpolate for doc info.
    333333        """
    334        
     334
    335335        # FIXME (Ole): I reckon we should change the interface so that
    336         # the user can specify the interpolation matrix instead of the 
     336        # the user can specify the interpolation matrix instead of the
    337337        # interpolation points to save time.
    338338
     
    340340            point_coordinates = point_coordinates.get_data_points(absolute=True)
    341341
    342         # Convert lists to Numeric arrays if necessary
    343         point_coordinates = ensure_numeric(point_coordinates, num.Float)
    344         f = ensure_numeric(f, num.Float)               
     342        # Convert lists to numeric arrays if necessary
     343        point_coordinates = ensure_numeric(point_coordinates, num.float)
     344        f = ensure_numeric(f, num.float)
    345345
    346346        from anuga.caching import myhash
    347         import sys 
    348          
     347        import sys
     348
    349349        if use_cache is True:
    350350            if sys.platform != 'win32':
    351351                # FIXME (Ole): (Why doesn't this work on windoze?)
    352352                # Still absolutely fails on Win 24 Oct 2008
    353            
     353
    354354                X = cache(self._build_interpolation_matrix_A,
    355355                          args=(point_coordinates,),
    356                           kwargs={'verbose': verbose},                       
    357                           verbose=verbose)       
     356                          kwargs={'verbose': verbose},
     357                          verbose=verbose)
    358358            else:
    359359                # FIXME
     
    361361                # This will work on Linux as well if we want to use it there.
    362362                key = myhash(point_coordinates)
    363        
    364                 reuse_A = False 
    365            
     363
     364                reuse_A = False
     365
    366366                if self.interpolation_matrices.has_key(key):
    367                     X, stored_points = self.interpolation_matrices[key] 
     367                    X, stored_points = self.interpolation_matrices[key]
    368368                    if num.alltrue(stored_points == point_coordinates):
    369                         reuse_A = True          # Reuse interpolation matrix
    370                
     369                        reuse_A = True                # Reuse interpolation matrix
     370
    371371                if reuse_A is False:
    372372                    X = self._build_interpolation_matrix_A(point_coordinates,
     
    375375        else:
    376376            X = self._build_interpolation_matrix_A(point_coordinates,
    377                                                    verbose=verbose)           
    378 
    379         # Unpack result                                       
     377                                                   verbose=verbose)
     378
     379        # Unpack result
    380380        self._A, self.inside_poly_indices, self.outside_poly_indices = X
    381381
     
    389389        msg += ' I got %d points and %d matrix rows.' \
    390390               % (point_coordinates.shape[0], self._A.shape[0])
    391         assert point_coordinates.shape[0] == self._A.shape[0], msg       
     391        assert point_coordinates.shape[0] == self._A.shape[0], msg
    392392
    393393        msg = 'The number of columns in matrix A must be the same as the '
    394394        msg += 'number of mesh vertices.'
    395395        msg += ' I got %d vertices and %d matrix columns.' \
    396                % (f.shape[0], self._A.shape[1])       
     396               % (f.shape[0], self._A.shape[1])
    397397        assert self._A.shape[1] == f.shape[0], msg
    398398
     
    409409        """
    410410        Return the point data, z.
    411        
     411
    412412        Precondition: The _A matrix has been created
    413413        """
     
    416416
    417417        # Taking into account points outside the mesh.
    418         for i in self.outside_poly_indices: 
     418        for i in self.outside_poly_indices:
    419419            z[i] = NAN
    420420        return z
     
    447447        if verbose: print 'Building interpolation matrix'
    448448
    449         # Convert point_coordinates to Numeric arrays, in case it was a list.
    450         point_coordinates = ensure_numeric(point_coordinates, num.Float)
     449        # Convert point_coordinates to numeric arrays, in case it was a list.
     450        point_coordinates = ensure_numeric(point_coordinates, num.float)
    451451
    452452        if verbose: print 'Getting indices inside mesh boundary'
     
    456456                                   self.mesh.get_boundary_polygon(),
    457457                                   closed=True, verbose=verbose)
    458        
     458
    459459        # Build n x m interpolation matrix
    460460        if verbose and len(outside_poly_indices) > 0:
    461461            print '\n WARNING: Points outside mesh boundary. \n'
    462            
     462
    463463        # Since you can block, throw a warning, not an error.
    464464        if verbose and 0 == len(inside_poly_indices):
    465465            print '\n WARNING: No points within the mesh! \n'
    466            
     466
    467467        m = self.mesh.number_of_nodes  # Nbr of basis functions (1/vertex)
    468468        n = point_coordinates.shape[0] # Nbr of data points
     
    474474
    475475        n = len(inside_poly_indices)
    476        
     476
    477477        # Compute matrix elements for points inside the mesh
    478478        if verbose: print 'Building interpolation matrix from %d points' %n
     
    499499                    A[i, j] = sigmas[j]
    500500            else:
    501                 msg = 'Could not find triangle for point', x 
     501                msg = 'Could not find triangle for point', x
    502502                raise Exception(msg)
    503503        return A, inside_poly_indices, outside_poly_indices
    504504
    505505
    506        
    507        
    508        
    509        
     506
     507
     508
     509
    510510##
    511511# @brief ??
     
    526526    points: Interpolate mesh data to these positions.
    527527            List of coordinate pairs [x, y] of
    528             data points or an nx2 Numeric array or a Geospatial_data object
    529              
     528            data points or an nx2 numeric array or a Geospatial_data object
     529
    530530    No test for this yet.
    531531    Note, this has no time the input data has no time dimension.  Which is
    532532    different from most of the data we interpolate, eg sww info.
    533  
     533
    534534    Output:
    535535        Interpolated values at inputted points.
     
    537537
    538538    interp = Interpolate(vertices,
    539                          triangles, 
     539                         triangles,
    540540                         max_vertices_per_cell=max_points_per_cell,
    541541                         mesh_origin=mesh_origin)
    542            
     542
    543543    calc = interp.interpolate(vertex_attributes,
    544544                              points,
     
    554554# @param velocity_y_file Name of the output y velocity  file.
    555555# @param stage_file Name of the output stage file.
    556 # @param froude_file 
     556# @param froude_file
    557557# @param time_thinning Time thinning step to use.
    558558# @param verbose True if this function is to be verbose.
     
    604604                                 time_thinning=time_thinning,
    605605                                 use_cache=use_cache)
    606    
     606
    607607    depth_writer = writer(file(depth_file, "wb"))
    608608    velocity_x_writer = writer(file(velocity_x_file, "wb"))
     
    620620    velocity_y_writer.writerow(heading)
    621621    if stage_file is not None:
    622         stage_writer.writerow(heading) 
     622        stage_writer.writerow(heading)
    623623    if froude_file is not None:
    624         froude_writer.writerow(heading)     
    625    
     624        froude_writer.writerow(heading)
     625
    626626    for time in callable_sww.get_time():
    627627        depths = [time]
    628628        velocity_xs = [time]
    629629        velocity_ys = [time]
    630         if stage_file is not None: 
    631             stages = [time] 
    632         if froude_file is not None: 
    633             froudes = [time] 
     630        if stage_file is not None:
     631            stages = [time]
     632        if froude_file is not None:
     633            froudes = [time]
    634634        for point_i, point in enumerate(points):
    635635            quantities = callable_sww(time,point_i)
    636            
     636
    637637            w = quantities[0]
    638638            z = quantities[1]
    639639            momentum_x = quantities[2]
    640640            momentum_y = quantities[3]
    641             depth = w - z 
    642              
     641            depth = w - z
     642
    643643            if w == NAN or z == NAN or momentum_x == NAN:
    644644                velocity_x = NAN
     
    677677
    678678        if stage_file is not None:
    679             stage_writer.writerow(stages)   
     679            stage_writer.writerow(stages)
    680680        if froude_file is not None:
    681             froude_writer.writerow(froudes)           
     681            froude_writer.writerow(froudes)
    682682
    683683
    684684##
    685 # @brief 
     685# @brief
    686686class Interpolation_function:
    687687    """Interpolation_interface - creates callable object f(t, id) or f(t,x,y)
     
    694694
    695695    Mandatory input
    696         time:                 px1 array of monotonously increasing times (Float)
    697         quantities:           Dictionary of arrays or 1 array (Float)
     696        time:                 px1 array of monotonously increasing times (float)
     697        quantities:           Dictionary of arrays or 1 array (float)
    698698                              The arrays must either have dimensions pxm or mx1.
    699699                              The resulting function will be time dependent in
    700700                              the former case while it will be constant with
    701701                              respect to time in the latter case.
    702        
     702
    703703    Optional input:
    704704        quantity_names:       List of keys into the quantities dictionary for
    705705                              imposing a particular order on the output vector.
    706         vertex_coordinates:   mx2 array of coordinates (Float)
    707         triangles:            nx3 array of indices into vertex_coordinates (Int)
    708         interpolation_points: Nx2 array of coordinates to be interpolated to 
     706        vertex_coordinates:   mx2 array of coordinates (float)
     707        triangles:            nx3 array of indices into vertex_coordinates (int)
     708        interpolation_points: Nx2 array of coordinates to be interpolated to
    709709        verbose:              Level of reporting
    710710
     
    742742                 time,
    743743                 quantities,
    744                  quantity_names=None, 
     744                 quantity_names=None,
    745745                 vertex_coordinates=None,
    746746                 triangles=None,
     
    762762            print 'Interpolation_function: input checks'
    763763
    764         # Check temporal info
     764        # Check temporal info
    765765        time = ensure_numeric(time)
    766766        if not num.alltrue(time[1:] - time[:-1] >= 0):
     
    791791            if triangles is not None:
    792792                triangles = ensure_numeric(triangles)
    793             self.spatial = True         
     793            self.spatial = True
    794794
    795795        if verbose is True:
    796796            print 'Interpolation_function: thinning by %d' % time_thinning
    797797
    798            
     798
    799799        # Thin timesteps if needed
    800800        # Note array() is used to make the thinned arrays contiguous in memory
    801         self.time = num.array(time[::time_thinning])         
     801        self.time = num.array(time[::time_thinning])
    802802        for name in quantity_names:
    803803            if len(quantities[name].shape) == 2:
     
    806806        if verbose is True:
    807807            print 'Interpolation_function: precomputing'
    808            
     808
    809809        # Save for use with statistics
    810810        self.quantities_range = {}
    811811        for name in quantity_names:
    812             q = quantities[name][:].flat
     812            q = quantities[name][:].flatten()
    813813            self.quantities_range[name] = [min(q), max(q)]
    814        
    815         self.quantity_names = quantity_names       
    816         self.vertex_coordinates = vertex_coordinates 
     814
     815        self.quantity_names = quantity_names
     816        self.vertex_coordinates = vertex_coordinates
    817817        self.interpolation_points = interpolation_points
    818818
     
    825825            #if self.spatial is False:
    826826            #    raise 'Triangles and vertex_coordinates must be specified'
    827             # 
     827            #
    828828            try:
    829                 self.interpolation_points = \
     829                self.interpolation_points = \
    830830                    interpolation_points = ensure_numeric(interpolation_points)
    831831            except:
    832                 msg = 'Interpolation points must be an N x 2 Numeric array ' \
     832                msg = 'Interpolation points must be an N x 2 numeric array ' \
    833833                      'or a list of points\n'
    834                 msg += 'Got: %s.' %(str(self.interpolation_points)[:60] + '...')
     834                msg += 'Got: %s.' %(str(self.interpolation_points)[:60] + '...')
    835835                raise msg
    836836
     
    842842                # mesh boundary as defined by triangles and vertex_coordinates.
    843843                from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
    844                 from anuga.utilities.polygon import outside_polygon           
     844                from anuga.utilities.polygon import outside_polygon
    845845
    846846                # Create temporary mesh object from mesh info passed
    847                 # into this function. 
     847                # into this function.
    848848                mesh = Mesh(vertex_coordinates, triangles)
    849849                mesh_boundary_polygon = mesh.get_boundary_polygon()
     
    871871                            # FIXME (Ole): Why only Windoze?
    872872                            from anuga.utilities.polygon import plot_polygons
    873                             #out_interp_pts = num.take(interpolation_points,[indices])
    874873                            title = ('Interpolation points fall '
    875874                                     'outside specified mesh')
     
    889888                        print msg
    890889                    #raise Exception(msg)
    891                    
     890
    892891            elif triangles is None and vertex_coordinates is not None:    #jj
    893892                #Dealing with sts file
     
    915914            m = len(self.interpolation_points)
    916915            p = len(self.time)
    917            
    918             for name in quantity_names:
    919                 self.precomputed_values[name] = num.zeros((p, m), num.Float)
     916
     917            for name in quantity_names:
     918                self.precomputed_values[name] = num.zeros((p, m), num.float)
    920919
    921920            if verbose is True:
    922921                print 'Build interpolator'
    923922
    924                
     923
    925924            # Build interpolator
    926925            if triangles is not None and vertex_coordinates is not None:
    927                 if verbose:               
     926                if verbose:
    928927                    msg = 'Building interpolation matrix from source mesh '
    929928                    msg += '(%d vertices, %d triangles)' \
     
    931930                              triangles.shape[0])
    932931                    print msg
    933                
     932
    934933                # This one is no longer needed for STS files
    935934                interpol = Interpolate(vertex_coordinates,
    936935                                       triangles,
    937                                        verbose=verbose)               
    938                
     936                                       verbose=verbose)
     937
    939938            elif triangles is None and vertex_coordinates is not None:
    940939                if verbose:
     
    947946                print 'Interpolating (%d interpolation points, %d timesteps).' \
    948947                      %(self.interpolation_points.shape[0], self.time.shape[0]),
    949            
     948
    950949                if time_thinning > 1:
    951950                    print 'Timesteps were thinned by a factor of %d' \
     
    954953                    print
    955954
    956             for i, t in enumerate(self.time):
     955            for i, t in enumerate(self.time):
    957956                # Interpolate quantities at this timestep
    958957                if verbose and i%((p+10)/10) == 0:
    959958                    print '  time step %d of %d' %(i, p)
    960                    
     959
    961960                for name in quantity_names:
    962961                    if len(quantities[name].shape) == 2:
     
    967966                    if verbose and i%((p+10)/10) == 0:
    968967                        print '    quantity %s, size=%d' %(name, len(Q))
    969                        
    970                     # Interpolate 
     968
     969                    # Interpolate
    971970                    if triangles is not None and vertex_coordinates is not None:
    972971                        result = interpol.interpolate(Q,
     
    980979                                                      interpolation_points=\
    981980                                                          self.interpolation_points)
    982                        
     981
    983982                    #assert len(result), len(interpolation_points)
    984983                    self.precomputed_values[name][i, :] = result
     
    10071006    def __call__(self, t, point_id=None, x=None, y=None):
    10081007        """Evaluate f(t) or f(t, point_id)
    1009        
    1010         Inputs:
    1011           t:        time - Model time. Must lie within existing timesteps
    1012           point_id: index of one of the preprocessed points.
    1013 
    1014           If spatial info is present and all of point_id
    1015           are None an exception is raised 
    1016                    
     1008
     1009        Inputs:
     1010          t:        time - Model time. Must lie within existing timesteps
     1011          point_id: index of one of the preprocessed points.
     1012
     1013          If spatial info is present and all of point_id
     1014          are None an exception is raised
     1015
    10171016          If no spatial info is present, point_id arguments are ignored
    10181017          making f a function of time only.
    10191018
    1020           FIXME: f(t, x, y) x, y could overrided location, point_id ignored 
    1021           FIXME: point_id could also be a slice
    1022           FIXME: What if x and y are vectors?
     1019          FIXME: f(t, x, y) x, y could overrided location, point_id ignored
     1020          FIXME: point_id could also be a slice
     1021          FIXME: What if x and y are vectors?
    10231022          FIXME: What about f(x,y) without t?
    10241023        """
    10251024
    10261025        from math import pi, cos, sin, sqrt
    1027         from anuga.abstract_2d_finite_volumes.util import mean       
     1026        from anuga.abstract_2d_finite_volumes.util import mean
    10281027
    10291028        if self.spatial is True:
     
    10601059
    10611060        # Compute interpolated values
    1062         q = num.zeros(len(self.quantity_names), num.Float)
    1063         for i, name in enumerate(self.quantity_names):
     1061        q = num.zeros(len(self.quantity_names), num.float)
     1062        for i, name in enumerate(self.quantity_names):
    10641063            Q = self.precomputed_values[name]
    10651064
    10661065            if self.spatial is False:
    1067                 # If there is no spatial info               
     1066                # If there is no spatial info
    10681067                assert len(Q.shape) == 1
    10691068
     
    10801079                        Q1 = Q[self.index+1, point_id]
    10811080
    1082             # Linear temporal interpolation   
     1081            # Linear temporal interpolation
    10831082            if ratio > 0:
    10841083                if Q0 == NAN and Q1 == NAN:
     
    10961095            # Replicate q according to x and y
    10971096            # This is e.g used for Wind_stress
    1098             if x is None or y is None: 
     1097            if x is None or y is None:
    10991098                return q
    11001099            else:
     
    11091108                    res = []
    11101109                    for col in q:
    1111                         res.append(col*num.ones(N, num.Float))
    1112                        
     1110                        res.append(col*num.ones(N, num.float))
     1111
    11131112                return res
    11141113
     
    11261125        """Output statistics about interpolation_function
    11271126        """
    1128        
     1127
    11291128        vertex_coordinates = self.vertex_coordinates
    1130         interpolation_points = self.interpolation_points               
     1129        interpolation_points = self.interpolation_points
    11311130        quantity_names = self.quantity_names
    11321131        #quantities = self.quantities
    1133         precomputed_values = self.precomputed_values                 
    1134                
     1132        precomputed_values = self.precomputed_values
     1133
    11351134        x = vertex_coordinates[:,0]
    1136         y = vertex_coordinates[:,1]               
     1135        y = vertex_coordinates[:,1]
    11371136
    11381137        str =  '------------------------------------------------\n'
     
    11481147        for name in quantity_names:
    11491148            minq, maxq = self.quantities_range[name]
    1150             str += '    %s in [%f, %f]\n' %(name, minq, maxq)           
    1151             #q = quantities[name][:].flat
     1149            str += '    %s in [%f, %f]\n' %(name, minq, maxq)
     1150            #q = quantities[name][:].flatten()
    11521151            #str += '    %s in [%f, %f]\n' %(name, min(q), max(q))
    11531152
    1154         if interpolation_points is not None:   
     1153        if interpolation_points is not None:
    11551154            str += '  Interpolation points (xi, eta):'\
    11561155                   ' number of points == %d\n' %interpolation_points.shape[0]
     
    11601159                                             max(interpolation_points[:,1]))
    11611160            str += '  Interpolated quantities (over all timesteps):\n'
    1162        
     1161
    11631162            for name in quantity_names:
    1164                 q = precomputed_values[name][:].flat
     1163                q = precomputed_values[name][:].flatten()
    11651164                str += '    %s at interpolation points in [%f, %f]\n'\
    11661165                       %(name, min(q), max(q))
     
    11891188    print "x",x
    11901189    print "y",y
    1191    
     1190
    11921191    print "time", time
    11931192    print "quantities", quantities
    11941193
    11951194    #Add the x and y together
    1196     vertex_coordinates = num.concatenate((x[:,num.NewAxis], y[:,num.NewAxis]),axis=1)
     1195    vertex_coordinates = num.concatenate((x[:,num.newaxis], y[:,num.newaxis]),
     1196                                         axis=1)
    11971197
    11981198    #Will return the quantity values at the specified times and locations
    11991199    interp = Interpolation_interface(time,
    12001200                                     quantities,
    1201                                      quantity_names=quantity_names, 
     1201                                     quantity_names=quantity_names,
    12021202                                     vertex_coordinates=vertex_coordinates,
    12031203                                     triangles=volumes,
     
    12121212    """
    12131213    obsolete - Nothing should be calling this
    1214    
     1214
    12151215    Read in an sww file.
    1216    
     1216
    12171217    Input;
    12181218    file_name - the sww file
    1219    
     1219
    12201220    Output;
    12211221    x - Vector of x values
     
    12301230    msg = 'Function read_sww in interpolat.py is obsolete'
    12311231    raise Exception, msg
    1232    
     1232
    12331233    #FIXME Have this reader as part of data_manager?
    1234    
    1235     from Scientific.IO.NetCDF import NetCDFFile     
     1234
     1235    from Scientific.IO.NetCDF import NetCDFFile
    12361236    import tempfile
    12371237    import sys
    12381238    import os
    1239    
     1239
    12401240    #Check contents
    12411241    #Get NetCDF
    1242    
     1242
    12431243    # see if the file is there.  Throw a QUIET IO error if it isn't
    12441244    # I don't think I could implement the above
    1245    
     1245
    12461246    #throws prints to screen if file not present
    12471247    junk = tempfile.mktemp(".txt")
     
    12491249    stdout = sys.stdout
    12501250    sys.stdout = fd
    1251     fid = NetCDFFile(file_name, netcdf_mode_r) 
     1251    fid = NetCDFFile(file_name, netcdf_mode_r)
    12521252    sys.stdout = stdout
    12531253    fd.close()
    12541254    #clean up
    1255     os.remove(junk)     
    1256      
     1255    os.remove(junk)
     1256
    12571257    # Get the variables
    12581258    x = fid.variables['x'][:]
    12591259    y = fid.variables['y'][:]
    1260     volumes = fid.variables['volumes'][:] 
     1260    volumes = fid.variables['volumes'][:]
    12611261    time = fid.variables['time'][:]
    12621262
     
    12661266    keys.remove("volumes")
    12671267    keys.remove("time")
    1268      #Turn NetCDF objects into Numeric arrays
     1268     #Turn NetCDF objects into numeric arrays
    12691269    quantities = {}
    12701270    for name in keys:
    12711271        quantities[name] = fid.variables[name][:]
    1272            
     1272
    12731273    fid.close()
    12741274    return x, y, volumes, time, quantities
Note: See TracChangeset for help on using the changeset viewer.