Changeset 5485 for anuga_core/source/anuga/shallow_water/data_manager.py
- Timestamp:
- Jul 10, 2008, 2:14:22 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r5474 r5485 48 48 49 49 """ 50 51 # This file was reverted from changeset:5484 to changeset:5470 on 10th July 52 # by Ole. 50 53 51 54 import exceptions … … 4838 4841 NORTH_VELOCITY_MUX2_LABEL = '-n-mux2' 4839 4842 4840 def read_mux2_py(filenames,weights,permutation=None,verbose=False): 4841 """ 4842 Access the mux files specified in the filenames list. Combine the 4843 data found therin as a weighted linear sum as specifed by the weights. 4844 If permutation is None extract timeseries data for all gauges within the 4845 files. 4846 4847 Input: 4848 filenames: List of filenames specifiying the file containing the 4849 timeseries data (mux2 format) for each source 4850 weights: Weights associated with each source 4851 permutation: Specifies the gauge numbers that for which data is to be 4852 extracted 4853 """ 4843 def read_mux2_py(filenames,weights,verbose=False): 4844 4854 4845 from Numeric import ones,Float,compress,zeros,arange 4855 4846 from urs_ext import read_mux2 … … 4865 4856 verbose=0 4866 4857 4867 data=read_mux2(numSrc,filenames,weights,file_params, permutation,verbose)4858 data=read_mux2(numSrc,filenames,weights,file_params,verbose) 4868 4859 4869 4860 msg='File parameter values were not read in correctly from c file' … … 5046 5037 raise IOError, msg 5047 5038 5048 if ordering_filename is not None: 5049 # Read ordering file 5050 5051 try: 5052 fid=open(ordering_filename, 'r') 5053 file_header=fid.readline().split(',') 5054 ordering_lines=fid.readlines() 5055 fid.close() 5056 except: 5057 msg = 'Cannot open %s'%ordering_filename 5058 raise Exception, msg 5059 5060 reference_header = 'index, longitude, latitude\n' 5061 reference_header_split = reference_header.split(',') 5062 for i in range(3): 5063 if not file_header[i].strip() == reference_header_split[i].strip(): 5064 msg = 'File must contain header: '+reference_header+'\n' 5065 raise Exception, msg 5066 5067 if len(ordering_lines)<2: 5068 msg = 'File must contain at least two points' 5069 raise Exception, msg 5070 5071 5072 5073 permutation = [int(line.split(',')[0]) for line in ordering_lines] 5074 else: 5075 permutation = None 5076 5039 #need to do this for velocity-e-mux2 and velocity-n-mux2 files as well 5040 #for now set x_momentum and y_moentum quantities to zero 5077 5041 if (verbose): print 'reading mux2 file' 5078 5042 mux={} 5079 5043 for i,quantity in enumerate(quantities): 5080 5044 # For each quantity read the associated list of source mux2 file with extenstion associated with that quantity 5081 times, latitudes_urs, longitudes_urs, elevation, mux[quantity],starttime = read_mux2_py(files_in[i],weights, permutation=permutation,verbose=verbose)5045 times, latitudes_urs, longitudes_urs, elevation, mux[quantity],starttime = read_mux2_py(files_in[i],weights,verbose=verbose) 5082 5046 if quantity!=quantities[0]: 5083 5047 msg='%s, %s and %s have inconsitent gauge data'%(files_in[0],files_in[1],files_in[2]) … … 5092 5056 elevation_old=elevation 5093 5057 starttime_old=starttime 5058 5094 5059 5095 5060 if ordering_filename is not None: 5096 latitudes = latitudes_urs 5097 longitudes = longitudes_urs 5061 # Read ordering file 5062 5063 try: 5064 fid=open(ordering_filename, 'r') 5065 file_header=fid.readline().split(',') 5066 ordering_lines=fid.readlines() 5067 fid.close() 5068 except: 5069 msg = 'Cannot open %s'%ordering_filename 5070 raise Exception, msg 5071 5072 reference_header = 'index, longitude, latitude\n' 5073 reference_header_split = reference_header.split(',') 5074 for i in range(3): 5075 if not file_header[i] == reference_header_split[i]: 5076 msg = 'File must contain header: '+reference_header+'\n' 5077 raise Exception, msg 5078 5079 if len(ordering_lines)<2: 5080 msg = 'File must contain at least two points' 5081 raise Exception, msg 5082 5083 5084 5085 permutation = [int(line.split(',')[0]) for line in ordering_lines] 5086 5087 latitudes = take(latitudes_urs, permutation) 5088 longitudes = take(longitudes_urs, permutation) 5098 5089 5099 5090 # Self check - can be removed to improve speed … … 5128 5119 longitudes=longitudes_urs 5129 5120 permutation = range(latitudes.shape[0]) 5121 5130 5122 5131 5123 msg='File is empty and or clipped region not in file region' … … 5189 5181 if verbose: print 'Converting quantities' 5190 5182 for j in range(len(times)): 5191 for i in range(number_of_points):5192 w = zscale*mux['HA'][i ,j] + mean_stage5193 h=w-elevation[i ]5183 for i, index in enumerate(permutation): 5184 w = zscale*mux['HA'][index,j] + mean_stage 5185 h=w-elevation[index] 5194 5186 stage[j,i] = w 5195 5187 5196 xmomentum[j,i] = mux['UA'][i ,j]*h5197 ymomentum[j,i] = mux['VA'][i ,j]*h5188 xmomentum[j,i] = mux['UA'][index,j]*h 5189 ymomentum[j,i] = mux['VA'][index,j]*h 5198 5190 5199 5191 outfile.close()
Note: See TracChangeset
for help on using the changeset viewer.