Ignore:
Timestamp:
Jul 22, 2009, 9:22:11 AM (16 years ago)
Author:
rwilson
Message:

Replaced 'print' statements with log.critical() calls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r7276 r7317  
    2626from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a
    2727from anuga.config import netcdf_float
     28import anuga.utilities.log as log
    2829
    2930
     
    170171            if verbose is True:
    171172                if file_name is not None:
    172                     print 'Loading Geospatial data from file: %s' % file_name
     173                    log.critical('Loading Geospatial data from file: %s'
     174                                 % file_name)
    173175
    174176            self.import_points_file(file_name, verbose=verbose)
     
    181183        if verbose is True:
    182184            if file_name is not None:
    183                 print 'Geospatial data created from file: %s' % file_name
     185                log.critical('Geospatial data created from file: %s'
     186                             % file_name)
    184187                if load_file_now is False:
    185                     print 'Data will be loaded blockwise on demand'
     188                    log.critical('Data will be loaded blockwise on demand')
    186189
    187190                    if file_name.endswith('csv') or file_name.endswith('txt'):
     
    437440
    438441        if self.verbose is True:
    439             print 'Using attribute %s' %attribute_name
    440             print 'Available attributes: %s' %(self.attributes.keys())
     442            log.critical('Using attribute %s' % attribute_name)
     443            log.critical('Available attributes: %s' % (self.attributes.keys()))
    441444
    442445        msg = 'Attribute name %s does not exist in data set' % attribute_name
     
    696699
    697700        # Find unique random numbers
    698         if verbose: print "make unique random number list and get indices"
     701        if verbose: log.critical("make unique random number list "
     702                                 "and get indices")
    699703
    700704        total = num.array(range(self_size), num.int)    #array default#
    701705        total_list = total.tolist()
    702706
    703         if verbose: print "total list len", len(total_list)
     707        if verbose: log.critical("total list len=%d" % len(total_list))
    704708
    705709        # There will be repeated random numbers however will not be a
     
    708712        # still basically random
    709713        ## create list of non-unquie random numbers
    710         if verbose: print "create random numbers list %s long" %new_size
     714        if verbose: log.critical("create random numbers list %s long"
     715                                 % str(new_size))
    711716
    712717        # Set seed if provided, mainly important for unit test!
     
    717722            seed()
    718723
    719         #if verbose: print "seed:", get_seed()
    720 
    721724        random_num = randint(0, self_size-1, (int(new_size),))
    722725        random_num = random_num.tolist()
     
    726729        random_num.reverse()
    727730
    728         if verbose: print "make random number list and get indices"
     731        if verbose: log.critical("make random number list and get indices")
    729732
    730733        j = 0
     
    740743            # prints progress
    741744            if verbose and round(random_num_len/10*k) == j:
    742                 print '(%s/%s)' % (j, random_num_len)
     745                log.critical('(%s/%s)' % (j, random_num_len))
    743746                k += 1
    744747
     
    755758
    756759        # Get new samples
    757         if verbose: print "get values of indices for random list"
     760        if verbose: log.critical("get values of indices for random list")
    758761        G1 = self.get_sample(random_list)
    759         if verbose: print "get values of indices for opposite of random list"
     762        if verbose: log.critical("get values of indices for "
     763                                 "opposite of random list")
    760764        G2 = self.get_sample(remainder_list)
    761765
     
    800804
    801805            if self.verbose is True:
    802                 print ('Reading %d points (in ~%d blocks) from file %s. '
    803                        % (self.number_of_points, self.number_of_blocks,
    804                           self.file_name)),
    805                 print ('Each block consists of %d data points'
    806                        % self.max_read_lines)
     806                log.critical('Reading %d points (in ~%d blocks) from file %s. '
     807                             % (self.number_of_points, self.number_of_blocks,
     808                                self.file_name))
     809                log.critical('Each block consists of %d data points'
     810                             % self.max_read_lines)
    807811        else:
    808812            # Assume the file is a csv file
     
    837841                if (self.show_verbose >= self.start_row
    838842                    and self.show_verbose < fin_row):
    839                     print ('Reading block %d (points %d to %d) out of %d'
    840                            % (self.block_number, self.start_row,
    841                               fin_row, self.number_of_blocks))
     843                    log.critical('Reading block %d (points %d to %d) out of %d'
     844                                 % (self.block_number, self.start_row,
     845                                    fin_row, self.number_of_blocks))
    842846
    843847                    self.show_verbose += max(self.max_read_lines,
     
    976980    """
    977981
    978     if verbose: print 'Reading ', file_name
     982    if verbose: log.critical('Reading %s' % file_name)
    979983
    980984    # See if the file is there.  Throw a QUIET IO error if it isn't
     
    988992    keys = fid.variables.keys()
    989993
    990     if verbose: print 'Got %d variables: %s' % (len(keys), keys)
     994    if verbose: log.critical('Got %d variables: %s' % (len(keys), keys))
    991995
    992996    try:
     
    9991003    attributes = {}
    10001004    for key in keys:
    1001         if verbose: print "reading attribute '%s'" % key
     1005        if verbose: log.critical("reading attribute '%s'" % key)
    10021006
    10031007        attributes[key] = num.array(fid.variables[key])
     
    11731177        raise IOError, msg
    11741178
    1175     if verbose: print 'Got %d variables: %s' % (len(keys), keys)
     1179    if verbose: log.critical('Got %d variables: %s' % (len(keys), keys))
    11761180
    11771181    try:
     
    15621566
    15631567    if mesh_file is None:
    1564         if verbose: print "building mesh"
     1568        if verbose: log.critical("building mesh")
    15651569        mesh_file = 'temp.msh'
    15661570
     
    15971601
    15981602    # split topo data
    1599     if verbose: print 'Reading elevation file: %s' % data_file
     1603    if verbose: log.critical('Reading elevation file: %s' % data_file)
    16001604    G = Geospatial_data(file_name = data_file)
    1601     if verbose: print 'Start split'
     1605    if verbose: log.critical('Start split')
    16021606    G_small, G_other = G.split(split_factor, seed_num, verbose=verbose)
    1603     if verbose: print 'Finish split'
     1607    if verbose: log.critical('Finish split')
    16041608    points = G_small.get_data_points()
    16051609
    1606     if verbose: print "Number of points in sample to compare: ", len(points)
     1610    if verbose: log.critical("Number of points in sample to compare: %d"
     1611                             % len(points))
    16071612
    16081613    if alpha_list == None:
     
    16281633    normal_cov = num.array(num.zeros([len(alphas), 2]), dtype=num.float)
    16291634
    1630     if verbose: print 'Setup computational domains with different alphas'
     1635    if verbose: log.critical('Setup computational domains with '
     1636                             'different alphas')
    16311637
    16321638    for i, alpha in enumerate(alphas):
    16331639        # add G_other data to domains with different alphas
    16341640        if verbose:
    1635             print '\nCalculating domain and mesh for Alpha =', alpha, '\n'
     1641            log.critical('Calculating domain and mesh for Alpha=%s'
     1642                         % str(alpha))
    16361643        domain = Domain(mesh_file, use_cache=cache, verbose=verbose)
    1637         if verbose: print domain.statistics()
     1644        if verbose: log.critical(domain.statistics())
    16381645        domain.set_quantity(attribute_smoothed,
    16391646                            geospatial_data=G_other,
     
    16471654        # returns the predicted elevation of the points that were "split" out
    16481655        # of the original data set for one particular alpha
    1649         if verbose: print 'Get predicted elevation for location to be compared'
     1656        if verbose: log.critical('Get predicted elevation for location '
     1657                                 'to be compared')
    16501658        elevation_predicted = \
    16511659                domain.quantities[attribute_smoothed].\
     
    16601668
    16611669        if verbose:
    1662             print 'Covariance for alpha ', normal_cov[i][0], '= ', \
    1663                       normal_cov[i][1]
    1664             print '-------------------------------------------- \n'
     1670            log.critical('Covariance for alpha %s=%s'
     1671                         % (normal_cov[i][0], normal_cov[i][1]))
     1672            log.critical('--------------------------------------------')
    16651673
    16661674    normal_cov0 = normal_cov[:,0]
     
    16781686
    16791687    if verbose:
    1680         print 'Final results:'
     1688        log.critical('Final results:')
    16811689        for i, alpha in enumerate(alphas):
    1682             print ('covariance for alpha %s = %s '
    1683                    % (normal_cov[i][0], normal_cov[i][1]))
    1684         print ('\nOptimal alpha is: %s '
    1685                % normal_cov_new[(num.argmin(normal_cov_new, axis=0))[1], 0])
     1690            log.critical('covariance for alpha %s = %s '
     1691                         % (normal_cov[i][0], normal_cov[i][1]))
     1692        log.critical('Optimal alpha is: %s '
     1693                     % normal_cov_new[(num.argmin(normal_cov_new, axis=0))[1], 0])
    16861694
    16871695    # covariance and optimal alpha
     
    18021810    # split topo data
    18031811    G = Geospatial_data(file_name=data_file)
    1804     if verbose: print 'start split'
     1812    if verbose: log.critical('start split')
    18051813    G_small, G_other = G.split(split_factor, seed_num, verbose=verbose)
    1806     if verbose: print 'finish split'
     1814    if verbose: log.critical('finish split')
    18071815    points = G_small.get_data_points()
    18081816
    1809     if verbose: print "Number of points in sample to compare: ", len(points)
     1817    if verbose: log.critical("Number of points in sample to compare: %d"
     1818                             % len(points))
    18101819
    18111820    if alpha_list == None:
     
    18181827    domains = {}
    18191828
    1820     if verbose: print 'Setup computational domains with different alphas'
     1829    if verbose: log.critical('Setup computational domains with '
     1830                             'different alphas')
    18211831
    18221832    for alpha in alphas:
    18231833        # add G_other data to domains with different alphas
    18241834        if verbose:
    1825             print '\nCalculating domain and mesh for Alpha =', alpha, '\n'
     1835            log.critical('Calculating domain and mesh for Alpha = %s' %
     1836                         str(alpha))
    18261837        domain = Domain(mesh_file, use_cache=cache, verbose=verbose)
    1827         if verbose: print domain.statistics()
     1838        if verbose: log.critical(domain.statistics())
    18281839        domain.set_quantity(attribute_smoothed,
    18291840                            geospatial_data=G_other,
     
    18491860
    18501861    if verbose:
    1851         print 'Determine difference between predicted results and actual data'
     1862        log.critical('Determine difference between predicted results '
     1863                     'and actual data')
    18521864
    18531865    for i, alpha in enumerate(domains):
     
    18671879        ele_cov = cov(elevation_sample - elevation_predicted)
    18681880        normal_cov[i,:] = [alpha,ele_cov / sample_cov]
    1869         print 'memory usage during compare', mem_usage()
    1870         if verbose: print 'cov', normal_cov[i][0], '= ', normal_cov[i][1]
     1881        log.critical('memory usage during compare: %s' % str(mem_usage()))
     1882        if verbose: log.critical('cov %s = %s'
     1883                                 % (normal_cov[i][0], normal_cov[i][1]))
    18711884
    18721885    normal_cov0 = normal_cov[:,0]
Note: See TracChangeset for help on using the changeset viewer.