Skip to content

Commit a3c6c14

Browse files
committed
Print basic shape and padding info in _GMT_IMAGE doctest
Trying to match some of the doctests in _GMT_GRID.
1 parent 5f25669 commit a3c6c14

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

pygmt/datatypes/image.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,28 @@ class _GMT_IMAGE(ctp.Structure): # noqa: N801
2424
>>> with Session() as lib:
2525
... with lib.virtualfile_out(kind="image") as voutimg:
2626
... lib.call_module("read", f"@earth_day_01d {voutimg} -Ti")
27-
... ds = lib.read_virtualfile(vfname=voutimg, kind="image").contents
28-
... header = ds.header.contents
29-
... pad = header.pad[:]
30-
... print(ds.type, header.n_bands, header.n_rows, header.n_columns)
27+
... # Read the image from the virtual file
28+
... image = lib.read_virtualfile(vfname=voutimg, kind="image").contents
29+
... # The image header
30+
... header = image.header.contents
31+
... # Access the header properties
32+
... print(image.type, header.n_bands, header.n_rows, header.n_columns)
3133
... print(header.pad[:])
34+
... # The x and y coordinates
35+
... x = image.x[: header.n_columns]
36+
... y = image.y[: header.n_rows]
37+
... # The data array (with paddings)
3238
... data = np.reshape(
33-
... ds.data[: header.n_bands * header.mx * header.my],
39+
... image.data[: header.n_bands * header.mx * header.my],
3440
... (header.my, header.mx, header.n_bands),
3541
... )
42+
... # The data array (without paddings)
43+
... pad = header.pad[:]
3644
... data = data[pad[2] : header.my - pad[3], pad[0] : header.mx - pad[1], :]
37-
... x = ds.x[: header.n_columns]
38-
... y = ds.y[: header.n_rows]
39-
>>> da = xr.DataArray(
40-
... data=data,
41-
... dims=["y", "x", "band"],
42-
... coords={"y": y, "x": x, "band": [1, 2, 3]},
43-
... )
44-
>>> da = da.transpose("band", "y", "x")
45-
>>> da = da.sortby(list(data.dims))
46-
>>> da.plot.imshow()
45+
... print(data.shape)
46+
1 3 180 360
47+
[2, 2, 2, 2]
48+
(180, 360, 3)
4749
"""
4850

4951
_fields_: ClassVar = [

0 commit comments

Comments
 (0)