Esempio n. 1
0
    def _map(self, i):
        import maps
        log.debug('map of {}'.format([getattr(self, v)[i] for v in 'sxyzc']))
        kwargs = self.opts(i)
        x, y, z = self.data(i)
        o = get_args_from(kwargs, margin = 0.05, width = 10e6, height = None, boundarylat = 50, projection = 'cyl',
                          drawcoastline = 1, drawgrid = 1, drawspecgrid = 1, drawcountries = 0, bluemarble = 0, nightshade = None)

        m = maps.drawmap(y, x, **o)
        x, y = m(x, y)

        if z is None:
            l, = plt.plot(x, y, **kwargs)
        else:
            # linestyle must not be 'none' when plotting 3D
            if 'linestyle' in kwargs and kwargs['linestyle'] == 'none':
                kwargs['linestyle'] = ':'

            o = get_args_from(kwargs, markersize = 6, cbfrac = 0.04, cblabel = self.alabel('z'))
            p = set_defaults(kwargs, zorder = 100)
            l = plt.scatter(x, y, c = z, s = o.markersize ** 2, edgecolor = 'none', **p)

            m = 6.0
            dmin, dmax = np.nanmin(z), np.nanmax(z)
            cticks = ticks.get_ticks(dmin, dmax, m, only_inside = 1)
            formatter = mpl.ticker.FuncFormatter(func = lambda x, i:number_mathformat(x))
            cb = plt.colorbar(fraction = o.cbfrac, pad = 0.01, aspect = 40, ticks = cticks, format = formatter)
            cb.set_label(o.cblabel)

        self.legend.append((l, self.llabel(i)))
Esempio n. 2
0
    def _profile(self, i):
        log.debug('profile of {}'.format([getattr(self, v)[i] for v in 'sxyzc']))
        kwargs = self.opts(i)
        x, y, z = self.data(i)
        o = get_args_from(kwargs, xerr = 0, yerr = 0)

        # make x binning
        xedges, xcenters, xwidths = get_binning(self.bins(i, 'x'), x)

        # compute avg and std for each x bin
        xx = xcenters
        xerr = 0.5 * xwidths if o.xerr else None
        yy = []
        yerr = []
        for l, u in zip(xedges[:-1], xedges[1:]):
            bindata = y[(l <= x) & (x < u)]
            yy.append(np.mean(bindata))
            yerr.append(np.std(bindata))
        if not o.yerr:
            yerr = None

        pargs = set_defaults(kwargs, capsize = 3, marker = '.', linestyle = 'none')
        l, _d, _d = plt.errorbar(xx, yy, yerr, xerr, **pargs)

        self.legend.append((l, self.llabel(i)))

        self.fit(i, xx, yy, yerr)
