- Timestamp:
- Oct 11, 2006, 5:46:10 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/test_data_manager.py
r3750 r3761 4269 4269 4270 4270 4271 def NOT_test_dem2pts(self):4272 """Test conversion from dem in ascii format to native NetCDF xya format4273 """4274 4275 import time, os4276 from Numeric import array, zeros, allclose, Float, concatenate4277 from Scientific.IO.NetCDF import NetCDFFile4278 4279 #Write test asc file4280 root = 'demtest'4281 4282 filename = root+'.asc'4283 fid = open(filename, 'w')4284 fid.write("""ncols 54285 nrows 64286 xllcorner 2000.54287 yllcorner 3000.54288 cellsize 254289 NODATA_value -99994290 """)4291 #Create linear function4292 4293 ref_points = []4294 ref_elevation = []4295 for i in range(6):4296 y = (6-i)*25.04297 for j in range(5):4298 x = j*25.04299 z = x+2*y4300 4301 ref_points.append( [x,y] )4302 ref_elevation.append(z)4303 fid.write('%f ' %z)4304 fid.write('\n')4305 4306 fid.close()4307 4308 #Write prj file with metadata4309 metafilename = root+'.prj'4310 fid = open(metafilename, 'w')4311 4312 4313 fid.write("""Projection UTM4314 Zone 564315 Datum WGS844316 Zunits NO4317 Units METERS4318 Spheroid WGS844319 Xshift 0.00000000004320 Yshift 10000000.00000000004321 Parameters4322 """)4323 fid.close()4324 4325 #Convert to NetCDF pts4326 convert_dem_from_ascii2netcdf(root)4327 dem2pts(root)4328 4329 #Check contents4330 #Get NetCDF4331 fid = NetCDFFile(root+'.pts', 'r')4332 4333 # Get the variables4334 #print fid.variables.keys()4335 points = fid.variables['points']4336 elevation = fid.variables['elevation']4337 4338 #Check values4339 4340 #print points[:]4341 #print ref_points4342 assert allclose(points, ref_points)4343 4344 #print attributes[:]4345 #print ref_elevation4346 assert allclose(elevation, ref_elevation)4347 4348 #Cleanup4349 fid.close()4350 4351 4352 os.remove(root + '.pts')4353 os.remove(root + '.dem')4354 os.remove(root + '.asc')4355 os.remove(root + '.prj')4356 4357 4358 4359 def NOT_test_dem2pts_bounding_box(self):4360 """Test conversion from dem in ascii format to native NetCDF xya format4361 """4362 4363 import time, os4364 from Numeric import array, zeros, allclose, Float, concatenate4365 from Scientific.IO.NetCDF import NetCDFFile4366 4367 #Write test asc file4368 root = 'demtest'4369 4370 filename = root+'.asc'4371 fid = open(filename, 'w')4372 fid.write("""ncols 54373 nrows 64374 xllcorner 2000.54375 yllcorner 3000.54376 cellsize 254377 NODATA_value -99994378 """)4379 #Create linear function4380 4381 ref_points = []4382 ref_elevation = []4383 for i in range(6):4384 y = (6-i)*25.04385 for j in range(5):4386 x = j*25.04387 z = x+2*y4388 4389 ref_points.append( [x,y] )4390 ref_elevation.append(z)4391 fid.write('%f ' %z)4392 fid.write('\n')4393 4394 fid.close()4395 4396 #Write prj file with metadata4397 metafilename = root+'.prj'4398 fid = open(metafilename, 'w')4399 4400 4401 fid.write("""Projection UTM4402 Zone 564403 Datum WGS844404 Zunits NO4405 Units METERS4406 Spheroid WGS844407 Xshift 0.00000000004408 Yshift 10000000.00000000004409 Parameters4410 """)4411 fid.close()4412 4413 #Convert to NetCDF pts4414 convert_dem_from_ascii2netcdf(root)4415 dem2pts(root, easting_min=2010.0, easting_max=2110.0,4416 northing_min=3035.0, northing_max=3125.5)4417 4418 #Check contents4419 #Get NetCDF4420 fid = NetCDFFile(root+'.pts', 'r')4421 4422 # Get the variables4423 #print fid.variables.keys()4424 points = fid.variables['points']4425 elevation = fid.variables['elevation']4426 4427 #Check values4428 assert fid.xllcorner[0] == 2010.04429 assert fid.yllcorner[0] == 3035.04430 4431 #create new reference points4432 ref_points = []4433 ref_elevation = []4434 for i in range(4):4435 y = (4-i)*25.0 + 25.04436 y_new = y + 3000.5 - 3035.04437 for j in range(4):4438 x = j*25.0 + 25.04439 x_new = x + 2000.5 - 2010.04440 z = x+2*y4441 4442 ref_points.append( [x_new,y_new] )4443 ref_elevation.append(z)4444 4445 #print points[:]4446 #print ref_points4447 assert allclose(points, ref_points)4448 4449 #print attributes[:]4450 #print ref_elevation4451 assert allclose(elevation, ref_elevation)4452 4453 #Cleanup4454 fid.close()4455 4456 4457 os.remove(root + '.pts')4458 os.remove(root + '.dem')4459 os.remove(root + '.asc')4460 os.remove(root + '.prj')4461 4462 4463 4464 def NOT_test_dem2pts_remove_Nullvalues(self):4465 """Test conversion from dem in ascii format to native NetCDF xya format4466 """4467 4468 import time, os4469 from Numeric import array, zeros, allclose, Float, concatenate4470 from Scientific.IO.NetCDF import NetCDFFile4471 4472 #Write test asc file4473 root = 'demtest'4474 4475 filename = root+'.asc'4476 fid = open(filename, 'w')4477 fid.write("""ncols 54478 nrows 64479 xllcorner 2000.54480 yllcorner 3000.54481 cellsize 254482 NODATA_value -99994483 """)4484 #Create linear function4485 # ref_ will write all the values4486 # new_ref_ will write the values except for NODATA_values4487 ref_points = []4488 ref_elevation = []4489 new_ref_pts = []4490 new_ref_elev = []4491 NODATA_value = -99994492 for i in range(6):4493 y = (6-i)*25.04494 for j in range(5):4495 x = j*25.04496 z = x+2*y4497 if j == 4: z = NODATA_value # column4498 if i == 2 and j == 2: z = NODATA_value # random4499 if i == 5 and j == 1: z = NODATA_value4500 if i == 1: z = NODATA_value # row4501 if i == 3 and j == 1: z = NODATA_value # two pts/row4502 if i == 3 and j == 3: z = NODATA_value4503 4504 4505 if z <> NODATA_value:4506 new_ref_elev.append(z)4507 new_ref_pts.append( [x,y] )4508 4509 ref_points.append( [x,y] )4510 ref_elevation.append(z)4511 4512 fid.write('%f ' %z)4513 fid.write('\n')4514 4515 fid.close()4516 4517 4518 #Write prj file with metadata4519 metafilename = root+'.prj'4520 fid = open(metafilename, 'w')4521 4522 4523 fid.write("""Projection UTM4524 Zone 564525 Datum WGS844526 Zunits NO4527 Units METERS4528 Spheroid WGS844529 Xshift 0.00000000004530 Yshift 10000000.00000000004531 Parameters4532 """)4533 fid.close()4534 4535 #Convert to NetCDF pts4536 convert_dem_from_ascii2netcdf(root)4537 dem2pts(root)4538 4539 #Check contents4540 #Get NetCDF4541 fid = NetCDFFile(root+'.pts', 'r')4542 4543 # Get the variables4544 #print fid.variables.keys()4545 points = fid.variables['points']4546 elevation = fid.variables['elevation']4547 4548 #Check values4549 #print 'points', points[:]4550 assert len(points) == len(new_ref_pts), 'length of returned points not correct'4551 assert allclose(points, new_ref_pts), 'points do not align'4552 4553 #print 'elevation', elevation[:]4554 assert len(elevation) == len(new_ref_elev), 'length of returned elevation not correct'4555 assert allclose(elevation, new_ref_elev), 'elevations do not align'4556 4557 #Cleanup4558 fid.close()4559 4560 4561 os.remove(root + '.pts')4562 os.remove(root + '.dem')4563 os.remove(root + '.asc')4564 os.remove(root + '.prj')4565 4566 def NOT_test_dem2pts_bounding_box_Nullvalues(self):4567 """Test conversion from dem in ascii format to native NetCDF xya format4568 """4569 4570 import time, os4571 from Numeric import array, zeros, allclose, Float, concatenate4572 from Scientific.IO.NetCDF import NetCDFFile4573 4574 #Write test asc file4575 root = 'demtest'4576 4577 filename = root+'.asc'4578 fid = open(filename, 'w')4579 fid.write("""ncols 54580 nrows 64581 xllcorner 2000.54582 yllcorner 3000.54583 cellsize 254584 NODATA_value -99994585 """)4586 #Create linear function4587 4588 ref_points = []4589 ref_elevation = []4590 new_ref_pts1 = []4591 new_ref_elev1 = []4592 NODATA_value = -99994593 for i in range(6):4594 y = (6-i)*25.04595 for j in range(5):4596 x = j*25.04597 z = x+2*y4598 if j == 4: z = NODATA_value # column4599 if i == 2 and j == 2: z = NODATA_value # random4600 if i == 5 and j == 1: z = NODATA_value4601 if i == 1: z = NODATA_value # row4602 if i == 3 and j == 1: z = NODATA_value # two pts/row4603 if i == 3 and j == 3: z = NODATA_value4604 4605 if z <> NODATA_value:4606 new_ref_elev1.append(z)4607 new_ref_pts1.append( [x,y] )4608 4609 ref_points.append( [x,y] )4610 ref_elevation.append(z)4611 fid.write('%f ' %z)4612 fid.write('\n')4613 4614 fid.close()4615 4616 #Write prj file with metadata4617 metafilename = root+'.prj'4618 fid = open(metafilename, 'w')4619 4620 4621 fid.write("""Projection UTM4622 Zone 564623 Datum WGS844624 Zunits NO4625 Units METERS4626 Spheroid WGS844627 Xshift 0.00000000004628 Yshift 10000000.00000000004629 Parameters4630 """)4631 fid.close()4632 4633 #Convert to NetCDF pts4634 convert_dem_from_ascii2netcdf(root)4635 dem2pts(root, easting_min=2010.0, easting_max=2110.0,4636 northing_min=3035.0, northing_max=3125.5)4637 4638 #Check contents4639 #Get NetCDF4640 fid = NetCDFFile(root+'.pts', 'r')4641 4642 # Get the variables4643 #print fid.variables.keys()4644 points = fid.variables['points']4645 elevation = fid.variables['elevation']4646 4647 #Check values4648 assert fid.xllcorner[0] == 2010.04649 assert fid.yllcorner[0] == 3035.04650 4651 #create new reference points4652 ref_points = []4653 ref_elevation = []4654 new_ref_pts2 = []4655 new_ref_elev2 = []4656 for i in range(4):4657 y = (4-i)*25.0 + 25.04658 y_new = y + 3000.5 - 3035.04659 for j in range(4):4660 x = j*25.0 + 25.04661 x_new = x + 2000.5 - 2010.04662 z = x+2*y4663 4664 if j == 3: z = NODATA_value # column4665 if i == 1 and j == 1: z = NODATA_value # random4666 if i == 4 and j == 0: z = NODATA_value4667 if i == 0: z = NODATA_value # row4668 if i == 2 and j == 0: z = NODATA_value # two pts/row4669 if i == 2 and j == 2: z = NODATA_value4670 4671 if z <> NODATA_value:4672 new_ref_elev2.append(z)4673 new_ref_pts2.append( [x_new,y_new] )4674 4675 4676 ref_points.append( [x_new,y_new] )4677 ref_elevation.append(z)4678 4679 #print points[:]4680 #print ref_points4681 #assert allclose(points, ref_points)4682 4683 #print attributes[:]4684 #print ref_elevation4685 #assert allclose(elevation, ref_elevation)4686 4687 4688 assert len(points) == len(new_ref_pts2), 'length of returned points not correct'4689 assert allclose(points, new_ref_pts2), 'points do not align'4690 4691 #print 'elevation', elevation[:]4692 assert len(elevation) == len(new_ref_elev2), 'length of returned elevation not correct'4693 assert allclose(elevation, new_ref_elev2), 'elevations do not align'4694 #Cleanup4695 fid.close()4696 4697 4698 os.remove(root + '.pts')4699 os.remove(root + '.dem')4700 os.remove(root + '.asc')4701 os.remove(root + '.prj')4702 4703 4271 4704 4272 ########## testing nbed class ##################
Note: See TracChangeset
for help on using the changeset viewer.