How to use the spectral.BandResampler function in spectral

To help you get started, we’ve selected a few spectral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rmkemker / EarthMapper / utils / utils.py View on Github external
the band centers of the input hyperspectral cube
    bands2 : numpy array [1 x num target bands], 
		the band centers of the output hyperspectral cube
    fwhm1  : numpy array [1 x num source bands], 
		the full-width half-max of the input hyperspectral cube
    fwhm2 : numpy array [1 x num target bands],
		the full-width half-max of the output hyperspectral cube
	mask : numpy array (height x width), optional mask to perform the band-
		resampling operation on.

    Returns
    -------
	output - numpy array (height x width x N)

    """
    resample = BandResampler(bands1,bands2,fwhm1,fwhm2)
    dataSize = data.shape
    data = data.reshape((-1,dataSize[2]))
    
    if mask is None:
        out = resample.matrix.dot(data.T).T
    else:
        out = np.zeros((data.shape[0], len(bands2)), dtype=data.dtype)
        mask = mask.ravel()
        out[mask] = resample.matrix.dot(data[mask].T).T
        
    out[np.isnan(out)] = 0
    return out.reshape((dataSize[0],dataSize[1],len(bands2)))
github capstone-coal / pycoal / examples / example_sam.py View on Github external
library = spectral.open_image(library_filename)

# open the image
image_filename = \
    '../pycoal/tests/images/ang20150422t163638_corr_v1e_img_4000-4010_550' \
    '-560.hdr'

image = spectral.open_image(image_filename)

# access a pixel known
x = 4
y = 7
pixel = image[x, y]

# define a resampler
resample = spectral.BandResampler([x / 1000 for x in image.bands.centers],
                                  library.bands.centers)

# resample the pixel
resampled_pixel = numpy.nan_to_num(resample(pixel))

# calculate spectral angles
angles = spectral.spectral_angles(
    resampled_pixel[numpy.newaxis, numpy.newaxis, ...], library.spectra)

# normalize confidence values from [pi,0] to [0,1]
for z in range(angles.shape[2]):
    angles[0, 0, z] = 1 - angles[0, 0, z] / math.pi

# get angles, classes, and indices
angle_list = list(numpy.ndarray.flatten(angles))
angle_class_list = zip(angle_list, library.names, range(0, len(library.names)))