|
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"preprocess_daily.py"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np\n",
|
|
"import os, sys, copy, argparse, json, pickle, sys\n",
|
|
"import sumolib, traci\n",
|
|
"from tqdm import tqdm\n",
|
|
"from datetime import datetime\n",
|
|
"path_root = os.path.dirname(os.path.dirname(os.path.abspath('.')))\n",
|
|
"path_scr = os.path.join(path_root, 'scripts')\n",
|
|
"sys.path.append(path_scr)\n",
|
|
"from preprocess_daily import DailyPreprocessor\n",
|
|
"from generate_signals import SignalGenerator"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"config_name = 'revised'\n",
|
|
"file_net = 'sn.net.xml'\n",
|
|
"self = DailyPreprocessor(config_name=config_name, file_net=file_net)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1. 데이터를 로드합니다.\n",
|
|
"1-1. 네트워크가 로드되었습니다.\n",
|
|
"1-2. 테이블들이 로드되었습니다.\n",
|
|
"1-3. 네트워크의 모든 clean state requirement들을 체크했습니다.\n",
|
|
"1-5. 테이블을 표준화했습니다.\n",
|
|
"1-6. 주요 객체 (리스트, 딕셔너리)들을 저장했습니다.\n",
|
|
"2. 중간산출물을 생성합니다.\n",
|
|
"2-1. 매칭 테이블들을 생성했습니다.\n",
|
|
"2-2. 초기화 신호가 지정되었습니다. (우회전 : g)\n",
|
|
"2-3. 유턴 인덱스 / 비보호좌회전 인덱스를 지정했습니다.\n",
|
|
"2-4. 직진 및 좌회전(G)을 배정했습니다.\n",
|
|
"2-5. node2num_cycles.json를 저장했습니다.\n",
|
|
"3. 이슈사항을 저장합니다.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"self.main()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1. 데이터를 준비합니다.\n",
|
|
"1-1. 네트워크가 로드되었습니다.\n",
|
|
"1-2. 테이블들이 로드되었습니다.\n",
|
|
"1-5. 필요한 보조 객체들이 모두 준비되었습니다.\n",
|
|
"2. 신호이력 테이블을 변환합니다.\n",
|
|
"3. 이동류정보 테이블을 변환합니다.\n",
|
|
"4. 통합 테이블을 생성합니다.\n",
|
|
"5. 신호를 생성합니다.\n",
|
|
"6. 이슈사항을 저장합니다.\n",
|
|
"(1) 0:00:01.848446\n",
|
|
"(1-1) 0:00:01.781893\n",
|
|
"(1-2) 0:00:00.050542\n",
|
|
"(1-3) 0:00:00\n",
|
|
"(1-4) 0:00:00\n",
|
|
"(1-5) 0:00:00.016011\n",
|
|
"(2) 0:00:00.032995\n",
|
|
"(2-1) 0:00:00.015911\n",
|
|
"(2-2) 0:00:00.017084\n",
|
|
"(2-3) 0:00:00\n",
|
|
"(3) 0:00:00.262816\n",
|
|
"(3-1) 0:00:00.259815\n",
|
|
"(3-2) 0:00:00.003001\n",
|
|
"(4) 0:00:00.037998\n",
|
|
"(4-1) 0:00:00.000926\n",
|
|
"(4-2) 0:00:00.002999\n",
|
|
"(4-2) 0:00:00.034073\n",
|
|
"(5) 0:00:00.270916\n",
|
|
"(5-1) 0:00:00.003018\n",
|
|
"(5-2) 0:00:00.265888\n",
|
|
"(5-3) 0:00:00.002010\n",
|
|
"(6) 0:00:00\n",
|
|
"total time : 0:00:02.453171\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"c:\\github\\siggen\\scripts\\generate_signals.py:693: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
|
|
" SIG[['phas_A', 'state_A']] = SIG[['phas_A', 'state_A']].fillna(method='ffill')\n",
|
|
"c:\\github\\siggen\\scripts\\generate_signals.py:694: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
|
|
" SIG[['phas_B', 'state_B']] = SIG[['phas_B', 'state_B']].fillna(method='ffill')\n",
|
|
"c:\\github\\siggen\\scripts\\generate_signals.py:693: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
|
|
" SIG[['phas_A', 'state_A']] = SIG[['phas_A', 'state_A']].fillna(method='ffill')\n",
|
|
"c:\\github\\siggen\\scripts\\generate_signals.py:694: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
|
|
" SIG[['phas_B', 'state_B']] = SIG[['phas_B', 'state_B']].fillna(method='ffill')\n",
|
|
"c:\\github\\siggen\\scripts\\generate_signals.py:693: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
|
|
" SIG[['phas_A', 'state_A']] = SIG[['phas_A', 'state_A']].fillna(method='ffill')\n",
|
|
"c:\\github\\siggen\\scripts\\generate_signals.py:694: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n",
|
|
" SIG[['phas_B', 'state_B']] = SIG[['phas_B', 'state_B']].fillna(method='ffill')\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"self = SignalGenerator()\n",
|
|
"self.main()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"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"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"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",
|
|
"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": 6,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" inter_no phase_no ring_type move_no inc_dire out_dire inc_angle \\\n",
|
|
"0 175 1 A 8 남 북 179 \n",
|
|
"1 175 1 B 4 북 남 003 \n",
|
|
"2 175 2 A 7 북 동 001 \n",
|
|
"3 175 2 B 3 남 서 179 \n",
|
|
"4 175 3 A 6 동 서 092 \n",
|
|
"5 175 3 B 1 동 남 090 \n",
|
|
"6 175 4 A 5 서 북 268 \n",
|
|
"7 175 4 B 2 서 동 270 \n",
|
|
"\n",
|
|
" out_angle inc_edge_id out_edge_id node_id node_type turn_type \n",
|
|
"0 004 -571542797_02 571500487_01 u00 u_turn straight \n",
|
|
"1 176 -571500487_01 571542797_02 u00 u_turn straight \n",
|
|
"2 095 -571500487_01 571545870_01 u00 u_turn left \n",
|
|
"3 271 -571542797_02 571510153_01 u00 u_turn left \n",
|
|
"4 270 571545870_02 571510153_01 u00 u_turn straight \n",
|
|
"5 180 571545870_02 571542797_02 u00 u_turn left \n",
|
|
"6 358 571510153_02 571500487_01 u00 u_turn left \n",
|
|
"7 090 571510153_02 571545870_01 u00 u_turn straight \n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(cmatch)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>inc_edge_id</th>\n",
|
|
" <th>out_edge_id</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>-571542797_02</td>\n",
|
|
" <td>571500487_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>-571500487_01</td>\n",
|
|
" <td>571542797_02</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>-571500487_01</td>\n",
|
|
" <td>571545870_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>-571542797_02</td>\n",
|
|
" <td>571510153_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>571545870_02</td>\n",
|
|
" <td>571510153_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>571545870_02</td>\n",
|
|
" <td>571542797_02</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>6</th>\n",
|
|
" <td>571510153_02</td>\n",
|
|
" <td>571500487_01</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>7</th>\n",
|
|
" <td>571510153_02</td>\n",
|
|
" <td>571545870_01</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" inc_edge_id out_edge_id\n",
|
|
"0 -571542797_02 571500487_01\n",
|
|
"1 -571500487_01 571542797_02\n",
|
|
"2 -571500487_01 571545870_01\n",
|
|
"3 -571542797_02 571510153_01\n",
|
|
"4 571545870_02 571510153_01\n",
|
|
"5 571545870_02 571542797_02\n",
|
|
"6 571510153_02 571500487_01\n",
|
|
"7 571510153_02 571545870_01"
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"cmatch[['inc_edge_id', 'out_edge_id']]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>inc_edge_id</th>\n",
|
|
" <th>out_edge_id</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>571500487_02</td>\n",
|
|
" <td>571500487_01.32</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>5</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>6</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>7</th>\n",
|
|
" <td>NaN</td>\n",
|
|
" <td>NaN</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" inc_edge_id out_edge_id\n",
|
|
"0 NaN NaN\n",
|
|
"1 NaN NaN\n",
|
|
"2 571500487_02 571500487_01.32\n",
|
|
"3 NaN NaN\n",
|
|
"4 NaN NaN\n",
|
|
"5 NaN NaN\n",
|
|
"6 NaN NaN\n",
|
|
"7 NaN NaN"
|
|
]
|
|
},
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"cmatch[['inc_edge_id', 'out_edge_id']] = cmatch[['inc_edge_id', 'out_edge_id']].astype('object')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# 보행신호시/좌회전시 진입/진출 엣지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]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 37,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:73: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571500487_02' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[right_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:73: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571500487_01.32' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[right_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:71: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571542810_01.51' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:71: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571542810_02' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:71: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571556452_01' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:71: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571556452_02' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:71: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571500475_02' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:71: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571500475_01.26' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:71: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571540303_02' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:71: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '-571540303_02' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:73: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '571500535_02' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[right_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
"C:\\Users\\Uinetworks\\AppData\\Local\\Temp\\ipykernel_18920\\3718306561.py:73: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '-571500535_02' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.\n",
|
|
" cmatch.loc[right_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# 각 uturn node에 대하여 (inc_edge_id, out_edge_id) 부여\n",
|
|
"cmatches = []\n",
|
|
"for row in self.uturn.itertuples():\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",
|
|
" 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\n",
|
|
"\n",
|
|
" # 보행신호시/좌회전시 진입/진출 엣지id 배정\n",
|
|
" cmatch[['inc_edge_id', 'out_edge_id']] = np.nan\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",
|
|
"\n",
|
|
" if uturn_not_assigned:\n",
|
|
" # 좌회전시\n",
|
|
" if right_flag.any():\n",
|
|
" cmatch.loc[right_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
" # 보행신호시\n",
|
|
" elif pedes_flag.any():\n",
|
|
" cmatch.loc[pedes_flag, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
" # 보행신호이동류(17) 발생시\n",
|
|
" elif crosswalk_on.any():\n",
|
|
" cmatch.loc[crosswalk_on, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
" # 신호없음이동류(18) 발생시\n",
|
|
" elif all_redsigns.any():\n",
|
|
" cmatch.loc[all_redsigns, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
" # 진출엣지 미포함시\n",
|
|
" elif out_true.any():\n",
|
|
" cmatch.loc[~ out_true, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n",
|
|
" cmatches.append(cmatch)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"# 각 연등교차로(coordination node)에 대하여 (inc_edge_id, out_edge_id) 부여\n",
|
|
"self.coord['inter_no'] = self.coord['parent_id'].map(self.node2inter)\n",
|
|
"self.coord = self.coord.rename(columns={'child_id':'node_id'})\n",
|
|
"self.coord[['inc_dire', 'out_dire', 'inc_angle','out_angle']] = np.nan\n",
|
|
"self.coord['move_no'] = 20\n",
|
|
"self.coord = self.coord[['inter_no', 'phase_no', 'ring_type', 'move_no', 'inc_dire', 'out_dire', 'inc_angle','out_angle', 'inc_edge_id', 'out_edge_id', 'node_id']]\n",
|
|
"self.coord['node_type'] = 'coord'\n",
|
|
"\n",
|
|
"cmatches = pd.concat(cmatches)\n",
|
|
"self.match6 = pd.concat([self.match5, cmatches, self.coord]).drop_duplicates().sort_values(by=['inter_no', 'node_id', 'phase_no', 'ring_type'])\n",
|
|
"self.match6 = self.match6.reset_index(drop=True)\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "siggen_env",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|