コード例 #1
0
    def _read_envi(path: Path) -> Tuple[ndarray, BandInfo, dict]:
        """Read array data from ENVI binary and header file.

        This function uses imageio to read the image and adds the
        BandInfo and metadata from the ENVI header file.

        Args:
            path: Path to ENVI binary file (usually .raw or .img).

        Returns:
            image, bandinfo, meta
            Tuple containing ndarray of the image data, BandInfo object and
            metadata dictionary.
        """
        hsi = imageio.imread(path, format='gdal')
        if hsi.ndim == 2:
            hsi = hsi[..., np.newaxis]

        # Transpose axis as imageio uses (ch, x, y) shape for spectral images
        hsi = np.transpose(hsi, (1, 2, 0))

        meta = SpectralArray.read_envi_header(path.with_suffix('.hdr'))
        bandinfo = BandInfo.from_envi_header(meta)

        return hsi, bandinfo, meta
コード例 #2
0
def test_band_info_envi():
    """Test ``from_envi`` class method.
    """
    testing.needs_internet()

    envi_file = testing.get_remote_file(TEST_ENVI_HDR)
    d = SpectralArray.read_envi_header(envi_file)

    band_info = BandInfo.from_envi_header(d)
    centers_exp = np.asarray([400.6, 450.3, 500, 551.7, 600.666, 760.9])
    bandwiths_exp = np.asarray([1.1, 1.2, 1.3, 1.4, 1.5, 1.6])

    assert 6 == band_info.num_channels
    assert band_info.type is None
    assert band_info.centers_std is None
    assert band_info.bandwidths_std is None
    assert np.array_equal(centers_exp, band_info.centers)
    assert np.array_equal(bandwiths_exp, band_info.bandwidths)

    return