From d0bb062e2e712ceaedadd6c9193af4a5b0503944 Mon Sep 17 00:00:00 2001 From: Ruben1729 Date: Wed, 21 Feb 2024 12:44:08 -0500 Subject: [PATCH] Working viewport --- __pycache__/matsim_visualizer.cpython-39.pyc | Bin 4812 -> 4666 bytes main.py | 2 +- matsim_visualizer.py | 29 +++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/__pycache__/matsim_visualizer.cpython-39.pyc b/__pycache__/matsim_visualizer.cpython-39.pyc index bab6254e6d71dc1d010fa55a58b2a61370e65fac..e80f40ff7a3820d986892b568a86d0b6a6c9ae05 100644 GIT binary patch delta 2449 zcmZuzO>7%Q6rR~Xuh-u7U*gzpV@xS+U7%^90z`q9QUt0B2P#0cs;rG?lX_!&-PviH zL~D#lPe_5nNL-*&as`3lhTy`10|JB)AP##)LV^foQ8t%Xuo;${$}RAeQ*8s zouBOUeAjgd{AP~)7<^Ls$U8*GCa$-CNbB%C4o`dypi2_cCX0xaA!-VBg@!^?p`|dB z7@%V(I$$=TfKH+T=0twe-9md$6c}aNHL{Mh^jy&9;}j!PQ~Jg?v+c z^3N%>-UWlZPR4h7ClWa{yfr!mFSxprf<=8Ix@CbhFX~k32jEMka!ux z8QMz*PqqU~!mN^9SCZ@!;cqEP7W5n?c{f3O2W&n>3KBrV97x6_{#=Q2VDzODv@RbL z@cKaX92H{{mKojBUf(sMLfpC5iLHQ_{#h)D^RE-w_8HT8mG87N5#a2pi($&ns_@@VTbZq1+Jp;SKuO3@KnYS zLf0g9!ZHs)upcID3Y<9q=7Hig@-P8l{PBc_BTgqSU=Zh8BS_Z!hB>ZlKdr-$-4lZ>&y&zt5=Yr*6AmYiC z8d%7wAy$V0V7D*N*@xsS_Wp6JmKuv|-C=4(!(hOt(G_l-nnRz*L29lHeQ_x@7kZH| zQhhNHyns4I1gt_{MyMd<5b^-2fn`a*G$nttvNE4rZ|tOtpM>38Srxa`?24ct^SXRLH%n*aSGnfQ zUJ$1l3`o1nQmYe1oW*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8hM-cOh{HHEY9 z?fW=OI^TfI4NQ!)sP7p}ptpgyB`%e89yL55zVMmK*je$@A@lXZs4o+hgwiaZM)aDNdV^|N>JF^1*D6*D1MAX-2MPy#=8 zg$(AZ$2pt2)34LBa6|}>szwxLV>!j6H>z4ubb$XFY>$2(i(ga=NutTPo#V`yLld%) zX6b^Nco30bFSr}j0w=hvjm~@eb#x*YIm%KSy#&jE;>cdQUKSUm?=;!Pv!AHSx1~9c zaPwUM+1YARan*#{Q#GLfXma}oZ=V}H$m|K8-@u$xuHVIM!``<^gnu5aa&D7X$tmoD LrlIlH>F4|pnEa)U diff --git a/main.py b/main.py index c47503b..2dfc576 100644 --- a/main.py +++ b/main.py @@ -28,7 +28,7 @@ try: Matsim(city, 'output_files').export() MatSimEngine('output_files/Montreal_config.xml').run() - visualizer = MatsimVisualizer('output_files/Montreal/output_network.xml.gz', 'output_files/Montreal/output_events.xml.gz', 'output_files', (3827652.8297388176, 6039933.844748944, 3873591.6501221485, 6042487.096594835)) + visualizer = MatsimVisualizer('output_files/Montreal/output_network.xml.gz', 'output_files/Montreal/output_events.xml.gz', 'output_files', (3830263.051512, 6043256.513982, 3866288.881858, 6012487.188767)) visualizer.visualize() except Exception as ex: diff --git a/matsim_visualizer.py b/matsim_visualizer.py index 1326f1a..1a77be0 100644 --- a/matsim_visualizer.py +++ b/matsim_visualizer.py @@ -15,6 +15,11 @@ class MatsimVisualizer(): self._links = [] self._pos = None self.norm = None + + self._max_x = None + self._min_x = None + self._max_y = None + self._min_y = None self._viewport = viewport self._output_file_path = output_file_path @@ -27,6 +32,8 @@ class MatsimVisualizer(): self._tick = 0 self._max_traffic = 0 + self._max_traffic_link = None + self._max_traffic_tick = None def load_data(self): # ====== LOAD NETWORK ====== # @@ -36,7 +43,20 @@ class MatsimVisualizer(): for node in network_doc.xpath('/network/nodes/node'): x = float(node.get('x')) y = float(node.get('y')) - if self._viewport[0] < x < self._viewport[2] and self._viewport[1] < y < self._viewport[3]: + + if self._max_x is None or x > self._max_x: + self._max_x = x + + if self._min_x is None or x < self._min_x: + self._min_x = x + + if self._max_y is None or y > self._max_y: + self._max_y = y + + if self._min_y is None or y < self._min_y: + self._min_y = y + + if self._viewport[0] < x < self._viewport[2] and self._viewport[1] > y > self._viewport[3]: self._nodes[node.get('id')] = (x, y) for link in network_doc.xpath('/network/links/link'): @@ -73,6 +93,8 @@ class MatsimVisualizer(): # We need to find the maximum value for traffic at any given point for the heatmap if self._max_traffic < cumulative_traffic[link_id]: self._max_traffic = cumulative_traffic[link_id] + self._max_traffic_link = link_id + self._max_traffic_tick = self._tick elif event_type in ['left link', 'vehicle leaves traffic']: self._traffic_per_tick[self._tick][link_id] -= 1 cumulative_traffic[link_id] -= 1 @@ -101,7 +123,6 @@ class MatsimVisualizer(): for link_id, change in traffic_change.items(): if link_id == link['id']: link['vehicles'] += change - break edge_colors.append(self._cmap(link['vehicles'])) edge_widths.append(1 + self.norm(link['vehicles']) * 10) @@ -121,6 +142,8 @@ class MatsimVisualizer(): fig, ax = plt.subplots() + ax.set_aspect((self._max_x - self._min_x) / (self._max_y - self._min_y)) + sm = plt.cm.ScalarMappable(cmap=self._cmap, norm=self.norm) sm.set_array([]) plt.colorbar(sm, ax=ax, label='Traffic Density') @@ -129,3 +152,5 @@ class MatsimVisualizer(): ani = FuncAnimation(fig, self.update, frames=len(self._traffic_per_tick), repeat=False) ani.save(f"{self._output_file_path}/traffic_animation.gif", writer='ffmpeg', fps=5) plt.show() + + print(f"Largest amount of vehicles ({self._max_traffic}) seen at {self._max_traffic_tick} on link {self._max_traffic_link}")