How to use the spectral.io.envi 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 capstone-coal / pycoal / pycoal / mineral.py View on Github external
# get the scores for each class considered
            predict = model.predict(pixel)

            # get the index of the class into the outputted list
            index_of_max = numpy.argmax(predict).astype(numpy.uint16)

            # store the class index (0 meaning nodata)
            classified[x, y] = index_of_max + 1

            # store the outcome score
            if scores_file_name is not None:
                scored[x, y] = predict[0][index_of_max]

    # save the classified image to a file
    spectral.io.envi.save_classification(classified_file_name, classified,
                                         class_names=['No data'] + class_names,
                                         metadata={'data ignore value': 0,
                                                   'description': 'COAL ' +
                                                   pycoal.version + ' mineral '
                                                                  'classified '
                                                                  'image.',
                                                   'map info':
                                                       image.metadata.get(
                                                        'map info')})

    if scores_file_name is not None:
        # save the scored image to a file
        spectral.io.envi.save_image(scores_file_name, scored,
                                    dtype=numpy.float64,
                                    metadata={'data ignore value': -50,
                                              'description': 'COAL ' +
github capstone-coal / pycoal / pycoal / mineral.py View on Github external
numpy.logical_or(
            numpy.isclose(data[:, :, 0], -0.005), data[:, :, 0] == -50))

    # Set classifid and scored values for ignored pixels to 0
    classified[nopixel_indices] = 0
    scored[nopixel_indices] = 0

    # Find indices where the scored values are below threshold
    below_threshold_indices = numpy.where(scored[:][:] <= threshold)

    # Set classifid and scored values for values below threshold to 0
    classified[below_threshold_indices] = 0
    scored[below_threshold_indices] = 0

    # save the classified image to a file
    spectral.io.envi.save_classification(classified_file_name, classified,
                                         class_names=['No data'] +
                                         library.names,
                                         metadata={'data ignore value': 0,
                                                   'description': 'COAL ' +
                                                   pycoal.version + ' '
                                                   'mineral classified '
                                                   'image.',
                                                   'map info':
                                                       image.metadata.get(
                                                        'map info')})

    # remove unused classes from the image
    pycoal.mineral.MineralClassification.filter_classes(classified_file_name)

    if scores_file_name is not None:
        # save the scored image to a file
github capstone-coal / pycoal / pycoal / environment.py View on Github external
'_' + vector_name + '_proximity.hdr'
            proximity_image_name = proximity_header_name[:-4] + '.img'
            EnvironmentalCorrelation.proximity(feature_image_name,
                                               proximity_image_name)
            proximity_image = spectral.open_image(proximity_header_name)

            # intersect features within proximity
            for x in range(mining_image.shape[0]):
                for y in range(mining_image.shape[1]):
                    if mining_image[x, y, 0] == 1 \
                            and proximity_image[x, y, 0] * pixel_size <= proximity:
                        correlated_image[x, y, 0] = mining_image[x, y, 0]

        # save the environmental correlation image with proximity data
        # from each type of hydrographic data passed as input
        spectral.io.envi.save_classification(correlated_filename,
                                             correlated_image,
                                             class_names=mining_image.
                                             metadata.get('class names'),
                                             metadata={'data ignore value': 0,
                                                       'description': 'COAL ' +
                                                       pycoal.version + ' '
                                                       'environmental '
                                                       'correlation image.',
                                                       'map info':
                                                           mining_image.
                                                           metadata.get(
                                                               'map info')})
        logging.info(
            "Successfully saved Environmental Correlation image to '%s'.",
            correlated_filename)
        end = time.time()
github rmkemker / EarthMapper / fileIO / utils.py View on Github external
def readENVIHeader(fName):
    """
    Reads envi header

    Parameters
    ----------
    fName : String, Path to .hdr file
    
    Returns
    -------
    centers : Band-centers
	fwhm : full-width half-maxes
    """
    hdr = envi.read_envi_header(fName)
    centers = np.array(hdr['wavelength'],dtype=np.float)
    fwhm = np.array(hdr['fwhm'],dtype=np.float)
    return centers, fwhm
github capstone-coal / pycoal / pycoal / mineral.py View on Github external
# empty list for names
        names = []

        # copy class spectra and names
        for new_index, class_name in enumerate(class_names):
            old_index = spectral_library.names.index(class_name)
            spectra[new_index] = spectral_library.spectra[old_index]
            names.append(class_name)

        # copy metadata
        metadata = {'wavelength units': spectral_library.metadata.get(
            'wavelength units'), 'spectra names': names,
            'wavelength': spectral_library.bands.centers}

        # return new spectral library
        return spectral.io.envi.SpectralLibrary(spectra, metadata, {})