Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Peter230655
Copy link
Contributor

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

@@ -1,3 +1,4 @@
# %%
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Not sure, I understand what slicing means - my Python skill are limited. Could you explain, please.
This "range thing" I understand, I will try!

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 :-(

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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')
Copy link
Member

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.

Copy link
Contributor Author

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.

@Peter230655
Copy link
Contributor Author

The way you suggested to reduce the number of frames is really MUCH simpler and more elegant.
Will do change on the other PRs, too.

@@ -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
Copy link
Member

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?

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants