Skip to content

Commit a42ff55

Browse files
authored
Merge pull request #117 from nmpeterson/master
Improved transit project completion year validation
2 parents 82df514 + bf32cf6 commit a42ff55

2 files changed

Lines changed: 54 additions & 15 deletions

File tree

incorporate_edits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@
354354
zoned_node[1] = 9999
355355
zoned_node[3] = 11
356356
zoned_nodes_cursor.updateRow(zoned_node)
357-
#elif node < MHN.min_poe and node != zone:
358-
# arcpy.AddWarning('WARNING -- Zone ' + str(node) + ' centroid is in zone ' + str(zone) + '! Please verify that this is intentional.')
357+
elif node < MHN.min_poe and node != zone:
358+
arcpy.AddWarning('-- WARNING: Zone ' + str(node) + ' centroid is in zone ' + str(zone) + '! Please verify that this is intentional.')
359359
else:
360360
pass
361361
arcpy.AddMessage('-- Node {0}, {1} & {2} fields recalculated'.format(MHN.zone_attr, MHN.subzone_attr, MHN.capzone_attr))

update_highway_project_years.py

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'''
33
update_highway_project_years.py
44
Author: npeterson
5-
Revised: 12/18/17
5+
Revised: 5/9/18
66
---------------------------------------------------------------------------
77
This script updates the completion years of projects to be included in
88
Conformity analyses. The final completion year file is received from the
@@ -60,6 +60,8 @@
6060
# -----------------------------------------------------------------------------
6161
tipid_all_csv = os.path.join(MHN.temp_dir, 'tipid_all.csv')
6262
early_scenarios_csv = os.path.join(MHN.out_dir, 'early_transit_scenarios.csv')
63+
late_scenarios_csv = os.path.join(MHN.out_dir, 'late_transit_scenarios.csv')
64+
unknown_trans_ids_csv = os.path.join(MHN.out_dir, 'unknown_transit_tipids.csv')
6365
in_year_not_mhn_txt = os.path.join(MHN.out_dir, 'in_year_not_mhn.txt')
6466
in_mhn_not_year_txt = os.path.join(MHN.out_dir, 'in_mhn_not_year.txt')
6567

@@ -111,7 +113,8 @@
111113
# -----------------------------------------------------------------------------
112114
arcpy.AddMessage('{0}Checking future transit projects...'.format('\n'))
113115

114-
def clear_transit_project_years(proj_years_dict, rail_fc, bus_fc, mover_table, early_scenarios_csv):
116+
def clear_transit_project_years(proj_years_dict, hwyproj_ids, rail_fc, bus_fc, mover_table,
117+
early_scenarios_csv, late_scenarios_csv, unknown_trans_ids_csv):
115118
''' Remove transit project TIPIDs from the dict after verifying that their
116119
scenarios specified in the MHN/MRN are no earlier than their completion
117120
years. '''
@@ -132,21 +135,55 @@ def clear_transit_project_years(proj_years_dict, rail_fc, bus_fc, mover_table, e
132135

133136
# Compare transit project scenarios against project completion years.
134137
# If any errors exist, write them to file and stop processing.
135-
early_scenarios = []
138+
early_scenarios = set()
139+
late_scenarios = set()
140+
unknown_tipids = set()
136141
for tipid, scen in trans_proj_scens.items():
137-
if tipid in proj_years_dict and MHN.scenario_years[(str(scen))] < proj_years_dict[tipid]:
138-
early_scenarios.append(tipid)
142+
if tipid in proj_years_dict and MHN.scenario_years[str(scen)] < proj_years_dict[tipid]:
143+
early_scenarios.add(tipid)
144+
elif tipid in proj_years_dict and MHN.scenario_years[str(scen - 100)] > proj_years_dict[tipid]:
145+
late_scenarios.add(tipid)
146+
elif tipid not in proj_years_dict and MHN.scenario_years[str(scen)] < MHN.max_year:
147+
unknown_tipids.add(tipid)
148+
139149
if early_scenarios:
140150
with open(early_scenarios_csv, 'w') as w:
141151
w.write('TIPID,COMPLETION_YEAR,FIRST_SCENARIO\n')
142-
for tipid in early_scenarios:
152+
for tipid in sorted(early_scenarios):
143153
w.write('{0},{1},{2}\n'.format(MHN.tipid_from_int(tipid), proj_years_dict[tipid], trans_proj_scens[tipid]))
144154
MHN.die((
145155
'''ERROR: Some transit projects (future bus, rail and/or people '''
146156
'''mover) reference a scenario that is earlier than their TIPID's '''
147157
'''specified completion year. See {0} for details.'''
148158
).format(early_scenarios_csv))
149159

