Commit 80bf5fb1 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed issue #50 (Quicklook images only contain noise). Fix for using the wrong...

Fixed issue #50

 (Quicklook images only contain noise). Fix for using the wrong bands for the SWIR quicklook image.
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent b4fe9481
Pipeline #8425 passed with stage
in 15 minutes and 33 seconds
......@@ -2,6 +2,13 @@
History
=======
0.12.3 (2020-04-21)
-------------------
* Fixed issue #50 (Quicklook images only contain noise).
* Fix for using the wrong bands for the SWIR quicklook image.
0.12.2 (2020-04-21)
-------------------
......
......@@ -30,7 +30,7 @@
"""EnPT EnMAP object base classes."""
from types import SimpleNamespace
from typing import Tuple, Optional # noqa: F401
from typing import List, Optional # noqa: F401
import numpy as np
# noinspection PyPackageRequirements
......@@ -322,21 +322,23 @@ class _EnMAP_Image(object):
return gA
def generate_quicklook(self, bands2use: Tuple[int, int, int]) -> GeoArray:
def generate_quicklook(self, bands2use: List[int]) -> GeoArray:
"""
Generate image quicklook and save into a file
Generate image quicklook and save into a file.
:param bands2use: (red, green, blue) band indices of self.data to be used for quicklook image, e.g., (3, 2, 1)
:param bands2use: band indices of self.data to be used as (red, green, blue) for quicklook image,
e.g., [3, 2, 1]
:return: GeoArray
"""
red, green, blue = [self.data[:, :, bandidx] for bandidx in bands2use]
def rescale(bandarray):
p2 = np.percentile(bandarray, 2)
p98 = np.percentile(bandarray, 98)
return exposure.rescale_intensity(bandarray, (p2, p98))
pixvals = np.ma.masked_equal(bandarray, self.data.nodata).compressed() \
if self.data.nodata is not None else bandarray
p2, p98 = np.nanpercentile(pixvals, 2), np.nanpercentile(pixvals, 98)
pix = np.dstack((rescale(red), rescale(green), rescale(blue)))
pix = np.uint8(pix * 255)
return exposure.rescale_intensity(bandarray, in_range=(p2, p98), out_range=(0, 255))
pix = np.dstack((rescale(red), rescale(green), rescale(blue))).astype(np.uint8)
return GeoArray(pix)
......@@ -145,8 +145,11 @@ class EnMAP_Metadata_L2A_MapGeo(object):
self.unit = meta_l1b.vnir.unit
self.unitcode = meta_l1b.vnir.unitcode
self.preview_wvls_vnir = meta_l1b.vnir.preview_wvls
self.preview_wvls_swir = meta_l1b.swir.preview_wvls
self.preview_bands_vnir = meta_l1b.vnir.preview_bands
self.preview_bands_swir = meta_l1b.swir.preview_bands
self.preview_bands_swir = np.array([np.argmin(np.abs(self.wvl_center - wvl))
for wvl in meta_l1b.swir.preview_wvls]) # must index from VNIR band 0
self.snr = None
if meta_l1b.vnir.snr is not None:
......
......@@ -107,7 +107,8 @@ class EnMAP_Metadata_L1B_Detector_SensorGeo(object):
self.lons: Optional[np.ndarray] = None # 2D array of longitude coordinates according to given lon/lat sampling
self.unit: str = '' # radiometric unit of pixel values
self.unitcode: str = '' # code of radiometric unit
self.preview_bands = None
self.preview_wvls: Optional[List[float]] = None # wavelengths to be used for quicklook images
self.preview_bands: Optional[List[int]] = None # band indices to be used for quicklook images
self.snr: Optional[np.ndarray] = None # Signal to noise ratio as computed from radiance data
def read_metadata(self, path_xml):
......@@ -184,8 +185,8 @@ class EnMAP_Metadata_L1B_Detector_SensorGeo(object):
wvl_red = float(xml.find("product/image/%s/qlChannels/red" % lbl).text)
wvl_green = float(xml.find("product/image/%s/qlChannels/green" % lbl).text)
wvl_blue = float(xml.find("product/image/%s/qlChannels/blue" % lbl).text)
self.preview_bands = np.array([np.argmin(np.abs(self.wvl_center - wvl))
for wvl in [wvl_red, wvl_green, wvl_blue]])
self.preview_wvls = [wvl_red, wvl_green, wvl_blue]
self.preview_bands = np.array([np.argmin(np.abs(self.wvl_center - wvl)) for wvl in self.preview_wvls])
# read RPC coefficients
for bID in xml.findall("product/navigation/RPC/bandID")[subset]:
......@@ -261,6 +262,7 @@ class EnMAP_Metadata_L1B_Detector_SensorGeo(object):
self.lats = self.interpolate_corners(*self.lat_UL_UR_LL_LR, self.ncols, self.nrows)
self.lons = self.interpolate_corners(*self.lon_UL_UR_LL_LR, self.ncols, self.nrows)
self.preview_wvls = np.array([self.wvl_center[i] for i in self.preview_bands])
# compute metadata derived from read data
self.smile = self.calc_smile()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment