Changeset 9323


Ignore:
Timestamp:
Sep 4, 2014, 6:45:53 PM (10 years ago)
Author:
steve
Message:

Found bug with reading in xya type data

Location:
trunk/anuga_core/source/anuga
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py

    r9319 r9323  
    384384        nodes = num.array([a, b, c, d, e, f])
    385385
    386        
    387386        #                        bac,     bce,     ecf,     dbe
    388387        triangles = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], num.int)
  • trunk/anuga_core/source/anuga/fit_interpolate/fit.py

    r8970 r9323  
    527527    """
    528528
    529     from load_mesh.loadASCII import import_mesh_file, \
     529    from anuga.load_mesh.loadASCII import import_mesh_file, \
    530530         export_mesh_file, concatinate_attributelist
    531531
  • trunk/anuga_core/source/anuga/load_mesh/loadASCII.py

    r8780 r9323  
    7070
    7171from anuga.file.netcdf import NetCDFFile
     72from anuga.utilities.numerical_tools import ensure_numeric
    7273
    7374import numpy as num
     
    9697    #FIXME No test for ValueError
    9798    except (TitleError, SyntaxError, IndexError, ValueError):
    98         msg = 'File could not be opened'
     99        msg = 'File %s could not be opened' % ofile
    99100        raise IOError, msg
     101   
    100102    return dict
    101103
     
    350352            else:
    351353                regionmaxareas.append(float(fragments[0]))
    352         except IndexError, e:
     354        except (ValueError, IndexError), e:
    353355            regionmaxareas.append(None)
    354356
     
    376378    vertices = gen_dict['vertices']
    377379    vertices_attributes = gen_dict['vertex_attributes']
     380
    378381    try:
    379382        vertices_attribute_titles = gen_dict['vertex_attribute_titles']
     
    381384        #FIXME is this the best way?
    382385        if vertices_attributes == [] or vertices_attributes[0] == []:
    383              vertices_attribute_titles = []
     386            vertices_attribute_titles = []
    384387        else:
    385388            raise KeyError, e
     389       
    386390
    387391    triangles = gen_dict['triangles']
     
    400404        numVertAttrib = "0"
    401405    else:
    402         numVertAttrib = str(len(vertices_attributes[0]))
     406        #numVertAttrib = str(len(vertices_attributes[0]))
     407        try:
     408            numVertAttrib = str(len(vertices_attributes[0]))
     409        except TypeError:
     410            vertices_attributes = [ [entry] for entry in vertices_attributes]
     411            numVertAttrib = str(len(vertices_attributes[0]))
     412       
     413
    403414
    404415    fd.write(numVert + " " + numVertAttrib +
  • trunk/anuga_core/source/anuga/load_mesh/test_loadASCII.py

    r8120 r9323  
    3737        self.dict['vertex_attribute_titles'] = ['bed elevation', 'height']
    3838        self.dict['geo_reference'] = Geo_reference(56, 1.9, 1.9)
     39       
     40       
     41        self.dict_1 = {}
     42        self.dict_1['outline_segments'] = [(0, 1), (1, 2), (0, 2), (0, 3)]
     43        self.dict_1['outline_segment_tags'] = ['50', '40', '30', '20']
     44        self.dict_1['holes'] = [(0.2, 0.6)]
     45        self.dict_1['point_attributes'] = [[5], [4], [3], [2]]
     46        self.dict_1['regions'] = [(0.3, 0.3), (0.3, 0.4)]
     47        self.dict_1['region_tags'] = ['1.3', 'yeah']
     48        self.dict_1['region_max_areas'] = [36.0, -7.1]
     49        self.dict_1['points'] = [(0.0, 0.0), (0.0, 4.0), (4.0, 0.0), (1.0, 1.0)]
     50        self.dict_1['vertices'] = [(0.0, 0.0), (0.0, 4.0), (4.0, 0.0),
     51                                 (1.0, 1.0), (2.0, 2.0)]
     52        self.dict_1['triangles'] = [(3, 2, 4), (1, 0, 3), (3, 4,1), (2, 3, 0)]
     53        self.dict_1['segments'] = [(0, 1), (1, 4), (2, 0), (0, 3), (4, 2)]
     54        self.dict_1['triangle_tags'] = ['1.3', '1.3', '1.3', '1.3']
     55        self.dict_1['vertex_attributes'] = [[1.2], [1.2], [1.2],
     56                                         [1.2], [1.2]]
     57        self.dict_1['triangle_neighbors'] = [[-1, 2, 3], [3, 2, -1],
     58                                           [-1, 1, 0], [1, -1, 0]]
     59        self.dict_1['segment_tags'] = ['50', '40', '30', '20', '40']
     60        self.dict_1['vertex_attribute_titles'] = ['height']
     61        self.dict_1['geo_reference'] = Geo_reference(56, 1.9, 1.9)       
    3962
    4063        self.sparse_dict = {}
     
    201224
    202225        os.remove(fileName)
     226       
     227       
     228    def test_export_mesh_1_file(self):
     229        meshDict = self.dict_1
     230        fileName = tempfile.mktemp('.tsh')
     231        export_mesh_file(fileName, meshDict)
     232        loadedDict = import_mesh_file(fileName)
     233       
     234
     235        self.failUnless(num.alltrue(num.array(meshDict['vertices']) ==
     236                                    num.array(loadedDict['vertices'])),
     237                        'test_export_mesh_file failed. Test 1')
     238        self.failUnless(num.alltrue(num.array(meshDict['triangles']) ==
     239                                    num.array(loadedDict['triangles'])),
     240                        'test_export_mesh_file failed. Test 2')
     241        self.failUnless(num.alltrue(num.array(meshDict['segments']) ==
     242                                    num.array(loadedDict['segments'])),
     243                        'test_export_mesh_file failed. Test 3')
     244        self.failUnless(num.alltrue(num.array(meshDict['triangle_tags']) ==
     245                                    num.array(loadedDict['triangle_tags'])),
     246                        'test_export_mesh_file failed. Test 4')
     247
     248        self.failUnless(meshDict['vertex_attributes'] ==
     249                        loadedDict['vertex_attributes'],
     250                        'test_export_mesh_file failed. Test 5')
     251        self.failUnless(num.alltrue(num.array(meshDict['triangle_neighbors']) ==
     252                                    num.array(loadedDict['triangle_neighbors'])),
     253                        'test_export_mesh_file failed. Test 6')
     254        self.failUnless(num.alltrue(num.array(meshDict['segment_tags']) ==
     255                                    num.array(loadedDict['segment_tags'])),
     256                        'test_export_mesh_file failed. Test 7')
     257        self.failUnless(num.alltrue(num.array(meshDict['vertex_attribute_titles']) ==
     258                                    num.array(loadedDict['vertex_attribute_titles'])),
     259                        'test_export_mesh_file failed. Test 8')
     260        self.failUnless(num.alltrue(num.array(meshDict['geo_reference']) ==
     261                                    num.array(loadedDict['geo_reference'])),
     262                        'test_export_mesh_file failed. Test 9')
     263
     264
     265        #os.remove(fileName)       
    203266
    204267    def test_read_write_tsh_file(self):
Note: See TracChangeset for help on using the changeset viewer.