Changeset 5463


Ignore:
Timestamp:
Jul 4, 2008, 12:35:42 PM (15 years ago)
Author:
ole
Message:

Now assume that sts file stores urs gauge information in appropriate order

Location:
anuga_core/source/anuga/shallow_water
Files:
2 edited

Legend:

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

    r5462 r5463  
    50615061            raise Exception, msg
    50625062
    5063         reference_header = 'index, longitude, latitude\n'.split(',')
     5063        reference_header = 'index, longitude, latitude\n'
     5064        reference_header_split = reference_header.split(',')
    50645065        for i in range(3):
    5065             if not file_header[i] == reference_header[i]:
    5066                 msg = 'File must contain header\n'+header+'\n'
     5066            if not file_header[i] == reference_header_split[i]:
     5067                msg = 'File must contain header: '+reference_header+'\n'
    50675068                raise Exception, msg
    50685069
     
    51815182    outfile.close()
    51825183
    5183 def create_sts_boundary(order_file,stsname,lat_long=True):
     5184def create_sts_boundary(stsname):
    51845185    """
    51855186        Create boundary segments from .sts file. Points can be stored in
    51865187    arbitrary order within the .sts file. The order in which the .sts points
    51875188    make up the boundary are given in order.txt file
    5188     """
    5189    
    5190     if not order_file[-3:] == 'txt':
    5191         msg = 'Order file must be a txt file'
    5192         raise Exception, msg
    5193 
    5194     try:
    5195         fid=open(order_file,'r')
    5196         file_header=fid.readline()
    5197         lines=fid.readlines()
    5198         fid.close()
    5199     except:
    5200         msg = 'Cannot open %s'%filename
    5201         raise msg
    5202 
    5203     header="index,longitude,latitude\n"
    5204 
    5205     if not file_header==header:
    5206         msg = 'File must contain header\n'+header+"\n"
    5207         raise Exception, msg
    5208 
    5209     if len(lines)<2:
    5210         msg = 'File must contain at least two points'
    5211         raise Exception, msg
    5212 
     5189   
     5190    FIXME:
     5191    Point coordinates are stored in relative eastings and northings.
     5192    But boundary is produced in absolute coordinates
     5193   
     5194    """
    52135195    try:
    52145196        fid = NetCDFFile(stsname+'.sts', 'r')
     
    52295211    sts_points = concatenate((x,y), axis=1)
    52305212
    5231     xllcorner = fid.xllcorner[0]
    5232     yllcorner = fid.yllcorner[0]
    5233 
    5234     # Walk through ordering file
    5235     boundary_polygon=[]
    5236     for line in lines:
    5237         fields = line.split(',')
    5238         index=int(fields[0])
    5239         if lat_long:
    5240             zone,easting,northing=redfearn(float(fields[1]),float(fields[2]))
    5241             if not zone == fid.zone[0]:
    5242                 msg = 'Inconsistent zones'
    5243                 raise Exception, msg
    5244         else:
    5245             easting = float(fields[1])
    5246             northing = float(fields[2])
    5247            
    5248         if not allclose(array([easting,northing]),sts_points[index]):
    5249             msg = "Points in sts file do not match those in the"+\
    5250                 ".txt file specifying the order of the boundary points"
    5251             raise Exception, msg
    5252         boundary_polygon.append(sts_points[index].tolist())
    5253 
    5254     fid.close()
    5255    
    5256     return boundary_polygon
     5213    return sts_points.tolist()
    52575214
    52585215class Write_sww:
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r5462 r5463  
    69376937        fid=open(order_file,'w')
    69386938        #Write Header
    6939         header="index,longitude,latitude\n"
     6939        header='index, longitude, latitude\n'
    69406940        fid.write(header)
    69416941        indices=[3,0,1]
    69426942        for i in indices:
    6943             line=str(i)+d+str(lat_long_points[i][0])+d+\
    6944                 str(lat_long_points[i][1])+"\n"
     6943            line=str(i)+d+str(lat_long_points[i][1])+d+\
     6944                str(lat_long_points[i][0])+"\n"
    69456945            fid.write(line)
    69466946        fid.close()
    69476947
    69486948        sts_file=base_name
    6949         urs2sts(base_name,sts_file,mean_stage=tide,verbose=False)
     6949        urs2sts(base_name, basename_out=sts_file,
     6950                ordering_filename=order_file,
     6951                mean_stage=tide,
     6952                verbose=False)
    69506953        self.delete_mux(files)
    69516954
    6952         boundary_polygon = create_sts_boundary(order_file,base_name)
     6955        boundary_polygon = create_sts_boundary(base_name)
    69536956
    69546957        os.remove(order_file)
Note: See TracChangeset for help on using the changeset viewer.