Changeset 5582
- Timestamp:
- Jul 29, 2008, 10:51:48 AM (16 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r5579 r5582 5011 5011 msg = 'When combining multiple sources must specify a weight for '+\ 5012 5012 'mux2 source file' 5013 assert len(weights)== numSrc, msg 5013 assert len(weights) == numSrc, msg 5014 5015 if verbose: 5016 print 'Weights used in urs2sts:', weights 5014 5017 5015 5018 # Check output filename -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r5556 r5582 6131 6131 va=va) 6132 6132 6133 weights=ones(1, Float)6133 weights=ones(1, Float) 6134 6134 #ensure that files are indeed mux2 files 6135 6135 times, latitudes, longitudes, elevation, stage, starttime =read_mux2_py([files[0]],weights) … … 6188 6188 va=va) 6189 6189 6190 weights=ones(1, Float)6190 weights=ones(1, Float) 6191 6191 #ensure that files are indeed mux2 files 6192 6192 times, latitudes, longitudes, elevation, stage,starttime=read_mux2_py([files[0]],weights) … … 6249 6249 va=va) 6250 6250 6251 weights=ones(1, Float)6251 weights=ones(1, Float) 6252 6252 #ensure that files are indeed mux2 files 6253 6253 times, latitudes, longitudes, elevation, stage,starttime=read_mux2_py([files[0]],weights) … … 6448 6448 urs2sts([base_nameI, base_nameII], 6449 6449 basename_out=base_nameI, 6450 weights=[1.0, 1.0],6450 weights=[1.0, 1.0], 6451 6451 mean_stage=tide, 6452 6452 verbose=False) … … 6604 6604 basename_out=base_nameI, 6605 6605 ordering_filename=ordering_filename, 6606 weights=[1.0, 1.0],6606 weights=[1.0, 1.0], 6607 6607 mean_stage=tide, 6608 6608 verbose=False) … … 6782 6782 basename_out=base_nameI, 6783 6783 ordering_filename=ordering_filename, 6784 weights=[1.0, 1.0],6784 weights=[1.0, 1.0], 6785 6785 mean_stage=tide, 6786 6786 verbose=False) … … 6814 6814 6815 6815 # Create non-trivial weights 6816 weights = [0.8, 1.5] 6816 #weights = [0.8, 1.5] # OK 6817 #weights = [0.8, 10.5] # Fail (up to allclose tolerance) 6818 #weights = [10.5, 10.5] # OK 6819 #weights = [0.0, 10.5] # OK 6820 #weights = [0.8, 0.] # OK 6821 #weights = [8, 0.1] # OK 6822 #weights = [0.8, 10.0] # OK 6823 #weights = [0.8, 10.6] # OK 6824 weights = [3.8, 7.6] # OK 6825 #weights = [0.5, 0.5] # OK 6826 #weights = [2., 2.] # OK 6827 #weights = [0.0, 0.5] # OK 6828 #weights = [1.0, 1.0] # OK 6829 6817 6830 6818 6831 # Create different timeseries starting and ending at different times … … 6860 6873 6861 6874 6875 6862 6876 #print 6863 6877 #print 'using varying start and end time' 6864 #print 'ha0', ha0 6878 #print 'ha0', ha0[4] 6865 6879 #print 'ua0', ua0 6866 6880 #print 'va0', va0 … … 6878 6892 6879 6893 # Create data to be written to second mux file 6880 ha1= zeros((n,time_step_count),Float)6894 ha1=ones((n,time_step_count),Float) 6881 6895 ha1[0]=sin(times_ref) 6882 6896 ha1[1]=2*sin(times_ref - 3) … … 6909 6923 #print 6910 6924 #print 'using varying start and end time' 6911 #print 'ha1', ha1 6925 #print 'ha1', ha1[4] 6912 6926 #print 'ua1', ua1 6913 6927 #print 'va1', va1 … … 6938 6952 6939 6953 6940 6941 # Call urs2sts with multiple mux files 6942 urs2sts([base_nameI, base_nameII], 6954 #------------------------------------------------------------ 6955 # Now read the mux files one by one with out weights and test 6956 6957 # Call urs2sts with mux file #0 6958 urs2sts([base_nameI], 6943 6959 basename_out=base_nameI, 6944 6960 ordering_filename=ordering_filename, 6945 weights=weights,6946 6961 mean_stage=tide, 6947 6962 verbose=False) … … 6979 6994 6980 6995 6996 # Check sts values for mux #0 6997 stage0 = fid.variables['stage'][:].copy() 6998 xmomentum0 = fid.variables['xmomentum'][:].copy() 6999 ymomentum0 = fid.variables['ymomentum'][:].copy() 7000 elevation0 = fid.variables['elevation'][:].copy() 7001 7002 7003 #print 'stage', stage0 7004 #print 'xmomentum', xmomentum0 7005 #print 'ymomentum', ymomentum0 7006 #print 'elevation', elevation0 7007 7008 # The quantities stored in the .sts file should be the weighted sum of the 7009 # quantities written to the mux2 files subject to the permutation vector. 7010 7011 ha_ref = take(ha0, permutation) 7012 ua_ref = take(ua0, permutation) 7013 va_ref = take(va0, permutation) 7014 7015 gauge_depth_ref = take(gauge_depth, permutation) 7016 7017 7018 #print 7019 #print stage0 7020 #print transpose(ha_ref)+tide - stage0 7021 7022 7023 assert allclose(transpose(ha_ref)+tide, stage0) # Meters 7024 7025 #Check the momentums - ua 7026 #momentum = velocity*(stage-elevation) 7027 # elevation = - depth 7028 #momentum = velocity_ua *(stage+depth) 7029 7030 depth_ref = zeros((len(permutation), time_step_count), Float) 7031 for i in range(len(permutation)): 7032 depth_ref[i]=gauge_depth_ref[i]+tide+ha_ref[i] 7033 7034 7035 # The xmomentum stored in the .sts file should be the sum of the ua 7036 # in the two mux2 files multiplied by the depth. 7037 assert allclose(transpose(ua_ref*depth_ref), xmomentum0) 7038 7039 #Check the momentums - va 7040 #momentum = velocity*(stage-elevation) 7041 # elevation = - depth 7042 #momentum = velocity_va *(stage+depth) 7043 7044 # The ymomentum stored in the .sts file should be the sum of the va 7045 # in the two mux2 files multiplied by the depth. 7046 7047 7048 #print transpose(va_ref*depth_ref) 7049 #print ymomentum 7050 assert allclose(transpose(va_ref*depth_ref), ymomentum0) 7051 7052 # check the elevation values. 7053 # -ve since urs measures depth, sww meshers height, 7054 assert allclose(-gauge_depth_ref, elevation0) 7055 7056 fid.close() 7057 os.remove(sts_file) 7058 7059 7060 7061 7062 # Call urs2sts with mux file #1 7063 urs2sts([base_nameII], 7064 basename_out=base_nameI, 7065 ordering_filename=ordering_filename, 7066 mean_stage=tide, 7067 verbose=False) 7068 7069 # Now read the sts file and check that values have been stored correctly. 7070 sts_file = base_nameI + '.sts' 7071 fid = NetCDFFile(sts_file) 7072 7073 # Make x and y absolute 7074 x = fid.variables['x'][:] 7075 y = fid.variables['y'][:] 7076 7077 geo_reference = Geo_reference(NetCDFObject=fid) 7078 points = geo_reference.get_absolute(map(None, x, y)) 7079 points = ensure_numeric(points) 7080 7081 x = points[:,0] 7082 y = points[:,1] 7083 7084 for i, index in enumerate(permutation): 7085 # Check that STS points are stored in the correct order 7086 7087 # Work out the UTM coordinates sts point i 7088 zone, e, n = redfearn(lat_long_points[index][0], 7089 lat_long_points[index][1]) 7090 7091 #print i, [x[i],y[i]], [e,n] 7092 assert allclose([x[i],y[i]], [e,n]) 7093 7094 7095 # Check the time vector 7096 times = fid.variables['time'][:] 7097 assert allclose(ensure_numeric(times), 7098 ensure_numeric(times_ref)) 7099 7100 7101 # Check sts values for mux #1 7102 stage1 = fid.variables['stage'][:].copy() 7103 xmomentum1 = fid.variables['xmomentum'][:].copy() 7104 ymomentum1 = fid.variables['ymomentum'][:].copy() 7105 elevation1 = fid.variables['elevation'][:].copy() 7106 7107 7108 #print 'stage', stage1 7109 #print 'xmomentum', xmomentum1 7110 #print 'ymomentum', ymomentum1 7111 #print 'elevation', elevation1 7112 7113 # The quantities stored in the .sts file should be the weighted sum of the 7114 # quantities written to the mux2 files subject to the permutation vector. 7115 7116 ha_ref = take(ha1, permutation) 7117 ua_ref = take(ua1, permutation) 7118 va_ref = take(va1, permutation) 7119 7120 gauge_depth_ref = take(gauge_depth, permutation) 7121 7122 7123 #print 7124 #print stage1 7125 #print transpose(ha_ref)+tide - stage1 7126 7127 7128 assert allclose(transpose(ha_ref)+tide, stage1) # Meters 7129 #import sys; sys.exit() 7130 7131 #Check the momentums - ua 7132 #momentum = velocity*(stage-elevation) 7133 # elevation = - depth 7134 #momentum = velocity_ua *(stage+depth) 7135 7136 depth_ref = zeros((len(permutation), time_step_count), Float) 7137 for i in range(len(permutation)): 7138 depth_ref[i]=gauge_depth_ref[i]+tide+ha_ref[i] 7139 7140 7141 # The xmomentum stored in the .sts file should be the sum of the ua 7142 # in the two mux2 files multiplied by the depth. 7143 assert allclose(transpose(ua_ref*depth_ref), xmomentum1) 7144 7145 #Check the momentums - va 7146 #momentum = velocity*(stage-elevation) 7147 # elevation = - depth 7148 #momentum = velocity_va *(stage+depth) 7149 7150 # The ymomentum stored in the .sts file should be the sum of the va 7151 # in the two mux2 files multiplied by the depth. 7152 7153 7154 #print transpose(va_ref*depth_ref) 7155 #print ymomentum 7156 assert allclose(transpose(va_ref*depth_ref), ymomentum1) 7157 7158 # check the elevation values. 7159 # -ve since urs measures depth, sww meshers height, 7160 assert allclose(-gauge_depth_ref, elevation1) 7161 7162 fid.close() 7163 os.remove(sts_file) 7164 7165 7166 7167 #---------------------- 7168 # Then read the mux files together and test 7169 7170 7171 # Call urs2sts with multiple mux files 7172 urs2sts([base_nameI, base_nameII], 7173 basename_out=base_nameI, 7174 ordering_filename=ordering_filename, 7175 weights=weights, 7176 mean_stage=tide, 7177 verbose=False) 7178 7179 # Now read the sts file and check that values have been stored correctly. 7180 sts_file = base_nameI + '.sts' 7181 fid = NetCDFFile(sts_file) 7182 7183 # Make x and y absolute 7184 x = fid.variables['x'][:] 7185 y = fid.variables['y'][:] 7186 7187 geo_reference = Geo_reference(NetCDFObject=fid) 7188 points = geo_reference.get_absolute(map(None, x, y)) 7189 points = ensure_numeric(points) 7190 7191 x = points[:,0] 7192 y = points[:,1] 7193 7194 for i, index in enumerate(permutation): 7195 # Check that STS points are stored in the correct order 7196 7197 # Work out the UTM coordinates sts point i 7198 zone, e, n = redfearn(lat_long_points[index][0], 7199 lat_long_points[index][1]) 7200 7201 #print i, [x[i],y[i]], [e,n] 7202 assert allclose([x[i],y[i]], [e,n]) 7203 7204 7205 # Check the time vector 7206 times = fid.variables['time'][:] 7207 assert allclose(ensure_numeric(times), 7208 ensure_numeric(times_ref)) 7209 7210 6981 7211 # Check sts values 6982 stage = fid.variables['stage'][:] 6983 xmomentum = fid.variables['xmomentum'][:] 6984 ymomentum = fid.variables['ymomentum'][:] 6985 elevation = fid.variables['elevation'][:] 7212 stage = fid.variables['stage'][:].copy() 7213 xmomentum = fid.variables['xmomentum'][:].copy() 7214 ymomentum = fid.variables['ymomentum'][:].copy() 7215 elevation = fid.variables['elevation'][:].copy() 6986 7216 6987 7217 … … 6998 7228 gauge_depth_ref = take(gauge_depth, permutation) 6999 7229 7000 7230 7231 #print 7232 #print stage 7233 #print transpose(ha_ref)+tide - stage 7234 7001 7235 assert allclose(transpose(ha_ref)+tide, stage) # Meters 7002 7236 … … 7047 7281 7048 7282 7283 7284 #--------------- 7285 # "Manually" add the timeseries up with weights and test 7286 # Tide is discounted from individual results and added back in 7287 # 7288 7289 stage_man = weights[0]*(stage0-tide) + weights[1]*(stage1-tide) + tide 7290 assert allclose(stage_man, stage) 7291 7049 7292 7050 7293 -
anuga_core/source/anuga/shallow_water/urs_ext.c
r5560 r5582 125 125 char isdata(float x) 126 126 { 127 //char value;128 127 if(x < NODATA + EPSILON && NODATA < x + EPSILON) 129 128 { 130 129 return 0; 131 130 } 132 131 else 133 132 { 134 133 return 1; 135 134 } 136 135 } … … 272 271 273 272 /* Compute the size of the data block for this source */ 274 numData = getNumData(fros + i*(*total_number_of_stations), lros + i*(*total_number_of_stations), (*total_number_of_stations)); 273 numData = getNumData(fros + i*(*total_number_of_stations), 274 lros + i*(*total_number_of_stations), 275 (*total_number_of_stations)); 275 276 276 277 /* Sanity check */ … … 289 290 } 290 291 292 // Store time resolution and number of timesteps 293 // These are the same for all stations, so 294 // we take the first one. 291 295 *delta_t = (double)mytgs0[0].dt; 292 296 *number_of_time_steps = mytgs0[0].nt; 293 297 294 298 free(mytgs); 295 299 296 300 return 1;
Note: See TracChangeset
for help on using the changeset viewer.