Changeset 4576


Ignore:
Timestamp:
Jul 2, 2007, 5:25:38 PM (17 years ago)
Author:
ole
Message:

Improved verbose reporting when large data files are
processed block wise. This works best for pts files,
but would be good to do for txt and cvs as well.

Location:
anuga_core/source/anuga
Files:
2 edited

Legend:

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

    r4572 r4576  
    325325            assert point_origin is None, msg
    326326            filename = point_coordinates_or_filename
    327            
    328             for i, geo_block in enumerate(Geospatial_data(filename,
    329                                               max_read_lines=max_read_lines,
    330                                               load_file_now=False,
    331                                               verbose=verbose)):
     327
     328            G_data = Geospatial_data(filename,
     329                                     max_read_lines=max_read_lines,
     330                                     load_file_now=False,
     331                                     verbose=verbose)
     332            for i, geo_block in enumerate(G_data):
    332333                if verbose is True and 0 == i%200: # round every 5 minutes
    333334                    # But this is dependant on the # of Triangles, so it
    334335                    #isn't every 5 minutes.
    335                     print 'Block %i' %i
     336                       
     337                    print 'Processing Block %d' %i
     338                    # FIXME (Ole): It would be good to say how many blocks
     339                    # there are here. But this is no longer necessary
     340                    # for pts files as they are reported in geospatial_data
     341                    # I suggest deleting this verbose output and make
     342                    # Geospatial_data more informative for txt files.
     343           
     344
     345                   
    336346                # build the array
    337347                points = geo_block.get_data_points(absolute=True)
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r4575 r4576  
    165165            # attributes etc are provided!!
    166166            # if file name then all provided info will be removed!
     167
     168            #if verbose is True:
     169            #    if file_name is not None:
     170            #        print 'Loading Geospatial data from file: %s' %file_name
     171           
    167172            self.import_points_file(file_name, delimiter, verbose)
    168173               
     
    172177            self.set_default_attribute_name(default_attribute_name)
    173178
     179
    174180        #Why?   
    175181        #assert self.attributes is None or isinstance(self.attributes, DictType)
    176182        #This is a hassle when blocking, so I've removed it.
    177        
     183
     184
     185        if verbose is True:
     186            if file_name is not None:
     187                print 'Geospatial data created from file: %s' %file_name
     188                if load_file_now is False:
     189                    print 'Data will be loaded blockwise on demand'
     190
     191                    if file_name.endswith('csv') or file_name.endswith('txt'):
     192                        print 'ASCII formats are not that great for '
     193                        print 'blockwise reading. Consider storing this'
     194                        print 'data as a pts NetCDF format'
    178195
    179196    def __len__(self):
     
    255272        if verbose in [False, True]:
    256273            self.verbose = verbose
    257            
    258             if verbose is True:
    259                 print 'Geospatial_data.verbose = True'
    260274        else:
    261275            msg = 'Illegal value: %s' %str(verbose)
     
    759773        #FIXME - what to do if the file isn't there
    760774
     775        # FIXME (Ole): Shouldn't this go into the constructor?
     776        # ... and shouldn't it be called block_size?
     777        if self.max_read_lines is None:
     778            self.max_read_lines = MAX_READ_LINES
     779       
     780
    761781        if self.file_name[-4:] == ".xya":
    762782            # FIXME (Ole): shouldn't the xya format be replaced by txt/csv?
     
    774794            self.fid = NetCDFFile(self.file_name, 'r')
    775795           
    776             self.blocking_georef, self.blocking_keys, self.last_row = \
    777                      _read_pts_file_header(self.fid, self.verbose)
     796            self.blocking_georef, self.blocking_keys, self.number_of_points =\
     797                                  _read_pts_file_header(self.fid,
     798                                                        self.verbose)
    778799            self.start_row = 0
     800            self.last_row = self.number_of_points           
    779801            self.show_verbose = 0
    780802            self.verbose_block_size = (self.last_row + 10)/10
     803            self.block_number = 0
     804            self.number_of_blocks = self.number_of_points/self.max_read_lines
     805            # This computes the number of full blocks. The last block may be
     806            # smaller and won't be ircluded in this estimate.
    781807           
    782808            if self.verbose is True:
    783                 print 'Reading %d points (blocking) from file %s'\
    784                       %(self.last_row,
    785                         self.file_name)
     809                print 'Reading %d points (in ~%d blocks) from file %s. '\
     810                      %(self.number_of_points,
     811                        self.number_of_blocks,
     812                        self.file_name),
     813                print 'Each block consists of %d data points'\
     814                      %self.max_read_lines
    786815           
    787816        else:
     
    791820                         _read_csv_file_header(file_pointer)
    792821            self.blocking_georef = None # Used for reconciling zones
    793            
    794         if self.max_read_lines is None:
    795             self.max_read_lines = MAX_READ_LINES
     822
    796823        return self
     824   
    797825   
    798826    def next(self):
     
    828856                fin_row = self.last_row
    829857
    830                 
     858               
    831859           
    832860            if self.verbose is True:
    833861                if self.show_verbose >= self.start_row and \
    834862                       self.show_verbose < fin_row:
    835                  print 'Doing %d of %d' %(self.start_row, self.last_row+10)
    836                  self.show_verbose += max(self.max_read_lines,
    837                                           self.verbose_block_size)
    838             #call stuff
     863
     864                   
     865                    #print 'Doing %d of %d' %(self.start_row, self.last_row+10)
     866
     867                    print 'Reading block %d (points %d to %d) out of %d'\
     868                          %(self.block_number,
     869                            self.start_row,
     870                            fin_row,
     871                            self.number_of_blocks)
     872
     873                   
     874                    self.show_verbose += max(self.max_read_lines,
     875                                             self.verbose_block_size)
     876
     877                 
     878            # Read next block
    839879            pointlist, att_dict, = \
    840                    _read_pts_file_blocking(self.fid,
    841                                            self.start_row,
    842                                            fin_row,
    843                                            self.blocking_keys)
     880                       _read_pts_file_blocking(self.fid,
     881                                               self.start_row,
     882                                               fin_row,
     883                                               self.blocking_keys)
    844884           
    845885            geo = Geospatial_data(pointlist, att_dict, self.blocking_georef)
    846886            self.start_row = fin_row
     887           
     888            self.block_number += 1           
    847889           
    848890        else:
Note: See TracChangeset for help on using the changeset viewer.