-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
mypy fixes for boids example #563
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# mypy: ignore-errors | ||
from __future__ import annotations | ||
import pandas as pd | ||
from scipy import spatial | ||
|
||
|
@@ -43,7 +43,7 @@ def on_time_step(self, event: Event) -> None: | |
# Pipeline sources and modifiers # | ||
################################## | ||
|
||
def get_neighbors(self, index: pd.Index) -> pd.Series: | ||
def get_neighbors(self, index: pd.Index[int]) -> pd.Series[list[int]]: # type: ignore[type-var] | ||
if not self.neighbors_calculated: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is that someone common pandas error where it doesn't list out the entire line of expected items:
|
||
self._calculate_neighbors() | ||
return self._neighbors[index] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# mypy: ignore-errors | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
# mypy: ignore-errors | ||
import matplotlib.pyplot as plt | ||
from matplotlib.animation import FuncAnimation | ||
|
||
from vivarium import InteractiveContext | ||
|
||
def plot_boids(simulation, plot_velocity=False): | ||
|
||
def plot_boids(simulation: InteractiveContext, plot_velocity: bool=False) -> None: | ||
width = simulation.configuration.field.width | ||
height = simulation.configuration.field.height | ||
pop = simulation.get_population() | ||
|
||
plt.figure(figsize=[12, 12]) | ||
plt.figure(figsize=(12, 12)) | ||
plt.scatter(pop.x, pop.y, color=pop.color) | ||
if plot_velocity: | ||
plt.quiver(pop.x, pop.y, pop.vx, pop.vy, color=pop.color, width=0.002) | ||
plt.xlabel("x") | ||
plt.ylabel("y") | ||
plt.axis([0, width, 0, height]) | ||
plt.axis((0, width, 0, height)) | ||
plt.show() | ||
|
||
|
||
def plot_boids_animated(simulation): | ||
def plot_boids_animated(simulation: InteractiveContext) -> FuncAnimation: | ||
width = simulation.configuration.field.width | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure tbh. The example docs is all about interactive, but maybe it could be used in a simulation context? |
||
height = simulation.configuration.field.height | ||
pop = simulation.get_population() | ||
|
||
fig = plt.figure(figsize=[12, 12]) | ||
fig = plt.figure(figsize=(12, 12)) | ||
ax = fig.add_subplot(111) | ||
s = ax.scatter(pop.x, pop.y, color=pop.color) | ||
plt.xlabel("x") | ||
plt.ylabel("y") | ||
plt.axis([0, width, 0, height]) | ||
plt.axis((0, width, 0, height)) | ||
|
||
frames = range(2_000) | ||
frame_pops = [] | ||
for _ in frames: | ||
simulation.step() | ||
frame_pops.append(simulation.get_population()[["x", "y"]]) | ||
|
||
def animate(i): | ||
def animate(i: int) -> None: | ||
s.set_offsets(frame_pops[i]) | ||
|
||
return FuncAnimation(fig, animate, frames=frames, interval=10) | ||
return FuncAnimation(fig, animate, frames=frames, interval=10) # type: ignore[arg-type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to merge from main again? I already released 3.2.12