source: anuga_work/production/gosford/fitting_problem.py @ 6684

Last change on this file since 6684 was 6684, checked in by kristy, 16 years ago

added Gosford

File size: 7.5 KB
Line 
1"""This scripts recreates fitting problem where values seem to go towards zero
2in areas with missing data.
3"""
4from os.path import join
5from anuga.utilities.polygon import read_polygon
6from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf
7from anuga.shallow_water.data_manager import dem2pts
8from anuga.geospatial_data.geospatial_data import Geospatial_data
9from anuga.interface import create_domain_from_regions
10from anuga.interface import Reflective_boundary
11
12import project, os
13import sys
14from anuga.shallow_water.data_manager import start_screen_catcher
15from anuga.shallow_water.data_manager import copy_code_files
16from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
17from anuga.shallow_water.data_manager import sww2dem
18from os import sep
19
20# Application specific imports
21from setup_model import project   # Definition of file names and polygons
22
23
24#-------------------------------------------------------------------------------
25# Setup
26#-------------------------------------------------------------------------------
27
28scenario_name = 'fitting_problem_' + project.extent
29
30# Initial bounding polygon for data clipping
31bounding_polygon = read_polygon(join(project.polygons_folder, project.extent)+'.csv')
32
33output_run = join(project.output_folder, project.run_time) + scenario_name
34
35#-------------------------------------------------------------------------------
36# Copy scripts to time stamped output directory and capture screen
37# output to file. Copy script must be before screen_catcher
38#-------------------------------------------------------------------------------
39copy_code_files(output_run, __file__, 
40                os.path.join(os.path.dirname(project.__file__),
41                             project.__name__+'.py'))
42start_screen_catcher(output_run, 0, 1)
43
44#-----------------------------------------------------------------------------
45# Preparation of topographic data
46#
47# Convert ASC 2 DEM 2 PTS using source data and store result in source data
48# Do for coarse and fine data
49# Fine pts file to be clipped to area of interest
50#-----------------------------------------------------------------------------
51
52print 'bounding_polygon', bounding_polygon
53combined_elevation = project.combined_elevation + '_' + scenario_name + '.pts'
54print 'combined_elevation', combined_elevation
55if not os.path.exists(combined_elevation):
56    print 'Hello, Create Geospatial data'
57    # Creating Geospatial data from ASCII files'
58    geospatial_data = {}
59    topographies_folder = join(project.topographies_folder, 'original')
60    if not project.ascii_grid_filenames == []:
61        for filename in project.ascii_grid_filenames:
62            absolute_filename = join(topographies_folder, filename)
63            convert_dem_from_ascii2netcdf(absolute_filename,
64                                          basename_out=absolute_filename,
65                                          use_cache=True,
66                                          verbose=True)
67            dem2pts(absolute_filename, use_cache=True, verbose=True)
68
69            G_grid = Geospatial_data(file_name=absolute_filename+'.pts',
70                                                        verbose=True)
71            print 'Clip geospatial object'
72            geospatial_data[filename] = G_grid.clip(bounding_polygon)
73
74    # Create Geospatial data from TXT files
75    if not project.point_filenames == []:
76        for filename in project.point_filenames:
77            absolute_filename = join(topographies_folder, filename)
78            G_points = Geospatial_data(file_name=absolute_filename,
79                                                        verbose=True)
80            print 'Clip geospatial object'
81            geospatial_data[filename] = G_points.clip(bounding_polygon)
82
83
84    #------------------------------------------------------------------------------
85    # Combine, clip and export dataset
86    #------------------------------------------------------------------------------
87
88    print 'Add geospatial objects'
89    G = None
90    for key in geospatial_data:
91        G += geospatial_data[key]
92                   
93    print 'Export combined DEM file'
94    G.export_points_file(combined_elevation)
95
96    print 'Do txt version too'
97    # Use for comparision in ARC
98    G.export_points_file(combined_elevation[:-4] + '.txt')
99
100
101#------------------------------------------------------------------------------
102# Create ANUGA mesh and fit
103#------------------------------------------------------------------------------
104
105tags = {'x': range(len(bounding_polygon))} # All segments tagged the same
106domain = create_domain_from_regions(bounding_polygon,
107                                    boundary_tags=tags,
108                                    maximum_triangle_area=project.extent_maxarea,
109                                    interior_regions=project.interior_regions,
110                                    mesh_filename=project.meshes,
111                                    use_cache=False,
112                                    verbose=True)
113print domain.statistics()
114
115
116domain.set_name(scenario_name)
117domain.set_datadir(output_run) 
118domain.set_minimum_storable_height(0.01)    # Don't store depth less than 1cm
119
120#------------------------------------------------------------------------------
121# Setup initial conditions
122#------------------------------------------------------------------------------
123
124print 'Setup initial conditions'
125domain.set_quantity('stage', 0.0)
126domain.set_quantity('friction', 0.01)
127domain.set_quantity('elevation', 
128                    filename=combined_elevation,
129                    use_cache=True,
130                    verbose=True,
131                    alpha=0.1)
132
133#------------------------------------------------------------------------------
134# Setup boundary conditions
135#------------------------------------------------------------------------------
136
137print 'Set boundary - available tags:', domain.get_boundary_tags()
138Br = Reflective_boundary(domain)
139domain.set_boundary({'x': Br}) 
140
141#-----------------------------------------------------------------------------
142# Take a few steps
143#-----------------------------------------------------------------------------
144
145
146for t in domain.evolve(yieldstep=1, 
147                       finaltime=3): 
148    print domain.timestepping_statistics()
149    print domain.boundary_statistics(tags='x')
150
151print 'Done'
152
153
154#-----------------------------------------------------------------------------
155# Exporting Grid
156# Define allowed variable names and associated equations to generate values.
157# This would not normally change.
158#-----------------------------------------------------------------------------
159var_equations = {'stage':     'stage',
160                 'momentum':  '(xmomentum**2 + ymomentum**2)**0.5',
161                 'depth':     'stage-elevation',
162                 'speed':     '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)',
163                 'elevation': 'elevation' }
164
165# one or more key strings from var_equations above
166var = ['elevation']
167
168######
169# Start running the various conversions we require.
170######
171
172for which_var in var:
173    if which_var not in var_equations:
174        print 'Unrecognized variable name: %s' % which_var
175        break
176   
177    name = join(output_run, scenario_name)
178    outname = name + '_' + which_var
179    quantityname = var_equations[which_var]
180
181    print 'start sww2dem: name=%s' % name
182   
183    sww2dem(name, basename_out = outname,
184                quantity = quantityname,
185                timestep = 0,
186                cellsize = 10,   
187                reduction = max, 
188                verbose = True,
189                format = 'asc')
190
191
192
Note: See TracBrowser for help on using the repository browser.