-
Notifications
You must be signed in to change notification settings - Fork 235
Figure.savefig: Support generating GeoTIFF file (with extension '.tiff') #2698
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
Changes from 8 commits
41767a2
cd9918f
f2348cc
921912d
a83862f
51c8dbe
cf771cc
3303ba4
4fd2f50
9e77ef3
d5e6617
f1f41bf
252514b
c4d480e
2137682
d57d8e0
44bfcfe
e7c2b36
9127756
26837e8
d5ececc
05ef422
71611df
916b4a8
6a1caa3
da9ca29
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 |
|---|---|---|
|
|
@@ -92,6 +92,46 @@ def test_figure_savefig_exists(): | |
| fname.unlink() | ||
|
|
||
|
|
||
| def test_figure_savefig_geotiff(): | ||
| """ | ||
| Make sure .tif generates a normal TIFF file and .tiff generates a GeoTIFF | ||
| file. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[0, 10, 0, 10], projection="M10c", frame=True) | ||
|
|
||
| # Save as GeoTIFF | ||
| geofname = Path("test_figure_savefig_geotiff.tiff") | ||
| fig.savefig(geofname) | ||
| assert geofname.exists() | ||
| assert geofname.with_suffix(".pgw").exists() # The companion world file | ||
|
||
|
|
||
| # Save as TIFF | ||
| fname = Path("test_figure_savefig_geotiff.tif") | ||
seisman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fig.savefig(fname) | ||
| assert fname.exists() | ||
|
|
||
| # Check if a TIFF is georeferenced or not | ||
| try: | ||
| # pylint: disable=import-outside-toplevel | ||
| import rioxarray | ||
| from rasterio.errors import NotGeoreferencedWarning | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # GeoTIFF | ||
| with rioxarray.open_rasterio(geofname) as xds: | ||
| assert xds.rio.crs is not None | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # TIFF | ||
| with pytest.warns(expected_warning=NotGeoreferencedWarning) as record: | ||
| with rioxarray.open_rasterio(fname) as xds: | ||
| assert xds.rio.crs is None | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert len(record) == 1 | ||
| except ImportError: | ||
| pass | ||
| geofname.unlink() | ||
| geofname.with_suffix(".pgw").unlink() | ||
| fname.unlink() | ||
|
|
||
|
|
||
| def test_figure_savefig_directory_nonexists(): | ||
| """ | ||
| Make sure that Figure.savefig() raises a FileNotFoundError when the parent | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.