Skip to content

Commit 6cb93af

Browse files
author
emily selwood
committed
add lots of logging
1 parent a87fae9 commit 6cb93af

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

datacube_utilities/import_export.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import time
23
import numpy as np
34
import xarray as xr
@@ -127,9 +128,11 @@ def export_xarray_to_geotiff(data, tif_path, bands=None, no_data=-9999, crs="EPS
127128
x_coord, y_coord: string
128129
The string names of the x and y dimensions.
129130
"""
131+
logging.info(f"starting output to {tif_path}")
130132
if isinstance(data, xr.DataArray):
131133
height, width = data.sizes[y_coord], data.sizes[x_coord]
132134
count, dtype = 1, data.dtype
135+
logging.info(f"got an xarray with width {width} and height {height} and datatype {dtype}")
133136
else:
134137
if bands is None:
135138
bands = list(data.data_vars.keys())
@@ -139,6 +142,7 @@ def export_xarray_to_geotiff(data, tif_path, bands=None, no_data=-9999, crs="EPS
139142
assert len(bands) > 0 and isinstance(bands[0], str), assrt_msg_begin + "You must supply at least one band."
140143
height, width = data.dims[y_coord], data.dims[x_coord]
141144
count, dtype = len(bands), data[bands[0]].dtype
145+
logging.info(f"got not an xarray with width {width} and height {height} and datatype {dtype}")
142146
with rasterio.open(
143147
tif_path,
144148
'w',
@@ -150,11 +154,16 @@ def export_xarray_to_geotiff(data, tif_path, bands=None, no_data=-9999, crs="EPS
150154
crs=crs,
151155
transform=_get_transform_from_xr(data, x_coord=x_coord, y_coord=y_coord),
152156
nodata=no_data) as dst:
157+
logging.info(f"opened {tif_path}")
153158
if isinstance(data, xr.DataArray):
154159
dst.write(data.values, 1)
160+
logging.info(f"written xarray band")
155161
else:
156162
for index, band in enumerate(bands):
157163
dst.write(data[band].values.astype(dtype), index + 1)
164+
logging.info(f"written non xarray band {index}")
158165
dst.close()
166+
logging.info(f"done writing {tif_path}")
167+
159168

160169
## End export ##

0 commit comments

Comments
 (0)