Skip to content

Commit

Permalink
fix floating point tiff saving.
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Raspaud <martin.raspaud@smhi.se>
  • Loading branch information
mraspaud committed Feb 26, 2014
1 parent 769fe61 commit 2f3f54f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mpop/imageo/geo_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,14 @@ def geotiff_save(self, filename, compression=6,
if self.mode != "L":
raise ValueError("Image must be in 'L' mode for floating point"
" geotif saving")
if self.fill_value is None:
logger.warning("Image cannot be transparent, "
"so setting fill_value to 0")
self.fill_value = 0
channels = [self.channels[0].astype(np.float64)]
fill_value = self.fill_value or 0
fill_value = self.fill_value or [0]
gformat = gdal.GDT_Float64
opacity = 0
else:
nbits = int(tags.get("NBITS", "8"))
if nbits > 16:
Expand All @@ -169,6 +174,7 @@ def geotiff_save(self, filename, compression=6,
else:
dtype = np.uint8
gformat = gdal.GDT_Byte
opacity = np.iinfo(dtype).max
channels, fill_value = self._finalize(dtype)

logger.debug("Saving to GeoTiff.")
Expand Down Expand Up @@ -208,7 +214,7 @@ def geotiff_save(self, filename, compression=6,
gformat,
g_opts)
self._gdal_write_channels(dst_ds, channels,
np.iinfo(dtype).max, fill_value)
opacity, fill_value)
elif(self.mode == "LA"):
ensure_dir(filename)
g_opts.append("ALPHA=YES")
Expand Down Expand Up @@ -240,7 +246,7 @@ def geotiff_save(self, filename, compression=6,
g_opts)

self._gdal_write_channels(dst_ds, channels,
np.iinfo(dtype).max, fill_value)
opacity, fill_value)

elif(self.mode == "RGBA"):
ensure_dir(filename)
Expand Down

0 comments on commit 2f3f54f

Please sign in to comment.