Changeset 4571
- Timestamp:
- Jun 29, 2007, 3:33:37 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r4568 r4571 10 10 11 11 from os import remove, mkdir, access, F_OK, W_OK, sep 12 from os.path import exists, basename 12 from os.path import exists, basename, split 13 13 from warnings import warn 14 14 from shutil import copy … … 688 688 time_min = None, 689 689 time_max = None, 690 time_thinning = 1, 690 691 time_unit = None, 691 692 title_on = None, … … 716 717 'boundaries': 'urs boundary'} 717 718 this will use the second part as the label and the first part 718 as the ? 719 as the ? 720 #FIXME: Is it a list or a dictionary 721 # This is probably obsolete by now 719 722 720 723 report - if True, then write figures to report_figures directory in … … 773 776 ['stage', 'elevation', 'xmomentum', 'ymomentum'] 774 777 If this has not occurred then sww2timeseries will not work. 778 779 780 Usage example 781 texname = sww2timeseries({project.boundary_name + '.sww': ''}, 782 project.polygons_dir + sep + 'boundary_extent.csv', 783 project.anuga_dir, 784 report = False, 785 plot_quantity = ['stage', 'speed', 'bearing'], 786 time_min = None, 787 time_max = None, 788 title_on = True, 789 verbose = True) 790 775 791 """ 776 792 … … 786 802 time_min, 787 803 time_max, 804 time_thinning, 788 805 time_unit, 789 806 title_on, … … 803 820 time_min = None, 804 821 time_max = None, 822 time_thinning = 1, 805 823 time_unit = None, 806 824 title_on = None, … … 858 876 raise msg 859 877 878 print 'swwfile', swwfile 879 880 # Extract parent dir name and use as label 881 path, _ = os.path.split(swwfile) 882 _, label = os.path.split(path) 883 884 #print 'label', label 885 leg_label.append(label) 886 887 888 860 889 f = file_function(swwfile, 861 890 quantities = sww_quantity, 862 891 interpolation_points = gauges, 892 time_thinning = time_thinning, 863 893 verbose = verbose, 864 894 use_cache = use_cache) … … 867 897 count = 0 868 898 gauge_index = [] 869 print 'swwfile', swwfile870 899 for k, g in enumerate(gauges): 871 900 if f(0.0, point_id = k)[2] > 1.0e6: … … 886 915 file_loc.append(swwfile[:index+1]) 887 916 label_id.append(swwfiles[swwfile]) 888 leg_label.append(production_dirs[swwfiles[swwfile]]) 917 889 918 890 919 f_list.append(f) … … 936 965 gaugelocation = [] 937 966 elev = [] 967 968 # Check header information 938 969 line1 = lines[0] 939 970 line11 = line1.split(',') 940 east_index = len(line11)+1 941 north_index = len(line11)+1 942 name_index = len(line11)+1 943 elev_index = len(line11)+1 944 for i in range(len(line11)): 945 if line11[i].strip('\n').strip(' ').lower() == 'easting': east_index = i 946 if line11[i].strip('\n').strip(' ').lower() == 'northing': north_index = i 947 if line11[i].strip('\n').strip(' ').lower() == 'name': name_index = i 948 if line11[i].strip('\n').strip(' ').lower() == 'elevation': elev_index = i 949 950 for line in lines[1:]: 971 972 if line11[0] is basestring: 973 # We have found text in the first line 974 975 east_index = len(line11)+1 976 north_index = len(line11)+1 977 name_index = len(line11)+1 978 elev_index = len(line11)+1 979 for i in range(len(line11)): 980 if line11[i].strip('\n').strip(' ').lower() == 'easting': east_index = i 981 if line11[i].strip('\n').strip(' ').lower() == 'northing': north_index = i 982 if line11[i].strip('\n').strip(' ').lower() == 'name': name_index = i 983 if line11[i].strip('\n').strip(' ').lower() == 'elevation': elev_index = i 984 985 if east_index < len(line11) and north_index < len(line11): 986 pass 987 else: 988 msg = 'WARNING: %s does not contain correct header information' %(filename) 989 msg += 'The header must be: easting, northing, name, elevation' 990 raise Exception, msg 991 992 if elev_index >= len(line11): 993 raise Exception 994 995 if name_index >= len(line11): 996 raise Exception 997 998 lines = lines[1:] # Remove header from data 999 else: 1000 # No header, assume that this is a simple easting, northing file 1001 1002 msg = 'There was no header in file %s and the number of columns is %d' %(filename, len(line11)) 1003 msg += '- I was assuming two columns corresponding to Easting and Northing' 1004 assert len(line11) == 2, msg 1005 1006 east_index = 0 1007 north_index = 1 1008 1009 N = len(lines) 1010 elev = [-9999]*N 1011 gaugelocation = range(N) 1012 1013 1014 # Read in gauge data 1015 for line in lines: 951 1016 fields = line.split(',') 952 if east_index < len(line11) and north_index < len(line11): 953 gauges.append([float(fields[east_index]), float(fields[north_index])]) 954 else: 955 msg = 'WARNING: %s does not contain location information' %(filename) 956 raise Exception, msg 957 if elev_index < len(line11): elev.append(float(fields[elev_index])) 958 if name_index < len(line11): 1017 1018 gauges.append([float(fields[east_index]), float(fields[north_index])]) 1019 1020 if len(fields) > 2: 1021 elev.append(float(fields[elev_index])) 959 1022 loc = fields[name_index] 960 1023 gaugelocation.append(loc.strip('\n')) 1024 961 1025 962 1026 return gauges, gaugelocation, elev 1027 1028 963 1029 964 1030 def check_list(quantity): … … 1091 1157 max_speed = 0 1092 1158 max_depth = 0 1093 gaugeloc = locations[k] 1094 thisfile = file_loc[j]+sep+'gauges_time_series'+'_'+gaugeloc+'.csv' 1159 gaugeloc = str(locations[k]) 1160 thisfile = file_loc[j]+sep+'gauges_time_series'+'_'\ 1161 +gaugeloc+'.csv' 1095 1162 fid_out = open(thisfile, 'w') 1096 1163 s = 'Time, Stage, Momentum, Speed, Elevation, xmom, ymom \n' … … 1262 1329 if len(label_id) > 1: legend((leg_label),loc='upper right') 1263 1330 1264 gaugeloc1 = gaugeloc.replace(' ','')1331 #gaugeloc1 = gaugeloc.replace(' ','') 1265 1332 #gaugeloc2 = gaugeloc1.replace('_','') 1266 gaugeloc2 = locations[k].replace(' ','') 1267 graphname = '%sgauge%s_%s' %(file_loc[j], gaugeloc2, which_quantity) 1333 gaugeloc2 = str(locations[k]).replace(' ','') 1334 graphname = '%sgauge%s_%s' %(file_loc[j], 1335 gaugeloc2, 1336 which_quantity) 1268 1337 1269 1338 if report == True and len(label_id) > 1:
Note: See TracChangeset
for help on using the changeset viewer.