1 | """ |
---|
2 | Generate images of "gauges" for production run |
---|
3 | |
---|
4 | Inputs: |
---|
5 | |
---|
6 | production dirs: dictionary of production directories with a |
---|
7 | association to that simulation run, eg high tide, |
---|
8 | low tide and MSL. |
---|
9 | |
---|
10 | Outputs: |
---|
11 | |
---|
12 | * figures used for report stored in the report_figure directory |
---|
13 | |
---|
14 | """ |
---|
15 | from os import getcwd, sep, altsep, mkdir, access, F_OK |
---|
16 | import project |
---|
17 | from anuga.abstract_2d_finite_volumes.util import sww2timeseries |
---|
18 | from anuga.shallow_water import Domain |
---|
19 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
20 | from anuga.shallow_water import File_boundary |
---|
21 | #from anuga.fit_interpolate import Interpolation_function |
---|
22 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher |
---|
23 | |
---|
24 | |
---|
25 | start_screen_catcher(project.temp_dir_name, print_to_screen=True) |
---|
26 | |
---|
27 | # Create report directory |
---|
28 | reportdir = getcwd()+sep+'report'+sep |
---|
29 | if access(reportdir,F_OK) == 0: |
---|
30 | mkdir (reportdir) |
---|
31 | |
---|
32 | # sww file created from URS boundary |
---|
33 | production_dirs = {#'20070206_005106_run': '10000 yr wave height'} |
---|
34 | 'boundaries': 'URS boundary condition'} |
---|
35 | |
---|
36 | meshes_dir_name = project.meshes_dir_name+'.msh' |
---|
37 | print 'create mesh' |
---|
38 | create_mesh_from_regions(project.poly_all, |
---|
39 | boundary_tags=None, |
---|
40 | maximum_triangle_area=500000, |
---|
41 | interior_regions=None, |
---|
42 | filename=meshes_dir_name, |
---|
43 | use_cache=False, |
---|
44 | verbose=True) |
---|
45 | |
---|
46 | domain = Domain(meshes_dir_name, use_cache=True, verbose=True) |
---|
47 | #print"domain id", id(domain) |
---|
48 | |
---|
49 | print domain.statistics() |
---|
50 | boundaries_dir_name=project.boundaries_dir_name |
---|
51 | |
---|
52 | domain.set_quantity('stage', 2.4) |
---|
53 | print 'Reading Boundary file', boundaries_dir_name |
---|
54 | Bf = File_boundary(project.boundaries_dir_name3 + '.sww', |
---|
55 | domain, time_thinning=1, use_cache=True, verbose=True) |
---|
56 | #print "domain id", id(domain) |
---|
57 | print "Bf id", id(Bf) |
---|
58 | |
---|
59 | print "dir,bf", dir(Bf) |
---|
60 | #print 'finished reading boundary file', Bf.get_midpoint_coords() |
---|
61 | print 'finished reading boundary file', Bf.midpoint_coordinates.shape[0],Bf.midpoint_coordinates[0] |
---|
62 | |
---|
63 | # interpolation_points[0] |
---|
64 | |
---|
65 | #number_of_points = Bf.midpoint_coordinates.shape[0] |
---|
66 | number_of_points = (50,200,324) |
---|
67 | |
---|
68 | #number_of_points = Bf.interpolation_points.shape[0] |
---|
69 | print "number_of_points", number_of_points |
---|
70 | dir(Bf.F) |
---|
71 | #for id in range(number_of_points)[10:]: |
---|
72 | for id in number_of_points: |
---|
73 | print "id", id |
---|
74 | x,y=Bf.midpoint_coordinates[id] |
---|
75 | # x,y=Bf.interpolation_points[id] |
---|
76 | print"x,y",x,y |
---|
77 | t_boundary = Bf.F.precomputed_values["stage"][:,id] |
---|
78 | print "t_boundary", t_boundary |
---|
79 | |
---|
80 | #t_file = |
---|
81 | |
---|
82 | |
---|
83 | import sys |
---|
84 | sys.exit() |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | is_parallel = False |
---|
89 | if is_parallel == True: |
---|
90 | nodes = 2 |
---|
91 | |
---|
92 | # Generate figures |
---|
93 | swwfiles = {} |
---|
94 | |
---|
95 | if is_parallel == True: |
---|
96 | |
---|
97 | for i in range(nodes): |
---|
98 | print 'Sending node %d of %d' %(i,nodes) |
---|
99 | swwfiles = {} |
---|
100 | #reportname = report_name + '_%s' %(i) |
---|
101 | for label_id in production_dirs.keys(): |
---|
102 | if label_id == 'boundaries': |
---|
103 | file_loc = project.boundaries_in_dir |
---|
104 | swwfile = file_loc + sep + '20061102_221245_build' + sep + 'dampier.sww' |
---|
105 | print 'hi' |
---|
106 | #else: |
---|
107 | #file_loc = project.output_dir + label_id + sep |
---|
108 | #sww_extra = '_P%s_%s' %(i,nodes) |
---|
109 | #swwfile = file_loc + project.scenario_name + sww_extra + '.sww' |
---|
110 | swwfiles[swwfile] = label_id |
---|
111 | |
---|
112 | texname, elev_output = sww2timeseries(swwfiles, |
---|
113 | project.gauges_dir_name, |
---|
114 | production_dirs, |
---|
115 | report = False, |
---|
116 | #reportname = reportname, |
---|
117 | plot_quantity = ['stage', 'momentum'], |
---|
118 | generate_fig = False, |
---|
119 | surface = False, |
---|
120 | time_min = None, |
---|
121 | time_max = None, |
---|
122 | title_on = False, |
---|
123 | verbose = True) |
---|
124 | |
---|
125 | #latex_output.append(texname) |
---|
126 | |
---|
127 | else: |
---|
128 | |
---|
129 | for label_id in production_dirs.keys(): |
---|
130 | |
---|
131 | if label_id == 'boundaries': |
---|
132 | file_loc = project.boundaries_in_dir |
---|
133 | swwfile = project.boundaries_dir_name3 + '.sww' |
---|
134 | else: |
---|
135 | file_loc = project.output_dir + label_id + sep |
---|
136 | swwfile = file_loc + project.scenario_name + '.sww' |
---|
137 | swwfiles[swwfile] = label_id |
---|
138 | |
---|
139 | texname, elev_output = sww2timeseries(swwfiles, |
---|
140 | project.gauges_dir_name_test, |
---|
141 | production_dirs, |
---|
142 | report = False, |
---|
143 | #reportname = report_name, |
---|
144 | plot_quantity = ['stage', 'momentum'], |
---|
145 | surface = False, |
---|
146 | time_min = None, |
---|
147 | time_max = None, |
---|
148 | title_on = False, |
---|
149 | verbose = True) |
---|
150 | |
---|
151 | fid = open(filename) |
---|
152 | lines = fid.readlines() |
---|
153 | fid.close() |
---|
154 | polygon = [] |
---|
155 | for line in lines: |
---|
156 | fields = line.split(split) |
---|
157 | polygon.append( [float(fields[0]), float(fields[1])] ) |
---|
158 | |
---|
159 | |
---|