Changeset 3761 for anuga_core/source/obsolete_code
- Timestamp:
- Oct 11, 2006, 5:46:10 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/obsolete_code/data_manager_obsolete_stuff.py
r3565 r3761 391 391 fid.close() 392 392 393 394 395 396 def NOT_test_dem2pts(self): 397 """Test conversion from dem in ascii format to native NetCDF xya format 398 """ 399 400 import time, os 401 from Numeric import array, zeros, allclose, Float, concatenate 402 from Scientific.IO.NetCDF import NetCDFFile 403 404 #Write test asc file 405 root = 'demtest' 406 407 filename = root+'.asc' 408 fid = open(filename, 'w') 409 fid.write("""ncols 5 410 nrows 6 411 xllcorner 2000.5 412 yllcorner 3000.5 413 cellsize 25 414 NODATA_value -9999 415 """) 416 #Create linear function 417 418 ref_points = [] 419 ref_elevation = [] 420 for i in range(6): 421 y = (6-i)*25.0 422 for j in range(5): 423 x = j*25.0 424 z = x+2*y 425 426 ref_points.append( [x,y] ) 427 ref_elevation.append(z) 428 fid.write('%f ' %z) 429 fid.write('\n') 430 431 fid.close() 432 433 #Write prj file with metadata 434 metafilename = root+'.prj' 435 fid = open(metafilename, 'w') 436 437 438 fid.write("""Projection UTM 439 Zone 56 440 Datum WGS84 441 Zunits NO 442 Units METERS 443 Spheroid WGS84 444 Xshift 0.0000000000 445 Yshift 10000000.0000000000 446 Parameters 447 """) 448 fid.close() 449 450 #Convert to NetCDF pts 451 convert_dem_from_ascii2netcdf(root) 452 dem2pts(root) 453 454 #Check contents 455 #Get NetCDF 456 fid = NetCDFFile(root+'.pts', 'r') 457 458 # Get the variables 459 #print fid.variables.keys() 460 points = fid.variables['points'] 461 elevation = fid.variables['elevation'] 462 463 #Check values 464 465 #print points[:] 466 #print ref_points 467 assert allclose(points, ref_points) 468 469 #print attributes[:] 470 #print ref_elevation 471 assert allclose(elevation, ref_elevation) 472 473 #Cleanup 474 fid.close() 475 476 477 os.remove(root + '.pts') 478 os.remove(root + '.dem') 479 os.remove(root + '.asc') 480 os.remove(root + '.prj') 481 482 483 484 def NOT_test_dem2pts_bounding_box(self): 485 """Test conversion from dem in ascii format to native NetCDF xya format 486 """ 487 488 import time, os 489 from Numeric import array, zeros, allclose, Float, concatenate 490 from Scientific.IO.NetCDF import NetCDFFile 491 492 #Write test asc file 493 root = 'demtest' 494 495 filename = root+'.asc' 496 fid = open(filename, 'w') 497 fid.write("""ncols 5 498 nrows 6 499 xllcorner 2000.5 500 yllcorner 3000.5 501 cellsize 25 502 NODATA_value -9999 503 """) 504 #Create linear function 505 506 ref_points = [] 507 ref_elevation = [] 508 for i in range(6): 509 y = (6-i)*25.0 510 for j in range(5): 511 x = j*25.0 512 z = x+2*y 513 514 ref_points.append( [x,y] ) 515 ref_elevation.append(z) 516 fid.write('%f ' %z) 517 fid.write('\n') 518 519 fid.close() 520 521 #Write prj file with metadata 522 metafilename = root+'.prj' 523 fid = open(metafilename, 'w') 524 525 526 fid.write("""Projection UTM 527 Zone 56 528 Datum WGS84 529 Zunits NO 530 Units METERS 531 Spheroid WGS84 532 Xshift 0.0000000000 533 Yshift 10000000.0000000000 534 Parameters 535 """) 536 fid.close() 537 538 #Convert to NetCDF pts 539 convert_dem_from_ascii2netcdf(root) 540 dem2pts(root, easting_min=2010.0, easting_max=2110.0, 541 northing_min=3035.0, northing_max=3125.5) 542 543 #Check contents 544 #Get NetCDF 545 fid = NetCDFFile(root+'.pts', 'r') 546 547 # Get the variables 548 #print fid.variables.keys() 549 points = fid.variables['points'] 550 elevation = fid.variables['elevation'] 551 552 #Check values 553 assert fid.xllcorner[0] == 2010.0 554 assert fid.yllcorner[0] == 3035.0 555 556 #create new reference points 557 ref_points = [] 558 ref_elevation = [] 559 for i in range(4): 560 y = (4-i)*25.0 + 25.0 561 y_new = y + 3000.5 - 3035.0 562 for j in range(4): 563 x = j*25.0 + 25.0 564 x_new = x + 2000.5 - 2010.0 565 z = x+2*y 566 567 ref_points.append( [x_new,y_new] ) 568 ref_elevation.append(z) 569 570 #print points[:] 571 #print ref_points 572 assert allclose(points, ref_points) 573 574 #print attributes[:] 575 #print ref_elevation 576 assert allclose(elevation, ref_elevation) 577 578 #Cleanup 579 fid.close() 580 581 582 os.remove(root + '.pts') 583 os.remove(root + '.dem') 584 os.remove(root + '.asc') 585 os.remove(root + '.prj') 586 587 588 589 def NOT_test_dem2pts_remove_Nullvalues(self): 590 """Test conversion from dem in ascii format to native NetCDF xya format 591 """ 592 593 import time, os 594 from Numeric import array, zeros, allclose, Float, concatenate 595 from Scientific.IO.NetCDF import NetCDFFile 596 597 #Write test asc file 598 root = 'demtest' 599 600 filename = root+'.asc' 601 fid = open(filename, 'w') 602 fid.write("""ncols 5 603 nrows 6 604 xllcorner 2000.5 605 yllcorner 3000.5 606 cellsize 25 607 NODATA_value -9999 608 """) 609 #Create linear function 610 # ref_ will write all the values 611 # new_ref_ will write the values except for NODATA_values 612 ref_points = [] 613 ref_elevation = [] 614 new_ref_pts = [] 615 new_ref_elev = [] 616 NODATA_value = -9999 617 for i in range(6): 618 y = (6-i)*25.0 619 for j in range(5): 620 x = j*25.0 621 z = x+2*y 622 if j == 4: z = NODATA_value # column 623 if i == 2 and j == 2: z = NODATA_value # random 624 if i == 5 and j == 1: z = NODATA_value 625 if i == 1: z = NODATA_value # row 626 if i == 3 and j == 1: z = NODATA_value # two pts/row 627 if i == 3 and j == 3: z = NODATA_value 628 629 630 if z <> NODATA_value: 631 new_ref_elev.append(z) 632 new_ref_pts.append( [x,y] ) 633 634 ref_points.append( [x,y] ) 635 ref_elevation.append(z) 636 637 fid.write('%f ' %z) 638 fid.write('\n') 639 640 fid.close() 641 642 643 #Write prj file with metadata 644 metafilename = root+'.prj' 645 fid = open(metafilename, 'w') 646 647 648 fid.write("""Projection UTM 649 Zone 56 650 Datum WGS84 651 Zunits NO 652 Units METERS 653 Spheroid WGS84 654 Xshift 0.0000000000 655 Yshift 10000000.0000000000 656 Parameters 657 """) 658 fid.close() 659 660 #Convert to NetCDF pts 661 convert_dem_from_ascii2netcdf(root) 662 dem2pts(root) 663 664 #Check contents 665 #Get NetCDF 666 fid = NetCDFFile(root+'.pts', 'r') 667 668 # Get the variables 669 #print fid.variables.keys() 670 points = fid.variables['points'] 671 elevation = fid.variables['elevation'] 672 673 #Check values 674 #print 'points', points[:] 675 assert len(points) == len(new_ref_pts), 'length of returned points not correct' 676 assert allclose(points, new_ref_pts), 'points do not align' 677 678 #print 'elevation', elevation[:] 679 assert len(elevation) == len(new_ref_elev), 'length of returned elevation not correct' 680 assert allclose(elevation, new_ref_elev), 'elevations do not align' 681 682 #Cleanup 683 fid.close() 684 685 686 os.remove(root + '.pts') 687 os.remove(root + '.dem') 688 os.remove(root + '.asc') 689 os.remove(root + '.prj') 690 691 def NOT_test_dem2pts_bounding_box_Nullvalues(self): 692 """Test conversion from dem in ascii format to native NetCDF xya format 693 """ 694 695 import time, os 696 from Numeric import array, zeros, allclose, Float, concatenate 697 from Scientific.IO.NetCDF import NetCDFFile 698 699 #Write test asc file 700 root = 'demtest' 701 702 filename = root+'.asc' 703 fid = open(filename, 'w') 704 fid.write("""ncols 5 705 nrows 6 706 xllcorner 2000.5 707 yllcorner 3000.5 708 cellsize 25 709 NODATA_value -9999 710 """) 711 #Create linear function 712 713 ref_points = [] 714 ref_elevation = [] 715 new_ref_pts1 = [] 716 new_ref_elev1 = [] 717 NODATA_value = -9999 718 for i in range(6): 719 y = (6-i)*25.0 720 for j in range(5): 721 x = j*25.0 722 z = x+2*y 723 if j == 4: z = NODATA_value # column 724 if i == 2 and j == 2: z = NODATA_value # random 725 if i == 5 and j == 1: z = NODATA_value 726 if i == 1: z = NODATA_value # row 727 if i == 3 and j == 1: z = NODATA_value # two pts/row 728 if i == 3 and j == 3: z = NODATA_value 729 730 if z <> NODATA_value: 731 new_ref_elev1.append(z) 732 new_ref_pts1.append( [x,y] ) 733 734 ref_points.append( [x,y] ) 735 ref_elevation.append(z) 736 fid.write('%f ' %z) 737 fid.write('\n') 738 739 fid.close() 740 741 #Write prj file with metadata 742 metafilename = root+'.prj' 743 fid = open(metafilename, 'w') 744 745 746 fid.write("""Projection UTM 747 Zone 56 748 Datum WGS84 749 Zunits NO 750 Units METERS 751 Spheroid WGS84 752 Xshift 0.0000000000 753 Yshift 10000000.0000000000 754 Parameters 755 """) 756 fid.close() 757 758 #Convert to NetCDF pts 759 convert_dem_from_ascii2netcdf(root) 760 dem2pts(root, easting_min=2010.0, easting_max=2110.0, 761 northing_min=3035.0, northing_max=3125.5) 762 763 #Check contents 764 #Get NetCDF 765 fid = NetCDFFile(root+'.pts', 'r') 766 767 # Get the variables 768 #print fid.variables.keys() 769 points = fid.variables['points'] 770 elevation = fid.variables['elevation'] 771 772 #Check values 773 assert fid.xllcorner[0] == 2010.0 774 assert fid.yllcorner[0] == 3035.0 775 776 #create new reference points 777 ref_points = [] 778 ref_elevation = [] 779 new_ref_pts2 = [] 780 new_ref_elev2 = [] 781 for i in range(4): 782 y = (4-i)*25.0 + 25.0 783 y_new = y + 3000.5 - 3035.0 784 for j in range(4): 785 x = j*25.0 + 25.0 786 x_new = x + 2000.5 - 2010.0 787 z = x+2*y 788 789 if j == 3: z = NODATA_value # column 790 if i == 1 and j == 1: z = NODATA_value # random 791 if i == 4 and j == 0: z = NODATA_value 792 if i == 0: z = NODATA_value # row 793 if i == 2 and j == 0: z = NODATA_value # two pts/row 794 if i == 2 and j == 2: z = NODATA_value 795 796 if z <> NODATA_value: 797 new_ref_elev2.append(z) 798 new_ref_pts2.append( [x_new,y_new] ) 799 800 801 ref_points.append( [x_new,y_new] ) 802 ref_elevation.append(z) 803 804 #print points[:] 805 #print ref_points 806 #assert allclose(points, ref_points) 807 808 #print attributes[:] 809 #print ref_elevation 810 #assert allclose(elevation, ref_elevation) 811 812 813 assert len(points) == len(new_ref_pts2), 'length of returned points not correct' 814 assert allclose(points, new_ref_pts2), 'points do not align' 815 816 #print 'elevation', elevation[:] 817 assert len(elevation) == len(new_ref_elev2), 'length of returned elevation not correct' 818 assert allclose(elevation, new_ref_elev2), 'elevations do not align' 819 #Cleanup 820 fid.close() 821 822 823 os.remove(root + '.pts') 824 os.remove(root + '.dem') 825 os.remove(root + '.asc') 826 os.remove(root + '.prj') 827 393 828 #******************** 394 829 #*** END OF OBSOLETE FUNCTIONS
Note: See TracChangeset
for help on using the changeset viewer.