Ignore:
Timestamp:
Mar 29, 2005, 1:09:46 PM (20 years ago)
Author:
prow
Message:

sww2domian - weeding non-unique coordinates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/data_manager.py

    r1145 r1155  
    18351835
    18361836
    1837 def sww2domain(filename,t=None,fail_if_NaN=True,NaN_filler=0,verbose = True):
     1837def sww2domain(filename,boundary=None,t=None,\
     1838               fail_if_NaN=True,NaN_filler=0\
     1839               ,verbose = True,very_verbose = False):
    18381840    """
    18391841    Usage: domain = sww2domain('file.sww',t=time (default = last time in file))
    18401842
    1841     If the sww has stages, but not
     1843    Boundary is not recommended if domian.smooth is not selected, as it       
     1844    uses unique coordinates, but not unique boundaries. This means that
     1845    the boundary file will not be compatable with the coordiantes, and will
     1846    give a different final boundary, or crash.
    18421847    """
    18431848    NaN=9.969209968386869e+036
     
    18451850
    18461851    from Scientific.IO.NetCDF import NetCDFFile
    1847     from domain import Domain
    1848     from Numeric import asarray, transpose
     1852    from shallow_water import Domain
     1853    from Numeric import asarray, transpose, resize
    18491854
    18501855    if verbose: print 'Reading from ', filename
     
    18911896
    18921897    if verbose: print '    building domain'
    1893     domain = Domain(coordinates, volumes,\
    1894                     conserved_quantities = conserved_quantities,\
    1895                     other_quantities = other_quantities,zone=zone,\
    1896                     xllcorner=xllcorner, yllcorner=yllcorner)
    1897     domain.starttime=starttime
    1898     domain.time=t
     1898#    From domain.Domain:
     1899#    domain = Domain(coordinates, volumes,\
     1900#                    conserved_quantities = conserved_quantities,\
     1901#                    other_quantities = other_quantities,zone=zone,\
     1902#                    xllcorner=xllcorner, yllcorner=yllcorner)
     1903
     1904#   From shallow_water.Domain:
     1905    coordinates=coordinates.tolist()
     1906    volumes=volumes.tolist()
     1907    #FIXME:should this be in mesh?(peter row)
     1908    unique,coordinates,volumes,boundary=weed(coordinates,volumes,boundary)
     1909
     1910    domain = Domain(coordinates, volumes, boundary)
     1911
     1912    if not boundary is None:
     1913        domain.boundary = boundary
     1914    domain.zone=zone
     1915    domain.xllcorner=float(xllcorner)
     1916    domain.yllcorner=float(yllcorner)
     1917
     1918    domain.starttime=float(starttime)+float(t)
     1919    domain.time=0.0
     1920
    18991921    for quantity in other_quantities:
    19001922        try:
     
    19181940                data = (X<>NaN)
    19191941                X = (X*data)+(data==0)*NaN_filler
     1942        if unique:
     1943            X = resize(X,(len(X)/3,3))
    19201944        domain.set_quantity(quantity,X)
    19211945#
     
    19411965                data = (X<>NaN)
    19421966                X = (X*data)+(data==0)*NaN_filler
     1967        if unique:
     1968            X = resize(X,(X.shape[0]/3,3))
    19431969        domain.set_quantity(quantity,X)
    19441970    fid.close()
     
    19852011
    19862012
     2013def weed(coordinates,volumes,boundary = None):
     2014    if type(coordinates)=='array':
     2015        coordinates = coordinates.tolist()
     2016    if type(volumes)=='array':
     2017        volumes = volumes.tolist()
     2018
     2019    unique = False
     2020    point_dict = {}
     2021    same_point = {}
     2022    for i in range(len(coordinates)):
     2023        point = tuple(coordinates[i])
     2024        if point_dict.has_key(point):
     2025            unique = True
     2026            same_point[i]=point
     2027            #to change all point i references to point j
     2028        else:
     2029            point_dict[point]=i
     2030            same_point[i]=point
     2031
     2032    coordinates = []
     2033    i = 0
     2034    for point in point_dict.keys():
     2035        point = tuple(point)
     2036        coordinates.append(list(point))
     2037        point_dict[point]=i
     2038        i+=1
     2039
     2040
     2041    for volume in volumes:
     2042        for i in range(len(volume)):
     2043            index = volume[i]
     2044            if index>-1:
     2045                volume[i]=point_dict[same_point[index]]
     2046
     2047    new_boundary = {}
     2048    if not boundary is None:
     2049        for segment in boundary.keys():
     2050            point0 = point_dict[same_point[segment[0]]]
     2051            point1 = point_dict[same_point[segment[1]]]
     2052            label = boundary[segment]
     2053            #FIXME should the bounday attributes be concaterated
     2054            #('exterior, pond') or replaced ('pond')(peter row)
     2055
     2056            if new_boundary.has_key((point0,point1)):
     2057                new_boundary[(point0,point1)]=new_boundary[(point0,point1)]#\
     2058                                              #+','+label
     2059
     2060            elif new_boundary.has_key((point1,point0)):
     2061                new_boundary[(point1,point0)]=new_boundary[(point1,point0)]#\
     2062                                              #+','+label
     2063            else: new_boundary[(point0,point1)]=label
     2064
     2065        boundary = new_boundary               
     2066
     2067    return unique,coordinates,volumes,boundary
     2068       
     2069       
    19872070
    19882071#OBSOLETE STUFF
Note: See TracChangeset for help on using the changeset viewer.