Changeset 1661
- Timestamp:
- Aug 1, 2005, 12:11:53 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r1660 r1661 51 51 from Numeric import concatenate 52 52 53 from coordinate_transforms.geo_reference import Geo_reference , DEFAULT_ZONE53 from coordinate_transforms.geo_reference import Geo_reference 54 54 55 55 def make_filename(s): … … 921 921 return cls(domain, mode) 922 922 923 def xya2pts(basename_in, basename_out=None, verbose=False, 924 #easting_min=None, easting_max=None, 925 #northing_min=None, northing_max=None, 926 attribute_name = 'elevation'): 927 """Read points data from ascii (.xya) 928 929 Example: 930 931 x(m) y(m) z(m) 932 0.00000e+00 0.00000e+00 1.3535000e-01 933 0.00000e+00 1.40000e-02 1.3535000e-01 934 935 936 937 Convert to NetCDF pts format which is 938 939 points: (Nx2) Float array 940 elevation: N Float array 941 942 Only lines that contain three numeric values are processed 943 """ 944 945 import os 946 from Scientific.IO.NetCDF import NetCDFFile 947 from Numeric import Float, arrayrange, concatenate 948 949 root, ext = os.path.splitext(basename_in) 950 951 if ext == '': ext = '.xya' 952 953 #Get NetCDF 954 infile = open(root + ext, 'r') #Open existing xya file for read 955 956 if verbose: print 'Reading xya points from %s' %(root + ext) 957 958 points = [] 959 attribute = [] 960 for i, line in enumerate(infile.readlines()): 961 fields = line.split() 962 963 try: 964 assert len(fields) == 3 965 except: 966 print 'WARNING: Line %d doesn\'t have 3 elements: %s' %(i, line) 967 968 try: 969 x = float( fields[0] ) 970 y = float( fields[1] ) 971 z = float( fields[2] ) 972 except: 973 continue 974 975 points.append( [x, y] ) 976 attribute.append(z) 977 978 979 #Get output file 980 if basename_out == None: 981 ptsname = root + '.pts' 982 else: 983 ptsname = basename_out + '.pts' 984 985 if verbose: print 'Store to NetCDF file %s' %ptsname 986 # NetCDF file definition 987 outfile = NetCDFFile(ptsname, 'w') 988 989 #Create new file 990 outfile.institution = 'Geoscience Australia' 991 outfile.description = 'NetCDF pts format for compact and '\ 992 'portable storage of spatial point data' 993 994 995 #Georeferencing 996 from coordinate_transforms.geo_reference import Geo_reference 997 Geo_reference().write_NetCDF(outfile) 998 999 1000 outfile.createDimension('number_of_points', len(points)) 1001 outfile.createDimension('number_of_dimensions', 2) #This is 2d data 1002 1003 # variable definitions 1004 outfile.createVariable('points', Float, ('number_of_points', 1005 'number_of_dimensions')) 1006 outfile.createVariable(attribute_name, Float, ('number_of_points',)) 1007 1008 # Get handles to the variables 1009 nc_points = outfile.variables['points'] 1010 nc_attribute = outfile.variables[attribute_name] 1011 1012 #Store data 1013 nc_points[:, :] = points 1014 nc_attribute[:] = attribute 1015 1016 infile.close() 1017 outfile.close() 1018 923 1019 def dem2pts(basename_in, basename_out=None, verbose=False, 924 1020 easting_min=None, easting_max=None, … … 1144 1240 if origin is None: 1145 1241 1146 # get geo_reference1242 #Get geo_reference 1147 1243 #sww files don't have to have a geo_ref 1148 1244 try: 1149 1245 geo_reference = Geo_reference(NetCDFObject=fid) 1150 1246 except AttributeError, e: 1151 geo_reference = Geo_reference( DEFAULT_ZONE,0,0)1247 geo_reference = Geo_reference() #Default georef object 1152 1248 1153 1249 xllcorner = geo_reference.get_xllcorner()
Note: See TracChangeset
for help on using the changeset viewer.