Changeset 1155 for inundation/ga/storm_surge/pyvolution/data_manager.py
- Timestamp:
- Mar 29, 2005, 1:09:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r1145 r1155 1835 1835 1836 1836 1837 def sww2domain(filename,t=None,fail_if_NaN=True,NaN_filler=0,verbose = True): 1837 def sww2domain(filename,boundary=None,t=None,\ 1838 fail_if_NaN=True,NaN_filler=0\ 1839 ,verbose = True,very_verbose = False): 1838 1840 """ 1839 1841 Usage: domain = sww2domain('file.sww',t=time (default = last time in file)) 1840 1842 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. 1842 1847 """ 1843 1848 NaN=9.969209968386869e+036 … … 1845 1850 1846 1851 from Scientific.IO.NetCDF import NetCDFFile 1847 from domainimport Domain1848 from Numeric import asarray, transpose 1852 from shallow_water import Domain 1853 from Numeric import asarray, transpose, resize 1849 1854 1850 1855 if verbose: print 'Reading from ', filename … … 1891 1896 1892 1897 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 1899 1921 for quantity in other_quantities: 1900 1922 try: … … 1918 1940 data = (X<>NaN) 1919 1941 X = (X*data)+(data==0)*NaN_filler 1942 if unique: 1943 X = resize(X,(len(X)/3,3)) 1920 1944 domain.set_quantity(quantity,X) 1921 1945 # … … 1941 1965 data = (X<>NaN) 1942 1966 X = (X*data)+(data==0)*NaN_filler 1967 if unique: 1968 X = resize(X,(X.shape[0]/3,3)) 1943 1969 domain.set_quantity(quantity,X) 1944 1970 fid.close() … … 1985 2011 1986 2012 2013 def 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 1987 2070 1988 2071 #OBSOLETE STUFF
Note: See TracChangeset
for help on using the changeset viewer.