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')
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
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
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)
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)
def __init__(self, lib_name): rd = spectro.EnviReader(lib_name) self.lib = spectro.USGS06SpecLib(rd)