From cdfea63c7cff5c86881749572f328c63be4e260a Mon Sep 17 00:00:00 2001 From: govin08 Date: Fri, 12 Apr 2024 20:50:26 +0900 Subject: [PATCH] maybe 0411_uturn.ipynb is restored --- .../0411_uturn.ipynb | 1370 +++++++++++++++++ .../raw_tables/angle_to_be_modified.csv | 49 + 2 files changed, 1419 insertions(+) create mode 100644 Analysis/0411_unp-left_p-right-uturn/0411_uturn.ipynb create mode 100644 Data/tables/raw_tables/angle_to_be_modified.csv diff --git a/Analysis/0411_unp-left_p-right-uturn/0411_uturn.ipynb b/Analysis/0411_unp-left_p-right-uturn/0411_uturn.ipynb new file mode 100644 index 000000000..abab7fdad --- /dev/null +++ b/Analysis/0411_unp-left_p-right-uturn/0411_uturn.ipynb @@ -0,0 +1,1370 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import pandas as pd\n", + "import numpy as np\n", + "import sys\n", + "sys.path.append('../../Scripts')\n", + "from preprocess_daily import DailyPreprocessor\n", + "from generate_signals import SignalGenerator" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "비보호좌회전, 신호우회전, 유턴\n", + "\n", + "줄임말 목록\n", + "- `i` : 교차로번호, `inter_no`\n", + "- `f` : 진입, from, `inc_edge_id`\n", + "- `t` : 진출, to, `out_edge_id`\n", + "- `vec` : 방향벡터, unit vector (`np.array([0.6, 0.8])`)\n", + "- `dire` : 방위, direction (동, 서, 남, 북, 북동, 북서, 남동, 남서)\n", + "- `rvec` : 정방향 방향벡터, unit vector to the right direction (`np.array([0,1])`)\n", + "\n", + "필요한 객체들 목록\n", + "\n", + "- `inter2dire2rvec` : `inter_no` $\\mapsto$ `dire2rvec`\n", + " - `dire2rvec` : `dire` $\\mapsto$ `rvec`\n", + "- `inter2incs` : `inter_no` $\\mapsto$ `inc_edge_ids`\n", + "- `inter2outs` : `inter_no` $\\mapsto$ `out_edge_ids`\n", + "- `inter2inc2dire` : `inter_no` $\\mapsto$ `int2dire`\n", + " - `inc2dire` : `out_edge_id` $\\mapsto$ `dire`\n", + "- `inter2out2dire` : `inter_no` $\\mapsto$ `out2dire`\n", + " - `out2dire` : `inc_edge_id` $\\mapsto$ `dire`\n", + "- `inter2inc2vec` : `inter_no` $\\mapsto$ `int2vec`\n", + " - `inc2vec` : `out_edge_id` $\\mapsto$ `vec`\n", + "- `inter2out2vec` : `inter_no` $\\mapsto$ `out2vec`\n", + " - `out2vec` : `inc_edge_id` $\\mapsto$ `vec`\n", + "\n", + "좌회전 판단\n", + "\n", + "Given `inter_no`, `inc_edge_id` and `out_edge_id`, we have `inc_vec = inter2inc2vec[inter_no][inc_edge_id]` and `out_vec = inter2out2vec[inter_no][out_edge_id]`.\n", + "Rotate `inc_vec` by 90, 180 and 270 degrees clockwise, to define \n", + "`out_vec_left`, `out_vec_straight` and `out_vec_right`.\n", + "Define `out_vecs={'right':out_vec_left, 'straight':out_vec_straight, 'right':out_vec_right}`.\n", + "Select the key that maximize the similarity of the corresponding value of the key and `inc_vec`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1. 데이터를 로드합니다.\n", + "1-1. 네트워크가 로드되었습니다.\n", + "1-2. 테이블들이 로드되었습니다.\n", + "1-3. 네트워크의 모든 clean state requirement들을 체크했습니다.\n", + "1-4. 테이블들의 무결성 검사를 완료했습니다.\n", + "1-5. 주요 객체 (리스트, 딕셔너리)들을 저장했습니다.\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
parent_idchild_iddirectionconditioninc_edge_idout_edge_id
0i0u00좌회전시571500487_02571500487_01.32
1i2u20보행신호시571542810_01.51571542810_02
2i3u30보행신호시571556452_01571556452_02
3i3u31보행신호시571500475_02571500475_01.26
4i3u32보행신호시571540303_02-571540303_02
5i6u60좌회전시571500535_02-571500535_02
\n", + "
" + ], + "text/plain": [ + " parent_id child_id direction condition inc_edge_id out_edge_id\n", + "0 i0 u00 북 좌회전시 571500487_02 571500487_01.32\n", + "1 i2 u20 북 보행신호시 571542810_01.51 571542810_02\n", + "2 i3 u30 북 보행신호시 571556452_01 571556452_02\n", + "3 i3 u31 동 보행신호시 571500475_02 571500475_01.26\n", + "4 i3 u32 서 보행신호시 571540303_02 -571540303_02\n", + "5 i6 u60 서 좌회전시 571500535_02 -571500535_02" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
parent_idchild_idhead_edge_idfrom_edge_idto_edge_id
0i0u00-571500487_01571500487_02571500487_01.32
1i2u20571542811_02571542810_01.51571542810_02
2i3u30571556450_02571556452_01571556452_02
3i3u31-571500475_01571500475_02571500475_01.26
4i3u32571540303_02.21571540303_02-571540303_02
5i6u60571500535_02.18571500535_02-571500535_02
\n", + "
" + ], + "text/plain": [ + " parent_id child_id head_edge_id from_edge_id to_edge_id\n", + "0 i0 u00 -571500487_01 571500487_02 571500487_01.32\n", + "1 i2 u20 571542811_02 571542810_01.51 571542810_02\n", + "2 i3 u30 571556450_02 571556452_01 571556452_02\n", + "3 i3 u31 -571500475_01 571500475_02 571500475_01.26\n", + "4 i3 u32 571540303_02.21 571540303_02 -571540303_02\n", + "5 i6 u60 571500535_02.18 571500535_02 -571500535_02" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
parent_idchild_idhead_edge_idfrom_edge_idto_edge_idcondition
0i0u00-571500487_01571500487_02571500487_01.32좌회전시
1i2u20571542811_02571542810_01.51571542810_02보행신호시
2i3u30571556450_02571556452_01571556452_02보행신호시
3i3u31-571500475_01571500475_02571500475_01.26보행신호시
4i3u32571540303_02.21571540303_02-571540303_02보행신호시
5i6u60571500535_02.18571500535_02-571500535_02좌회전시
\n", + "
" + ], + "text/plain": [ + " parent_id child_id head_edge_id from_edge_id to_edge_id \\\n", + "0 i0 u00 -571500487_01 571500487_02 571500487_01.32 \n", + "1 i2 u20 571542811_02 571542810_01.51 571542810_02 \n", + "2 i3 u30 571556450_02 571556452_01 571556452_02 \n", + "3 i3 u31 -571500475_01 571500475_02 571500475_01.26 \n", + "4 i3 u32 571540303_02.21 571540303_02 -571540303_02 \n", + "5 i6 u60 571500535_02.18 571500535_02 -571500535_02 \n", + "\n", + " condition \n", + "0 좌회전시 \n", + "1 보행신호시 \n", + "2 보행신호시 \n", + "3 보행신호시 \n", + "4 보행신호시 \n", + "5 좌회전시 " + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "self = DailyPreprocessor()\n", + "self.load_data()\n", + "self.make_match1()\n", + "self.make_match2()\n", + "self.make_match3()\n", + "self.make_match4()\n", + "self.make_match5()\n", + "display(self.uturn)\n", + "display(self.u_turn)\n", + "self.u_turn = pd.merge(self.u_turn, self.u_condition, on='child_id')\n", + "self.u_turn" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [], + "source": [ + "# n2inc_edge2angle : node_id to inc_edge2angle\n", + "n2inc_edge2angle = dict()\n", + "# n2out_edge2angle : node_id to out_edge2angle\n", + "n2out_edge2angle = dict()\n", + "# n2inc_angle2edge : node_id to inc_angle2edge\n", + "n2inc_angle2edge = dict()\n", + "# n2out_angle2edge : node_id to out_angle2edge\n", + "n2out_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", + " n2inc_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", + " n2out_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", + " n2inc_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", + " n2out_angle2edge[node_id] = out_angle2edge" + ] + }, + { + "cell_type": "code", + "execution_count": 173, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "parent_id i2\n", + "child_id u20\n", + "head_edge_id 571542811_02\n", + "from_edge_id 571542810_01.51\n", + "to_edge_id 571542810_02\n", + "condition 보행신호시\n", + "Name: 1, dtype: object" + ] + }, + "execution_count": 173, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "i = 1\n", + "row = self.u_turn.iloc[i]\n", + "\n", + "parent_id = row.parent_id\n", + "child_id = row.child_id\n", + "condition = row.condition\n", + "inc_edge_id = row.from_edge_id\n", + "out_edge_id = row.to_edge_id\n", + "head_edge_id = row.head_edge_id\n", + "row" + ] + }, + { + "cell_type": "code", + "execution_count": 174, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i2 u20 보행신호시\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
inter_nophase_noring_typemove_noinc_direout_direinc_angleout_angleinc_edge_idout_edge_idnode_idturn_type
01771A8179000-571542809_01571542811_01u20left
11771B4000180571542811_02571542809_01u20straight
21772A7000090571542811_02571542107_01u20left
31772B3179270-571542809_01571542809_01u20left
41774A5268000-571542809_01571542811_01u20left
51774B1090180571542107_02571542809_01u20left
\n", + "
" + ], + "text/plain": [ + " inter_no phase_no ring_type move_no inc_dire out_dire inc_angle \\\n", + "0 177 1 A 8 남 북 179 \n", + "1 177 1 B 4 북 남 000 \n", + "2 177 2 A 7 북 동 000 \n", + "3 177 2 B 3 남 서 179 \n", + "4 177 4 A 5 서 북 268 \n", + "5 177 4 B 1 동 남 090 \n", + "\n", + " out_angle inc_edge_id out_edge_id node_id turn_type \n", + "0 000 -571542809_01 571542811_01 u20 left \n", + "1 180 571542811_02 571542809_01 u20 straight \n", + "2 090 571542811_02 571542107_01 u20 left \n", + "3 270 -571542809_01 571542809_01 u20 left \n", + "4 000 -571542809_01 571542811_01 u20 left \n", + "5 180 571542107_02 571542809_01 u20 left " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# match5에서 부모노드id에 해당하는 행들을 가져옴 (cmatch)\n", + "cmatch = self.match5.copy()[self.match5.node_id==parent_id] # match dataframe for a child node\n", + "cmatch = cmatch.dropna(subset=['inc_angle', 'out_angle'])\n", + "cmatch = cmatch.sort_values(by=['phase_no', 'ring_type']).reset_index(drop=True)\n", + "cmatch['node_id'] = child_id\n", + "print(parent_id, child_id, condition)\n", + "display(cmatch)" + ] + }, + { + "cell_type": "code", + "execution_count": 184, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
node_idinc_edge_idout_edge_idturn_type
13i2-571542809_01571542811_01straight
14i2571542811_02571542809_01straight
15i2571542811_02571542107_01left
16i2-571542809_01571542809_01left
17i2-571542809_01571542811_01left
18i2571542107_02571542809_01left
\n", + "
" + ], + "text/plain": [ + " node_id inc_edge_id out_edge_id turn_type\n", + "13 i2 -571542809_01 571542811_01 straight\n", + "14 i2 571542811_02 571542809_01 straight\n", + "15 i2 571542811_02 571542107_01 left\n", + "16 i2 -571542809_01 571542809_01 left\n", + "17 i2 -571542809_01 571542811_01 left\n", + "18 i2 571542107_02 571542809_01 left" + ] + }, + "execution_count": 184, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "self.turn_type[self.turn_type.node_id=='i2']" + ] + }, + { + "cell_type": "code", + "execution_count": 181, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i0\n", + "{('-571542797_02', '571500487_01'): 'straight', ('-571500487_01', '571542797_02'): 'straight', ('-571500487_01', '571545870_01'): 'left', ('-571542797_02', '571510153_01'): 'left', ('571545870_02', '571510153_01'): 'straight', ('571545870_02', '571542797_02'): 'left', ('571510153_02', '571500487_01'): 'left', ('571510153_02', '571545870_01'): 'straight'}\n", + "i1\n", + "{('-571542810_01', '-571542797_02.99'): 'straight', ('571542797_02.99', '571542810_01'): 'straight', ('-571542810_01', '571543469_01'): 'left', ('571543469_02', '-571542797_02.99'): 'left'}\n", + "i2\n", + "{('-571542809_01', '571542811_01'): 'left', ('571542811_02', '571542809_01'): 'straight', ('571542811_02', '571542107_01'): 'left', ('-571542809_01', '571542809_01'): 'left', ('571542107_02', '571542809_01'): 'left'}\n", + "i3\n", + "{('571540304_02', '571556450_01'): 'straight', ('571556450_02', '571540304_01'): 'straight', ('571556450_02', '571500475_01'): 'left', ('571540304_02', '571540303_01'): 'left', ('571540303_02.21', '571556450_01'): 'left', ('571540303_02.21', '571500475_01'): 'straight', ('-571500475_01', '571540303_01'): 'straight', ('-571500475_01', '571540304_01'): 'left'}\n", + "i6\n", + "{('-571542115_01', '571500535_01'): 'straight', ('571500535_02.18', '571511538_01'): 'left', ('571500535_02.18', '571542115_01'): 'straight', ('571511538_02.121', '571542115_01'): 'left', ('571511538_02.121', '571500585_01'): 'straight', ('571500585_02', '571511538_01'): 'straight', ('571500585_02', '571500535_01'): 'left'}\n", + "i7\n", + "{('-571511538_02', '571542073_02'): 'straight', ('571542073_01', '571511538_02'): 'straight'}\n", + "i8\n", + "{('-571500569_01', '571500583_02'): 'straight', ('-571500569_01', '571500618_01'): 'left', ('571500618_02', '571500583_02'): 'left', ('571500618_02', '571500617_01'): 'straight', ('571500617_02', '571500618_01'): 'straight', ('571500617_02', '571500569_01'): 'left', ('571500583_01', '571500617_01'): 'left', ('571500583_01', '571500569_01'): 'straight'}\n", + "i9\n", + "{('571510152_02', '-571510152_01'): 'straight', ('571510152_01', '571510152_01.65'): 'straight'}\n" + ] + } + ], + "source": [ + "# dictionary that maps node_id to io2turn\n", + "n2io2turn = dict()\n", + "for node_id in self.parent_ids:\n", + " print(node_id)\n", + " turn = self.turn_type[self.turn_type.node_id==node_id]\n", + " io = list(zip(turn.inc_edge_id, turn.out_edge_id))\n", + " # dictionary that maps (inc_edge_id, out_edge_id) to turn_type\n", + " io2turn = dict(zip(io, turn.turn_type))\n", + " n2io2turn[node_id] = io2turn\n", + " print(io2turn)\n", + "\n", + "for i, row in self.match5.iterrows():\n", + " node_id = row.node_id\n", + " inc_edge_id = row.inc_edge_id\n", + " out_edge_id = row.out_edge_id\n", + " if not (pd.isna(inc_edge_id) and pd.isna(out_edge_id)):\n", + " turn_type = n2io2turn[node_id][(inc_edge_id, out_edge_id)]\n", + " self.match5.at[i, 'turn_type'] = turn_type\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# 헤드엣지가 포함된 행\n", + "head_true = cmatch.inc_edge_id==head_edge_id\n", + "\n", + "# 헤드엣지 각도\n", + "inc_angle_head = n2inc_edge2angle[parent_id][head_edge_id]\n", + "print(inc_angle_head)\n", + "\n", + "# 이격각도\n", + "self.angle_separation = 10\n", + "\n", + "# 진입로 각도 목록\n", + "inc_angles = cmatch.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", + "print(inc_angles)\n", + "\n", + "# 보행신호시의 진입로 각도\n", + "inc_angles_left = inc_angles[inc_angles >= inc_angle_head + self.angle_separation]\n", + "inc_angle_pedes = np.sort(inc_angles_left)[0] % 360\n", + "print(inc_angles_left)\n", + "print(inc_angle_pedes)\n", + "\n", + "# 보행신호시의 진입로 엣지id\n", + "inc_angle2edge = n2inc_angle2edge[parent_id]\n", + "inc_edge_id_pedes = inc_angle2edge[inc_angle_pedes]\n", + "print(inc_edge_id_pedes)\n", + "\n", + "# 진출로 각도 목록\n", + "out_angles = cmatch.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", + "print(out_angles)\n", + "\n", + "# 보행신호시의 진입로 각도\n", + "out_angles_right = out_angles[out_angles <= inc_angle_head - self.angle_separation]\n", + "out_angle_pedes = np.sort(out_angles_right)[-1] % 360\n", + "print(out_angles_right)\n", + "\n", + "print(out_angle_pedes)\n", + "\n", + "# 보행신호시의 진입로 엣지id\n", + "out_angle2edge = n2out_angle2edge[parent_id]\n", + "out_edge_id_pedes = out_angle2edge[out_angle_pedes]\n", + "print(out_edge_id_pedes)\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 = head_true & (cmatch.turn_type=='left')\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", + "display(cmatch)" + ] + }, + { + "cell_type": "code", + "execution_count": 190, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i2 u20 보행신호시\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
inter_nophase_noring_typemove_noinc_direout_direinc_angleout_angleinc_edge_idout_edge_idnode_idturn_type
01771A8179000-571542809_01571542811_01u20left
11771B4000180571542811_02571542809_01u20straight
21772A7000090571542811_02571542107_01u20left
31772B3179270-571542809_01571542809_01u20left
41774A5268000-571542809_01571542811_01u20left
51774B1090180571542107_02571542809_01u20left
\n", + "
" + ], + "text/plain": [ + " inter_no phase_no ring_type move_no inc_dire out_dire inc_angle \\\n", + "0 177 1 A 8 남 북 179 \n", + "1 177 1 B 4 북 남 000 \n", + "2 177 2 A 7 북 동 000 \n", + "3 177 2 B 3 남 서 179 \n", + "4 177 4 A 5 서 북 268 \n", + "5 177 4 B 1 동 남 090 \n", + "\n", + " out_angle inc_edge_id out_edge_id node_id turn_type \n", + "0 000 -571542809_01 571542811_01 u20 left \n", + "1 180 571542811_02 571542809_01 u20 straight \n", + "2 090 571542811_02 571542107_01 u20 left \n", + "3 270 -571542809_01 571542809_01 u20 left \n", + "4 000 -571542809_01 571542811_01 u20 left \n", + "5 180 571542107_02 571542809_01 u20 left " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "[-360 -270 -181 -92 0 90 179 268 360 450 539 628]\n", + "[ 90 179 268 360 450 539 628]\n", + "90\n", + "571542107_02\n", + "[-360 -270 -180 -90 0 90 180 270 360 450 540 630]\n", + "[-360 -270 -180 -90]\n", + "270\n", + "571542809_01\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
inter_nophase_noring_typemove_noinc_direout_direinc_angleout_angleinc_edge_idout_edge_idnode_idturn_type
01771A8179000NaNNaNu20left
11771B4000180NaNNaNu20straight
21772A7000090NaNNaNu20left
31772B3179270NaNNaNu20left
41774A5268000NaNNaNu20left
51774B1090180571542810_01.51571542810_02u20left
\n", + "
" + ], + "text/plain": [ + " inter_no phase_no ring_type move_no inc_dire out_dire inc_angle \\\n", + "0 177 1 A 8 남 북 179 \n", + "1 177 1 B 4 북 남 000 \n", + "2 177 2 A 7 북 동 000 \n", + "3 177 2 B 3 남 서 179 \n", + "4 177 4 A 5 서 북 268 \n", + "5 177 4 B 1 동 남 090 \n", + "\n", + " out_angle inc_edge_id out_edge_id node_id turn_type \n", + "0 000 NaN NaN u20 left \n", + "1 180 NaN NaN u20 straight \n", + "2 090 NaN NaN u20 left \n", + "3 270 NaN NaN u20 left \n", + "4 000 NaN NaN u20 left \n", + "5 180 571542810_01.51 571542810_02 u20 left " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "i = 1\n", + "row = self.u_turn.iloc[i]\n", + "\n", + "parent_id = row.parent_id\n", + "child_id = row.child_id\n", + "condition = row.condition\n", + "inc_edge_id = row.from_edge_id\n", + "out_edge_id = row.to_edge_id\n", + "head_edge_id = row.head_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.dropna(subset=['inc_angle', 'out_angle'])\n", + "cmatch = cmatch.sort_values(by=['phase_no', 'ring_type']).reset_index(drop=True)\n", + "cmatch['node_id'] = child_id\n", + "print(parent_id, child_id, condition)\n", + "display(cmatch)\n", + "\n", + "# 헤드엣지가 포함된 행\n", + "head_true = cmatch.inc_edge_id==head_edge_id\n", + "\n", + "# 헤드엣지 각도\n", + "inc_angle_head = n2inc_edge2angle[parent_id][head_edge_id]\n", + "print(inc_angle_head)\n", + "\n", + "# 이격각도\n", + "self.angle_separation = 10\n", + "\n", + "# 진입로 각도 목록\n", + "inc_angles = cmatch.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", + "print(inc_angles)\n", + "\n", + "# 보행신호시의 진입로 각도\n", + "inc_angles_left = inc_angles[inc_angles >= inc_angle_head + self.angle_separation]\n", + "inc_angle_pedes = np.sort(inc_angles_left)[0] % 360\n", + "print(inc_angles_left)\n", + "print(inc_angle_pedes)\n", + "\n", + "# 보행신호시의 진입로 엣지id\n", + "inc_angle2edge = n2inc_angle2edge[parent_id]\n", + "inc_edge_id_pedes = inc_angle2edge[inc_angle_pedes]\n", + "print(inc_edge_id_pedes)\n", + "\n", + "# 진출로 각도 목록\n", + "out_angles = cmatch.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", + "print(out_angles)\n", + "\n", + "# 보행신호시의 진입로 각도\n", + "out_angles_right = out_angles[out_angles <= inc_angle_head - self.angle_separation]\n", + "out_angle_pedes = np.sort(out_angles_right)[-1] % 360\n", + "print(out_angles_right)\n", + "\n", + "print(out_angle_pedes)\n", + "\n", + "# 보행신호시의 진입로 엣지id\n", + "out_angle2edge = n2out_angle2edge[parent_id]\n", + "out_edge_id_pedes = out_angle2edge[out_angle_pedes]\n", + "print(out_edge_id_pedes)\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 = head_true & (cmatch.turn_type=='left')\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", + "display(cmatch)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# 각 uturn node에 대하여 (inc_edge_id, out_edge_id) 부여\n", + "cmatches = []\n", + "for _, row in self.uturn.iterrows():\n", + " child_id = row.child_id\n", + " parent_id = row.parent_id\n", + " dire = row.direction\n", + " condition = row.condition\n", + " inc_edge_id = row.inc_edge_id\n", + " out_edge_id = row.out_edge_id\n", + "\n", + " print(parent_id, condition)\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[['inc_edge_id', 'out_edge_id']] = np.nan\n", + " display(cmatch)\n", + "\n", + " # 보행신호시/좌회전시 진입/진출방향\n", + " ind = self.dires.index(dire)\n", + " inc_dire_pedes = self.dires[(ind + 2) % len(self.dires)]\n", + " out_dire_pedes = self.dires[(ind - 2) % len(self.dires)]\n", + " inc_dire_right = dire\n", + " out_dire_right = self.dires[(ind + 2) % len(self.dires)]\n", + "\n", + " if condition == '보행신호시':\n", + " print(inc_dire_pedes, out_dire_pedes)\n", + " else:\n", + " print(inc_dire_right, out_dire_right)\n", + "\n", + " # 보행신호시/좌회전시 조건\n", + " pedes_exists = (cmatch.inc_dire==inc_dire_pedes) & (cmatch.out_dire==out_dire_pedes)\n", + " right_exists = (cmatch.inc_dire==inc_dire_right) & (cmatch.out_dire==out_dire_right)\n", + "\n", + " # 보행신호시/좌회전시 진입/진출 엣지id 배정\n", + " ind = self.dires.index(dire)\n", + " if condition == \"보행신호시\":\n", + " cmatch.loc[pedes_exists, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n", + " elif condition == \"좌회전시\":\n", + " cmatch.loc[right_exists, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n", + " display(cmatch)\n", + "\n", + " # 신호없음이동류발생시/보행신호이동류발생시 조건\n", + " all_redsigns = cmatch.move_no == 18\n", + " crosswalk_on = cmatch.move_no == 17\n", + "\n", + " # 만약 어떤 유턴신호도 배정되지 않았다면\n", + " # 좌회전시 → 보행신호시 → 보행신호이동류발생시 → 신호없음이동류발생시 순으로 진입/진출 엣지id 배정\n", + " uturn_not_assigned = cmatch[['inc_edge_id','out_edge_id']].isna().any(axis=1).all()\n", + " if uturn_not_assigned:\n", + " # 좌회전시\n", + " if right_exists.any():\n", + " cmatch.loc[right_exists, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n", + " # 보행신호시\n", + " elif pedes_exists.any():\n", + " cmatch.loc[pedes_exists, ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n", + " # 보행신호이동류(17) 발생시\n", + " elif crosswalk_on.any():\n", + " cmatch.loc[crosswalk_on & (cmatch.out_dire!=dire), ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n", + " # 신호없음이동류(18) 발생시\n", + " elif all_redsigns.any():\n", + " cmatch.loc[all_redsigns & (cmatch.out_dire!=dire), ['inc_edge_id', 'out_edge_id']] = [inc_edge_id, out_edge_id]\n", + " display(cmatch)\n", + "cmatches.append(cmatch)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "'''Given `inter_no`, `inc_edge_id` and `out_edge_id`, we have `inc_vec = inter2inc2vec[inter_no][inc_edge_id]` and `out_vec = inter2out2vec[inter_no][out_edge_id]`.\n", + "Rotate `inc_vec` by 90, 180 and 270 degrees clockwise, to define \n", + "`out_vec_left`, `out_vec_straight` and `out_vec_right`.\n", + "Define `out_vecs={'right':out_vec_left, 'straight':out_vec_straight, 'right':out_vec_right}`.\n", + "Select the key that maximize the similarity of the corresponding value of the key and `inc_vec`.'''" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "sts", + "language": "python", + "name": "sts" + }, + "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.8.10" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Data/tables/raw_tables/angle_to_be_modified.csv b/Data/tables/raw_tables/angle_to_be_modified.csv new file mode 100644 index 000000000..7fae31614 --- /dev/null +++ b/Data/tables/raw_tables/angle_to_be_modified.csv @@ -0,0 +1,49 @@ +inter_no,move_no,angle_code +175,1,090180 +175,2,270090 +175,3,179270 +175,4,001180 +175,5,270000 +175,6,090270 +175,7,001090 +175,8,179000 +176,3,180270 +176,4,359180 +176,5,270356 +176,8,180356 +177,1,090180 +177,2,268090 +177,3,179270 +177,4,000180 +177,5,268000 +177,6,090270 +177,7,000090 +177,8,179000 +178,1,090180 +178,2,270090 +178,3,180270 +178,4,000180 +178,5,270000 +178,6,090270 +178,7,000090 +178,8,180000 +201,1,090180 +201,2,270090 +201,3,180270 +201,4,000180 +201,5,270000 +201,6,090270 +201,7,000090 +201,8,180000 +202,2,270090 +202,6,090270 +206,4,000180 +206,8,180000 +210,1,090180 +210,2,270090 +210,3,180270 +210,4,000180 +210,5,270000 +210,6,090270 +210,7,000090 +210,8,180000