source: trunk/anuga_work/development/Busselton/BP3Hydro/setup_model.py @ 8449

Last change on this file since 8449 was 8449, checked in by martins, 13 years ago

Checking in Busselton NCI code

  • Property svn:executable set to *
File size: 6.4 KB
Line 
1"""
2Module to import the project.py 'configuration' file and perform
3sanity checks plus a quick check on mesh generation.
4
5Also callable as a stand-alone program, mainly to view the results
6of the mesh generation.
7"""
8
9import os
10
11from os.path import join, exists
12from anuga.geometry.polygon import read_polygon, number_mesh_triangles
13from anuga.file.csv_file import load_csv_as_polygons as csv2polygons
14import project
15
16
17
18#-------------------------------------------------------------------------------
19# Sanity checks - check that required files/directories, etc, exist.
20#-------------------------------------------------------------------------------
21
22# flag - we check many things and then don't proceed if anything wrong
23sanity_error = False               # checked at bottom of this file
24
25# Test that environment variables are defined.
26#if os.getenv(project.ENV_INUNDATIONHOME) is None:
27#    print "Environment variable '%s' is not set" % project.ENV_INUNDATIONHOME
28#    sanity_error = True
29
30#-------------------------------------------------------------------------------
31# Directory Structure
32#-------------------------------------------------------------------------------
33
34# check folders generated from environment variables.
35if not exists(project.home):
36    print "Sorry, data directory '%s' doesn't exist" % project.home
37    sanity_error = True
38       
39if not exists(project.anuga_folder):
40    print "Sorry, ANUGA directory '%s' doesn't exist" % project.anuga_folder
41    sanity_error = True
42
43if not exists(project.topographies_folder):
44    print ("Sorry, topo directory '%s' doesn't exist"
45           % project.topographies_folder)
46    sanity_error = True
47
48if not exists(project.polygons_folder):
49    print ("Sorry, polygon directory '%s' doesn't exist"
50           % project.polygons_folder)
51    sanity_error = True
52
53# if not exists(project.rain_folder):
54#    print ("Sorry, rain directory '%s' doesn't exist"
55#           % project.rain_folder)
56#    sanity_error = True
57
58#if not exists(project.output_folder):
59#    print "Sorry, outputs directory '%s' doesn't exist" % project.output_folder
60#    sanity_error = True
61
62if not exists(project.hydrographs_folder):
63    print "Sorry, hydrographs directory '%s' doesn't exist" % project.hydrographs_folder
64    sanity_error = True
65       
66#if not exists(project.ocean_folder):
67#    print "Sorry, ocean directory '%s' doesn't exist" % project.ocean_folder
68#    sanity_error = True
69
70#-------------------------------------------------------------------------------
71# Determine type of run
72#-------------------------------------------------------------------------------
73# parameters in this can be changed if desired.
74if project.setup == 'trial':
75    project.scale_factor = 100      # multiplies the triangles in mesh by 100   
76    project.time_thinning = 96
77#    project.yieldstep = 240         # data is only stored at 240 sec intervals
78elif project.setup == 'basic': 
79    project.scale_factor = 4
80    project.time_thinning = 12
81#    project.yieldstep = 120
82elif project.setup == 'final': 
83    project.scale_factor = 1       
84    project.time_thinning = 4
85#    project.yieldstep = 60
86else:
87    print ("Sorry, you must set the 'setup' variable to one of:"
88           '   trial - coarsest mesh, fast\n'
89           '   basic - coarse mesh\n'
90           '   final - fine mesh, slowest\n'
91           '\n'
92           "'setup' was set to '%s'" % project.setup)
93    sanity_error = True
94
95#-------------------------------------------------------------------------------
96# Check for errors detected above.
97#-------------------------------------------------------------------------------
98
99if sanity_error:
100    msg = 'You must fix the above errors before continuing.'
101    raise Exception, msg
102
103#-------------------------------------------------------------------------------
104# Reading polygons and creating interior regions
105#-------------------------------------------------------------------------------
106
107# Create list of land polygons with initial conditions
108##project.land_initial_conditions = []
109### if it's a list, then it's a list of land condition filenames
110### else it's a string - a single file, multiple land conditions
111##if isinstance(project.land_initial_conditions_filename, list):
112##    for filename, MSL in project.land_initial_conditions_filename:
113##        polygon = read_polygon(join(project.polygons_folder, filename))
114##        project.land_initial_conditions.append([polygon, MSL])
115##elif isinstance(project.land_initial_conditions_filename, basestring):
116##    polygons, MSL = csv2polygons(join(project.polygons_folder,
117##                                      project.land_initial_conditions_filename))
118##    for i, key in enumerate(polygons):
119##        if i%100==0: print i
120##        poly = polygons[key]
121##        land = float(MSL[key])
122##        project.land_initial_conditions.append([poly, land])
123##else:
124##    msg = ('project.land_initial_conditions_filename must be a list or '
125##           'string, got %s'
126##           % type(project.land_initial_conditions_filename))
127##    raise Exception, msg
128### Create list of interior polygons with scaling factor
129project.interior_regions = []
130
131if project.PriorityArea_filename is not None:
132    polygons, maxareas = csv2polygons(project.PriorityAreas)
133    print 'Creating %d internal polygons' % len(polygons)
134    #def create_polygon_function(polygons, geo_reference=None):
135    project.interior_regions = []
136    for i, key in enumerate(polygons):
137        if i%100==0: print i
138        poly = polygons[key]
139        maxarea = float(maxareas[key])
140        project.interior_regions.append([poly,
141                                         maxarea*project.scale_factor])
142
143for filename, maxarea in project.interior_regions_data:
144    polygon = read_polygon(join(project.polygons_folder, filename))
145    project.interior_regions.append([polygon,
146                                     maxarea*project.scale_factor])
147
148# Initial bounding polygon for data clipping
149project.bounding_polygon = read_polygon(join(project.polygons_folder, 
150                                             project.bounding_polygon_filename))
151project.bounding_maxarea = project.bounding_polygon_maxarea*project.scale_factor
152
153project.num_boundary_segments = len(project.bounding_polygon) - 1
154
155# Estimate the number of triangles                     
156trigs_min = number_mesh_triangles(project.interior_regions,
157                                  project.bounding_polygon,
158                                  project.bounding_maxarea)
159
160#print 'min estimated number of triangles', trigs_min
Note: See TracBrowser for help on using the repository browser.