Ignore:
Timestamp:
Jul 10, 2008, 2:14:22 PM (15 years ago)
Author:
ole
Message:

Reverted MUX reader to revision 5470 - the last working version.
This one still has servere memory leaks and needs to be redeveloped.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r5474 r5485  
    4848
    4949"""
     50
     51# This file was reverted from changeset:5484 to changeset:5470 on 10th July
     52# by Ole.
    5053
    5154import exceptions
     
    48384841NORTH_VELOCITY_MUX2_LABEL =  '-n-mux2'   
    48394842
    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     """
     4843def read_mux2_py(filenames,weights,verbose=False):
     4844
    48544845    from Numeric import ones,Float,compress,zeros,arange
    48554846    from urs_ext import read_mux2
     
    48654856        verbose=0
    48664857       
    4867     data=read_mux2(numSrc,filenames,weights,file_params,permutation,verbose)
     4858    data=read_mux2(numSrc,filenames,weights,file_params,verbose)
    48684859
    48694860    msg='File parameter values were not read in correctly from c file'
     
    50465037                raise IOError, msg
    50475038
    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
    50775041    if (verbose): print 'reading mux2 file'
    50785042    mux={}
    50795043    for i,quantity in enumerate(quantities):
    50805044        # 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)
    50825046        if quantity!=quantities[0]:
    50835047            msg='%s, %s and %s have inconsitent gauge data'%(files_in[0],files_in[1],files_in[2])
     
    50925056        elevation_old=elevation
    50935057        starttime_old=starttime
     5058
    50945059       
    50955060    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)
    50985089       
    50995090        # Self check - can be removed to improve speed
     
    51285119        longitudes=longitudes_urs
    51295120        permutation = range(latitudes.shape[0])               
     5121       
    51305122
    51315123    msg='File is empty and or clipped region not in file region'
     
    51895181    if verbose: print 'Converting quantities'
    51905182    for j in range(len(times)):
    5191         for i in range(number_of_points):
    5192             w = zscale*mux['HA'][i,j] + mean_stage
    5193             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]
    51945186            stage[j,i] = w
    51955187
    5196             xmomentum[j,i] = mux['UA'][i,j]*h
    5197             ymomentum[j,i] = mux['VA'][i,j]*h
     5188            xmomentum[j,i] = mux['UA'][index,j]*h
     5189            ymomentum[j,i] = mux['VA'][index,j]*h
    51985190
    51995191    outfile.close()
Note: See TracChangeset for help on using the changeset viewer.