-
Notifications
You must be signed in to change notification settings - Fork 238
Figure.savefig: Add the 'worldfile' parameter to write a companion world file for raster images #2766
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
Figure.savefig: Add the 'worldfile' parameter to write a companion world file for raster images #2766
Changes from 14 commits
797e5c6
a36cef7
0c4c9d3
184d5b1
3139130
20e79db
6062666
57c020f
e50ab6d
da5c6d2
a863132
316e5df
2c149bb
1784a2f
9dc40fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,6 +292,27 @@ def mock_psconvert(*args, **kwargs): # pylint: disable=unused-argument | |
| } | ||
|
|
||
|
|
||
| def test_figure_savefig_worldfile(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a reason to switch from the parametrized tests to a single test in a863132? It'll be harder to see which formats/extensions fail, if e.g. the first one in a list like ['.bmp', '.jpg', ...] raises an AssertionError, because the others in the list won't be tested.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main idea is to reducing the number of tests and also testing times. Comparing https://github.com/GenericMappingTools/pygmt/actions/runs/6677102075/job/18146781350?pr=2766 and https://github.com/GenericMappingTools/pygmt/actions/runs/6648648090/job/18065964154?pr=2766, the old way (using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, I see that we avoid having to call |
||
| """ | ||
| Check if a world file is created for supported formats and raise an error | ||
| for unsupported formats. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True) | ||
| # supported formats | ||
| for fmt in [".bmp", ".jpg", ".png", ".ppm", ".tif"]: | ||
| with GMTTempFile(prefix="pygmt-worldfile", suffix=fmt) as imgfile: | ||
| fig.savefig(fname=imgfile.name, worldfile=True) | ||
| assert Path(imgfile.name).stat().st_size > 0 | ||
| worldfile_suffix = "." + fmt[1] + fmt[3] + "w" | ||
| assert Path(imgfile.name).with_suffix(worldfile_suffix).stat().st_size > 0 | ||
| # unsupported formats | ||
| for fmt in [".eps", ".kml", ".pdf", ".tiff"]: | ||
| with GMTTempFile(prefix="pygmt-worldfile", suffix=fmt) as imgfile: | ||
| with pytest.raises(GMTInvalidInput): | ||
| fig.savefig(fname=imgfile.name, worldfile=True) | ||
|
|
||
|
|
||
| @pytest.mark.skipif(IPython is None, reason="run when IPython is installed") | ||
| def test_figure_show(): | ||
| """ | ||
|
|
||
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.
(Geo)TIFF is a raster file format, but a worldfile won't be produced. Also, maybe best to just list out the supported extensions.
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.
In PR #2771 (commit 0c81847), we have revised the function description to separate the list of raster and vector formats (preview: https://www.pygmt.org/dev/api/generated/pygmt.Figure.savefig.html#pygmt.Figure.savefig).
So I prefer to not list the formats again and prefer to revise the docstring to
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.
Oh right, totally missed that. Your shorter suggestion sounds good.