Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force close the gdal dataset before writing exif metadata #214

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading