예제 #1
0
def load_modelspecs(modelspecs, uris, IsReload=False, **context):
    '''
    i.e. Load a modelspec from a specific place. This is not
    the same as reloading a model for later inspection; it would be more
    appropriate when doing something complicated with several different
    models.
    '''
    if not IsReload:
        modelspecs = [load_resource(uri) for uri in uris]
    return {'modelspecs': modelspecs}
예제 #2
0
def reload_model(model_uri):
    '''
    Reloads an xspec and modelspec that were saved in some directory somewhere.
    This recreates the context that occurred during the fit.
    Passes additional context {'IsReload': True}, which xforms should react to
    if they are not intended to be run on a reload.
    '''
    xfspec_uri = model_uri + 'xfspec.json'

    # TODO: instead of just reading the first modelspec, read ALL of the modelspecs
    # I'm not sure how to know how many there are without a directory listing!
    modelspec_uri = model_uri + 'modelspec.0000.json'

    xfspec = load_resource(xfspec_uri)
    modelspec = load_resource(modelspec_uri)

    ctx, reloadlog = xforms.evaluate(xfspec, {
        'IsReload': True,
        'modelspecs': [modelspec]
    })

    return ctx
예제 #3
0
파일: params.py 프로젝트: LBHB/nems_db
def _get_modelspecs(cellids, batch, modelname, multi='mean'):
    filepaths = load_batch_modelpaths(batch,
                                      modelname,
                                      cellids,
                                      eval_model=False)
    speclists = []
    for path in filepaths:
        mspaths = []
        path = path.replace('http://hyrax.ohsu.edu:3003/',
                            '/auto/data/nems_db/')
        if get_setting('NEMS_RESULTS_DIR').startswith("/Volumes"):
            path = path.replace('/auto/', '/Volumes/')
        for file in os.listdir(path):
            if file.startswith("modelspec"):
                mspaths.append(os.path.join(path, file))
        speclists.append([load_resource(p) for p in mspaths])

    modelspecs = []
    for m in speclists:
        if len(m) > 1:
            if multi == 'first':
                this_mspec = m[0]
            elif multi == 'all':
                this_mspec = m
            elif multi == 'mean':
                stats = ms.summary_stats(m)
                temp_spec = copy.deepcopy(m[0])
                phis = [m['phi'] for m in temp_spec]
                for p in phis:
                    for k in p:
                        for s in stats:
                            if s.endswith('--' + k):
                                p[k] = stats[s]['mean']
                for m, p in zip(temp_spec, phis):
                    m['phi'] = p
                this_mspec = temp_spec
            else:
                log.warning(
                    "Couldn't interpret <multi> parameter. Got: %s,\n"
                    "Expected one of: 'mean, first, random, all'.\n"
                    "Using first modelspec instead.", multi)
                this_mspec = m[0]
        else:
            this_mspec = m[0]

        modelspecs.append(ms.ModelSpec([this_mspec]))

    return modelspecs
예제 #4
0
def get_preview():
    """Queries the database for the filepath to the preview image
    for the selected cell, batch and model combination(s)

    """

    session = Session()
    Results = Tables()['Results']

    # Only get the numerals for the selected batch, not the description.
    bSelected = request.args.get('bSelected', type=str)[:3]
    cSelected = request.args.getlist('cSelected[]')
    mSelected = request.args.getlist('mSelected[]')

    figurefile = None
    path = (
            session.query(Results)
            .filter(Results.batch == bSelected)
            .filter(Results.cellid.in_(cSelected))
            .filter(Results.modelname.in_(mSelected))
            .first()
            )

    if not path:
        session.close()
        return jsonify(image='missing preview')
    else:
        figurefile = str(path.figurefile)
        session.close()

    # Another temporary compatibility hack to convert
    # s3://... to https://
    if figurefile.startswith('s3'):
        prefix = 'https://s3-us-west2.amazonaws.com'
        parsed = urlparse(figurefile)
        bucket = parsed.netloc
        path = parsed.path
        figurefile = prefix + '/' + bucket + '/' + path

    # TODO: this should eventually be the only thing that gets
    #       called - above try/except ugliness is temporary for
    #       backwards compatibility
    image_bytes = load_resource(figurefile)
    b64img = str(b64encode(image_bytes))[2:-1]
    return jsonify(image=b64img)
예제 #5
0
def load_xform(uri):
    '''
    Loads and returns xform saved as a JSON.
    '''
    xform = load_resource(uri)
    return xform