-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Conversation
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 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.
@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
.
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.
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.
@anntzer That makes sense.
I guess we can't make it the default then though, because there'd be no way to override...
You can put it as default in rcParams["convert.extra_args"]
? Then it's overridable by setting the rcparams.
That seems reasonable to me.
I'll check that out and update the PR sometime in the next week or so 👍
Any progress here?
I've gotta dig into the rcparams stuff a bit before I can do the suggested changes. Maybe this weekend.
I don't anticipate digging into this code again, unfortunately. Feel free to close.
PR Summary
Follow-up to my previous PR #15739. Adding a simple
compress
arg toImageMagickWriter
andImageMagickFileWriter
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
indocs/
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:
python
doesn't point atpython3
by default? I modified the docs Makefile to usepython3
, 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
.PR Checklist