Changeset 4643


Ignore:
Timestamp:
Jul 30, 2007, 12:34:40 PM (17 years ago)
Author:
nick
Message:

added a function to easily get the runup data near a several certain locations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r4635 r4643  
    19001900    return min1, max1
    19011901
    1902    
    1903    
    1904    
    1905 
    1906 
    1907        
     1902
     1903def get_runup_data_for_locations_from_file(gauge_filename,
     1904                                           sww_filename,
     1905                                           runup_filename,
     1906                                           size=10,
     1907                                           verbose=False):
     1908
     1909    '''this will read a csv file with the header x,y. Then look in a square 'size'x2
     1910    around this position for the 'max_inundaiton_height' in the 'sww_filename' and
     1911    report the findings in the 'runup_filename
     1912   
     1913    WARNING: NO TESTS!
     1914    '''
     1915
     1916    from anuga.shallow_water.data_manager import get_all_directories_with_name,\
     1917                                                 get_maximum_inundation_data,\
     1918                                                 csv2dict
     1919                                                 
     1920    file = open(runup_filename,"w")
     1921    file.write("easting,northing,runup \n ")
     1922    file.close()
     1923   
     1924    #read gauge csv file to dictionary
     1925    attribute_dic, title_index_dic = csv2dict(gauge_filename)
     1926    northing = [float(x) for x in attribute_dic["y"]]
     1927    easting = [float(x) for x in attribute_dic["x"]]
     1928
     1929    print 'Reading %s' %sww_filename
     1930
     1931    runup_locations=[]
     1932    for i, x in enumerate(northing):
     1933#        print 'easting,northing',i,easting[i],northing[i]
     1934        poly = [[int(easting[i]+size),int(northing[i]+size)],
     1935                [int(easting[i]+size),int(northing[i]-size)],
     1936                [int(easting[i]-size),int(northing[i]-size)],
     1937                [int(easting[i]-size),int(northing[i]+size)]]
     1938       
     1939        run_up, x_y = get_maximum_inundation_data(filename=sww_filename,
     1940                                              polygon=poly,
     1941                                              verbose=False)
     1942        #if no runup will return 0 instead of NONE
     1943        if run_up==None: run_up=0
     1944        if x_y==None: x_y=[0,0]
     1945       
     1946        if verbose:print 'maximum inundation runup near %s is %s meters' %(x_y,run_up)
     1947       
     1948        #writes to file
     1949        file = open(runup_filename,"a")
     1950        temp = '%s,%s,%s \n' %(x_y[0], x_y[1], run_up)
     1951        file.write(temp)
     1952        file.close()
Note: See TracChangeset for help on using the changeset viewer.