Ticket #344: makeASC.py

File makeASC.py, 3.2 KB (added by sexton, 15 years ago)

script supplied by Peter Wells highlighting error

Line 
1import os
2import sys
3
4from anuga.shallow_water.data_manager import sww2dem
5from anuga.shallow_water.data_manager import get_flow_through_cross_section
6from anuga.abstract_2d_finite_volumes.util import start_screen_catcher
7
8from Scientific.IO.NetCDF import NetCDFFile
9from numpy import size
10
11name = "testCase6A_001_bug_report"
12dx = 0.1
13#timeSeconds = 4.0 * 3600.0
14#quantity = 'stage-elevation' #Depth
15#quantity_name = 'depth'
16quantity = 'stage' #Stage
17quantity_name = 'stage'
18#quantity = '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-30)' #Velocity
19#quantity_name = 'velocity'
20
21# Open SWW file and get correct time index
22"""ifile = NetCDFFile(name+'.sww', 'r')
23nt = ifile.variables['time'].shape[0]
24tIndex = 0
25for i in range(nt):
26  if ifile.variables['time'][i] == timeSeconds:
27    print 'Found time of ' + str(timeSeconds) + ' at index ' + str(i)
28    tIndex = i
29    break
30ifile.close()"""
31
32# Define study mask
33xMin = 0.0
34xMax = 110.0
35yMin = 0.0
36yMax = 20.0
37
38#outname = name + '_' + quantity + '_' + str(time)
39#outname = name + '_' + quantity_name + '_' + str(timeSeconds)
40outname = name + '_' + quantity_name + '_' + 'max'
41
42sww2dem(basename_in = name, basename_out = outname,
43            quantity = quantity,
44            #timestep = tIndex,
45            reduction = max,
46            cellsize = dx,
47            easting_min = xMin,
48            easting_max = xMax,
49            northing_min = yMin,
50            northing_max = yMax,       
51            verbose = True,
52            format = 'asc')
53
54"""# Define study mask
55xMin = 627350.0
56xMax = 636000.0
57yMin = 5625600.0
58yMax = 5635300.0
59
60print 'output dir:', name
61which_var = 0
62if which_var == 0:  # Stage
63    outname = name + '_stage'
64    quantityname = 'stage'
65
66if which_var == 1:  # Absolute Momentum
67    outname = name + '_momentum'
68    quantityname = '(xmomentum**2 + ymomentum**2)**0.5'  #Absolute momentum
69
70if which_var == 2:  # Depth
71    outname = name + '_depth'
72    quantityname = 'stage-elevation'  #Depth
73
74if which_var == 3:  # Speed
75    outname = name + '_speed'
76    quantityname = '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-30)'  #Speed
77
78if which_var == 4:  # Elevation
79    outname = name + '_elevation'
80    quantityname = 'elevation'  #Elevation
81   
82if which_var == 5:  # UK Hazard (with debris of 1.0) D*(V+0.5)+DF
83    outname = name + '_uk_haz'
84    quantityname = '((stage-elevation) * ( (xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-30) + 0.5) ) + 1.0'  #Elevation
85
86print 'start sww2dem'
87
88sww2dem(name, basename_out = outname,
89            quantity = quantityname,
90            cellsize = dx,     
91            easting_min = xMin,
92            easting_max = xMax,
93            northing_min = yMin,
94            northing_max = yMax,       
95            reduction = max,
96            verbose = True,
97            format = 'asc')
98           
99flow_line_1 = [ [536738.0, 6114801.0], [535749.0, 6113411.0] ]
100
101model_times, model_q = get_flow_through_cross_section(filename=name + ".sww", polyline=flow_line_1, verbose=True)
102
103fid = open( "flow_plot_out.csv", "w" )
104i = 0
105while i < len(model_times):
106  fid.write( str(model_times[i]) + ", " + str(model_q[i]) + "\n" )
107  i = i + 1
108fid.close()"""