Changeset 967
- Timestamp:
- Feb 28, 2005, 1:38:35 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r955 r967 840 840 return cls(domain, mode) 841 841 842 def dem2pts( filename, verbose=False):842 def dem2pts(basename_in, basename_out=None, verbose=False): 843 843 """Read Digitial Elevation model from the following NetCDF format (.dem) 844 844 … … 863 863 from Numeric import Float, arrayrange, concatenate 864 864 865 root , ext = os.path.splitext(filename)865 root = basename_in 866 866 867 867 #Get NetCDF 868 infile = NetCDFFile( filename, 'r') #Open existing netcdf file for read869 870 if verbose: print 'Reading DEM from %s' % filename868 infile = NetCDFFile(root + '.dem', 'r') #Open existing netcdf file for read 869 870 if verbose: print 'Reading DEM from %s' %(root + '.dem') 871 871 872 872 ncols = infile.ncols[0] … … 888 888 889 889 890 #Get output file 891 xyaname = root + '.pts' 892 if verbose: print 'Store to NetCDF file %s' %xyaname 890 #Get output file 891 if basename_out == None: 892 ptsname = root + '.pts' 893 else: 894 ptsname = basename_out + '.pts' 895 896 if verbose: print 'Store to NetCDF file %s' %ptsname 893 897 # NetCDF file definition 894 outfile = NetCDFFile( xyaname, 'w')898 outfile = NetCDFFile(ptsname, 'w') 895 899 896 900 #Create new file … … 946 950 947 951 948 def convert_dem_from_ascii2netcdf(filename, verbose=False): 952 def convert_dem_from_ascii2netcdf(basename_in, basename_out = None, 953 verbose=False): 949 954 """Read Digitial Elevation model from the following ASCII format (.asc) 950 955 … … 959 964 138.3698 137.4194 136.5062 135.5558 .......... 960 965 961 Convert to NetCDF format (.dem) mimcing the ASCII format closely. 962 963 964 An accompanying file with same basename but extension .prj must exist 966 Convert basename_in + '.asc' to NetCDF format (.dem) 967 mimicking the ASCII format closely. 968 969 970 An accompanying file with same basename_in but extension .prj must exist 965 971 and is used to fix the UTM zone, datum, false northings and eastings. 966 972 … … 982 988 from Numeric import Float, array 983 989 984 root, ext = os.path.splitext(filename) 990 #root, ext = os.path.splitext(basename_in) 991 root = basename_in 985 992 986 993 ########################################### … … 1028 1035 ########################################### 1029 1036 #Read DEM data 1030 datafile = open(filename) 1031 1032 if verbose: print 'Reading DEM from %s' %filename 1037 1038 datafile = open(basename_in + '.asc') 1039 1040 if verbose: print 'Reading DEM from %s' %(basename_in + '.asc') 1033 1041 lines = datafile.readlines() 1034 1042 datafile.close() … … 1048 1056 ########################################## 1049 1057 1050 1051 netcdfname = root + '.dem' 1058 1059 if basename_out == None: 1060 netcdfname = root + '.dem' 1061 else: 1062 netcdfname = basename_out + '.dem' 1063 1052 1064 if verbose: print 'Store to NetCDF file %s' %netcdfname 1053 1065 # NetCDF file definition … … 1096 1108 1097 1109 1098 1099 1100 def ferret2sww(basefilename, verbose=False, 1101 minlat = None, maxlat =None, 1102 minlon = None, maxlon =None, 1110 def ferret2sww(basename_in, basename_out = None, 1111 verbose = False, 1112 minlat = None, maxlat = None, 1113 minlon = None, maxlon = None, 1103 1114 mint = None, maxt = None, mean_stage = 0, 1104 1115 origin = None, zscale = 1): … … 1106 1117 sww format native to pyvolution. 1107 1118 1108 Specify only base filenameand read files of the form1119 Specify only basename_in and read files of the form 1109 1120 basefilename_ha.nc, basefilename_ua.nc, basefilename_va.nc containing 1110 1121 relative height, x-velocity and y-velocity, respectively. … … 1135 1146 1136 1147 #Get NetCDF data 1137 if verbose: print 'Reading files %s_*.nc' %basefilename 1138 file_h = NetCDFFile(basefilename + '_ha.nc', 'r') #Wave amplitude (cm) 1139 file_u = NetCDFFile(basefilename + '_ua.nc', 'r') #Velocity (x) (cm/s) 1140 file_v = NetCDFFile(basefilename + '_va.nc', 'r') #Velocity (y) (cm/s) 1141 1142 swwname = basefilename + '.sww' 1148 if verbose: print 'Reading files %s_*.nc' %basename_in 1149 file_h = NetCDFFile(basename_in + '_ha.nc', 'r') #Wave amplitude (cm) 1150 file_u = NetCDFFile(basename_in + '_ua.nc', 'r') #Velocity (x) (cm/s) 1151 file_v = NetCDFFile(basename_in + '_va.nc', 'r') #Velocity (y) (cm/s) 1152 1153 if basename_out is None: 1154 swwname = basename_in + '.sww' 1155 else: 1156 swwname = basename_out + '.sww' 1143 1157 1144 1158 times = file_h.variables['TIME'] … … 1215 1229 outfile.institution = 'Geoscience Australia' 1216 1230 outfile.description = 'Converted from Ferret files: %s, %s, %s'\ 1217 %(base filename+ '_ha.nc',1218 base filename+ '_ua.nc',1219 base filename+ '_va.nc')1231 %(basename_in + '_ha.nc', 1232 basename_in + '_ua.nc', 1233 basename_in + '_va.nc') 1220 1234 1221 1235 -
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r955 r967 508 508 509 509 #Write test asc file 510 root = 'demtest' +str(time.time())510 root = 'demtest' 511 511 512 512 filename = root+'.asc' … … 554 554 555 555 #Convert to NetCDF xya 556 convert_dem_from_ascii2netcdf( filename)557 dem2pts(root + '.dem')556 convert_dem_from_ascii2netcdf(root) 557 dem2pts(root) 558 558 559 559 #Check contents
Note: See TracChangeset
for help on using the changeset viewer.