Changeset 836
- Timestamp:
- Feb 7, 2005, 2:56:07 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r834 r836 8 8 9 9 10 Formats used within GANUGA:10 Formats used within ANUGA: 11 11 12 12 .sww: Netcdf format for storing model output 13 .xya: Either ASCII or NetCDF format for storing arbitrary points and associated attributed 13 14 .xya: ASCII format for storing arbitrary points and associated attributes 15 .pts: NetCDF format for storing arbitrary points and associated attributes 16 17 .asc: ASCII foramt of regular DEMs as output from ArcView 14 18 .dem: NetCDF representation of regular DEM data 19 15 20 .tsh: ASCII format for storing meshes and associated boundary and region info 21 22 23 #Not yet implemented 24 .nc: Native ferret NetCDF format 25 26 16 27 FIXME: What else 17 28 … … 799 810 return cls(domain, mode) 800 811 801 def dem2 xya(filename, verbose=False):812 def dem2pts(filename, verbose=False): 802 813 """Read Digitial Elevation model from the following NetCDF format (.dem) 803 814 … … 812 823 138.3698 137.4194 136.5062 135.5558 .......... 813 824 814 Convert to NetCDF xyz format (.xya)825 Convert to NetCDF pts format 815 826 """ 816 827 … … 835 846 836 847 #Get output file 837 xyaname = root + '. xya'848 xyaname = root + '.pts' 838 849 if verbose: print 'Store to NetCDF file %s' %xyaname 839 850 # NetCDF file definition … … 842 853 #Create new file 843 854 outfile.institution = 'Geoscience Australia' 844 outfile.description = 'NetCDF xyaformat for compact and portable storage ' +\855 outfile.description = 'NetCDF pts format for compact and portable storage ' +\ 845 856 'of spatial point data' 846 857 … … 866 877 867 878 #Store data 868 #FIXME: Could be faster using array operations879 #FIXME: Could perhaps be faster using array operations 869 880 for i in range(nrows): 870 881 if verbose: print 'Processing row %d of %d' %(i, nrows) … … 880 891 infile.close() 881 892 outfile.close() 882 883 884 # def dem2xya(filename, verbose=False):885 # """Read Digitial Elevation model from the following ASCII format (.asc)886 887 # Example:888 889 # ncols 3121890 # nrows 1800891 # xllcorner 722000892 # yllcorner 5893000893 # cellsize 25894 # NODATA_value -9999895 # 138.3698 137.4194 136.5062 135.5558 ..........896 897 # Convert to NetCDF xyz format (.xya)898 # """899 900 # import os901 # from Scientific.IO.NetCDF import NetCDFFile902 # from Numeric import Float, arrayrange, concatenate903 904 # root, ext = os.path.splitext(filename)905 # fid = open(filename)906 907 # if verbose: print 'Reading DEM from %s' %filename908 # lines = fid.readlines()909 # fid.close()910 911 # if verbose: print 'Got', len(lines), ' lines'912 913 # ncols = int(lines[0].split()[1].strip())914 # nrows = int(lines[1].split()[1].strip())915 # xllcorner = float(lines[2].split()[1].strip())916 # yllcorner = float(lines[3].split()[1].strip())917 # cellsize = float(lines[4].split()[1].strip())918 # NODATA_value = int(lines[5].split()[1].strip())919 920 # assert len(lines) == nrows + 6921 922 # netcdfname = root + '.xya'923 # if verbose: print 'Store to NetCDF file %s' %netcdfname924 # # NetCDF file definition925 # fid = NetCDFFile(netcdfname, 'w')926 927 # #Create new file928 # fid.institution = 'Geoscience Australia'929 # fid.description = 'NetCDF xya format for compact and portable storage ' +\930 # 'of spatial point data'931 932 # fid.ncols = ncols933 # fid.nrows = nrows934 935 936 # # dimension definitions937 # fid.createDimension('number_of_points', nrows*ncols)938 # fid.createDimension('number_of_attributes', 1) #Always 1 with the dem fmt939 # fid.createDimension('number_of_dimensions', 2) #This is 2d data940 941 942 # # variable definitions943 # fid.createVariable('points', Float, ('number_of_points',944 # 'number_of_dimensions'))945 # fid.createVariable('attributes', Float, ('number_of_points',946 # 'number_of_attributes'))947 948 # # Get handles to the variables949 # points = fid.variables['points']950 # attributes = fid.variables['attributes']951 952 # #Store data953 # #FIXME: Could be faster using array operations954 # #FIXME: Perhaps the y dimension needs to be reversed955 # #FIXME: x and y definitely needs to be swapped956 # for i, line in enumerate(lines[6:]):957 # fields = line.split()958 # if verbose: print 'Processing row %d of %d' %(i, nrows)959 960 # x = i*cellsize961 # for j, field in enumerate(fields):962 # index = i*ncols + j963 964 # y = j*cellsize965 # points[index, :] = [x,y]966 967 # z = float(field)968 # attributes[index, 0] = z969 970 # fid.close()971 893 972 894 -
inundation/ga/storm_surge/pyvolution/least_squares.py
r834 r836 147 147 148 148 149 def xya2rectangular(xya_name, M, N, alpha = DEFAULT_ALPHA,149 def pts2rectangular(pts_name, M, N, alpha = DEFAULT_ALPHA, 150 150 verbose = False, reduction = 1, format = 'netcdf'): 151 """Fits attributes from xyafile to MxN rectangular mesh152 153 Read xyafile and create rectangular mesh of resolution MxN such that154 it covers all points specified in xyafile.151 """Fits attributes from pts file to MxN rectangular mesh 152 153 Read pts file and create rectangular mesh of resolution MxN such that 154 it covers all points specified in pts file. 155 155 156 156 FIXME: This may be a temporary function until we decide on … … 160 160 import util, mesh_factory 161 161 162 if verbose: print 'Read xya'163 points, attributes, _ = util.read_xya( xya_name, format)162 if verbose: print 'Read pts' 163 points, attributes, _ = util.read_xya(pts_name, format) 164 164 165 165 #Reduce number of points a bit -
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r835 r836 498 498 499 499 500 def test_dem2 xya(self):500 def test_dem2pts(self): 501 501 """Test conversion from dem in ascii format to native NetCDF xya format 502 502 """ … … 537 537 #Convert to NetCDF xya 538 538 convert_dem_from_ascii2netcdf(filename) 539 dem2 xya(root + '.dem')540 541 #Check contents 542 #Get NetCDF 543 fid = NetCDFFile(root+'. xya', 'r')539 dem2pts(root + '.dem') 540 541 #Check contents 542 #Get NetCDF 543 fid = NetCDFFile(root+'.pts', 'r') 544 544 545 545 # Get the variables … … 561 561 562 562 563 os.remove(root + '. xya')563 os.remove(root + '.pts') 564 564 os.remove(root + '.dem') 565 565 os.remove(root + '.asc') -
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r835 r836 489 489 490 490 491 def test_ xya2rectangular(self):491 def test_pts2rectangular(self): 492 492 493 493 import time, os … … 500 500 501 501 points, triangles, boundary, attributes =\ 502 xya2rectangular(FN, 4, 4, format = 'asc')502 pts2rectangular(FN, 4, 4, format = 'asc') 503 503 504 504 z1 = [2, 4] -
inundation/ga/storm_surge/pyvolution/util.py
r835 r836 303 303 attribute names if present otherwise None 304 304 """ 305 #FIXME: Probably obsoleted by similar function in load_ASCII 305 306 306 307 from Scientific.IO.NetCDF import NetCDFFile
Note: See TracChangeset
for help on using the changeset viewer.