Compare commits

...

6 Commits

Author SHA1 Message Date
Andreas Tsouchlos
2a7f22c4e3 Changed savefig parameters 2022-04-27 15:49:00 +02:00
Andreas Tsouchlos
40a9bc5d98 Added legend to saved figures 2022-04-27 15:38:55 +02:00
Andreas Tsouchlos
c77e229d9c Updated 2022-04-27 15:24:00 +02:00
Andreas Tsouchlos
75d25bc9e4 Restructured project 2022-04-27 15:23:04 +02:00
Andreas Tsouchlos
ca7ba62e6b Fixed typo in filename 2022-04-27 15:13:21 +02:00
Andreas Tsouchlos
2ed95e235b Added Displayer::save_frames() 2022-04-27 14:13:49 +02:00
16 changed files with 44 additions and 39 deletions

8
.gitignore vendored
View File

@ -1,6 +1,2 @@
filter/__pycache__
filter/*.pyc
examples/__pycache__
examples/*.pyc
display/__pycache__
display/*.pyc
__pycache__
*.pyc

View File

@ -15,5 +15,7 @@ $ pip install numpy matplotlib geopy
From the root directory of this repository run
```bash
$ python main.py
```
$ python -m kalman_filter
```
Which example runs can be configured in `kalman_filter/__main__.py`

16
kalman_filter/__main__.py Normal file
View File

@ -0,0 +1,16 @@
from kalman_filter.examples import gps_measurement as gps
from kalman_filter.examples import second_order_system as sos
from kalman_filter.examples import second_order_system_animated as sos_anim
from kalman_filter.examples import gps_two_sources_animated as gps_ts_anim
from kalman_filter.filter.kalman_filter import LinearKalmanFilter
def main():
#gps.run(LinearKalmanFilter)
#sos.run(LinearKalmanFilter)
sos_anim.run(LinearKalmanFilter)
#gps_ts_anim.run(LinearKalmanFilter)
if __name__ == '__main__':
main()

View File

@ -1,6 +1,5 @@
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import numpy as np
class Displayer:
@ -44,7 +43,7 @@ class Displayer:
self._objects.append(self._circle_map[obj_name])
# Functions to be used in the animation callback
# Functions to be used in the callback
def move_object(self, obj_name, position):
@ -63,7 +62,7 @@ class Displayer:
self._circle_map[obj_name].set_alpha(1)
# Start the animation
# Display functions
def animate(self, n_steps, anim_callback):
@ -78,4 +77,17 @@ class Displayer:
interval=self._frame_interval,
init_func=self.__init_animation,
blit=False)
plt.show()
plt.show()
def save_frames(self, frames, callback, prefix="fig-", ext="png"):
n_steps = max(frames) + 1
self.__init_animation()
for t in range(1, n_steps):
callback(self, t)
self._ax.legend()
if t in frames:
self._fig.savefig(prefix + str(t) + "." + ext, transparent=True, bbox_inches='tight')

View File

@ -56,7 +56,7 @@ def run(kalman_filter_t):
# Read data
x0_ground_truth = [48.993552704, 8.371038159]
x_measurement = read_csv_lat_long('examples/res/29_03_2022_Unterreut_8_Karlsruhe.csv')
x_measurement = read_csv_lat_long('kalman_filter/examples/res/29_03_2022_Unterreut_8_Karlsruhe.csv')
# Simulation parameter definitions

View File

@ -1,9 +1,6 @@
import matplotlib.pyplot as plt
import numpy as np
from time import sleep
from matplotlib.animation import FuncAnimation
from display.dislpay_2d import Displayer
from kalman_filter.display.display_2d import Displayer
def run(kalman_filter_t):
@ -78,4 +75,5 @@ def run(kalman_filter_t):
disp.register_object("filtered", "blue")
disp.register_object("ground_truth", "green")
disp.animate(n_steps=n_iterations, anim_callback=update)
#disp.animate(n_steps=n_iterations, anim_callback=update)
disp.save_frames([1, 20, 70], update)

View File

@ -1,9 +1,6 @@
import matplotlib.pyplot as plt
import numpy as np
from time import sleep
from matplotlib.animation import FuncAnimation
from display.dislpay_2d import Displayer
from kalman_filter.display.display_2d import Displayer
def run(kalman_filter_t):
@ -55,7 +52,7 @@ def run(kalman_filter_t):
disp.move_object("measurement", [x_measurement[:, 0][t], 0])
disp.set_circle_radius("measurement", std_dev[0])
disp.move_object("filtered", [x_kalman[:, 0][t], 0])
disp.set_circle_radius("filtered", P_kalman[:,0][t])
disp.set_circle_radius("filtered", np.sqrt(P_kalman[:,0][t]))
disp.move_object("ground_truth", [x_ground_truth[:, 0][t], 0])
disp.set_circle_radius("ground_truth", 0)

View File

16
main.py
View File

@ -1,16 +0,0 @@
from examples import gps_measurement as gps
from examples import second_order_system as sos
from examples import second_order_system_animated as sos_anim
from examples import gps_two_sources_animated as gps_ts_anim
from filter.kalman_filter import LinearKalmanFilter
def main():
#gps.run(LinearKalmanFilter)
#sos.run(LinearKalmanFilter)
#sos_anim.run(LinearKalmanFilter)
gps_ts_anim.run(LinearKalmanFilter)
if __name__ == '__main__':
main()