| 1 | import os |
|---|
| 2 | import sys |
|---|
| 3 | |
|---|
| 4 | from anuga.shallow_water.data_manager import sww2dem |
|---|
| 5 | from anuga.shallow_water.data_manager import get_flow_through_cross_section |
|---|
| 6 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher |
|---|
| 7 | |
|---|
| 8 | from Scientific.IO.NetCDF import NetCDFFile |
|---|
| 9 | from numpy import size |
|---|
| 10 | |
|---|
| 11 | name = "testCase6A_001_bug_report" |
|---|
| 12 | dx = 0.1 |
|---|
| 13 | #timeSeconds = 4.0 * 3600.0 |
|---|
| 14 | #quantity = 'stage-elevation' #Depth |
|---|
| 15 | #quantity_name = 'depth' |
|---|
| 16 | quantity = 'stage' #Stage |
|---|
| 17 | quantity_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') |
|---|
| 23 | nt = ifile.variables['time'].shape[0] |
|---|
| 24 | tIndex = 0 |
|---|
| 25 | for 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 |
|---|
| 30 | ifile.close()""" |
|---|
| 31 | |
|---|
| 32 | # Define study mask |
|---|
| 33 | xMin = 0.0 |
|---|
| 34 | xMax = 110.0 |
|---|
| 35 | yMin = 0.0 |
|---|
| 36 | yMax = 20.0 |
|---|
| 37 | |
|---|
| 38 | #outname = name + '_' + quantity + '_' + str(time) |
|---|
| 39 | #outname = name + '_' + quantity_name + '_' + str(timeSeconds) |
|---|
| 40 | outname = name + '_' + quantity_name + '_' + 'max' |
|---|
| 41 | |
|---|
| 42 | sww2dem(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 |
|---|
| 55 | xMin = 627350.0 |
|---|
| 56 | xMax = 636000.0 |
|---|
| 57 | yMin = 5625600.0 |
|---|
| 58 | yMax = 5635300.0 |
|---|
| 59 | |
|---|
| 60 | print 'output dir:', name |
|---|
| 61 | which_var = 0 |
|---|
| 62 | if which_var == 0: # Stage |
|---|
| 63 | outname = name + '_stage' |
|---|
| 64 | quantityname = 'stage' |
|---|
| 65 | |
|---|
| 66 | if which_var == 1: # Absolute Momentum |
|---|
| 67 | outname = name + '_momentum' |
|---|
| 68 | quantityname = '(xmomentum**2 + ymomentum**2)**0.5' #Absolute momentum |
|---|
| 69 | |
|---|
| 70 | if which_var == 2: # Depth |
|---|
| 71 | outname = name + '_depth' |
|---|
| 72 | quantityname = 'stage-elevation' #Depth |
|---|
| 73 | |
|---|
| 74 | if which_var == 3: # Speed |
|---|
| 75 | outname = name + '_speed' |
|---|
| 76 | quantityname = '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-30)' #Speed |
|---|
| 77 | |
|---|
| 78 | if which_var == 4: # Elevation |
|---|
| 79 | outname = name + '_elevation' |
|---|
| 80 | quantityname = 'elevation' #Elevation |
|---|
| 81 | |
|---|
| 82 | if 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 | |
|---|
| 86 | print 'start sww2dem' |
|---|
| 87 | |
|---|
| 88 | sww2dem(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 | |
|---|
| 99 | flow_line_1 = [ [536738.0, 6114801.0], [535749.0, 6113411.0] ] |
|---|
| 100 | |
|---|
| 101 | model_times, model_q = get_flow_through_cross_section(filename=name + ".sww", polyline=flow_line_1, verbose=True) |
|---|
| 102 | |
|---|
| 103 | fid = open( "flow_plot_out.csv", "w" ) |
|---|
| 104 | i = 0 |
|---|
| 105 | while i < len(model_times): |
|---|
| 106 | fid.write( str(model_times[i]) + ", " + str(model_q[i]) + "\n" ) |
|---|
| 107 | i = i + 1 |
|---|
| 108 | fid.close()""" |
|---|