160+
if late_scenarios:
161+
with open(late_scenarios_csv, 'w') as w:
162+
w.write('TIPID,COMPLETION_YEAR,FIRST_SCENARIO\n')
163+
for tipid in sorted(late_scenarios):
164+
w.write('{0},{1},{2}\n'.format(MHN.tipid_from_int(tipid), proj_years_dict[tipid], trans_proj_scens[tipid]))
165+
MHN.die((
166+
'''ERROR: Some transit projects (future bus, rail and/or people '''
167+
'''mover) reference a scenario that is much later than their TIPID's '''
168+
'''specified completion year. See {0} for details.'''
169+
).format(late_scenarios_csv))
170+
171+
if unknown_tipids:
172+
with open(unknown_trans_ids_csv, 'w') as w:
173+
w.write('TIPID,FIRST_SCENARIO\n')
174+
for tipid in sorted(unknown_tipids):
175+
w.write('{0},{1}\n'.format(MHN.tipid_from_int(tipid), trans_proj_scens[tipid]))
176+
MHN.die((
177+
'''ERROR: Some transit projects (future bus, rail and/or people '''
178+
'''mover) have a TIPID that is not present in {0} or {1}. See {2} '''
179+
'''for details.'''
180+
).format(tipid_conformed_csv, tipid_exempt_csv, unknown_trans_ids_csv))
181+
182+
# Ignore transit projects that also have a highway component (e.g. new busway links)
183+
trans_proj_with_hwy_component = set(hwyproj_ids) & set(trans_proj_scens.keys())
184+
for tipid in trans_proj_with_hwy_component:
185+
del trans_proj_scens[tipid]
186+
150187
# Remove transit TIPIDs from project years dictionary
151188
hwyproj_years_dict = proj_years_dict.copy()
152189
for tipid in trans_proj_scens.keys():
@@ -183,25 +220,28 @@ def get_trans_proj_scens(table):
183220

184221
return tipid_scens
185222

186-
187-
hwyproj_years = clear_transit_project_years(proj_years, mrn_future_fc, MHN.bus_future, people_mover_table, early_scenarios_csv)
223+
# Remove transit-only (bus or rail) projects after checking their scenario codes
224+
common_id_field = MHN.route_systems[MHN.hwyproj][1]
225+
coded_hwyproj = [int(r[0]) for r in arcpy.da.SearchCursor(MHN.hwyproj, [common_id_field])]
226+
hwyproj_years = clear_transit_project_years(
227+
proj_years, coded_hwyproj, mrn_future_fc, MHN.bus_future, people_mover_table,
228+
early_scenarios_csv, late_scenarios_csv, unknown_trans_ids_csv
229+
)
188230

189231

190232
# -----------------------------------------------------------------------------
191233
# Read uncodable projects into dictionary.
192234
# -----------------------------------------------------------------------------
193-
uncodable_proj = []
235+
uncodable_proj = set() #[]
194236
with open(tipid_uncodable_csv, 'r') as no_code:
195237
for row in no_code:
196238
tipid = int(row.strip().split(',')[0])
197-
if tipid not in uncodable_proj:
198-
uncodable_proj.append(tipid)
239+
uncodable_proj.add(tipid)
199240

200241

201242
# -----------------------------------------------------------------------------
202243
# Check for inappropriately coded projects.
203244
# -----------------------------------------------------------------------------
204-
common_id_field = MHN.route_systems[MHN.hwyproj][1]
205245
hwyproj_view = 'hwyproj_view'
206246
arcpy.MakeTableView_management(MHN.hwyproj, hwyproj_view)
207247

@@ -239,7 +279,6 @@ def get_trans_proj_scens(table):
239279
# -----------------------------------------------------------------------------
240280
# Check for still-uncoded projects.
241281
# -----------------------------------------------------------------------------
242-
coded_hwyproj = [int(r[0]) for r in arcpy.da.SearchCursor(MHN.hwyproj, [common_id_field])]
243282
uncoded_hwyproj = [tipid for tipid in hwyproj_years if tipid not in coded_hwyproj and tipid not in uncodable_proj]
244283
if len(uncoded_hwyproj) == 0:
245284
arcpy.AddMessage((

0 commit comments

Comments
 (0)