Esempio n. 3
0
                _links['last'] = {'title': 'last page', 'href': '%s%s'
                                  % (resource_uri(resource), q)}

            if req.page > 1:
                q = querydef(req.max_results, req.where, req.sort, req.page - 1)
                _links['prev'] = {'title': 'previous page', 'href': '%s%s' %
                                  (resource_uri(resource), q)}
        """

        return _links


#class MyRestHandler(cyclone.web.RequestHandler, python_rest_handler.RestRequestHandler):
#    data_manager = MongoDBDataManager


if __name__ == "__main__":
    handlers = [
        #(r"/jobs/?", CycloneRestHandler, dict(rest_settings=set_defaults("/jobs"))),
        (r"/jobs/?([A-Za-z0-9]+/?)?", CycloneRestHandler, dict(rest_settings=set_defaults("/jobs"))),
        #(r"/jobs/?", CycloneRestHandler, dict(rest_settings=set_defaults("/jobs"))),
        #(r"/jobs/([A-Za-z0-9]+)/?", CycloneRestHandler, dict(rest_settings={})),
        #(r"/jobs/([A-Za-z0-9]+)/edit/?", CycloneRestHandler, dict(rest_settings={}))
        #(r"/jobs/?", CycloneRestHandler)
    ]
    application = cyclone.web.Application(handlers)

    log.startLogging(sys.stdout)
    reactor.listenTCP(8888, application, interface="127.0.0.1")
    reactor.run()
Esempio n. 4
0
# IMPORT MIR LIBRARIES
sys.path.append('../lib')
import librosa
import pymir
import midiutil

# IMPORT OUR MIR FUNCTIONS
sys.path.append('functions')
import utils
import dictionaries
import beatDetection
import chordPrediction
import midiConversion
import midiFileCreation

show_diagnostics, settings, save = utils.set_defaults()
print('\nWelcome to Play With Yourself Music Accompaniment Tool.'
      '\nType help for a list of valid commands')

while (True):
    cmd = raw_input('\nWhat would you like to do?\n')
    cmd, show_diagnostics, settings, save = utils.process_command(
        cmd, show_diagnostics, settings, save)
    if (cmd == 'load_yes'):
        UI_instrument_notes = int(settings['inst1'])
        UI_onset_threshold = float((10 - int(settings['busy'])) / 10.0)
        UI_instrument_chords = int(settings['inst2'])
        UI_dynamic_threshold = float(settings['dyn'] / 10.0)
        UI_instrument_beats = int(settings['inst3'])
        UI_beat_windowSize = float(settings['window'] / 10.0)
        #300 msec
Esempio n. 5
0
    def _hist2d(self, i):
        log.debug('2D histogram of {}'.format([getattr(self, v)[i] for v in 'sxyzc']))
        kwargs = self.opts(i)
        x, y, z = self.data(i)
        o = get_args_from(kwargs, style = 'color', density = False, log = False, cbfrac = 0.04, cblabel = 'bincontent', levels = 10)
        filled = 'color' in o.style or ('fill' in o.style)
        o.update(get_args_from(kwargs, hidezero = o.log or filled, colorbar = filled, clabels = not filled))

        # make binnings
        bins = self.bins(i, 'x')
        if  bins == 0:
            bins = int(1 + np.log2(len(x)))
        xedges, xcenters, xwidths = get_binning(bins, x)

        bins = self.bins(i, 'y')
        if  bins == 0:
            bins = int(1 + np.log2(len(y)))
        yedges, ycenters, ywidths = get_binning(bins, y)

        bincontents, _d1, _d2 = np.histogram2d(x, y, [xedges, yedges])
        bincontents = np.transpose(bincontents)
        assert np.all(_d1 == xedges)
        assert np.all(_d2 == yedges)

        # statsbox
        self.stats_fields2d(i, bincontents, xcenters, ycenters)

        if o.density:
            bincontents = get_density2d(bincontents, xwidths, ywidths)

        if o.hidezero:
            bincontents[bincontents == 0] = np.nan

        if o.log:
            bincontents = np.log10(bincontents)
            formatter = mpl.ticker.FuncFormatter(func = lambda x, i:number_mathformat(np.power(10, x)))
        else:
            formatter = mpl.ticker.FuncFormatter(func = lambda x, i:number_mathformat(x))

        if 'color' in o.style:
            pargs = set_defaults(kwargs, cmap = 'jet', edgecolor = 'none')
            plt.pcolor(xedges, yedges, ma.array(bincontents, mask = np.isnan(bincontents)), **kwargs)

        elif 'box' in o.style:
            pargs = set_defaults(kwargs, color = (1, 1, 1, 0), marker = 's', edgecolor = 'k')
            n = bincontents.size
            s = bincontents.reshape(n)
            s = s / np.nanmax(s) * (72. / 2. * self.w / max(len(xcenters), len(ycenters))) ** 2
            xcenters, ycenters = np.meshgrid(xcenters, ycenters)
            plt.scatter(xcenters.reshape(n), ycenters.reshape(n), s = s, **pargs)

        elif 'contour' in o.style:
            pargs = set_defaults(kwargs, cmap = 'jet')
            if not isinstance(pargs['cmap'], mpl.colors.Colormap):
                pargs['cmap'] = mpl.cm.get_cmap(pargs['cmap'])

            if filled:
                cs = plt.contourf(xcenters, ycenters, bincontents, o.levels, **pargs)
            else:
                cs = plt.contour(xcenters, ycenters, bincontents, o.levels, **pargs)
                if o.clabels:
                    plt.clabel(cs, inline = 1)

        else:
            raise ValueError('unknown style ' + o.style)

        if o.colorbar:
            m = 6.0
            dmin, dmax = np.nanmin(bincontents), np.nanmax(bincontents)
            if o.log:
                dmin, dmax = np.ceil(dmin), np.floor(dmax) + 1
                step = max(1, np.floor((dmax - dmin) / m))
                cticks = np.arange(dmin, dmax, step)
            else:
                cticks = ticks.get_ticks(dmin, dmax, m, only_inside = 1)

            cb = plt.colorbar(fraction = o.cbfrac, pad = 0.01, aspect = 40, ticks = cticks, format = formatter)
            cb.set_label(o.cblabel)
Esempio n. 6
0
    def _hist1d(self, i):
        self.plotted_lines = []
        log.debug('1D histogram of {}'.format([getattr(self, v)[i] for v in 'sxyzc']))
        kwargs = self.opts(i)
        x, y, z = self.data(i)

        o = get_args_from(kwargs, density = False, cumulative = 0)
        o.update(get_args_from(kwargs, style = 'histline' if o.density else 'hist'))
        err = 0  # o.style.startswith('s')
        o.update(get_args_from(kwargs, xerr = err, yerr = err, capsize = 3 if err else 0))

        bins = self.bins(i, 'x')
        if  bins == 0:
            bins = int(1 + np.log2(len(x)))
        binedges, bincenters, binwidths = get_binning(bins, x)

        bincontents, _d1 = np.histogram(x, binedges)
        assert np.all(binedges == _d1)
        binerrors = np.sqrt(bincontents)
        binerrors[binerrors == 0] = 1

        # statsbox
        self.stats_fields1d(i, x, bincontents, binerrors, binedges)

        if o.density:
            bincontents, binerrors = get_density(bincontents, binerrors, binwidths)

        if o.cumulative:
            bincontents, binerrors = get_cumulative(bincontents, binerrors, o.cumulative, binwidths if o.density else 1)

        if 'line' in o.style:
            x = bincenters
            y = bincontents
        else:
            x, y = get_step_points(bincontents, binedges)

        if 'fill' in o.style:
            l, = plt.fill(x, y, **kwargs)

        elif 'hist' in o.style:
            l, = plt.plot(x, y, **kwargs)

        elif 'scat' in o.style:
            pargs = set_defaults(kwargs, linestyle = '', marker = '.')
            l, = plt.plot(bincenters, bincontents, **pargs)

        else:
            raise ValueError('unknown style: ' + o.style)

        if o.xerr or o.yerr:
            pargs = set_defaults(kwargs, capsize = o.capsize, ecolor = 'k' if 'fill' in o.style else l.get_c())
            xerr = 0.5 * binwidths if o.xerr else None
            yerr = binerrors if o.yerr else None
            plt.errorbar(bincenters, bincontents, yerr, xerr, fmt = None, **pargs)


        adjust_limits('x', binedges)
        adjust_limits('y', bincontents + binerrors, marl = 0)

        self.legend.append((l, self.llabel(i)))

        self.fit(i, bincenters, bincontents, binerrors)
Esempio n. 7
0
        'parameters':
        Params.COUNT_PARAMS[:10] + Params.WORD2VEC_PARAMS +
        [Params.train_algorithm_w2v, Params.null_word, Params.cbow_mean],
        'default':
        '',
        'defaults': {}
    },
    'Doc2Vec': {
        'class':
        Doc2VecVectorizer,
        'parameters':
        Params.COUNT_PARAMS[:10] + Params.WORD2VEC_PARAMS + [
            Params.train_algorithm_d2v, Params.dbow_words, Params.dm_mean,
            Params.dm_concat, Params.dm_tag_count, Params.retrain_count
        ],
        'default':
        '',
        'defaults': {
            'token_pattern': r"(?u)[\b\w\w+\b]+|[.,!?();:\"{}\[\]]",
            'vector_size': 300,
            'window': 8
        }
    }
}

for item, settings in TRANSFORMERS.iteritems():
    TRANSFORMERS[item]['defaults'] = set_defaults(settings['defaults'],
                                                  settings['parameters'])
    TRANSFORMERS[item]['parameters'] = set_params_defaults(
        settings['parameters'], settings['defaults'])