-
Notifications
You must be signed in to change notification settings - Fork 279
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
enh: store basic software info in png metadata #4553
Conversation
pre-commit.ci autofix |
love the idea ! |
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.
strong approve
51c799f
to
bc6d5a1
Compare
pre-commit.ci autofix |
4bfc2af
to
2e14b20
Compare
2e14b20
to
4410766
Compare
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.
Maybe InteractiveCamera.save
could use some of this too, but I couldn't figure out how, and I'm not even sure it's actually feasible so it's not crucial. Other than that, I only have a couple minor comments
yt/funcs.py
Outdated
|
||
import numpy as np | ||
from more_itertools import always_iterable, collapse, first | ||
|
||
from yt._maintenance.deprecation import issue_deprecation_warning | ||
from yt._version import __version__ as yt_version |
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 would prefer we nest this import in get_version_stack
to avoid having to support people relying on from yt.funcs import yt_version
in the future. (I know people already use the indirection from yt.funcs import mylog
)
yt/funcs.py
Outdated
@@ -1447,3 +1448,25 @@ def validate_moment(moment, weight_field): | |||
"Weighted projections can only be made of averages " | |||
"(moment = 1) or standard deviations (moment = 2)!" | |||
) | |||
|
|||
|
|||
def setdefault_mpl_metadata(mpl_kwargs: Dict[str, Any], name: str) -> None: |
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.
took me a minute to realise but in this context, I think save_kwargs
may be a better name than mpl_kwargs
(which is also used in other places for completely different stuff)
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.
It's specifically a matplotlib kwarg {"metadata": {...}}
, not just yt's save.
yt/utilities/png_writer.py
Outdated
|
||
|
||
def call_png_write_png(buffer, fileobj, dpi): | ||
Image.fromarray(buffer).save(fileobj, dpi=(dpi, dpi), format="png") | ||
metadata = PngInfo() | ||
metadata.add_text("Software", f"{PIL.__name__}-{PIL.__version__}|yt-{yt_version}") |
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.
isn't PIL.__name__
always going to be 'PIL'
? (seems to be the case even with pillow
)
Cool! This is great! Don't have anything to add to the review... but I was playing around locally and devised a little self contained python-only example, might be useful for adding a test: from yt.testing import fake_amr_ds
from yt import SlicePlot
import PIL
ds = fake_amr_ds()
fn = SlicePlot(ds, "x", "Density").save()[0]
with PIL.Image.open(fn) as image:
assert 'Software' in image.text
assert 'Matplotlib version' in image.text['Software'] |
Co-authored-by: Clément Robert <cr52@protonmail.com>
dc93451
to
3415d12
Compare
3415d12
to
c6aa59d
Compare
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.
Actually looked through the code this time -- nothing to add, looks good!
@matthewturk you had a prior review on this, good to go?
PR Summary
Store information about used software (yt, matplotlib, numpy, PIL) in metadata of generated plots.
PR Checklist
How to test?