Browse Source

deleted argument named 'filename'

master
김선중 1 year ago
parent
commit
80ac86c5d8
3 changed files with 22 additions and 235 deletions
  1. BIN
      Scripts/__pycache__/preprocess_daily.cpython-312.pyc
  2. +4
    -8
      Scripts/preprocess_daily.py
  3. +18
    -227
      analysis/0725_main_test/4_use_class_pd.ipynb

BIN
Scripts/__pycache__/preprocess_daily.cpython-312.pyc View File


+ 4
- 8
Scripts/preprocess_daily.py View File

@ -7,9 +7,8 @@ from tqdm import tqdm
from datetime import datetime from datetime import datetime
class DailyPreprocessor(): class DailyPreprocessor():
def __init__(self, config_name='test_0721', file_net = 'sn.net.xml'):
def __init__(self, config_name='test_0721'):
self.config_name = config_name self.config_name = config_name
self.file_net = file_net
# 루트폴더 지정 # 루트폴더 지정
self.path_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) self.path_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -22,7 +21,6 @@ class DailyPreprocessor():
self.path_intermediates = os.path.join(self.path_root, *self.paths['intermediates']) self.path_intermediates = os.path.join(self.path_root, *self.paths['intermediates'])
self.path_results = os.path.join(self.path_root, *self.paths['results']) self.path_results = os.path.join(self.path_root, *self.paths['results'])
self.path_tables = os.path.join(self.path_root, *self.paths['tables']) self.path_tables = os.path.join(self.path_root, *self.paths['tables'])
self.path_networks = os.path.join(self.path_root, *self.paths['networks'])
self.path_network = os.path.join(self.path_root, *self.paths['network']) self.path_network = os.path.join(self.path_root, *self.paths['network'])
self.path_scripts = os.path.join(self.path_root, *self.paths['scripts']) self.path_scripts = os.path.join(self.path_root, *self.paths['scripts'])
@ -34,7 +32,7 @@ class DailyPreprocessor():
print('1. 데이터를 로드합니다.') print('1. 데이터를 로드합니다.')
self.load_networks() self.load_networks()
self.load_tables() self.load_tables()
self.check_networks()
# self.check_networks()
# self.check_tables() # self.check_tables()
self.standardize() self.standardize()
self.store_objects() self.store_objects()
@ -171,7 +169,7 @@ class DailyPreprocessor():
sys.path.append(tools) sys.path.append(tools)
else: else:
raise EnvironmentError("please declare environment variable 'SUMO_HOME'") raise EnvironmentError("please declare environment variable 'SUMO_HOME'")
traci.start([sumolib.checkBinary('sumo'), "-n", os.path.join(self.path_networks, self.file_net)])
traci.start([sumolib.checkBinary('sumo'), "-n", os.path.join(self.path_network)])
nodes = [node for node in self.net.getNodes() if node.getType() in ['traffic_light', 'traffic_light_right_on_red']] nodes = [node for node in self.net.getNodes() if node.getType() in ['traffic_light', 'traffic_light_right_on_red']]
for node in nodes: for node in nodes:
try: try:
@ -1144,10 +1142,8 @@ class DailyPreprocessor():
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-c','--config_name', dest='config_name', type=str, default='revised') parser.add_argument('-c','--config_name', dest='config_name', type=str, default='revised')
parser.add_argument('-n','--file_net', dest='file_net', type=str, default='sn.net.xml')
args = parser.parse_args() args = parser.parse_args()
config_name = args.config_name config_name = args.config_name
file_net = args.file_net
self = DailyPreprocessor(config_name=config_name, file_net=file_net)
self = DailyPreprocessor(config_name=config_name)
self.main() self.main()

+ 18
- 227
analysis/0725_main_test/4_use_class_pd.ipynb View File

