-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reduced frames in animation, better initial guess #244
base: master
Are you sure you want to change the base?
Conversation
@@ -1,3 +1,4 @@ | |||
# %% |
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.
Not sure why this is added as the first line, should be removed.
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.
Not sure why this is added as the first line, should be removed.
I have to add this in VSC so I can run the simulation from the begining.
I will remove before I push
coords1.append(coords[-1, :, :]) | ||
time1.append(time[-1]) | ||
time = np.array(time1) | ||
coords = np.array(coords1) |
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.
This is an overly complicated way to skip frames (if that is what it does). It isn't so favorable for such things to be in examples for beginners.
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.
Just use slicing in numpy
that would be a need approach. Though an easier approach in this case would be providing a range like range(0, len(time), 3)
to FuncAnimation
.
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.
This is an overly complicated way to skip frames (if that is what it does). It isn't so favorable for such things to be in examples for beginners.
Yes, I wanted to skip frames, and I could not think of a simpler way.
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 thought one of the examples already has exactly what Timo suggests.
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.
Just use slicing in
numpy
that would be a need approach. Though an easier approach in this case would be providing a range likerange(0, len(time), 3)
toFuncAnimation
.
Not sure, I understand what slicing means - my Python skill are limited. Could you explain, please.
This "range thing" I understand, I will try!
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 thought one of the examples already has exactly what Timo suggests.
I will look at the examples for this feature, I did not look before.
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.
Internet search of "numpy slicing" points to: https://numpy.org/doc/stable/user/basics.indexing.html#slicing-and-striding
Now clear! This I even know, just did not think about it :-(
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.
All the PRs I made today have equally clumsy ways of reducing the frames.
I will improve tomorrow.
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.
@Peter230655 in this case it is even easier to use ani = animation.FuncAnimation(fig, animate, range(0, len(time), 3),
than numpy slicing. Though learning more about numpy slicing is definitely useful.
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.
@Peter230655 in this case it is even easier to use
ani = animation.FuncAnimation(fig, animate, range(0, len(time), 3),
than numpy slicing. Though learning more about numpy slicing is definitely useful.
I will try this first thing tomorrow morning!! :-)
@@ -185,10 +186,14 @@ | |||
|
|||
# %% | |||
# Find the optimal solution. | |||
initial_guess = np.load('parallel_park_solution.npy') |
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.
If we add these to examples, we need to explain to the reader why we are doing so.
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.
If we add these to examples, we need to explain to the reader why we are doing so.
I will correct. Just slipped.
The way you suggested to reduce the number of frames is really MUCH simpler and more elegant. |
@@ -252,6 +258,8 @@ def frame(i): | |||
|
|||
fig, title_text, lines, Pr_path, Pf_path = frame(0) | |||
|
|||
time = list(time) | |||
time[-3:] = [time[-1]]*3 |
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.
What are you doing with these lines?
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.
What are you doing with these lines?
Without them I did not get the time showing on the animation to end at the correct time. It ended ar 29.88 sec (if I recall correctly) instead of at 30 sec.
Reduced number of frames in the animation fromm around 500 to around 167.
Gave better initial guess.
Made the animation perform faster than real time. I believe it still give a good idea what opty does.
This reduced running time from 44 sec to 21 sec on my PC