Changeset 4381
- Timestamp:
- Apr 16, 2007, 3:28:39 PM (18 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r4380 r4381 671 671 fid.sync() 672 672 fid.close() 673 674 675 676 677 678 #Function for storing xya output679 #FIXME Not done yet for this version680 #This is obsolete. Use geo_spatial_data instead681 class Data_format_xya(Data_format):682 """Generic interface to data formats683 """684 685 686 def __init__(self, domain, mode = 'w'):687 from Scientific.IO.NetCDF import NetCDFFile688 from Numeric import Int, Float, Float32689 690 self.precision = Float32 #Use single precision691 692 Data_format.__init__(self, domain, 'xya', mode)693 694 695 696 #FIXME -This is the old xya format697 def store_all(self):698 """Specialisation of store all for xya format699 700 Writes x,y,z coordinates of triangles constituting701 the bed elevation.702 """703 704 from Numeric import concatenate705 706 domain = self.domain707 708 fd = open(self.filename, 'w')709 710 711 if domain.smooth is True:712 number_of_points = len(domain.vertexlist)713 else:714 number_of_points = 3*self.number_of_volumes715 716 numVertAttrib = 3 #Three attributes is what is assumed by the xya format717 718 fd.write(str(number_of_points) + " " + str(numVertAttrib) +\719 " # <vertex #> <x> <y> [attributes]" + "\n")720 721 722 # Get X, Y, bed elevation and friction (index=0,1)723 X,Y,A,V = domain.get_vertex_values(xy=True, value_array='field_values',724 indices = (0,1), precision = self.precision)725 726 bed_eles = A[:,0]727 fricts = A[:,1]728 729 # Get stage (index=0)730 B,V = domain.get_vertex_values(xy=False, value_array='conserved_quantities',731 indices = (0,), precision = self.precision)732 733 stages = B[:,0]734 735 #<vertex #> <x> <y> [attributes]736 for x, y, bed_ele, stage, frict in map(None, X, Y, bed_eles,737 stages, fricts):738 739 s = '%.6f %.6f %.6f %.6f %.6f\n' %(x, y, bed_ele, stage, frict)740 fd.write(s)741 742 #close743 fd.close()744 745 746 def store_timestep(self, t, V0, V1, V2):747 """Store time, water heights (and momentums) to file748 """749 pass750 673 751 674 … … 1229 1152 return cls(domain, mode) 1230 1153 1231 #FIXME move into geospatial. There should only be one method that 1232 # reads xya, and writes pts. 1233 def xya2pts(basename_in, basename_out=None, verbose=False, 1234 #easting_min=None, easting_max=None, 1235 #northing_min=None, northing_max=None, 1236 stride = 1, 1237 attribute_name = 'elevation', 1238 z_func = None): 1239 """Read points data from ascii (.xya) 1240 1241 Example: 1242 1243 x(m) y(m) z(m) 1244 0.00000e+00 0.00000e+00 1.3535000e-01 1245 0.00000e+00 1.40000e-02 1.3535000e-01 1246 1247 1248 1249 Convert to NetCDF pts format which is 1250 1251 points: (Nx2) Float array 1252 elevation: N Float array 1253 1254 Only lines that contain three numeric values are processed 1255 1256 If z_func is specified, it will be applied to the third field 1257 """ 1258 1259 import os 1260 #from Scientific.IO.NetCDF import NetCDFFile 1261 from Numeric import Float, arrayrange, concatenate 1262 1263 root, ext = os.path.splitext(basename_in) 1264 1265 if ext == '': ext = '.xya' 1266 1267 #Get NetCDF 1268 infile = open(root + ext, 'r') #Open existing xya file for read 1269 1270 if verbose: print 'Reading xya points from %s' %(root + ext) 1271 1272 points = [] 1273 attribute = [] 1274 for i, line in enumerate(infile.readlines()): 1275 1276 if i % stride != 0: continue 1277 1278 fields = line.split() 1279 1280 try: 1281 assert len(fields) == 3 1282 except: 1283 print 'WARNING: Line %d doesn\'t have 3 elements: %s' %(i, line) 1284 1285 try: 1286 x = float( fields[0] ) 1287 y = float( fields[1] ) 1288 z = float( fields[2] ) 1289 except: 1290 continue 1291 1292 points.append( [x, y] ) 1293 1294 if callable(z_func): 1295 attribute.append(z_func(z)) 1296 else: 1297 attribute.append(z) 1298 1299 1300 #Get output file 1301 if basename_out == None: 1302 ptsname = root + '.pts' 1303 else: 1304 ptsname = basename_out + '.pts' 1305 1306 if verbose: print 'Store to NetCDF file %s' %ptsname 1307 write_ptsfile(ptsname, points, attribute, attribute_name) 1308 1309 1310 1311 ######Obsoleted by export_points in load_mesh 1312 def write_ptsfile(ptsname, points, attribute, attribute_name = None, 1313 zone=None, xllcorner=None, yllcorner=None): 1314 """Write points and associated attribute to pts (NetCDF) format 1315 """ 1316 1317 print 'WARNING: write_ptsfile is obsolete. Use export_points from load_mesh.loadASCII instead.' 1318 1319 from Numeric import Float 1320 1321 if attribute_name is None: 1322 attribute_name = 'attribute' 1323 1324 1325 from Scientific.IO.NetCDF import NetCDFFile 1326 1327 # NetCDF file definition 1328 outfile = NetCDFFile(ptsname, 'w') 1329 1330 1331 #Create new file 1332 outfile.institution = 'Geoscience Australia' 1333 outfile.description = 'NetCDF pts format for compact and '\ 1334 'portable storage of spatial point data' 1335 1336 1337 #Georeferencing 1338 from anuga.coordinate_transforms.geo_reference import Geo_reference 1339 if zone is None: 1340 assert xllcorner is None, 'xllcorner must be None' 1341 assert yllcorner is None, 'yllcorner must be None' 1342 Geo_reference().write_NetCDF(outfile) 1343 else: 1344 Geo_reference(zone, xllcorner, yllcorner).write_NetCDF(outfile) 1345 1346 1347 1348 outfile.createDimension('number_of_points', len(points)) 1349 outfile.createDimension('number_of_dimensions', 2) #This is 2d data 1350 1351 # variable definitions 1352 outfile.createVariable('points', Float, ('number_of_points', 1353 'number_of_dimensions')) 1354 outfile.createVariable(attribute_name, Float, ('number_of_points',)) 1355 1356 # Get handles to the variables 1357 nc_points = outfile.variables['points'] 1358 nc_attribute = outfile.variables[attribute_name] 1359 1360 #Store data 1361 nc_points[:, :] = points 1362 nc_attribute[:] = attribute 1363 1364 outfile.close() 1154 1365 1155 1366 1156 … … 2047 1837 2048 1838 #Interpolate 2049 #from least_squares import Interpolation2050 1839 from anuga.fit_interpolate.interpolate import Interpolate 2051 1840 … … 4492 4281 4493 4282 """ 4494 #FIXME cache this function!4495 4283 4496 4284 from sets import ImmutableSet … … 4533 4321 sqrt_2_rounded_up = 1.415 4534 4322 buffer = sqrt_2_rounded_up * grid_spacing 4535 4536 #4537 4323 4538 4324 max_lat = max(seg_lat_long[0][0], seg_lat_long[1][0]) + buffer … … 4693 4479 # This mesh has a problem. Triangles are streched over ungridded areas. 4694 4480 # If these areas could be described as holes in pmesh, that would be great 4695 4481 4482 # I can't just get the user to selection a point in the middle. 4483 # A boundary is needed around these points. 4484 # But if the zone of points is obvious enough auto-segment should do 4485 # a good boundary. 4696 4486 mesh = Mesh() 4697 4487 mesh.add_vertices(points_utm) -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r4378 r4381 572 572 os.remove(sww.filename) 573 573 574 575 #def test_write_pts(self):576 # #Obsolete577 #578 # #Get (enough) datapoints579 #580 # from Numeric import array581 # points = array([[ 0.66666667, 0.66666667],582 # [ 1.33333333, 1.33333333],583 # [ 2.66666667, 0.66666667],584 # [ 0.66666667, 2.66666667],585 # [ 0.0, 1.0],586 # [ 0.0, 3.0],587 # [ 1.0, 0.0],588 # [ 1.0, 1.0],589 # [ 1.0, 2.0],590 # [ 1.0, 3.0],591 # [ 2.0, 1.0],592 # [ 3.0, 0.0],593 # [ 3.0, 1.0]])594 #595 # z = points[:,0] + 2*points[:,1]596 #597 # ptsfile = 'testptsfile.pts'598 # write_ptsfile(ptsfile, points, z,599 # attribute_name = 'linear_combination')600 #601 # #Check contents602 # #Get NetCDF603 # from Scientific.IO.NetCDF import NetCDFFile604 # fid = NetCDFFile(ptsfile, 'r')605 #606 # # Get the variables607 # #print fid.variables.keys()608 # points1 = fid.variables['points']609 # z1 = fid.variables['linear_combination']610 #611 # #Check values#612 #613 # #print points[:]614 # #print ref_points615 # assert allclose(points, points1)616 #617 # #print attributes[:]618 # #print ref_elevation619 # assert allclose(z, z1)620 #621 # #Cleanup622 # fid.close()623 #624 # import os625 # os.remove(ptsfile)626 574 627 575 … … 5544 5492 fid.close() 5545 5493 self.delete_mux(files) 5546 #os.remove(sww_file)5494 os.remove(sww_file) 5547 5495 5548 5496 def test_urs_ungridded2swwIII (self):
Note: See TracChangeset
for help on using the changeset viewer.