@@ -24,26 +24,28 @@ class _GMT_IMAGE(ctp.Structure): # noqa: N801
24
24
>>> with Session() as lib:
25
25
... with lib.virtualfile_out(kind="image") as voutimg:
26
26
... 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)
31
33
... 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)
32
38
... data = np.reshape(
33
- ... ds .data[: header.n_bands * header.mx * header.my],
39
+ ... image .data[: header.n_bands * header.mx * header.my],
34
40
... (header.my, header.mx, header.n_bands),
35
41
... )
42
+ ... # The data array (without paddings)
43
+ ... pad = header.pad[:]
36
44
... 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)
47
49
"""
48
50
49
51
_fields_ : ClassVar = [
0 commit comments