How to use spectral - 10 common examples

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 JohnVinyard / zounds / zounds / analyze / feature / test_spectral.py View on Github external
def test_no_args_correct_inshape(self):
        ws = 2048
        Environment.instance = MockEnvironment(ws)
        re = RootExtractor(shape = 100)
        fft = FFT(needs = re)
        self.assertEqual((2048,),fft._inshape)
github JohnVinyard / zounds / zounds / analyze / feature / test_spectral.py View on Github external
def test_no_args_correct_dim(self):
        ws = 2048
        Environment.instance = MockEnvironment(ws)
        re = RootExtractor(shape = 100)
        fft = FFT(needs = re)
        self.assertEqual(1024,fft._dim)
github JohnVinyard / zounds / zounds / analyze / feature / test_spectral.py View on Github external
def test_no_args_oned_audio(self):
        ws = 2048
        Environment.instance = MockEnvironment(ws)
        re = RootExtractor(shape = ws)
        fft = FFT(needs = re)
        ec = ExtractorChain([re,fft])
        data = ec.collect()
        fftdata = np.concatenate(data[fft])
        self.assertEqual(1024,fftdata.shape[1])
github JohnVinyard / zounds / zounds / analyze / feature / test_spectral.py View on Github external
def test_reshape(self):
        re = RootExtractor(shape = 100)
        fft = FFT(needs = re, inshape = (10,10), axis = 1)
        ec = ExtractorChain([re,fft])
        data = ec.collect()
        # multiple power spectrums are always unravelled, so we should see
        # 10 frames with 50 coefficients each, i.e., each input is of shape
        # (10,10), which is reduced to shape (10,5) by performing an fft over 
        # the first dimension.  Finally, each frame of (10,5) is flattened to 
        # shape (50,)
        fftdata = np.concatenate(data[fft])
        self.assertEqual(50,fftdata.shape[1])
github JohnVinyard / zounds / zounds / analyze / feature / test_spectral.py View on Github external
def test_multiframe(self):
        # This test is nearly identical to test_reshape, except that it gathers
        # inputs of size (10,) for 10 frames before processing, instead of 
        # processing inputs of size 100 each frame.
        re = RootExtractor(shape = 10)
        fft = FFT(needs = re, inshape = (10,10), nframes = 10)
        ec = ExtractorChain([re,fft])
        data = ec.collect()
        fftdata = np.concatenate(data[fft])
        self.assertEqual((1,50),fftdata.shape)
        #self.assertTrue(np.all([50 == len(f) for f in data[fft]]))
github syhw / abnet / buckeye / buckeye.py View on Github external
@Memoize
def do_fbank(fname):
    try:
        with open(fname[:-3] + 'npy', 'rb') as rfb:
            fb = np.load(rfb)
    except IOError:
        srate, sound = wavfile.read(fname)
        fbanks = Spectral(nfilt=N_FBANKS,    # nb of filters in mel bank
                     alpha=0.97,             # pre-emphasis
                     do_dct=False,           # we do not want MFCCs
                     fs=srate,               # sampling rate
                     frate=FBANKS_RATE,      # frame rate
                     wlen=FBANKS_WINDOW,     # window length
                     nfft=1024,              # length of dft
                     do_deltas=False,       # speed
                     do_deltasdeltas=False  # acceleration
                     )
        fb = np.array(fbanks.transform(sound), dtype='float32')
        #with open(fname.split('.')[0] + '.npy', 'wb') as wfb:
        #    np.save(wfb, fb)
    print "did:", fname
    #print fb.shape
    return fb
github GenTang / intro_ds / ch10-unsupervised / clustering / spectral_clustering / gmm_vs_spectral.py View on Github external
def train_spectral_clustering(data, cluster_num):
    """
    训练谱聚类模型
    """
    model = SpectralClustering(n_clusters=cluster_num, affinity="rbf",
                               gamma=100, assign_labels="kmeans")
    model.fit(data)
    return model
github nshaud / DeepHyperX / utils.py View on Github external
def open_file(dataset):
    _, ext = os.path.splitext(dataset)
    ext = ext.lower()
    if ext == '.mat':
        # Load Matlab array
        return io.loadmat(dataset)
    elif ext == '.tif' or ext == '.tiff':
        # Load TIFF file
        return misc.imread(dataset)
    elif ext == '.hdr':
        img = spectral.open_image(dataset)
        return img.load()
    else:
        raise ValueError("Unknown file format: {}".format(ext))
github capstone-coal / pycoal / examples / example_spectra.py View on Github external
@copyright:  Copyright (C) 2017-2019 COAL Developers

@license:    GNU General Public License version 2

@contact:    coal-capstone@googlegroups.com
'''

import constants
import spectral
import matplotlib
import matplotlib.pyplot as plt

# load library
library_filename = constants.LIBRARY_FILENAME
library = spectral.open_image(library_filename)
schwert_index = library.names.index(u'Schwertmannite BZ93-1 s06av95a=b')
sldgwet_index = library.names.index(u'Renyolds_TnlSldgWet SM93-15w s06av95a=a')
sludge_index = library.names.index(u'Renyolds_Tnl_Sludge SM93-15 s06av95a=a')
bands = [1000 * band for band in library.bands.centers]

# customize figure
plt.rcParams['font.size'] = 8
plt.rcParams['legend.fontsize'] = 8
plt.rcParams['xtick.labelsize'] = 8
plt.rcParams['ytick.labelsize'] = 8
plt.rcParams['lines.linewidth'] = 2
plt.rcParams['text.color'] = 'white'
plt.rcParams['xtick.color'] = 'white'
plt.rcParams['ytick.color'] = 'white'
plt.rcParams['axes.labelcolor'] = 'white'
plt.rcParams['axes.edgecolor'] = 'white'
github capstone-coal / pycoal / pycoal / mineral.py View on Github external
model_file_name (str):          filename of the Keras model used to
        classify
        class_names (str[], optional):  list of names of classes handled by
        the model
        scores_file_name (str):         filename of the image to hold each
        pixel's classification score
        in_memory (boolean, optional):  enable loading entire image

    Returns:
        None
    """

    from keras.models import load_model

    # open the image
    image = spectral.open_image(image_file_name)
    if in_memory:
        data = image.load()
    else:
        data = image.asarray()
    m = image.shape[0]
    n = image.shape[1]

    # allocate a zero-initialized MxN array for the classified image
    classified = numpy.zeros(shape=(m, n), dtype=numpy.uint16)

    if scores_file_name is not None:
        # allocate a zero-initialized MxN array for the scores image
        scored = numpy.zeros(shape=(m, n), dtype=numpy.float64)

    model = load_model(model_file_name)