Skip to content

Add ImageMagick[File]Writer compression arg #15784

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

Closed
wants to merge 1 commit into from

Conversation

erelson
Copy link
Contributor

@erelson erelson commented Nov 28, 2019

PR Summary

Follow-up to my previous PR #15739. Adding a simple compress arg to ImageMagickWriter and ImageMagickFileWriter classes.

Questions

I'm suspecting that the docstring is not done right. Sphinx probably doesn't combine the MovieWriter.__init__() docstring and child class' __init__() docstrings automagically. Never dealt with child classes and shared docstrings when I more heavily used sphinx years ago. Is the correct thing to do here to just duplicate the shared args? From what I've seen looking around, I suspect not?

Also, I'm definitely curious to hear what the optimal approach to testing docstring changes/additions is? make html in docs/ is awfully slow. (d'oh, I see now there is a -O j4 option I can pass; will do that next time)

Further tangents on docs:

  • Is it just an artifact of Ubuntu 18.04 and/or WSL that python doesn't point at python3 by default? I modified the docs Makefile to use python3, as the format strings in (iirc) conf.py didn't make 2.x happy. I could imagine other distros that are more fully on Python3 do link /bin/python to /bin/python3.
  • Has anyone else ever get the docs to build in WSL's bash? I ended up switching to my linux machine to build the docs, since somehow, (if I understood errors correctly) MSVC++ DLLs were being looked for.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't like the idea of reproducing the imagemagick command line as kwargs. (Also, should this use -layers Optimize or -layers OptimizePlus? (https://www.imagemagick.org/script/command-line-options.php?#layers)). So I'm going to block this but am willing to back out if there's enough support for it.

I think better solutions would be to document this in the docstring of ImageMagickWriter/ImageMagickFileWriter, e.g. "For smaller animation sizes, consider setting extra_args to ["-layers", "OptimizePlus"]" -- or even to turn it on unconditionally.

@dopplershift
Copy link
Contributor

@anntzer Can you further detail your concerns? Right now, the entire purpose of ImageMagickWriter is essentially to "[reproduce] the imagemagick command line as kwargs". I mean it does it in an abstracted form so that users don't need to know esoteric details like -layers OptimizePlus, they just know the much more readily googl-able and readable compress=True.

@erelson
Copy link
Contributor Author

erelson commented Nov 29, 2019

Thanks for the feedback. I agree with @anntzer, in that reproducing common args from a utility as args in python does seem like a code smell.

I would be fully on board with making compression the de-facto behavior. I personally initially presumed that matplotlib's use of ImageMagick would do the obvious method of reducing file size by not making each frame of the .gif full-sized.

Doing the above, I'd be tempted to allow the end-user to disable with a no_compress=True arg, or similar. I don't claim to know the usecases that might commonly exist. However, to do that, it sounds like there isn't an elegant solution to how the docstring beyond putting it in the class's docstring instead of __init__'s as @anntzer mentioned.

Regarding OptimizePlus, I'll play with that and add that in if that seems to generally improve things. The linked documentation sounds like the various optimize options all have their good/bad, so that's another point in favor of allowing a no_compress=True + extra_args for those who really want to tweak output with more control of ImageMagick.

Btw, still curious if there's a faster method of iterating on checking the generated docstings.

@anntzer
Copy link
Contributor

anntzer commented Nov 29, 2019

Basically, committing to one's memory that the compress kwarg to ImageMagickWriter improves the size of the movie is a totally non-generalizable knowledge. It doesn't help you if you want to use imagemagick directly (and the imagemagick docs will obviously not point to that kwarg either), and it doesn't help you either if you switch to another animation writer class. Also, if imagemagick decides later to introduce a better optimization flag (OptimizePlusPlus), do we need to keep "compress=True" mapped to Optimize for backcompat?

Re: docs build: yeah, it's a bit of a pain. Builds after the first should be less awfully slow, though.
There are a few places where we use string interpolation to reuse parts of docstrings (see e.g. the spectral docs in mlab.py) but it's a bit of a mess and I would suggest not doing it unless really needed.

@dopplershift
Copy link
Contributor

@anntzer That makes sense.

I guess we can't make it the default then though, because there'd be no way to override...

@anntzer
Copy link
Contributor

anntzer commented Nov 30, 2019

You can put it as default in rcParams["convert.extra_args"]? Then it's overridable by setting the rcparams.

@dopplershift
Copy link
Contributor

That seems reasonable to me.

@erelson
Copy link
Contributor Author

erelson commented Dec 2, 2019

I'll check that out and update the PR sometime in the next week or so 👍

@QuLogic
Copy link
Member

QuLogic commented Apr 1, 2020

Any progress here?

@erelson
Copy link
Contributor Author

erelson commented Apr 9, 2020

I've gotta dig into the rcparams stuff a bit before I can do the suggested changes. Maybe this weekend.

@tacaswell tacaswell added this to the v3.4.0 milestone Apr 10, 2020
@jklymak jklymak marked this pull request as draft September 10, 2020 15:43
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 21, 2021
@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Aug 23, 2021
@timhoffm timhoffm modified the milestones: v3.6.0, unassigned Apr 30, 2022
@erelson
Copy link
Contributor Author

erelson commented Jun 29, 2022

I don't anticipate digging into this code again, unfortunately. Feel free to close.

@anntzer
Copy link
Contributor

anntzer commented Jun 29, 2022

Superseded by #23371. Thanks for the suggestion!

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

Successfully merging this pull request may close these issues.

6 participants