Changeset 1178
- Timestamp:
- Mar 31, 2005, 4:51:54 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r1171 r1178 50 50 from Numeric import concatenate 51 51 52 from coordinate_transforms.geo_reference import Geo_reference, DEFAULT_ZONE 52 53 53 54 def make_filename(s): … … 248 249 #FIXME: Use Georef 249 250 fid.starttime = domain.starttime 250 fid.xllcorner = domain.xllcorner251 fid.yllcorner = domain.yllcorner252 fid.zone = domain.zone253 251 254 252 # dimension definitions … … 267 265 fid.createVariable('y', self.precision, ('number_of_points',)) 268 266 fid.createVariable('elevation', self.precision, ('number_of_points',)) 269 267 if domain.geo_reference is not None: 268 domain.geo_reference.write_NetCDF(fid) 270 269 #FIXME: Backwards compatibility 271 270 fid.createVariable('z', self.precision, ('number_of_points',)) … … 1077 1076 false_northing = 10000000 1078 1077 NODATA_value = -9999 1079 #1080 1081 1078 1082 1079 if quantity is None: … … 1110 1107 number_of_points = fid.dimensions['number_of_points'] 1111 1108 if origin is None: 1112 xllcorner = fid.xllcorner[0] 1113 yllcorner = fid.yllcorner[0] 1114 zone = fid.zone[0] 1109 1110 # get geo_reference 1111 #sww files don't have to have a geo_ref 1112 try: 1113 geo_reference = Geo_reference(NetCDFObject=fid) 1114 except AttributeError, e: 1115 geo_reference = Geo_reference(DEFAULT_ZONE,0,0) 1116 1117 xllcorner = geo_reference.get_xllcorner() 1118 yllcorner = geo_reference.get_yllcorner() 1119 zone = geo_reference.get_zone() 1115 1120 else: 1116 1121 zone = origin[0] … … 1872 1877 ymomentum = fid.variables['ymomentum'] #Momentum in the y-direction 1873 1878 1874 xllcorner = fid.xllcorner[0]1875 yllcorner = fid.yllcorner[0]1876 1879 starttime = fid.starttime[0] 1877 zone = fid.zone1878 1880 volumes = fid.variables['volumes'][:] #Connectivity 1879 1881 coordinates=transpose(asarray([x.tolist(),y.tolist()])) … … 1883 1885 other_quantities = [] 1884 1886 1887 # get geo_reference 1888 #sww files don't have to have a geo_ref 1889 try: 1890 geo_reference = Geo_reference(NetCDFObject=fid) 1891 except AttributeError, e: 1892 geo_reference = None 1893 1885 1894 if verbose: print ' interpolating quantities' 1886 1895 for quantity in fid.variables.keys(): … … 1916 1925 if not boundary is None: 1917 1926 domain.boundary = boundary 1918 domain.zone=zone 1919 domain.xllcorner=float(xllcorner) 1920 domain.yllcorner=float(yllcorner) 1927 1928 domain.geo_reference = geo_reference 1921 1929 1922 1930 domain.starttime=float(starttime)+float(t) -
inundation/ga/storm_surge/pyvolution/domain.py
r1140 r1178 16 16 def __init__(self, coordinates, vertices, boundary = None, 17 17 conserved_quantities = None, other_quantities = None, 18 tagged_elements = None, zone=0, xllcorner=0, yllcorner=0): 19 20 Mesh.__init__(self, coordinates, vertices, boundary, tagged_elements) 18 tagged_elements = None, geo_reference = None): 19 20 Mesh.__init__(self, coordinates, vertices, boundary, 21 tagged_elements, geo_reference) 21 22 22 23 from Numeric import zeros, Float … … 73 74 #Origin in UTM coordinates 74 75 #FIXME: This should be set if read by a msh file 75 self.zone = zone76 self.xllcorner = xllcorner77 self.yllcorner = yllcorner76 #self.zone = zone 77 #self.xllcorner = xllcorner 78 #self.yllcorner = yllcorner 78 79 79 80 -
inundation/ga/storm_surge/pyvolution/general_mesh.py
r1011 r1178 1 1 2 from coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE 3 2 4 class General_mesh: 3 5 """Collection of triangular elements (purely geometric) … … 48 50 """ 49 51 50 def __init__(self, coordinates, triangles, origin = None): 52 def __init__(self, coordinates, triangles, 53 geo_reference=None): 51 54 """ 52 55 Build triangles from x,y coordinates (sequence of 2-tuples or … … 63 66 self.coordinates = array(coordinates) 64 67 65 self.origin = origin 68 if geo_reference is None: 69 self.geo_reference = Geo_reference(DEFAULT_ZONE,0.0,0.0) 70 else: 71 self.geo_reference = geo_reference 66 72 67 73 #Input checks -
inundation/ga/storm_surge/pyvolution/least_squares.py
r1160 r1178 28 28 from sparse import Sparse, Sparse_CSR 29 29 from cg_solve import conjugate_gradient, VectorShapeError 30 31 from coordinate_transforms.geo_reference import Geo_reference 32 30 33 import time 34 31 35 32 36 try: … … 303 307 #FIXME: Trying the normal mesh while testing precrop, 304 308 # The functionality of boundary_polygon is needed for that 309 310 #FIXME - geo ref does not have to go into mesh. 311 # Change the point co-ords to conform to the 312 # mesh co-ords early in the code 313 if mesh_origin == None: 314 geo = None 315 else: 316 geo = Geo_reference(mesh_origin[0],mesh_origin[1],mesh_origin[2]) 305 317 self.mesh = Mesh(vertex_coordinates, triangles, 306 origin = mesh_origin)318 geo_reference = geo) 307 319 #FIXME, remove if mesh checks it. 308 320 self.mesh.check_integrity() … … 392 404 393 405 #Shift data points to same origin as mesh (if specified) 394 mesh_origin = self.mesh.origin 406 407 #FIXME this will shift if there was no geo_ref. 408 #But all this should be removed amyhow. 409 #change coords before this point 410 mesh_origin = self.mesh.geo_reference.get_origin() 395 411 if point_coordinates is not None: 396 412 if data_origin is not None: -
inundation/ga/storm_surge/pyvolution/mesh.py
r1160 r1178 58 58 59 59 def __init__(self, coordinates, triangles, boundary = None, 60 tagged_elements = None, origin= None):60 tagged_elements = None, geo_reference = None): 61 61 """ 62 62 Build triangles from x,y coordinates (sequence of 2-tuples or … … 67 67 from Numeric import array, zeros, Int, Float, maximum, sqrt, sum 68 68 69 General_mesh.__init__(self, coordinates, triangles, origin)69 General_mesh.__init__(self, coordinates, triangles, geo_reference) 70 70 71 71 N = self.number_of_elements -
inundation/ga/storm_surge/pyvolution/pmesh2domain.py
r969 r1178 14 14 from domain import Domain 15 15 16 vertex_coordinates, volumes, tag_dict, vertex_quantity_dict ,tagged_elements_dict = \ 17 pmesh_to_domain(fileName, 18 setting_function=setting_function) 16 vertex_coordinates, volumes, tag_dict, vertex_quantity_dict \ 17 ,tagged_elements_dict, geo_reference = \ 18 pmesh_to_domain(fileName, 19 setting_function=setting_function) 19 20 20 assert issubclass(DomainClass, Domain), 21 assert issubclass(DomainClass, Domain),"DomainClass is not a subclass of Domain." 21 22 22 23 23 24 24 25 domain = DomainClass(vertex_coordinates, volumes, tag_dict, 25 tagged_elements = tagged_elements_dict ) 26 tagged_elements = tagged_elements_dict, 27 geo_reference = geo_reference ) 26 28 27 29 … … 35 37 # This doesn't work on the domain instance. 36 38 # This is still needed so -ve elevations don't cuase 'lakes' 37 # The fixme we discussed was to only create a quantity when its values are set. 39 # The fixme we discussed was to only create a quantity when its values 40 #are set. 38 41 # I think that's the way to go still 39 42 … … 70 73 volumes = mesh_dict['triangles'] 71 74 72 #if setting_function:73 # if not type(setting_function) is ListType:74 # setting_function = [setting_function]75 # for funct in setting_function:76 # mesh_dict = funct(mesh_dict, vertices = mesh_vertices,77 # volumes = volumes)78 79 80 75 vertex_quantity_dict = {} 81 76 point_atts = transpose(mesh_dict['vertex_attributes']) 82 77 point_titles = mesh_dict['vertex_attribute_titles'] 78 geo_reference = mesh_dict['geo_reference'] 83 79 for quantity, value_vector in map (None, point_titles, point_atts): 84 80 vertex_quantity_dict[quantity] = value_vector 85 81 tag_dict = pmesh_dict_to_tag_dict(mesh_dict) 86 82 tagged_elements_dict = build_tagged_elements_dictionary(mesh_dict) 87 return vertex_coordinates, volumes, tag_dict, vertex_quantity_dict,tagged_elements_dict 83 return vertex_coordinates, volumes, tag_dict, vertex_quantity_dict,tagged_elements_dict, geo_reference 88 84 89 85 -
inundation/ga/storm_surge/pyvolution/shallow_water.py
r1087 r1178 63 63 64 64 def __init__(self, coordinates, vertices, boundary = None, 65 tagged_elements = None ):65 tagged_elements = None, geo_reference = None): 66 66 67 67 conserved_quantities = ['stage', 'xmomentum', 'ymomentum'] 68 68 other_quantities = ['elevation', 'friction'] 69 70 69 Generic_domain.__init__(self, coordinates, vertices, boundary, 71 70 conserved_quantities, other_quantities, 72 tagged_elements )71 tagged_elements, geo_reference) 73 72 74 73 from config import minimum_allowed_height, g -
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r1171 r1178 10 10 from shallow_water import * 11 11 from config import epsilon 12 13 from coordinate_transforms.geo_reference import Geo_reference 12 14 13 15 class Test_Data_Manager(unittest.TestCase): … … 604 606 self.domain.set_quantity('elevation', lambda x,y: -x-y) 605 607 606 self.domain.xllcorner = 308500 607 self.domain.yllcorner = 6189000 608 self.domain.zone = 56 609 608 self.domain.geo_reference = Geo_reference(56,308500,6189000) 610 609 611 610 sww = get_dataobject(self.domain) … … 746 745 self.domain.set_quantity('elevation', lambda x,y: -x-y) 747 746 748 self.domain.xllcorner = 308500 749 self.domain.yllcorner = 6189000 750 self.domain.zone = 56 747 self.domain.geo_reference = Geo_reference(56,308500,6189000) 751 748 752 749 … … 897 894 domain.smooth = True 898 895 899 900 domain.xllcorner = 308500 901 domain.yllcorner = 6189000 902 domain.zone = 56 903 896 domain.geo_reference = Geo_reference(56,308500,6189000) 904 897 905 898 sww = get_dataobject(domain) … … 919 912 time = fid.variables['time'][:] 920 913 914 try: 915 geo_reference = Geo_reference(NetCDFObject=fid) 916 except AttributeError, e: 917 geo_reference = Geo_reference(DEFAULT_ZONE,0,0) 918 921 919 #Export to ascii/prj files 922 920 sww2asc(domain.filename, … … 1345 1343 yiel=0.01 1346 1344 points, vertices, boundary = rectangular(10,10) 1345 1347 1346 #Create shallow water domain 1348 1347 domain = Domain(points, vertices, boundary) 1348 domain.geo_reference = Geo_reference(56,11,11) 1349 1349 domain.smooth = False 1350 1350 domain.visualise = False … … 1395 1395 ################### 1396 1396 1397 bits = ['xllcorner','yllcorner','vertex_coordinates'] 1398 1397 bits = [ 'geo_reference.get_xllcorner()', 1398 'geo_reference.get_yllcorner()', 1399 'vertex_coordinates'] 1399 1400 for quantity in ['elevation']+domain.quantities_to_be_stored: 1400 1401 bits.append('quantities["%s"].get_integral()'%quantity) … … 1402 1403 1403 1404 for bit in bits: 1404 #print 'testing that domain.'+bit+' has been restored'1405 #print bit1405 #print 'testing that domain.'+bit+' has been restored' 1406 #print bit 1406 1407 #print 'done' 1407 1408 assert allclose(eval('domain.'+bit),eval('domain2.'+bit)) … … 1452 1453 ################## 1453 1454 1454 bits = ['xllcorner','yllcorner','vertex_coordinates'] 1455 bits = [ 'geo_reference.get_xllcorner()', 1456 'geo_reference.get_yllcorner()', 1457 'vertex_coordinates'] 1455 1458 1456 1459 for quantity in ['elevation','xmomentum','ymomentum']:#+domain.quantities_to_be_stored: … … 1528 1531 filler = 0 1529 1532 domain2 = sww2domain(filename,None,fail_if_NaN=False,NaN_filler = filler,verbose=False) 1530 1531 bits = ['xllcorner','yllcorner','vertex_coordinates'] 1533 bits = [ 'geo_reference.get_xllcorner()', 1534 'geo_reference.get_yllcorner()', 1535 'vertex_coordinates'] 1532 1536 1533 1537 for quantity in ['elevation']+domain.quantities_to_be_stored: … … 1569 1573 if __name__ == "__main__": 1570 1574 suite = unittest.makeSuite(Test_Data_Manager,'test') 1571 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2 asc_stage')1575 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2domain') 1572 1576 runner = unittest.TextTestRunner() 1573 1577 runner.run(suite) -
inundation/ga/storm_surge/pyvolution/test_pmesh2domain.py
r1028 r1178 22 22 from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ 23 23 Transmissive_boundary 24 25 from coordinate_transforms.geo_reference import Geo_reference 24 26 25 27 … … 64 66 2 2 0 0 \n \ 65 67 0 # <x> <y> ...Mesh Holes... \n \ 66 0 # <x> <y> <attribute>...Mesh Regions... \n") 68 0 # <x> <y> <attribute>...Mesh Regions... \n \ 69 0 # <x> <y> <attribute>...Mesh Regions, area... \n \ 70 # Geo reference \n \ 71 56 \n \ 72 140 \n \ 73 120 \n") 67 74 file.close() 68 75 … … 112 119 self.failUnless( len(domain.boundary) == 4, 113 120 "test_pmesh2Domain Too many boundaries") 121 #FIXME change to use get_xllcorner 122 self.failUnless(domain.geo_reference.xllcorner == 140.0, 123 "bad geo_referece") 124 114 125 def old_test_tags_to_boundaries (self): 115 126 meshDict = {}
Note: See TracChangeset
for help on using the changeset viewer.