hylite documentation|Stable (master)Development (dev)

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 numpy as np
  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.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    from hylite._deps import require
 30    plt = require("matplotlib.pyplot")
 31
 32    image.data = image.data.astype(np.float32)
 33
 34    # define indicative feature lines
 35    if method == "FT":
 36        checklines = [404.66, 435.83, 546.08, 611.08]
 37        image.data = np.nanmax(image.data) - image.data
 38    elif method == "LDPE":
 39        checklines = [1728., 1764., 2310., 2350.]
 40
 41    # calculate and plot accuracy assessment depending on defined dimensionality
 42    if dim == 0:
 43        image.data = np.mean(image.data, axis=(0, 1))
 44        for line in checklines:
 45            lim = image.get_fwhm()[image.get_band_index(float(line))]
 46            mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit)
 47            # plot warning if error exceeds FWHM
 48            if (line - mini) > lim:
 49                print("\x1b[31m" + "Spectral accuracy at " + str(line) + " nm:   " + "{:.4f}".format(
 50                    line - mini) + " nm - WARNING: OVER FWHM" + '\x1b[0m')
 51            else:
 52                print("\x1b[32m" + "Spectral accuracy at " + str(line) + " nm:   " + "{:.4f}".format(
 53                    line - mini) + " nm" + '\x1b[0m')
 54
 55    elif dim == 1:
 56        image.data = np.mean(image.data, axis=1)
 57        fig, axs = plt.subplots(2, 2, figsize=(15, 6))
 58        fig.subplots_adjust(hspace=.5, wspace=.3)
 59        axs = axs.ravel()
 60        i = 0
 61        for line in checklines:
 62            mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit)
 63
 64            # color plot based on fwhm
 65            lim = image.get_fwhm()[image.get_band_index(float(line))]
 66            if any(x > lim for x in (line - mini)):
 67                col = "orangered"
 68            else:
 69                col = "limegreen"
 70            axs[i].plot(line - mini, col)
 71            axs[i].set_title(str(line) + ' nm')
 72            axs[i].axhline(y=lim, color="grey", linestyle="--")
 73            axs[i].text(0.9, 0.9, 'FWHM', fontsize=10, color="grey", va='center', ha='center', backgroundcolor='w',
 74                        transform=axs[i].transAxes)
 75            i += 1
 76        for ax in axs.flat:
 77            ax.set(xlabel='swath pixels', ylabel='spectral accuracy [nm]')
 78
 79        plt.show()
 80
 81    elif dim == 2:
 82        from matplotlib import colors
 83        # color plot based on fwhm
 84        fig, axs = plt.subplots(2, 2, figsize=(15, 6))
 85        fig.subplots_adjust(hspace=.5, wspace=.1)
 86        axs = axs.ravel()
 87        i = 0
 88        for line in checklines:
 89            mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit)
 90            lim = image.get_fwhm()[image.get_band_index(float(line))]
 91            cmap = "RdYlGn_r"
 92            norm = colors.Normalize(vmin=0, vmax=lim * 2)
 93            im = axs[i].imshow(line - mini, cmap=cmap, norm=norm)
 94            axs[i].set_title(str(line) + ' nm')
 95            cbar = fig.colorbar(im, ax=axs[i], cmap=cmap, norm=norm)
 96            cbar.ax.locator_params(nbins=3)
 97            cbar.ax.set_yticklabels(['within limits', 'FWHM', 'exceeding FWHM'])
 98            i += 1
 99
100        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.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    from hylite._deps import require
 31    plt = require("matplotlib.pyplot")
 32
 33    image.data = image.data.astype(np.float32)
 34
 35    # define indicative feature lines
 36    if method == "FT":
 37        checklines = [404.66, 435.83, 546.08, 611.08]
 38        image.data = np.nanmax(image.data) - image.data
 39    elif method == "LDPE":
 40        checklines = [1728., 1764., 2310., 2350.]
 41
 42    # calculate and plot accuracy assessment depending on defined dimensionality
 43    if dim == 0:
 44        image.data = np.mean(image.data, axis=(0, 1))
 45        for line in checklines:
 46            lim = image.get_fwhm()[image.get_band_index(float(line))]
 47            mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit)
 48            # plot warning if error exceeds FWHM
 49            if (line - mini) > lim:
 50                print("\x1b[31m" + "Spectral accuracy at " + str(line) + " nm:   " + "{:.4f}".format(
 51                    line - mini) + " nm - WARNING: OVER FWHM" + '\x1b[0m')
 52            else:
 53                print("\x1b[32m" + "Spectral accuracy at " + str(line) + " nm:   " + "{:.4f}".format(
 54                    line - mini) + " nm" + '\x1b[0m')
 55
 56    elif dim == 1:
 57        image.data = np.mean(image.data, axis=1)
 58        fig, axs = plt.subplots(2, 2, figsize=(15, 6))
 59        fig.subplots_adjust(hspace=.5, wspace=.3)
 60        axs = axs.ravel()
 61        i = 0
 62        for line in checklines:
 63            mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit)
 64
 65            # color plot based on fwhm
 66            lim = image.get_fwhm()[image.get_band_index(float(line))]
 67            if any(x > lim for x in (line - mini)):
 68                col = "orangered"
 69            else:
 70                col = "limegreen"
 71            axs[i].plot(line - mini, col)
 72            axs[i].set_title(str(line) + ' nm')
 73            axs[i].axhline(y=lim, color="grey", linestyle="--")
 74            axs[i].text(0.9, 0.9, 'FWHM', fontsize=10, color="grey", va='center', ha='center', backgroundcolor='w',
 75                        transform=axs[i].transAxes)
 76            i += 1
 77        for ax in axs.flat:
 78            ax.set(xlabel='swath pixels', ylabel='spectral accuracy [nm]')
 79
 80        plt.show()
 81
 82    elif dim == 2:
 83        from matplotlib import colors
 84        # color plot based on fwhm
 85        fig, axs = plt.subplots(2, 2, figsize=(15, 6))
 86        fig.subplots_adjust(hspace=.5, wspace=.1)
 87        axs = axs.ravel()
 88        i = 0
 89        for line in checklines:
 90            mini, _, _ = image.minimum_wavelength(line - 10., line + 10., method=fit)
 91            lim = image.get_fwhm()[image.get_band_index(float(line))]
 92            cmap = "RdYlGn_r"
 93            norm = colors.Normalize(vmin=0, vmax=lim * 2)
 94            im = axs[i].imshow(line - mini, cmap=cmap, norm=norm)
 95            axs[i].set_title(str(line) + ' nm')
 96            cbar = fig.colorbar(im, ax=axs[i], cmap=cmap, norm=norm)
 97            cbar.ax.locator_params(nbins=3)
 98            cbar.ax.set_yticklabels(['within limits', 'FWHM', 'exceeding FWHM'])
 99            i += 1
100
101        plt.show()

Estimate the spectral quality of a sensor according to reference measurements. Mask image first if required.

Arguments:
  • image (hylite.hyimage.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).