@ -25,8 +25,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"self = DailyPreprocessor(config_name = 'test_0731',\n",
" file_net = 'new_sungnam_network_internal_target_0721.net.xml')"
"self = DailyPreprocessor(config_name = 'test_0731')"
] ]
}, },
{ {
@ -38,13 +37,17 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"1-1. 네트워크가 로드되었습니다.\n"
"1. 데이터를 로드합니다.\n",
"1-1. 네트워크가 로드되었습니다.\n",
"1-2. 테이블들이 로드되었습니다.\n",
"1-5. 테이블을 표준화했습니다.\n",
"1-6. 주요 객체 (리스트, 딕셔너리)들을 저장했습니다.\n"
] ]
} }
], ],
"source": [ "source": [
"# 1-1. 네트워크 불러오기\n",
"self.load_networks()"
"# 1. 데이터 불러오기\n",
"self.load_data()"
] ]
}, },
{ {
@ -56,13 +59,18 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"1-2. 테이블들이 로드되었습니다.\n"
"2. 중간산출물을 생성합니다.\n",
"2-1. 매칭 테이블들을 생성했습니다.\n",
"2-2. 초기화 신호가 지정되었습니다. (우회전 : g)\n",
"2-3. 유턴 인덱스 / 비보호좌회전 인덱스를 지정했습니다.\n",
"2-4. 직진 및 좌회전(G)을 배정했습니다.\n",
"2-5. node2num_cycles.json를 저장했습니다.\n"
] ]
} }
], ],
"source": [ "source": [
"# 1-2. 테이블 불러오기\n",
"self.load_tables()"
"# 2. 중간산출물 만들기\n",
"self.get_intermediates()"
] ]
}, },
{ {
@ -74,229 +82,12 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"1-5. 테이블을 표준화했습니다.\n"
]
}
],
"source": [
"# 1-5. 테이블 표준화\n",
"self.standardize()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1-5. 테이블을 표준화했습니다.\n"
]
}
],
"source": [
"# 1-5. 테이블 표준화\n",
"self.standardize()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1-6. 주요 객체 (리스트, 딕셔너리)들을 저장했습니다.\n"
"3. 이슈사항을 저장합니다.\n"
] ]
} }
], ],
"source": [ "source": [
"# 1-6. 주요 객체 (리스트, 딕셔너리) 저장\n",
"self.store_objects()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"self.make_match1()\n",
"self.make_match2()\n",
"self.make_match3()\n",
"self.make_match4()\n",
"self.make_match5()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"self.uturn = pd.merge(self.uturn, self.u_condition, on='child_id')\n",
"\n",
"# p2inc_edge2angle : node_id to inc_edge2angle\n",
"p2inc_edge2angle = dict()\n",
"# p2out_edge2angle : node_id to out_edge2angle\n",
"p2out_edge2angle = dict()\n",
"# p2inc_angle2edge : node_id to inc_angle2edge\n",
"p2inc_angle2edge = dict()\n",
"# p2out_angle2edge : node_id to out_angle2edge\n",
"p2out_angle2edge = dict()\n",
"for node_id in self.parent_ids:\n",
" m5 = self.match5[self.match5.node_id==node_id]\n",
" m5 = m5.dropna(subset=['inc_edge_id', 'out_edge_id'])\n",
" # inc_edge2angle : inc_edge_id to inc_angle\n",
" inc_edge2angle = dict(zip(m5.inc_edge_id, m5.inc_angle.astype(int)))\n",
" p2inc_edge2angle[node_id] = inc_edge2angle\n",
" # out_edge2angle : out_edge_id to out_angle\n",
" out_edge2angle = dict(zip(m5.out_edge_id, m5.out_angle.astype(int)))\n",
" p2out_edge2angle[node_id] = out_edge2angle\n",
" # inc_angle2edge : inc_angle to inc_edge_id\n",
" inc_angle2edge = dict(zip(m5.inc_angle.astype(int), m5.inc_edge_id))\n",
" p2inc_angle2edge[node_id] = inc_angle2edge\n",
" # out_angle2edge : out_angle to out_edge_id\n",
" out_angle2edge = dict(zip(m5.out_angle.astype(int), m5.out_edge_id))\n",
" p2out_angle2edge[node_id] = out_angle2edge\n",
"# 각 uturn node에 대하여 (inc_edge_id, out_edge_id) 부여\n",
"cmatches = []\n",
"row = self.uturn.iloc[0]\n",
"parent_id = row.parent_id\n",
"child_id = row.child_id\n",
"condition = row.condition\n",
"inc_edge_id = row.inc_edge_id\n",
"out_edge_id = row.out_edge_id\n",
"print(type(inc_edge_id))\n",
"adj_inc_edge_id = row.adj_inc_edge_id\n",
"adj_out_edge_id = row.adj_out_edge_id\n",
"\n",
"# match5에서 부모노드id에 해당하는 행들을 가져옴 (cmatch)\n",
"cmatch = self.match5.copy()[self.match5.node_id==parent_id] # match dataframe for a child node\n",
"cmatch = cmatch.sort_values(by=['phase_no', 'ring_type']).reset_index(drop=True)\n",
"cmatch['node_id'] = child_id\n",
"cmatch['node_type'] = 'u_turn'\n",
"\n",
"# 진입엣지 각도\n",
"inc_angle = p2inc_edge2angle[parent_id][adj_inc_edge_id]\n",
"\n",
"# 이격각도\n",
"self.angle_separation = 10\n",
"\n",
"# 진입로 각도 목록\n",
"inc_angles = cmatch.dropna(subset=['inc_angle', 'out_angle']).inc_angle.astype(int).unique()\n",
"inc_angles = np.sort(inc_angles)\n",
"inc_angles = list(inc_angles - 360) + list(inc_angles) + list(inc_angles + 360)\n",
"inc_angles = np.array(inc_angles)\n",
"\n",
"# 보행신호시의 진입로 각도\n",
"inc_angles_left = inc_angles[inc_angles >= inc_angle + self.angle_separation]\n",
"inc_angle_pedes = np.sort(inc_angles_left)[0] % 360\n",
"\n",
"# 보행신호시의 진입로 엣지id\n",
"inc_angle2edge = p2inc_angle2edge[parent_id]\n",
"inc_edge_id_pedes = inc_angle2edge[inc_angle_pedes]\n",
"\n",
"# 진출로 각도 목록\n",
"out_angles = cmatch.dropna(subset=['inc_angle', 'out_angle']).out_angle.astype(int).unique()\n",
"out_angles = np.sort(out_angles)\n",
"out_angles = list(out_angles - 360) + list(out_angles) + list(out_angles + 360)\n",
"out_angles = np.array(out_angles)\n",
"\n",
"# 보행신호시의 진출로 각도\n",
"out_angles_right = out_angles[out_angles <= inc_angle - self.angle_separation]\n",
"out_angle_pedes = np.sort(out_angles_right)[-1] % 360\n",
"\n",
"# 보행신호시의 진출로 엣지id\n",
"out_angle2edge = p2out_angle2edge[parent_id]\n",
"out_edge_id_pedes = out_angle2edge[out_angle_pedes]\n",
"\n",
"# 진입엣지/진출엣지 포함 조건\n",
"inc_true = (cmatch.inc_edge_id==adj_inc_edge_id)\n",
"out_true = (cmatch.out_edge_id==adj_out_edge_id)\n",
"\n",
"# 보행신호시 조건\n",
"pedes_flag = (cmatch.inc_edge_id==inc_edge_id_pedes) & (cmatch.out_edge_id==out_edge_id_pedes)\n",
"\n",
"# 좌회전시 조건\n",
"right_flag = inc_true & (cmatch.turn_type=='left')\n",
"\n",
"# 보행신호이동류(17) 조건\n",
"crosswalk_on = (cmatch.move_no==17) & ~ out_true\n",
"\n",
"# 신호없음이동류(18) 조건\n",
"all_redsigns = (cmatch.move_no==18) & ~ out_true"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(type(inc_edge_id))\n",
"print(type(out_edge_id))\n",
"print(cmatch[['inc_edge_id', 'out_edge_id']].info())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(inc_edge_id, out_edge_id)\n",
"# 보행신호시/좌회전시 진입/진출 엣지id 배정\n",
"cmatch[['inc_edge_id', 'out_edge_id']] = None\n",
"if condition == \"보행신호시\":\n",
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
"elif condition == \"좌회전시\":\n",
" cmatch.loc[right_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
"\n",
"uturn_not_assigned = cmatch[['inc_edge_id','out_edge_id']].isna().any(axis=1).all()\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2-1. 매칭 테이블들을 생성했습니다.\n",
"2-2. 초기화 신호가 지정되었습니다. (우회전 : g)\n",
"2-3. 유턴 인덱스 / 비보호좌회전 인덱스를 지정했습니다.\n",
"2-4. 직진 및 좌회전(G)을 배정했습니다.\n",
"2-5. node2num_cycles.json를 저장했습니다.\n"
]
}
],
"source": [
"# 2. 중간산출물 만들기\n",
"# 2-1 매칭테이블 생성\n",
"self.get_matches()\n",
"# 2-2 신호 초기화\n",
"self.initialize_state()\n",
"# 2-3 유턴 인덱스 / 비보호좌회전 인덱스 지정\n",
"self.assign_indices()\n",
"# 2-4 신호배정\n",
"self.assign_signals()\n",
"# 2-5 기반파일 저장\n",
"self.save_intermediates()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 3. 이슈사항 저장\n",
"self.write_issues()" "self.write_issues()"
] ]
} }

Loading…
Cancel
Save