hylite.sensors
Static classes for sensor-specific processing such as lens-correction, adjustments for sensor shift and conversions from digital numbers to radiance.
1""" 2Static classes for sensor-specific processing such as lens-correction, adjustments for sensor shift and conversions 3from digital numbers to radiance. 4""" 5import matplotlib.pyplot as plt 6from .sensor import Sensor 7from .fx import FX10 8from .fx import FX17 9from .fx import FX50 10from .owl import OWL 11from .fenix import Fenix 12from .rikola import Rikola, Rikola_HSC2, Rikola_RSC1 13from .fx import * 14from .telopsNano import TelopsNano 15 16# noinspection PyDefaultArgument 17def QAQC(image, method, dim=0, fit="minmax", checklines=[]): 18 """ 19 Estimate the spectral quality of a sensor according to reference measurements. Mask image first if required. 20 21 Args: 22 image (hylite.HyImage): the image containing data from the sensor.. 23 method (str): "LDPE" for SWIR using reference LDPE foil, "FT" for VNIR using fluorescence tube. 24 dim (int): dimensionality of the evaluation (0 = overall average, 1 = row-wise, 2 = full frame). 25 fit (str): method for peak fitting. For details, check hylite.analyse.mapping.minimum_wavelength( ... ). 26 checklines (list): define custom features to check for (list of ints or floats). 27 """ 28 29 image.data = image.data.astype(np.float32) 30 31 # define indicative feature lines 32 if method == "FT": 33 checklines = [404.66, 435.83, 546.08, 611.08] 34 image.data = np.nanmax(image.data) - image.data 35 elif method == "LDPE": 36 checklines = [1728., 1764., 2310., 2350.] 37 38 # calculate and plot accuracy assessment depending on defined dimensionality 39 if dim == 0: 40 image.data = np.mean(image.data, axis=(0, 1)) 41 for line in checklines: 42 lim = image.get_fwhm()[image.get_band_index(float(line))] 43 mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit) 44 # plot warning if error exceeds FWHM 45 if (line - mini) > lim: 46 print("\x1b[31m" + "Spectral accuracy at " + str(line) + " nm: " + "{:.4f}".format( 47 line - mini) + " nm - WARNING: OVER FWHM" + '\x1b[0m') 48 else: 49 print("\x1b[32m" + "Spectral accuracy at " + str(line) + " nm: " + "{:.4f}".format( 50 line - mini) + " nm" + '\x1b[0m') 51 52 elif dim == 1: 53 image.data = np.mean(image.data, axis=1) 54 fig, axs = plt.subplots(2, 2, figsize=(15, 6)) 55 fig.subplots_adjust(hspace=.5, wspace=.3) 56 axs = axs.ravel() 57 i = 0 58 for line in checklines: 59 mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit) 60 61 # color plot based on fwhm 62 lim = image.get_fwhm()[image.get_band_index(float(line))] 63 if any(x > lim for x in (line - mini)): 64 col = "orangered" 65 else: 66 col = "limegreen" 67 axs[i].plot(line - mini, col) 68 axs[i].set_title(str(line) + ' nm') 69 axs[i].axhline(y=lim, color="grey", linestyle="--") 70 axs[i].text(0.9, 0.9, 'FWHM', fontsize=10, color="grey", va='center', ha='center', backgroundcolor='w', 71 transform=axs[i].transAxes) 72 i += 1 73 for ax in axs.flat: 74 ax.set(xlabel='swath pixels', ylabel='spectral accuracy [nm]') 75 76 plt.show() 77 78 elif dim == 2: 79 from matplotlib import colors 80 # color plot based on fwhm 81 fig, axs = plt.subplots(2, 2, figsize=(15, 6)) 82 fig.subplots_adjust(hspace=.5, wspace=.1) 83 axs = axs.ravel() 84 i = 0 85 for line in checklines: 86 mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit) 87 lim = image.get_fwhm()[image.get_band_index(float(line))] 88 cmap = "RdYlGn_r" 89 norm = colors.Normalize(vmin=0, vmax=lim * 2) 90 im = axs[i].imshow(line - mini, cmap=cmap, norm=norm) 91 axs[i].set_title(str(line) + ' nm') 92 cbar = fig.colorbar(im, ax=axs[i], cmap=cmap, norm=norm) 93 cbar.ax.locator_params(nbins=3) 94 cbar.ax.set_yticklabels(['within limits', 'FWHM', 'exceeding FWHM']) 95 i += 1 96 97 plt.show()
def
QAQC(image, method, dim=0, fit='minmax', checklines=[]):
18def QAQC(image, method, dim=0, fit="minmax", checklines=[]): 19 """ 20 Estimate the spectral quality of a sensor according to reference measurements. Mask image first if required. 21 22 Args: 23 image (hylite.HyImage): the image containing data from the sensor.. 24 method (str): "LDPE" for SWIR using reference LDPE foil, "FT" for VNIR using fluorescence tube. 25 dim (int): dimensionality of the evaluation (0 = overall average, 1 = row-wise, 2 = full frame). 26 fit (str): method for peak fitting. For details, check hylite.analyse.mapping.minimum_wavelength( ... ). 27 checklines (list): define custom features to check for (list of ints or floats). 28 """ 29 30 image.data = image.data.astype(np.float32) 31 32 # define indicative feature lines 33 if method == "FT": 34 checklines = [404.66, 435.83, 546.08, 611.08] 35 image.data = np.nanmax(image.data) - image.data 36 elif method == "LDPE": 37 checklines = [1728., 1764., 2310., 2350.] 38 39 # calculate and plot accuracy assessment depending on defined dimensionality 40 if dim == 0: 41 image.data = np.mean(image.data, axis=(0, 1)) 42 for line in checklines: 43 lim = image.get_fwhm()[image.get_band_index(float(line))] 44 mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit) 45 # plot warning if error exceeds FWHM 46 if (line - mini) > lim: 47 print("\x1b[31m" + "Spectral accuracy at " + str(line) + " nm: " + "{:.4f}".format( 48 line - mini) + " nm - WARNING: OVER FWHM" + '\x1b[0m') 49 else: 50 print("\x1b[32m" + "Spectral accuracy at " + str(line) + " nm: " + "{:.4f}".format( 51 line - mini) + " nm" + '\x1b[0m') 52 53 elif dim == 1: 54 image.data = np.mean(image.data, axis=1) 55 fig, axs = plt.subplots(2, 2, figsize=(15, 6)) 56 fig.subplots_adjust(hspace=.5, wspace=.3) 57 axs = axs.ravel() 58 i = 0 59 for line in checklines: 60 mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit) 61 62 # color plot based on fwhm 63 lim = image.get_fwhm()[image.get_band_index(float(line))] 64 if any(x > lim for x in (line - mini)): 65 col = "orangered" 66 else: 67 col = "limegreen" 68 axs[i].plot(line - mini, col) 69 axs[i].set_title(str(line) + ' nm') 70 axs[i].axhline(y=lim, color="grey", linestyle="--") 71 axs[i].text(0.9, 0.9, 'FWHM', fontsize=10, color="grey", va='center', ha='center', backgroundcolor='w', 72 transform=axs[i].transAxes) 73 i += 1 74 for ax in axs.flat: 75 ax.set(xlabel='swath pixels', ylabel='spectral accuracy [nm]') 76 77 plt.show() 78 79 elif dim == 2: 80 from matplotlib import colors 81 # color plot based on fwhm 82 fig, axs = plt.subplots(2, 2, figsize=(15, 6)) 83 fig.subplots_adjust(hspace=.5, wspace=.1) 84 axs = axs.ravel() 85 i = 0 86 for line in checklines: 87 mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit) 88 lim = image.get_fwhm()[image.get_band_index(float(line))] 89 cmap = "RdYlGn_r" 90 norm = colors.Normalize(vmin=0, vmax=lim * 2) 91 im = axs[i].imshow(line - mini, cmap=cmap, norm=norm) 92 axs[i].set_title(str(line) + ' nm') 93 cbar = fig.colorbar(im, ax=axs[i], cmap=cmap, norm=norm) 94 cbar.ax.locator_params(nbins=3) 95 cbar.ax.set_yticklabels(['within limits', 'FWHM', 'exceeding FWHM']) 96 i += 1 97 98 plt.show()
Estimate the spectral quality of a sensor according to reference measurements. Mask image first if required.
Arguments:
- image (hylite.HyImage): the image containing data from the sensor..
- method (str): "LDPE" for SWIR using reference LDPE foil, "FT" for VNIR using fluorescence tube.
- dim (int): dimensionality of the evaluation (0 = overall average, 1 = row-wise, 2 = full frame).
- fit (str): method for peak fitting. For details, check hylite.analyse.mapping.minimum_wavelength( ... ).
- checklines (list): define custom features to check for (list of ints or floats).