comparison validate_temperature_data.py @ 6:418a11822c5a draft

Uploaded
author greg
date Tue, 27 Nov 2018 10:01:42 -0500
parents 467305a51829
children c5004164d035
comparison
equal deleted inserted replaced
5:467305a51829 6:418a11822c5a
82 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and 366 data lines).") 82 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and 366 data lines).")
83 stop_error(accumulated_msgs) 83 stop_error(accumulated_msgs)
84 if len(items) != 10: 84 if len(items) != 10:
85 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 10)." % (i, len(items))) 85 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 10)." % (i, len(items)))
86 stop_error(accumulated_msgs) 86 stop_error(accumulated_msgs)
87 stationid = items[0] 87 stationid = items[0].strip()
88 if len(stationid) == 0: 88 if len(stationid) == 0:
89 accumulated_msgs = empty_value(i, "stationid", accumulated_msgs) 89 accumulated_msgs = empty_value(i, "stationid", accumulated_msgs)
90 latitude = items[1] 90 latitude = items[1].strip()
91 accumulated_msgs = validate_decimal(i, latitude, accumulated_msgs, "latitude") 91 accumulated_msgs = validate_decimal(i, latitude, accumulated_msgs, "latitude")
92 longitude = items[2] 92 longitude = items[2].strip()
93 accumulated_msgs = validate_decimal(i, longitude, accumulated_msgs, "longitude") 93 accumulated_msgs = validate_decimal(i, longitude, accumulated_msgs, "longitude")
94 elev_m = items[3] 94 elev_m = items[3].strip()
95 accumulated_msgs = validate_decimal(i, elev_m, accumulated_msgs, "elev_m") 95 accumulated_msgs = validate_decimal(i, elev_m, accumulated_msgs, "elev_m")
96 name = items[4] 96 name = items[4].strip()
97 if len(name) == 0: 97 if len(name) == 0:
98 accumulated_msgs = empty_value(i, "name", accumulated_msgs) 98 accumulated_msgs = empty_value(i, "name", accumulated_msgs)
99 st = items[5] 99 st = items[5].strip()
100 if len(st) == 0: 100 if len(st) == 0:
101 accumulated_msgs = empty_value(i, "st", accumulated_msgs) 101 accumulated_msgs = empty_value(i, "st", accumulated_msgs)
102 mmdd = items[6] 102 mmdd = items[6].strip()
103 accumulated_msgs = validate_mmdd(i, mmdd, accumulated_msgs) 103 accumulated_msgs = validate_mmdd(i, mmdd, accumulated_msgs)
104 doy = items[7] 104 doy = items[7].strip()
105 accumulated_msgs = validate_integer(i, doy, accumulated_msgs, "doy") 105 accumulated_msgs = validate_integer(i, doy, accumulated_msgs, "doy")
106 # Make sure the DOY values are consecutive. 106 # Make sure the DOY values are consecutive.
107 try: 107 try:
108 if int(doy) != (last_doy + 1): 108 if int(doy) != (last_doy + 1):
109 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains a DOY (%s) that is not conexcutive." % (i, doy)) 109 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains a DOY (%s) that is not conexcutive." % (i, doy))
111 else: 111 else:
112 last_doy += 1 112 last_doy += 1
113 except Exception: 113 except Exception:
114 # The error for an invalid integer was captured above. 114 # The error for an invalid integer was captured above.
115 pass 115 pass
116 tmin = items[8] 116 tmin = items[8].strip()
117 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin") 117 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin")
118 tmax = items[9] 118 tmax = items[9].strip()
119 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax") 119 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax")
120 num_normals_rows += 1 120 num_normals_rows += 1
121 else: 121 else:
122 if i > 367: 122 if i > 367:
123 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and no more than 366 data lines).") 123 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains more than 367 lines (must be 1 header line and no more than 366 data lines).")
124 stop_error(accumulated_msgs) 124 stop_error(accumulated_msgs)
125 if len(items) != 6: 125 if len(items) != 6:
126 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 6)." % (i, len(items))) 126 accumulated_msgs = add_error_msg(accumulated_msgs, "Line %d contains %s columns, (must be 6)." % (i, len(items)))
127 stop_error(accumulated_msgs) 127 stop_error(accumulated_msgs)
128 latitude = items[0] 128 latitude = items[0].strip()
129 accumulated_msgs = validate_decimal(i, latitude, accumulated_msgs, "LATITUDE") 129 accumulated_msgs = validate_decimal(i, latitude, accumulated_msgs, "LATITUDE")
130 longitude = items[1] 130 longitude = items[1].strip()
131 accumulated_msgs = validate_decimal(i, longitude, accumulated_msgs, "LONGITUDE") 131 accumulated_msgs = validate_decimal(i, longitude, accumulated_msgs, "LONGITUDE")
132 date_string = items[2] 132 date_string = items[2].strip()
133 accumulated_msgs = validate_date_string(line_no, date_string, accumulated_msgs) 133 accumulated_msgs = validate_date_string(line_no, date_string, accumulated_msgs)
134 doy = items[3] 134 doy = items[3].strip()
135 accumulated_msgs = validate_integer(i, doy, accumulated_msgs, "doy") 135 accumulated_msgs = validate_integer(i, doy, accumulated_msgs, "doy")
136 # Make sure the DOY values are consecutive. 136 # Make sure the DOY values are consecutive.
137 if i==0: 137 if i==0:
138 try: 138 try:
139 last_doy = int(doy) 139 last_doy = int(doy)
148 else: 148 else:
149 last_doy += 1 149 last_doy += 1
150 except Exception: 150 except Exception:
151 # The error for an invalid integer was captured above. 151 # The error for an invalid integer was captured above.
152 pass 152 pass
153 tmin = items[8] 153 tmin = items[4].strip()
154 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin") 154 accumulated_msgs = validate_decimal(i, tmin, accumulated_msgs, "tmin")
155 tmax = items[9] 155 tmax = items[5].strip()
156 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax") 156 accumulated_msgs = validate_decimal(i, tmax, accumulated_msgs, "tmax")
157 if args.data_type == "normals" and num_normals_rows != 367: 157 if args.data_type == "normals" and num_normals_rows != 367:
158 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains %d rows, (must be 367)." % num_normals_rows) 158 accumulated_msgs = add_error_msg(accumulated_msgs, "The input file contains %d rows, (must be 367)." % num_normals_rows)
159 159
160 if len(accumulated_msgs) > 0: 160 if len(accumulated_msgs) > 0: