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

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).