Skip to content

Commit

Permalink
Merge pull request #214 from micasense/bug/gdal-dataset-close
Browse files Browse the repository at this point in the history
Force close the gdal dataset before writing exif metadata
  • Loading branch information
sebc06 authored Feb 26, 2024
2 parents 20d4149 + 44b5ad6 commit 90fbede
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions micasense/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ def save_capture_as_stack(self, outfilename, sort_by_wavelength=False, photometr
:param photometric: str GDAL argument for GTiff color matching
"""
from osgeo.gdal import GetDriverByName, GDT_UInt16
from osgeo import gdal
gdal.UseExceptions()

if self.__aligned_capture is None and self.__aligned_radiometric_pan_sharpened_capture is None:
raise RuntimeError(
"Call Capture.create_aligned_capture() prior to saving as stack.")
Expand Down Expand Up @@ -607,9 +610,8 @@ def save_capture_as_stack(self, outfilename, sort_by_wavelength=False, photometr
outdata = imageutils.normalize(aligned_cap[:, :, inband], multispec_min, multispec_max)
outdata[outdata < 0] = 0
outdata[outdata > 2] = 2 # limit reflectance data to 200% to allow some specular reflections
outdata = outdata * 32767 # scale reflectance images so 100% = 32768
outdata[outdata < 0] = 0
outdata[outdata > 65535] = 65535
outdata = outdata * 32767 # scale reflectance images so 100% = 32768
outdata = outdata.astype(np.ushort)
outband.SetDescription(eo_bands[outband_count])
outband.WriteArray(outdata)
outband.FlushCache()
Expand All @@ -618,12 +620,14 @@ def save_capture_as_stack(self, outfilename, sort_by_wavelength=False, photometr
outband = outRaster.GetRasterBand(len(eo_bands) + outband_count + 1)
outdata = (aligned_cap[:, :,
inband] + 273.15) * 100 # scale data from float degC to back to centi-Kelvin to fit into uint16
outband.SetDescription('LWIR')
outdata[outdata < 0] = 0
outdata[outdata > 65535] = 65535
outdata = outdata.astype(np.ushort)
outband.SetDescription('LWIR')
outband.WriteArray(outdata)
outband.FlushCache()
finally:
outRaster.Close()
if write_exif:
imageutils.write_exif_to_stack(self, outfilename)

Expand Down

0 comments on commit 90fbede

Please sign in to comment.