Exemplo n.º 1
0
def extract_features(fname,
                     file_type,
                     path_out,
                     baseline,
                     substance,
                     sample=None):
    """
    Process the s06av95a_envi file and extract the <substance> and/or <sample>
    features according to the <baseline> value.
    """
    print('Running extract_features')
    if file_type == 'ENVI': rd = spectro.EnviReader(fname)
    if file_type == 'JSON': rd = spectro.JSONReader(fname)
    lib = spectro.USGS06SpecLib(rd)
    wvl = lib.get_wvl()
    for spectrum, sample_id, descrip, idx in lib.get_substance(
            substance, sample):
        fea = spectro.FeaturesConvexHullQuotient(spectrum,
                                                 wvl,
                                                 baseline=baseline)
        plot_name = '{0}_{1}'.format(substance, sample_id)
        fea.plot_convex_hull_quotient(path_out, plot_name)
        fea.plot(path_out, plot_name, feature='all')
        #fea.plot(path_out, plot_name, feature=10)
        fea.print_stats('all')
Exemplo n.º 2
0
def search_biotite(lib_name, file_type, biotite, dist):
    """
    """
    if file_type == 'ENVI': rd = spectro.EnviReader(lib_name)
    if file_type == 'JSON': rd = spectro.JSONReader(lib_name)
    lib = spectro.USGS06SpecLib(rd)
    match_spectrum, where = lib.distance_match(biotite, distfn=dist)
    return where
Exemplo n.º 3
0
def get_biotite_WS660(lib_name, file_type):
    """
    """
    if file_type == 'ENVI': rd = spectro.EnviReader(lib_name)
    if file_type == 'JSON': rd = spectro.JSONReader(lib_name)
    lib = spectro.USGS06SpecLib(rd)
    for spectrum, sample_id, descrip, idx in lib.get_substance('Biotite', 'WS660'):
        return spectrum, idx
Exemplo n.º 4
0
def get_random_n_endmembers(fname, file_type, n):
    import random
    if file_type == 'ENVI': rd = spectro.EnviReader(fname)
    if file_type == 'JSON': rd = spectro.JSONReader(fname)
    lib = spectro.USGS06SpecLib(rd)
    dim = lib.get_dim()
    idx = random.sample(list(range(dim)), n)
    # 224 is the number of bands
    U = np.zeros((224, n), dtype=np.float)
    for i, j in enumerate(idx):
        U[:,i] = lib.get(j)
    # the USGS library sometimes have very small numbers that create numeric
    # instability, normalize get rid of them
    return util.normalize(U)
Exemplo n.º 5
0
def batch_usgs_spec_plot(fname, file_type, path_out):
    """
    Process the s06av95a_envi file and plot for each spectrum the spectrum,
    the convex hull and the convex hull quotient.
    """
    print('Running batch_usgs_spec_plot')
    if file_type == 'ENVI': rd = spectro.EnviReader(fname)
    if file_type == 'JSON': rd = spectro.JSONReader(fname)
    lib = spectro.USGS06SpecLib(rd)
    wvl = lib.get_wvl()

    for spectrum, mineral, sample_id, descrip, idx in lib.get_next():
        schq = spectro.SpectrumConvexHullQuotient(spectrum, wvl)
        plot_name = '{0}_{1}_{2}'.format(idx, mineral, sample_id)
        schq.plot(path_out, plot_name)