Ignore:
Timestamp:
Jul 4, 2008, 1:56:15 PM (16 years ago)
Author:
ole
Message:

updated boxingday scenario to use ordered sts file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/development/boxingday08/project.py

    r5458 r5465  
    22from Scientific.IO.NetCDF import NetCDFFile
    33from Numeric import asarray,transpose,sqrt,argmax,argmin,arange,Float,\
    4     compress,zeros,fabs,allclose
     4    compress,zeros,fabs,allclose,ones
    55from anuga.utilities.polygon import inside_polygon,read_polygon
    66from os import sep
    77from time import localtime, strftime, gmtime
    8 
    9 def create_sts_boundary_order_file(order_filename,stsfilename,verbose=False):
     8from anuga.shallow_water.data_manager import urs2sts,create_sts_boundary
     9import os
     10
     11def create_sts_boundary_order_file(urs_filename,order_filename,sts_filename,verbose=False):
    1012    """
    1113    Note This is not a robust algorithm. Be Careful when applying that
     
    1315    follows the path it is supposed too.
    1416    """
    15     fid = NetCDFFile(stsfilename+'.sts', 'r')    #Open existing file for read
    16     x = fid.variables['x'][:]+fid.xllcorner   #x-coordinates of vertices
    17     y = fid.variables['y'][:]+fid.yllcorner   #y-coordinates of vertices
    18     coordinates=transpose(asarray([x.tolist(),y.tolist()]))
     17    from anuga.shallow_water.data_manager import read_mux2_py
     18    times, y, x, elevation, quantity, starttime = read_mux2_py([urs_filename],weights=ones(1,Float))
    1919   
    2020    #find indices of the southernmost gauges
     
    6060             
    6161    #So far i cannot tell if the wrong point is closer.
     62   
     63    boundary=ensure_numeric(boundary)
     64    from anuga.coordinate_transforms import redfearn,convert_from_latlon_to_utm
     65    boundary_utm,zone=convert_from_latlon_to_utm(longitudes=list(boundary[:,0]),latitudes=list(boundary[:,1]))
     66
    6267    d=","
    6368    fid=open(order_filename,'w')
    64     header="index,longitude,latitude\n"
     69    header='index, longitude, latitude\n'
    6570    fid.write(header)
    6671    line=str(west_index)+d+str(x[west_index])+d+\
     
    7277            fid.write(line)
    7378    fid.close()
    74     return boundary
    75            
    76 
    77 #read in polyline boundary
    78 from anuga.shallow_water.data_manager import urs2sts,create_sts_boundary
    79 urs_name='polyline'
    80 #base_name=urs_name
    81 tide=0.35
    82 base_name='tide_polyline'
    83 #base_name='most_polyline'
    84 import os
    85 if os.path.exists(base_name+'.sts'):
    86     print 'sts boundary file already created.'
    87 else:
    88     print 'creatin sts file'
    89     urs2sts(urs_name,base_name,mean_stage=tide,verbose=False)
    90 
    91 order_filename='sts_order.txt'
    92 boundary=create_sts_boundary_order_file(order_filename,base_name,verbose=False)
    93 urs_boundary=create_sts_boundary(order_filename,base_name,lat_long=False)
    94 assert allclose(boundary.tolist(),urs_boundary)
    95 
    96 #Read in large domain boundary
    97 dir='mesh_polygons'
    98 extent = 'extent.csv'
    99 bp = read_polygon(dir+sep+extent)
    100 
    101 #Now order of boundary is correct clip sts boundary to small region for
    102 #this particular scenario
    103 indices=inside_polygon(urs_boundary, bp, closed=True, verbose=False)
    104 bounding_polygon=[]
    105 for i in indices[:-2]:
    106     #disregard last two entries because they are not on boundary
    107     bounding_polygon.append(urs_boundary[i])
    108 
    109 #Append clipped sts boundary to large domain boundary
    110 bounding_polygon.extend(bp[2:len(bp)])
    111 
    112 ###############################
    113 # Domain definitions
    114 ###############################
     79    return boundary,boundary_utm
     80
     81######################
     82# Domain definitions #
     83######################
    11584
    11685# Bathymetry and topography filenames
     
    12998extent = 'extent.csv'
    13099patong_bay_polygon = read_polygon(dir+sep+'patong_bay_polygon.csv')
     100   
     101tide=0.35
     102
     103######################################
     104# Create urs boundary from mux2files #
     105######################################
     106urs_filename='polyline'
     107base_name='tide_polyline'
     108order_filename='boxingday_boundary_order.txt'
     109
     110# Create ordering file
     111# Usually this would be provided before hand
     112boundary,boundary_utm=create_sts_boundary_order_file(urs_filename+'_waveheight-z-mux2',order_filename,base_name,verbose=False)
     113
     114# Create ordered sts file
     115if not os.path.exists(base_name+'.sts'):
     116    print 'creating sts file'
     117    urs2sts(urs_filename,basename_out=base_name,
     118    ordering_filename=order_filename,
     119    mean_stage=tide,
     120    verbose=False)
     121else:
     122    print 'sts file exists'
     123
     124# Read in boundary from ordered sts file
     125urs_boundary=create_sts_boundary(base_name)
     126
     127# Checks that the boundary read from the sts file is the same as the one
     128# defined by the function create_sts_boundary_order_file
     129assert allclose(boundary_utm,urs_boundary)
     130
     131#############################################################
     132# Add urs boundary segment to user defined boundary polygon #
     133#############################################################
     134
     135# Read in specific user defined boundary
     136dir='mesh_polygons'
     137extent = 'extent.csv'
     138user_boundary_polygon = read_polygon(dir+sep+extent)
     139
     140# The following is specific to this scenario
     141indices=inside_polygon(urs_boundary, user_boundary_polygon, closed=True, verbose=False)
     142bounding_polygon=[]
     143for i in indices[:-2]:
     144    #disregard last two entries because they are not on boundary
     145    bounding_polygon.append(urs_boundary[i])
     146
     147# Append clipped sts boundary to user defined domain boundary
     148bounding_polygon.extend(user_boundary_polygon[2:len(user_boundary_polygon)])
    131149
    132150###############################
    133 # Interior region definitions
     151# Interior region definitions #
    134152###############################
    135153
     
    141159patong = read_polygon(dir+sep+'patong.csv')
    142160bay = read_polygon(dir+sep+'bay.csv')
     161
     162##########################################
     163# Plot urs boundary and internal regions #
     164##########################################
    143165
    144166plot=False
     
    156178    show()
    157179
     180   
     181#######################
     182# For MOST SIMULATION #
     183#######################
    158184east  = 97.7
    159185west  = 96.7
Note: See TracChangeset for help on using the changeset viewer.