Ignore:
Timestamp:
Feb 25, 2009, 9:37:22 AM (15 years ago)
Author:
rwilson
Message:

numpy changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/numpy/anuga/fit_interpolate/interpolate.py

    r6304 r6410  
    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 
     78                        points constituting a mesh
    7979                        (or an m x 2 numeric array or
    8080                        a geospatial object)
     
    8383
    8484    triangles: List of 3-tuples (or a numeric array) of
    85                integers representing indices of all vertices 
     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
     
    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                
     295
    296296                f = ensure_numeric(f, num.float)
    297297                if len(f.shape) > 1:
     
    299299                else:
    300300                    z = num.zeros((0,), num.int)        #array default#
    301                    
     301
    302302                for end in range(start_blocking_len,
    303303                                 len(point_coordinates),
     
    313313                z = num.concatenate((z, t))
    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
     
    342342        # Convert lists to numeric arrays if necessary
    343343        point_coordinates = ensure_numeric(point_coordinates, num.float)
    344         f = ensure_numeric(f, 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
     
    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
     
    485485            element_found, sigma0, sigma1, sigma2, k = \
    486486                           search_tree_of_vertices(self.root, self.mesh, x)
    487            
    488             # Update interpolation matrix A if necessary
     487
     488            # Update interpolation matrix A if necessary
    489489            if element_found is True:
    490490                # Assign values to matrix A
     
    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 ??
     
    527527            List of coordinate pairs [x, y] of
    528528            data points or an nx2 numeric array or a Geospatial_data object
    529              
     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)
     
    695695    Mandatory input
    696696        time:                 px1 array of monotonously increasing times (float)
    697         quantities:           Dictionary of arrays or 1 array (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
     
    706706        vertex_coordinates:   mx2 array of coordinates (float)
    707707        triangles:            nx3 array of indices into vertex_coordinates (Int)
    708         interpolation_points: Nx2 array of coordinates to be interpolated to 
     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 = {}
     
    812812            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
     
    839839                # mesh boundary as defined by triangles and vertex_coordinates.
    840840                from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
    841                 from anuga.utilities.polygon import outside_polygon           
     841                from anuga.utilities.polygon import outside_polygon
    842842
    843843                # Create temporary mesh object from mesh info passed
    844                 # into this function. 
     844                # into this function.
    845845                mesh = Mesh(vertex_coordinates, triangles)
    846846                mesh_boundary_polygon = mesh.get_boundary_polygon()
     
    868868                            # FIXME (Ole): Why only Windoze?
    869869                            from anuga.utilities.polygon import plot_polygons
    870                             #out_interp_pts = num.take(interpolation_points,[indices])
    871870                            title = ('Interpolation points fall '
    872871                                     'outside specified mesh')
     
    886885                        print msg
    887886                    #raise Exception(msg)
    888                    
     887
    889888            elif triangles is None and vertex_coordinates is not None:    #jj
    890889                #Dealing with sts file
     
    911910            m = len(self.interpolation_points)
    912911            p = len(self.time)
    913            
    914             for name in quantity_names:
     912
     913            for name in quantity_names:
    915914                self.precomputed_values[name] = num.zeros((p, m), num.float)
    916915
     
    918917                print 'Build interpolator'
    919918
    920                
     919
    921920            # Build interpolator
    922921            if triangles is not None and vertex_coordinates is not None:
    923                 if verbose:               
     922                if verbose:
    924923                    msg = 'Building interpolation matrix from source mesh '
    925924                    msg += '(%d vertices, %d triangles)' \
     
    927926                              triangles.shape[0])
    928927                    print msg
    929                
     928
    930929                # This one is no longer needed for STS files
    931930                interpol = Interpolate(vertex_coordinates,
    932931                                       triangles,
    933                                        verbose=verbose)               
    934                
     932                                       verbose=verbose)
     933
    935934            elif triangles is None and vertex_coordinates is not None:
    936935                if verbose:
     
    943942                print 'Interpolating (%d interpolation points, %d timesteps).' \
    944943                      %(self.interpolation_points.shape[0], self.time.shape[0]),
    945            
     944
    946945                if time_thinning > 1:
    947946                    print 'Timesteps were thinned by a factor of %d' \
     
    950949                    print
    951950
    952             for i, t in enumerate(self.time):
     951            for i, t in enumerate(self.time):
    953952                # Interpolate quantities at this timestep
    954953                if verbose and i%((p+10)/10) == 0:
    955954                    print '  time step %d of %d' %(i, p)
    956                    
     955
    957956                for name in quantity_names:
    958957                    if len(quantities[name].shape) == 2:
     
    963962                    if verbose and i%((p+10)/10) == 0:
    964963                        print '    quantity %s, size=%d' %(name, len(Q))
    965                        
    966                     # Interpolate 
     964
     965                    # Interpolate
    967966                    if triangles is not None and vertex_coordinates is not None:
    968967                        result = interpol.interpolate(Q,
     
    976975                                                      interpolation_points=\
    977976                                                          self.interpolation_points)
    978                        
     977
    979978                    #assert len(result), len(interpolation_points)
    980979                    self.precomputed_values[name][i, :] = result
     
    10031002    def __call__(self, t, point_id=None, x=None, y=None):
    10041003        """Evaluate f(t) or f(t, point_id)
    1005        
    1006         Inputs:
    1007           t:        time - Model time. Must lie within existing timesteps
    1008           point_id: index of one of the preprocessed points.
    1009 
    1010           If spatial info is present and all of point_id
    1011           are None an exception is raised 
    1012                    
     1004
     1005        Inputs:
     1006          t:        time - Model time. Must lie within existing timesteps
     1007          point_id: index of one of the preprocessed points.
     1008
     1009          If spatial info is present and all of point_id
     1010          are None an exception is raised
     1011
    10131012          If no spatial info is present, point_id arguments are ignored
    10141013          making f a function of time only.
    10151014
    1016           FIXME: f(t, x, y) x, y could overrided location, point_id ignored 
    1017           FIXME: point_id could also be a slice
    1018           FIXME: What if x and y are vectors?
     1015          FIXME: f(t, x, y) x, y could overrided location, point_id ignored
     1016          FIXME: point_id could also be a slice
     1017          FIXME: What if x and y are vectors?
    10191018          FIXME: What about f(x,y) without t?
    10201019        """
    10211020
    10221021        from math import pi, cos, sin, sqrt
    1023         from anuga.abstract_2d_finite_volumes.util import mean       
     1022        from anuga.abstract_2d_finite_volumes.util import mean
    10241023
    10251024        if self.spatial is True:
     
    10571056        # Compute interpolated values
    10581057        q = num.zeros(len(self.quantity_names), num.float)
    1059         for i, name in enumerate(self.quantity_names):
     1058        for i, name in enumerate(self.quantity_names):
    10601059            Q = self.precomputed_values[name]
    10611060
    10621061            if self.spatial is False:
    1063                 # If there is no spatial info               
     1062                # If there is no spatial info
    10641063                assert len(Q.shape) == 1
    10651064
     
    10761075                        Q1 = Q[self.index+1, point_id]
    10771076
    1078             # Linear temporal interpolation   
     1077            # Linear temporal interpolation
    10791078            if ratio > 0:
    10801079                if Q0 == NAN and Q1 == NAN:
     
    10921091            # Replicate q according to x and y
    10931092            # This is e.g used for Wind_stress
    1094             if x is None or y is None: 
     1093            if x is None or y is None:
    10951094                return q
    10961095            else:
     
    11061105                    for col in q:
    11071106                        res.append(col*num.ones(N, num.float))
    1108                        
     1107
    11091108                return res
    11101109
     
    11221121        """Output statistics about interpolation_function
    11231122        """
    1124        
     1123
    11251124        vertex_coordinates = self.vertex_coordinates
    1126         interpolation_points = self.interpolation_points               
     1125        interpolation_points = self.interpolation_points
    11271126        quantity_names = self.quantity_names
    11281127        #quantities = self.quantities
    1129         precomputed_values = self.precomputed_values                 
    1130                
     1128        precomputed_values = self.precomputed_values
     1129
    11311130        x = vertex_coordinates[:,0]
    1132         y = vertex_coordinates[:,1]               
     1131        y = vertex_coordinates[:,1]
    11331132
    11341133        str =  '------------------------------------------------\n'
     
    11441143        for name in quantity_names:
    11451144            minq, maxq = self.quantities_range[name]
    1146             str += '    %s in [%f, %f]\n' %(name, minq, maxq)           
     1145            str += '    %s in [%f, %f]\n' %(name, minq, maxq)
    11471146            #q = quantities[name][:].flatten()
    11481147            #str += '    %s in [%f, %f]\n' %(name, min(q), max(q))
    11491148
    1150         if interpolation_points is not None:   
     1149        if interpolation_points is not None:
    11511150            str += '  Interpolation points (xi, eta):'\
    11521151                   ' number of points == %d\n' %interpolation_points.shape[0]
     
    11561155                                             max(interpolation_points[:,1]))
    11571156            str += '  Interpolated quantities (over all timesteps):\n'
    1158        
     1157
    11591158            for name in quantity_names:
    11601159                q = precomputed_values[name][:].flatten()
     
    11851184    print "x",x
    11861185    print "y",y
    1187    
     1186
    11881187    print "time", time
    11891188    print "quantities", quantities
     
    11951194    interp = Interpolation_interface(time,
    11961195                                     quantities,
    1197                                      quantity_names=quantity_names, 
     1196                                     quantity_names=quantity_names,
    11981197                                     vertex_coordinates=vertex_coordinates,
    11991198                                     triangles=volumes,
     
    12081207    """
    12091208    obsolete - Nothing should be calling this
    1210    
     1209
    12111210    Read in an sww file.
    1212    
     1211
    12131212    Input;
    12141213    file_name - the sww file
    1215    
     1214
    12161215    Output;
    12171216    x - Vector of x values
     
    12261225    msg = 'Function read_sww in interpolat.py is obsolete'
    12271226    raise Exception, msg
    1228    
     1227
    12291228    #FIXME Have this reader as part of data_manager?
    1230    
    1231     from Scientific.IO.NetCDF import NetCDFFile     
     1229
     1230    from Scientific.IO.NetCDF import NetCDFFile
    12321231    import tempfile
    12331232    import sys
    12341233    import os
    1235    
     1234
    12361235    #Check contents
    12371236    #Get NetCDF
    1238    
     1237
    12391238    # see if the file is there.  Throw a QUIET IO error if it isn't
    12401239    # I don't think I could implement the above
    1241    
     1240
    12421241    #throws prints to screen if file not present
    12431242    junk = tempfile.mktemp(".txt")
     
    12451244    stdout = sys.stdout
    12461245    sys.stdout = fd
    1247     fid = NetCDFFile(file_name, netcdf_mode_r) 
     1246    fid = NetCDFFile(file_name, netcdf_mode_r)
    12481247    sys.stdout = stdout
    12491248    fd.close()
    12501249    #clean up
    1251     os.remove(junk)     
    1252      
     1250    os.remove(junk)
     1251
    12531252    # Get the variables
    12541253    x = fid.variables['x'][:]
    12551254    y = fid.variables['y'][:]
    1256     volumes = fid.variables['volumes'][:] 
     1255    volumes = fid.variables['volumes'][:]
    12571256    time = fid.variables['time'][:]
    12581257
     
    12661265    for name in keys:
    12671266        quantities[name] = fid.variables[name][:]
    1268            
     1267
    12691268    fid.close()
    12701269    return x, y, volumes, time, quantities
Note: See TracChangeset for help on using the changeset viewer.