SlideShare a Scribd company logo
1 of 10
work/Error.bmp
work/Output.bmp
Codes.txt
#!/usr/bin/python
import math as _math
import traceback as _traceback
import os
import inro.modeller as _m
import inro.emme.core.exception as _except
class AdjacentNodes(_m.Tool()):
node_selection = _m.Attribute(unicode)
north_angle = _m.Attribute(float)
export_file = _m.Attribute(unicode)
export_file_5 = _m.Attribute(unicode)
export_file_6 = _m.Attribute(unicode)
scenario = _m.Attribute(_m.InstanceType)
tool_run_msg = ""
def __init__(self):
self.north_angle = 90
self.node_selection = "all"
def page(self):
pb = _m.ToolPageBuilder(self,
title="List Adjacent Nodes",
description="Exports the nodes specified by a selection
expression to "
"a text file, with a list of the adjacent nodes "
"sorted North, Northwest, West, Southwest, South,
Southeast, "
"East, and Northeast.<br>",
branding_text="INRO - Emme")
if self.tool_run_msg != "":
pb.tool_run_status(self.tool_run_msg_status)
pb.add_text_box("node_selection", size=20,
title="Node selection expression:", multi_line=True)
pb.add_text_box("north_angle", size=10,
title="North Angle:",
note="Angle which is North, counterclockwise relative
to the horizontal axis.")
pb.add_select_file("export_file",
window_type="save_file", file_filter="Text Documents (*.txt)",
start_path=os.path.dirname(_m.Modeller().desktop.project_file_
name()),
title="Export file (4 or less nodes) :")
pb.add_select_file("export_file_5",
window_type="save_file", file_filter="Text Documents (*.txt)",
start_path=os.path.dirname(_m.Modeller().desktop.project_file_
name()),
title="Export file (5 nodes):")
pb.add_select_file("export_file_6",
window_type="save_file", file_filter="Text Documents (*.txt)",
start_path=os.path.dirname(_m.Modeller().desktop.project_file_
name()),
title="Export file (6+ nodes):")
if not self.scenario:
self.scenario = _m.Modeller().desktop.data_explorer().
primary_scenario.core_scenario
pb.add_select_scenario("scenario", title="Scenario:")
return pb.render()
def run(self):
self.tool_run_msg = ""
try:
self(self.node_selection, self.north_angle,
self.export_file, self.export_file_5,
self.export_file_6,
self.scenario)
self.tool_run_msg = _m.PageBuilder.format_info("Tool
completed.")
except Exception, e:
self.tool_run_msg +=
_m.PageBuilder.format_exception(
e, _traceback.format_exc(e))
raise
@_m.logbook_trace(name="List nodes and directionally
sorted adjacent nodes",
save_arguments=True)
def __call__(self, node_selection, north_angle,
export_file, export_file_5, export_file_6, scenario):
UTILITIES_NAME = "inro.emme.utility.export_utilities"
export_utils = _m.Modeller().module(UTILITIES_NAME)
network = scenario.get_network()
node_ids = export_utils.apply_node_selection(scenario,
{"node": node_selection})
classify = ClassifyAdjacentNodes(north_angle)
f = None
f5 = None
f6 = None
file_hdr = "Node N NW W SW S SE
E NEn"
if export_file:
f = open(export_file, 'w')
f.write(file_hdr)
if export_file_5 and export_file_5 != export_file:
f5 = open(export_file_5, 'w')
f5.write(file_hdr)
if export_file_6 and export_file_6 != export_file and
export_file_6 != export_file_5:
f6 = open(export_file_6, 'w')
f6.write(file_hdr)
if not (f or f5 or f6):
raise _except.Error("Missing output file name")
for node_id in node_ids:
node = network.node(node_id)
adj, node_count = classify(node)
line_buf = str(node_id)
l = 0
while True:
for i in range(8):
d = ["N", "NW", "W", "SW", "S", "SE", "E",
"NE"][i]
if d in adj and l < len(adj[d]):
line_buf = "%-*s %s" % (i * 8 + 7, line_buf,
adj[d][l])
if not line_buf:
break
line_buf += "n"
if node_count < 5:
if f:
f.write(line_buf)
elif node_count < 6:
if f5:
f5.write(line_buf)
elif f6:
f6.write(line_buf)
line_buf = ""
l += 1
return
@_m.method(return_type=_m.UnicodeType)
def tool_run_msg_status(self):
return self.tool_run_msg
class ClassifyAdjacentNodes(object):
def __init__(self, north_angle=90):
self.directions = ["N", "NW", "W", "SW", "S", "SE", "E",
"NE"] # counter clockwise order, starting with North
self.expected_angles = [(x + north_angle) % 360 for x in
range(0, 360, 45)]
def __call__(self, at_node):
out_link_nodes = set([l.j_node for l in
at_node.outgoing_links()])
in_link_nodes = set([l.i_node for l in
at_node.incoming_links()])
adjacent_nodes = out_link_nodes.union(in_link_nodes)
directional_nodes = {}
for node in adjacent_nodes:
closest = self._closest_direction(at_node, node)
if not closest in directional_nodes:
directional_nodes[closest] = [node]
else:
directional_nodes[closest] += [node]
return directional_nodes, len(adjacent_nodes)
def _closest_direction(self, at_node, dir_node):
angle = _math.degrees(_math.atan2(dir_node.y -
at_node.y,
dir_node.x - at_node.x))
angle_names = zip(self.expected_angles, self.directions)
angle_diffs = [(self._normalize(a - angle), n) for a, n in
angle_names]
angle_diffs.sort()
return angle_diffs[0][1]
def _normalize(self, ang_diff):
v = abs(ang_diff) % 360
if v > 180:
return 360 - v
return v

More Related Content

Similar to workError.bmpworkOutput.bmpCodes.txt#!usrbinpytho.docx

Python Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdfPython Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdf
Rahul Jain
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
doughellmann
 
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfpython3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
info706022
 
selection_sort..c#include stdio.hheader file input output func.pdf
selection_sort..c#include stdio.hheader file input output func.pdfselection_sort..c#include stdio.hheader file input output func.pdf
selection_sort..c#include stdio.hheader file input output func.pdf
anton291
 
Cypherock Assessment (1).pdf
Cypherock Assessment (1).pdfCypherock Assessment (1).pdf
Cypherock Assessment (1).pdf
PARNIKA GUPTA
 
Using an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdfUsing an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdf
giriraj65
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
herminaherman
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
amit657720
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
gordienaysmythe
 
C programming. Answer question only in C code In the eighth part, yo.pdf
C programming. Answer question only in C code In the eighth part, yo.pdfC programming. Answer question only in C code In the eighth part, yo.pdf
C programming. Answer question only in C code In the eighth part, yo.pdf
mohammedfootwear
 

Similar to workError.bmpworkOutput.bmpCodes.txt#!usrbinpytho.docx (20)

Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Python Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdfPython Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdf
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
 
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfpython3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
 
selection_sort..c#include stdio.hheader file input output func.pdf
selection_sort..c#include stdio.hheader file input output func.pdfselection_sort..c#include stdio.hheader file input output func.pdf
selection_sort..c#include stdio.hheader file input output func.pdf
 
Cypherock Assessment (1).pdf
Cypherock Assessment (1).pdfCypherock Assessment (1).pdf
Cypherock Assessment (1).pdf
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
PyData NYC 2019
PyData NYC 2019PyData NYC 2019
PyData NYC 2019
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
 
Using an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdfUsing an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdf
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
 
2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt
 
C programming. Answer question only in C code In the eighth part, yo.pdf
C programming. Answer question only in C code In the eighth part, yo.pdfC programming. Answer question only in C code In the eighth part, yo.pdf
C programming. Answer question only in C code In the eighth part, yo.pdf
 

More from ericbrooks84875

Fundamentals of Risk and InsuranceEmmEtt J. Vaughan • .docx
Fundamentals of Risk and InsuranceEmmEtt J. Vaughan   •   .docxFundamentals of Risk and InsuranceEmmEtt J. Vaughan   •   .docx
Fundamentals of Risk and InsuranceEmmEtt J. Vaughan • .docx
ericbrooks84875
 
Fungi reproduce ___________________________ by fragmentation, buddin.docx
Fungi reproduce ___________________________ by fragmentation, buddin.docxFungi reproduce ___________________________ by fragmentation, buddin.docx
Fungi reproduce ___________________________ by fragmentation, buddin.docx
ericbrooks84875
 
Full-Circle LearningMyLab™ Learning Full Circle for Mar.docx
Full-Circle LearningMyLab™ Learning Full Circle for Mar.docxFull-Circle LearningMyLab™ Learning Full Circle for Mar.docx
Full-Circle LearningMyLab™ Learning Full Circle for Mar.docx
ericbrooks84875
 
Functional Behavior Assessment ExampleStudent NameInes SalazarD.docx
Functional Behavior Assessment ExampleStudent NameInes SalazarD.docxFunctional Behavior Assessment ExampleStudent NameInes SalazarD.docx
Functional Behavior Assessment ExampleStudent NameInes SalazarD.docx
ericbrooks84875
 
Functional Requirements Document TemplateVersionDescription .docx
Functional Requirements Document TemplateVersionDescription .docxFunctional Requirements Document TemplateVersionDescription .docx
Functional Requirements Document TemplateVersionDescription .docx
ericbrooks84875
 
FS-3FORD MOTOR COMPANY AND SUBSIDIARIESCONSOLIDATED INCO.docx
FS-3FORD MOTOR COMPANY AND SUBSIDIARIESCONSOLIDATED INCO.docxFS-3FORD MOTOR COMPANY AND SUBSIDIARIESCONSOLIDATED INCO.docx
FS-3FORD MOTOR COMPANY AND SUBSIDIARIESCONSOLIDATED INCO.docx
ericbrooks84875
 

More from ericbrooks84875 (20)

Fundamentals of Risk and InsuranceEmmEtt J. Vaughan • .docx
Fundamentals of Risk and InsuranceEmmEtt J. Vaughan   •   .docxFundamentals of Risk and InsuranceEmmEtt J. Vaughan   •   .docx
Fundamentals of Risk and InsuranceEmmEtt J. Vaughan • .docx
 
Fungi reproduce ___________________________ by fragmentation, buddin.docx
Fungi reproduce ___________________________ by fragmentation, buddin.docxFungi reproduce ___________________________ by fragmentation, buddin.docx
Fungi reproduce ___________________________ by fragmentation, buddin.docx
 
Full-Circle LearningMyLab™ Learning Full Circle for Mar.docx
Full-Circle LearningMyLab™ Learning Full Circle for Mar.docxFull-Circle LearningMyLab™ Learning Full Circle for Mar.docx
Full-Circle LearningMyLab™ Learning Full Circle for Mar.docx
 
Functional Behavior Assessment ExampleStudent NameInes SalazarD.docx
Functional Behavior Assessment ExampleStudent NameInes SalazarD.docxFunctional Behavior Assessment ExampleStudent NameInes SalazarD.docx
Functional Behavior Assessment ExampleStudent NameInes SalazarD.docx
 
Functional Requirements Document TemplateVersionDescription .docx
Functional Requirements Document TemplateVersionDescription .docxFunctional Requirements Document TemplateVersionDescription .docx
Functional Requirements Document TemplateVersionDescription .docx
 
Fully answer any ONE of the following essay questions1.  Is the.docx
Fully answer any ONE of the following essay questions1.  Is the.docxFully answer any ONE of the following essay questions1.  Is the.docx
Fully answer any ONE of the following essay questions1.  Is the.docx
 
Fully answer any ONE of the following essay questions1.  Is t.docx
Fully answer any ONE of the following essay questions1.  Is t.docxFully answer any ONE of the following essay questions1.  Is t.docx
Fully answer any ONE of the following essay questions1.  Is t.docx
 
From the weeks chapter reading, we learn from the authors that,.docx
From the weeks chapter reading, we learn from the authors that,.docxFrom the weeks chapter reading, we learn from the authors that,.docx
From the weeks chapter reading, we learn from the authors that,.docx
 
FTER watching the videos and reviewing the other materials in this.docx
FTER watching the videos and reviewing the other materials in this.docxFTER watching the videos and reviewing the other materials in this.docx
FTER watching the videos and reviewing the other materials in this.docx
 
fter completing the reading this week, we reflect on a few key conce.docx
fter completing the reading this week, we reflect on a few key conce.docxfter completing the reading this week, we reflect on a few key conce.docx
fter completing the reading this week, we reflect on a few key conce.docx
 
FS-3FORD MOTOR COMPANY AND SUBSIDIARIESCONSOLIDATED INCO.docx
FS-3FORD MOTOR COMPANY AND SUBSIDIARIESCONSOLIDATED INCO.docxFS-3FORD MOTOR COMPANY AND SUBSIDIARIESCONSOLIDATED INCO.docx
FS-3FORD MOTOR COMPANY AND SUBSIDIARIESCONSOLIDATED INCO.docx
 
Fromm’s concept of the syndrome of decay included three personality .docx
Fromm’s concept of the syndrome of decay included three personality .docxFromm’s concept of the syndrome of decay included three personality .docx
Fromm’s concept of the syndrome of decay included three personality .docx
 
From your readings in Chapter 4, choose one of the organizational sy.docx
From your readings in Chapter 4, choose one of the organizational sy.docxFrom your readings in Chapter 4, choose one of the organizational sy.docx
From your readings in Chapter 4, choose one of the organizational sy.docx
 
From your daily briefs, Kaiser Health News Morning Briefing or P.docx
From your daily briefs, Kaiser Health News Morning Briefing or P.docxFrom your daily briefs, Kaiser Health News Morning Briefing or P.docx
From your daily briefs, Kaiser Health News Morning Briefing or P.docx
 
From the perspective of the public safety field youre in, aspire to.docx
From the perspective of the public safety field youre in, aspire to.docxFrom the perspective of the public safety field youre in, aspire to.docx
From the perspective of the public safety field youre in, aspire to.docx
 
From the following terms Orthodox Judaism, Hassidic Judaism.  Brief.docx
From the following terms Orthodox Judaism, Hassidic Judaism.  Brief.docxFrom the following terms Orthodox Judaism, Hassidic Judaism.  Brief.docx
From the following terms Orthodox Judaism, Hassidic Judaism.  Brief.docx
 
From the end of Chapter 14, complete Discussion Question 3 What are.docx
From the end of Chapter 14, complete Discussion Question 3 What are.docxFrom the end of Chapter 14, complete Discussion Question 3 What are.docx
From the end of Chapter 14, complete Discussion Question 3 What are.docx
 
From the e-Activity, take a position on this statement People that .docx
From the e-Activity, take a position on this statement People that .docxFrom the e-Activity, take a position on this statement People that .docx
From the e-Activity, take a position on this statement People that .docx
 
From Chapter Seven How does horizontal growth differ from v.docx
From Chapter Seven How does horizontal growth differ from v.docxFrom Chapter Seven How does horizontal growth differ from v.docx
From Chapter Seven How does horizontal growth differ from v.docx
 
From the e-Activity, determine the fundamental differences between t.docx
From the e-Activity, determine the fundamental differences between t.docxFrom the e-Activity, determine the fundamental differences between t.docx
From the e-Activity, determine the fundamental differences between t.docx
 

Recently uploaded

Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfFinancial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
MinawBelay
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
17thcssbs2
 

Recently uploaded (20)

An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfFinancial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 

workError.bmpworkOutput.bmpCodes.txt#!usrbinpytho.docx

  • 1. work/Error.bmp work/Output.bmp Codes.txt #!/usr/bin/python import math as _math import traceback as _traceback import os import inro.modeller as _m import inro.emme.core.exception as _except class AdjacentNodes(_m.Tool()): node_selection = _m.Attribute(unicode) north_angle = _m.Attribute(float)
  • 2. export_file = _m.Attribute(unicode) export_file_5 = _m.Attribute(unicode) export_file_6 = _m.Attribute(unicode) scenario = _m.Attribute(_m.InstanceType) tool_run_msg = "" def __init__(self): self.north_angle = 90 self.node_selection = "all" def page(self): pb = _m.ToolPageBuilder(self, title="List Adjacent Nodes", description="Exports the nodes specified by a selection expression to " "a text file, with a list of the adjacent nodes " "sorted North, Northwest, West, Southwest, South, Southeast, " "East, and Northeast.<br>",
  • 3. branding_text="INRO - Emme") if self.tool_run_msg != "": pb.tool_run_status(self.tool_run_msg_status) pb.add_text_box("node_selection", size=20, title="Node selection expression:", multi_line=True) pb.add_text_box("north_angle", size=10, title="North Angle:", note="Angle which is North, counterclockwise relative to the horizontal axis.") pb.add_select_file("export_file", window_type="save_file", file_filter="Text Documents (*.txt)", start_path=os.path.dirname(_m.Modeller().desktop.project_file_ name()), title="Export file (4 or less nodes) :") pb.add_select_file("export_file_5", window_type="save_file", file_filter="Text Documents (*.txt)", start_path=os.path.dirname(_m.Modeller().desktop.project_file_ name()), title="Export file (5 nodes):")
  • 4. pb.add_select_file("export_file_6", window_type="save_file", file_filter="Text Documents (*.txt)", start_path=os.path.dirname(_m.Modeller().desktop.project_file_ name()), title="Export file (6+ nodes):") if not self.scenario: self.scenario = _m.Modeller().desktop.data_explorer(). primary_scenario.core_scenario pb.add_select_scenario("scenario", title="Scenario:") return pb.render() def run(self): self.tool_run_msg = "" try: self(self.node_selection, self.north_angle,
  • 5. self.export_file, self.export_file_5, self.export_file_6, self.scenario) self.tool_run_msg = _m.PageBuilder.format_info("Tool completed.") except Exception, e: self.tool_run_msg += _m.PageBuilder.format_exception( e, _traceback.format_exc(e)) raise @_m.logbook_trace(name="List nodes and directionally sorted adjacent nodes", save_arguments=True) def __call__(self, node_selection, north_angle, export_file, export_file_5, export_file_6, scenario): UTILITIES_NAME = "inro.emme.utility.export_utilities" export_utils = _m.Modeller().module(UTILITIES_NAME) network = scenario.get_network()
  • 6. node_ids = export_utils.apply_node_selection(scenario, {"node": node_selection}) classify = ClassifyAdjacentNodes(north_angle) f = None f5 = None f6 = None file_hdr = "Node N NW W SW S SE E NEn" if export_file: f = open(export_file, 'w') f.write(file_hdr) if export_file_5 and export_file_5 != export_file: f5 = open(export_file_5, 'w') f5.write(file_hdr) if export_file_6 and export_file_6 != export_file and export_file_6 != export_file_5: f6 = open(export_file_6, 'w') f6.write(file_hdr) if not (f or f5 or f6):
  • 7. raise _except.Error("Missing output file name") for node_id in node_ids: node = network.node(node_id) adj, node_count = classify(node) line_buf = str(node_id) l = 0 while True: for i in range(8): d = ["N", "NW", "W", "SW", "S", "SE", "E", "NE"][i] if d in adj and l < len(adj[d]): line_buf = "%-*s %s" % (i * 8 + 7, line_buf, adj[d][l]) if not line_buf: break line_buf += "n" if node_count < 5: if f: f.write(line_buf)
  • 8. elif node_count < 6: if f5: f5.write(line_buf) elif f6: f6.write(line_buf) line_buf = "" l += 1 return @_m.method(return_type=_m.UnicodeType) def tool_run_msg_status(self): return self.tool_run_msg class ClassifyAdjacentNodes(object): def __init__(self, north_angle=90): self.directions = ["N", "NW", "W", "SW", "S", "SE", "E", "NE"] # counter clockwise order, starting with North self.expected_angles = [(x + north_angle) % 360 for x in
  • 9. range(0, 360, 45)] def __call__(self, at_node): out_link_nodes = set([l.j_node for l in at_node.outgoing_links()]) in_link_nodes = set([l.i_node for l in at_node.incoming_links()]) adjacent_nodes = out_link_nodes.union(in_link_nodes) directional_nodes = {} for node in adjacent_nodes: closest = self._closest_direction(at_node, node) if not closest in directional_nodes: directional_nodes[closest] = [node] else: directional_nodes[closest] += [node] return directional_nodes, len(adjacent_nodes) def _closest_direction(self, at_node, dir_node):
  • 10. angle = _math.degrees(_math.atan2(dir_node.y - at_node.y, dir_node.x - at_node.x)) angle_names = zip(self.expected_angles, self.directions) angle_diffs = [(self._normalize(a - angle), n) for a, n in angle_names] angle_diffs.sort() return angle_diffs[0][1] def _normalize(self, ang_diff): v = abs(ang_diff) % 360 if v > 180: return 360 - v return v