Skip to content

Commit

Permalink
consistent recommendation about setting python's sys.path #2
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Apr 19, 2024
1 parent 84880fe commit ff0a605
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
3 changes: 2 additions & 1 deletion docs/web/docs/Developer/PythonFileTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import sys
import ...

# use the following when you depend on sumolib or traci
sys.path.append(os.path.join(os.environ["SUMO_HOME"], 'tools'))
if "SUMO_HOME" in os.environ:
sys.path.append(os.path.join(os.environ["SUMO_HOME"], 'tools'))
import sumolib  # noqa
# the noqa is needed to tell the style checker that it is OK to have an import which is not at the top of the file
```
8 changes: 3 additions & 5 deletions docs/web/docs/Tools/Sumolib.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ To use the library, the {{SUMO}}/tools directory must be on the python load
path. This is typically done with a stanza like this:

```python
import os, sys
import os
import sys
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:   
    sys.exit("please declare environment variable 'SUMO_HOME'")
    sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
```

# loading a network file
Expand Down
3 changes: 2 additions & 1 deletion docs/web/docs/Tutorials/CityMobil.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import os
import sys
from constants import PREFIX, DOUBLE_ROWS, ROW_DIST, SLOTS_PER_ROW, SLOT_WIDTH
... # more constants
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
if 'SUMO_HOME' in os.environ:
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
import sumolib
```

Expand Down
41 changes: 21 additions & 20 deletions docs/web/docs/Tutorials/HighwayDetector.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,28 @@ network. A starting point can be to use the python sumolib to match the
positions to the network:

```python
if 'SUMO_HOME' in os.environ:
sys.path.append(os.path.join(os.environ["SUMO_HOME"], 'tools'))
import sumolib

net = sumolib.net.readNet(<NETFILE>)
detectors = []
for id, lon, lat in <DETECTOR_INPUTFILE>:
xy_pos = net.convertLonLat2XY(lon, lat)
# look 10m around the position
lanes = net.getNeighboringLanes(xy_pos[0], xy_pos[1], 10)
# attention, result is unsorted
bestLane = None
ref_d = 9999.
for lane, dist in lanes:
# now process them and determine a "bestLane"
# ...
if dist < ref_d:
ref_d = dist
bestLane = lane
pos, d = bestLane.getClosestLanePosAndDist(xy_pos)
detectors.append(sumolib.sensors.inductive_loop.InductiveLoop(id, bestLane.getID(), pos))
sumolib.files.additional.write(<DETECTORFILE>, detectors)
import sumolib

net = sumolib.net.readNet(<NETFILE>)
detectors = []
for id, lon, lat in <DETECTOR_INPUTFILE>:
xy_pos = net.convertLonLat2XY(lon, lat)
# look 10m around the position
lanes = net.getNeighboringLanes(xy_pos[0], xy_pos[1], 10)
# attention, result is unsorted
bestLane = None
ref_d = 9999.
for lane, dist in lanes:
# now process them and determine a "bestLane"
# ...
if dist < ref_d:
ref_d = dist
bestLane = lane
pos, d = bestLane.getClosestLanePosAndDist(xy_pos)
detectors.append(sumolib.sensors.inductive_loop.InductiveLoop(id, bestLane.getID(), pos))
sumolib.files.additional.write(<DETECTORFILE>, detectors)
```

The period of data aggregation for data collection is 60 seconds by
Expand Down

0 comments on commit ff0a605

Please sign in to comment.