Changeset 6904


Ignore:
Timestamp:
Apr 25, 2009, 11:00:44 PM (15 years ago)
Author:
rwilson
Message:

Finished back-merge from Numeric trunk to numpy branch (and some code the other way).

Files:
11 edited

Legend:

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

    r6718 r6904  
    3535def list_names(names, func=None, col_width=None, page_width=None):
    3636    # set defaults
    37     p_width = page_width                # set page width
     37    p_width = page_width - 1            # set page width
    3838    if p_width is None:
    3939        p_width = 132                   # default page width
     
    4646                name = func(name)
    4747            c_width = max(c_width, len(name))
    48         c_width += 2                    # padding between columns
     48    c_width += 2                        # 2 column padding
    4949
    5050    # calculate number of columns allowed
     
    5656        if func:
    5757            name = func(name)
    58         print '%-*s' % (c_width, name),
     58        print '%-*s' % (c_width-1, name),
    5959        column += 1
    6060        if column >= max_columns:
     
    102102    print 'Testing path: %s' % path
    103103
     104    # get the terminal width
     105    term_width = terminal_width()
     106
    104107    # explain what we are doing
    105108    print
    106109    print "The following directories will be skipped over:"
    107110    exclude_dirs.sort()
    108     list_names(exclude_dirs)
     111    list_names(exclude_dirs, page_width=term_width)
    109112
    110113    # get all test_*.py and enclosing directories
     
    116119    print
    117120    print 'Paths searched:'
    118     list_names(path_files, os.path.basename)
     121    list_names(path_files, os.path.basename, page_width=term_width)
    119122
    120123    print   
    121124    print 'Files tested:'
    122     list_names(files)
     125    list_names(files, page_width=term_width)
    123126    print
    124127
  • anuga_core/source/anuga/utilities/system_tools.py

    r6892 r6904  
    303303           
    304304##
    305 # @brief Get list of variable names in an expression string.
     305# @brief Get list of variable names in a python expression string.
    306306# @param source A string containing a python expression.
    307307# @return A list of variable name strings.
  • branches/numpy/anuga/abstract_2d_finite_volumes/domain.py

    r6902 r6904  
    17581758        # We have a list with ghosts expecting updates
    17591759
    1760         from Numeric import take,put
    1761 
    1762 
    17631760        #Update of ghost cells
    17641761        iproc = self.processor
     
    17731770            for i, q in enumerate(self.conserved_quantities):
    17741771                Q_cv =  self.quantities[q].centroid_values
    1775                 put(Q_cv,     Idg, take(Q_cv,     Idf))
     1772                num.put(Q_cv, Idg, num.take(Q_cv, Idf, axis=0))
    17761773
    17771774 
  • branches/numpy/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py

    r6902 r6904  
    9898    # Transmissive_Momentum_Set_Stage_Boundary (cf posting by rrraman)
    9999    def __init__(self, domain=None,
    100                  f=None,
     100                 f=None, # Should be removed and replaced by function below
     101                 function=None,
    101102                 default_boundary=None,
    102103                 verbose=False):
  • branches/numpy/anuga/abstract_2d_finite_volumes/mesh_factory.py

    r6902 r6904  
    259259    E = EIndex(n,m)
    260260
    261     points = num.zeros( (Np,2), num.Float)
     261    points = num.zeros( (Np,2), num.float)
    262262
    263263    for i in range(m+1):
     
    271271
    272272
    273     elements = num.zeros( (Nt,3), num.Int)
     273    elements = num.zeros( (Nt,3), num.int)
    274274    boundary = {}
    275275    Idgl = []
     
    339339    Idgr.extend(Idgl)
    340340
    341     Idfl = num.array(Idfl, num.Int)
    342     Idgr = num.array(Idgr, num.Int)
     341    Idfl = num.array(Idfl, num.int)
     342    Idgr = num.array(Idgr, num.int)
    343343   
    344344    full_send_dict[processor]  = [Idfl, Idfl]
  • branches/numpy/anuga/compile_all.py

    r6553 r6904  
    2828   
    2929if sys.platform == 'win32':
    30     raw_input('Press any key')
     30    raw_input('Press the RETURN key')
  • branches/numpy/anuga/load_mesh/loadASCII.py

    r6902 r6904  
    817817        mesh['vertex_attributes'] = None
    818818
    819 #    mesh['vertex_attribute_titles'] = []
     819    mesh['vertex_attribute_titles'] = []
    820820    try:
    821821        titles = fid.variables['vertex_attribute_titles'][:]
     
    829829        mesh['segments'] = num.array([], num.int)      #array default#
    830830
    831 #    mesh['segment_tags'] = []
     831    mesh['segment_tags'] = []
    832832    try:
    833833        tags = fid.variables['segment_tags'][:]
     
    844844        mesh['triangle_neighbors'] = num.array([], num.int)     #array default#
    845845
    846 #    mesh['triangle_tags'] = []
     846    mesh['triangle_tags'] = []
    847847    try:
    848848        tags = fid.variables['triangle_tags'][:]
  • branches/numpy/anuga/load_mesh/test_loadASCII.py

    r6902 r6904  
    398398        assert num.allclose(num.array(dict['segments']),
    399399                            num.array(loaded_dict['segments']))
    400 
    401         self.failUnlessEqual(dict['triangle_tags'], loaded_dict['triangle_tags'])
    402 
    403400        for ob, ldob in map(None, dict['triangle_tags'],
    404401                            loaded_dict['triangle_tags']):
     
    424421            self.failUnless(seg == ldseg, fail_string + ' failed\n' + msg)
    425422
    426 #        dict_array = num.array(dict['vertex_attribute_titles'])
    427 #        loaded_dict_array = num.array(loaded_dict['vertex_attribute_titles'])
    428         try:
    429             assert num.allclose(dict_array, loaded_dict_array)
    430         #except TypeError:      #??#
     423        try:
     424            assert num.allclose(num.array(dict['vertex_attribute_titles']),
     425                                num.array(loaded_dict['vertex_attribute_titles']))
    431426        except IndexError:
    432             self.failUnless(num.alltrue(loaded_dict_array == dict_array),
     427            self.failUnless(num.alltrue(num.array(loaded_dict['vertex_attribute_titles'])
     428                            == num.array(dict['vertex_attribute_titles'])),
    433429                            fail_string + ' failed!! Test 8')
    434430
  • branches/numpy/anuga/test_all.py

    r6553 r6904  
    217217   
    218218    if sys.platform == 'win32':
    219         raw_input('Press any key')
     219        raw_input('Press the RETURN key')
  • branches/numpy/anuga/utilities/polygon_ext.c

    r6553 r6904  
    330330
    331331int __separate_points_by_polygon(int M,     // Number of points
    332                                 int N,     // Number of polygon vertices
    333                                 double* points,
    334                                 double* polygon,
    335                                 long* indices,  // M-Array for storage indices
    336                                 int closed,
    337                                 int verbose) {
     332                                 int N,     // Number of polygon vertices
     333                                 double* points,
     334                                 double* polygon,
     335                                 long* indices,  // M-Array for storage indices
     336                                 int closed,
     337                                 int verbose) {
    338338
    339339  double minpx, maxpx, minpy, maxpy, x, y, px_i, py_i, px_j, py_j, rtol=0.0, atol=0.0;
    340340  int i, j, k, outside_index, inside_index, inside;
    341341
    342   //Find min and max of poly used for optimisation when points
    343   //are far away from polygon
    344  
    345   //FIXME(Ole): Pass in rtol and atol from Python
     342  // Find min and max of poly used for optimisation when points
     343  // are far away from polygon
     344 
     345  // FIXME(Ole): Pass in rtol and atol from Python
    346346
    347347  minpx = polygon[0]; maxpx = minpx;
     
    358358  }
    359359
    360   //Begin main loop (for each point)
    361   inside_index = 0;    //Keep track of points inside
    362   outside_index = M-1; //Keep track of points outside (starting from end)   
     360  // Begin main loop (for each point)
     361  inside_index = 0;    // Keep track of points inside
     362  outside_index = M-1; // Keep track of points outside (starting from end)   
    363363  if (verbose){
    364364     printf("Separating %d points\n", M);
     
    374374    inside = 0;
    375375
    376     //Optimisation
     376    // Optimisation
    377377    if ((x > maxpx) || (x < minpx) || (y > maxpy) || (y < minpy)) {
    378       //Nothing
     378      // Nothing
    379379    } else {   
    380       //Check polygon
     380      // Check polygon
    381381      for (i=0; i<N; i++) {
    382         //printf("k,i=%d,%d\n", k, i);
    383382        j = (i+1)%N;
    384383
     
    388387        py_j = polygon[2*j+1];
    389388
    390         //Check for case where point is contained in line segment
     389        // Check for case where point is contained in line segment
    391390        if (__point_on_line(x, y, px_i, py_i, px_j, py_j, rtol, atol)) {
    392391          if (closed == 1) {
  • branches/numpy/anuga/utilities/system_tools.py

    r6825 r6904  
    5050
    5151def get_revision_number():
    52     """Get the version number of the SVN
     52    """Get the version number of this repository copy.
     53
     54    Try getting data from stored_version_info.py first, otherwise
     55    try using SubWCRev.exe (Windows) or svnversion (linux), otherwise
     56    try reading file .svn/entries for version information, otherwise
     57    throw an exception.
     58
    5359    NOTE: This requires that the command svn is on the system PATH
    5460    (simply aliasing svn to the binary will not work)
    5561    """
    5662
    57     # FIXME (Ole): Change this so that svn info is attempted first.
    58     # If that fails, try to read a stored file with that same info (this would
    59     # be created by e.g. the release script). Failing that, throw an exception.
    60     # FIXME (Ole): Move this and store_version_info to utilities
     63    def get_revision_from_svn_entries():
     64        '''Get a subversion revision number from the .svn/entires file.'''
     65
     66        msg = '''
     67No version info stored and command 'svn' is not recognised on the system PATH.
     68
     69If ANUGA has been installed from a distribution e.g. as obtained from SourceForge,
     70the version info should be available in the automatically generated file
     71'stored_version_info.py' in the anuga root directory.
     72
     73If run from a Subversion sandpit, ANUGA will try to obtain the version info by
     74using the command 'svn info'.  In this case, make sure the command line client
     75'svn' is accessible on the system path.  Simply aliasing 'svn' to the binary will
     76not work.
     77
     78If you are using Windows, you have to install the file svn.exe which can be
     79obtained from http://www.collab.net/downloads/subversion.
     80
     81Good luck!
     82'''
     83
     84        try:
     85            fd = open(os.path.join('.svn', 'entries'))
     86        except:
     87            raise Exception, msg
     88
     89        line = fd.readlines()[3]
     90        fd.close()
     91        try:
     92            revision_number = int(line)
     93        except:
     94            msg = ".svn/entries, line 4 was '%s'?" % line.strip()
     95            raise Exception, msg
     96
     97        return revision_number
     98
     99    def get_revision_from_svn_client():
     100        '''Get a subversion revision number from an svn client.'''
     101
     102        if sys.platform[0:3] == 'win':
     103            try:
     104                fid = os.popen(r'C:\Program Files\TortoiseSVN\bin\SubWCRev.exe')
     105            except:
     106                return get_revision_from_svn_entries()
     107            else:
     108                version_info = fid.read()
     109                if version_info == '':
     110                    return get_revision_from_svn_entries()
     111
     112            # split revision number from data
     113            for line in version_info.split('\n'):
     114                if line.startswith('Updated to revision '):
     115                    break
     116
     117            fields = line.split(' ')
     118            msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info
     119            assert fields[0].startswith('Updated'), msg
     120
     121            try:
     122                revision_number = int(fields[3])
     123            except:
     124                msg = ("Revision number must be an integer. I got '%s' from "
     125                       "'SubWCRev.exe'." % fields[3])
     126                raise Exception, msg
     127        else:                   # assume Linux
     128            try:
     129                fid = os.popen('svnversion -n . 2>/dev/null')
     130            except:
     131                return get_revision_from_svn_entries()
     132            else:
     133                version_info = fid.read()
     134                if version_info == '':
     135                    return get_revision_from_svn_entries()
     136
     137            # split revision number from data
     138            if ':' in version_info:
     139                (_, revision_number) =  version_info.split(':')
     140            elif version_info.endswith('M'):
     141                revision_number = version_info[:-1]
     142            else:
     143                revision_number = version_info
     144
     145            try:
     146                revision_number = int(revision_number)
     147            except:
     148                msg = ("Revision number must be an integer. I got '%s' from "
     149                       "'svn'." % version_info)
     150                raise Exception, msg
     151
     152        return revision_number
     153
     154    # try to get revision information from stored_version_info.py
    61155    try:
    62156        from anuga.stored_version_info import version_info
    63157    except:
    64         msg = '''
    65 No version info stored and command 'svn' is not recognised on the system PATH.
    66 
    67 If ANUGA has been installed from a distribution e.g. as obtained from
    68 SourceForge, the version info should be available in the automatically
    69 generated file 'stored_version_info.py' in the anuga root directory.
    70 
    71 If run from a Subversion sandpit, ANUGA will try to obtain the version info
    72 by using the command 'svn info'.  In this case, make sure 'svn' is accessible
    73 on the system PATH.  Simply aliasing 'svn' to the binary will not work.
    74 
    75 If you are using Windows, you have to install the file svn.exe which can be
    76 obtained from http://www.collab.net/downloads/subversion.
    77 
    78 Good luck!
    79 '''
    80 
    81         # No file available - try using Subversion
    82         try:
    83             # The null stuff is so this section fails quitly.
    84             # This could cause the svn info command to fail due to
    85             # the redirection being bad on some platforms.
    86             # If that occurs then change this code.
    87             if sys.platform[0:3] == 'win':
    88                 fid = os.popen('svn info 2> null')
    89             else:
    90                 fid = os.popen('svn info 2>/dev/null')
    91         except:
    92             raise Exception(msg)
    93         else:
    94             version_info = fid.read()
    95 
    96         if version_info == '':
    97             raise Exception, msg
    98     else:
    99         pass
    100         #print 'Got version from file'
    101            
     158        return get_revision_from_svn_client()
     159
     160    # split revision number from data
    102161    for line in version_info.split('\n'):
    103162        if line.startswith('Revision:'):
     
    106165    fields = line.split(':')
    107166    msg = 'Keyword "Revision" was not found anywhere in text: %s' % version_info
    108     assert fields[0].startswith('Revision'), msg           
     167    assert fields[0].startswith('Revision'), msg
    109168
    110169    try:
    111170        revision_number = int(fields[1])
    112171    except:
    113         msg = 'Revision number must be an integer. I got %s' %fields[1]
    114         msg += 'Check that the command svn is on the system path'
     172        msg = ("Revision number must be an integer. I got '%s'.\n"
     173               'Check that the command svn is on the system path.'
     174               % fields[1])
    115175        raise Exception, msg
    116176
     
    355415# @param auth Auth tuple (httpproxy, proxyuser, proxypass).
    356416# @param blocksize Read file in this block size.
    357 # @return 'auth' tuple for subsequent calls, if successful, else False.
     417# @return (True, auth) if successful, else (False, auth).
    358418# @note If 'auth' not supplied, will prompt user.
    359419# @note Will try using environment variable HTTP_PROXY for proxy server.
     
    379439    try:
    380440        urllib.urlretrieve(file_url, file_name)
    381         return None     # no proxy, no auth required
     441        return (True, auth)     # no proxy, no auth required
    382442    except IOError, e:
    383443        if e[1] == 407:     # proxy error
     
    385445        elif e[1][0] == 113:  # no route to host
    386446            print 'No route to host for %s' % file_url
    387             return False    # return False
     447            return (False, auth)    # return False
    388448        else:
    389449            print 'Unknown connection error to %s' % file_url
    390             return False
     450            return (False, auth)
    391451
    392452    # We get here if there was a proxy error, get file through the proxy
     
    437497    try:
    438498        webget = urllib2.urlopen(file_url)
    439     except urllib2.HTTPError:
    440         return False
     499    except urllib2.HTTPError, e:
     500        print 'Error received from proxy:\n%s' % str(e)
     501        print 'Possibly the user/password is wrong.'
     502        return (False, (httpproxy, proxyuser, proxypass))
    441503
    442504    # transfer file to local filesystem
     
    451513
    452514    # return successful auth info
    453     return (httpproxy, proxyuser, proxypass)
     515    return (True, (httpproxy, proxyuser, proxypass))
    454516
    455517
     
    483545
    484546##
    485 # @brief Return a hex digest string for a given file.
     547# @brief Return a hex digest (MD5) of a given file.
    486548# @param filename Path to the file of interest.
    487549# @param blocksize Size of data blocks to read.
Note: See TracChangeset for help on using the changeset viewer.