예제 #1
0
def aloi_writesubmit_supersim(inflist,
                              prepflist,
                              perceptflist,
                              runscr,
                              clean=False):
    """
    Write and execute a condor submission file with the IO specified in aloi_getpaths().

    Parameters
    ----------
    inflist, prepflist, perceptflist : lists
        lists containing IO created by aloi_getpaths.
    runscr : str
        path to bash script executed by condor.
    clean : bool
        remove submission file after execution?

    Returns
    -------
    perceptflist : list
        same as input, just passed along for convenience
    """
    submitf = write_submission_file(runscr, inflist, prepflist, perceptflist)
    exec_submission(submit_fpath=abp(submitf), cleanup=clean)
    print('Submitted ALOI selection to condor for simulation with script %s' % runscr)
    return perceptflist
예제 #2
0
def aloi_writesubmit_hmax(prepfiles, perceptfiles, intactouts, perceptouts,
                          runscr, clean=False):
    # merge input and output lists
    hmaxinputs = prepfiles + perceptfiles
    hmaxoutputs = intactouts + perceptouts

    submitf = write_submission_file(runscr, hmaxinputs, hmaxoutputs)
    exec_submission(submit_fpath=abp(submitf), cleanup=clean)
    print('Submitted ALOI prepped and percept files to condor for HMAXing with %s' % runscr)
    return hmaxinputs, hmaxoutputs
예제 #3
0
def hmax_image(image_infile,
               hmax_outfile,
               hmax_python_dir=pjoin('..', 'hmax-python')):
    """
    Run python-hmax on a single image.

    :param image_infile : str. path to input image file
    :param hmax_outfile: str. path to output hmax file. Note that file suffix must be '.ascii'
    :param hmax_python_dir:
    :return: outfile. str. Same as the input argument 'outfile' but returned for convenience in file handling later.
    """

    # get absolute path of in and out file
    infile_abs, outfile_abs = abp(image_infile), abp(hmax_outfile)
    # get absolute path to script with hmax python implementation
    script_abs = abp(pjoin(hmax_python_dir, 'runhmaxonimages.py'))
    # call pre-implemented hmax-python
    call(['python', script_abs, '-i', infile_abs, '-o', outfile_abs])
    return hmax_outfile
예제 #4
0
def hmax_filelist(filelist):

    for fname in filelist:

        # absolute path names
        fname_abp = abp(fname)
        if 'orig' in fname_abp:
            outname_abp = fname_abp.replace('orig', 'results') + '.ascii'
        elif 'sim' in fname_abp:
            outname_abp = fname_abp.replace('sim', 'results') + '.ascii'

        # call function
        if not os.path.exists(outname_abp):
            call([
                'python', 'runhmaxonimages.py', '-i', fname_abp, '-o',
                outname_abp
            ])
        else:
            print('file %s already exists' % outname_abp)
예제 #5
0
def hmaxfile2dict(hmax_file):
    """
    read a given output file returned by python-hmax and store its information in a dict.
    stim name, category name, vision type must be indicated by file name (e.g. 'apple_1_percept.png.ascii')

    :param hmax_file: str. path to .ascii file returned by python-hmax
    :return: pattern_dict. dict. contains stimulus name, category name, response pattern, and vision type
    """

    # in case of aloi stimuli, it looks like this:
    # /home/contier/ri_hmax/workdir/aloi/hmaxout/490_r90_percept.ascii

    # get hmax output vector
    hmax_df = pd.read_csv(hmax_file, header=None)
    pattern = np.array([row[0] for row in hmax_df.values])

    # removes all of path except name of the .ascii file, withoug suffix
    fname_nopath = hmax_file.split('/')[-1].replace('.ascii', '')
    # get stimulus name, category name, and vision
    catname, exemplar, vision = fname_nopath.split('_')[0:3]
    if vision == 'percept':
        vision = 'ri_' + vision

    # stimname = hmax_file.replace('.png', '')
    # for substring, vision in zip(['percept', 'intact'], ['ri_percept', 'intact']):
    #     if substring in hmax_file:
    #         vision = vision
    #         stimname = hmax_file.replace('_' + substring, '')  # result should be 'apple_1'
    # catname = stimname.split('_')[0]  # result should be 'apple'

    # create file specific dict
    pattern_dict = {
        'pattern': pattern,
        'category': catname,
        'exemplar': exemplar,
        'vision': vision,
        'filename': abp(hmax_file)
    }
    return pattern_dict
예제 #6
0
    target = pd.DataFrame(
        [[1, "2016-01-01T00:00:00"], [2, "2016-01-01T00:00:00"],
         [3, "2016-01-01T00:00:00"], [4, "2016-01-01T00:00:00"],
         [5, "2016-01-01T00:00:00"], [6, "2016-01-01T00:00:00"],
         [7, "2016-01-01T00:00:00"], [8, "2016-01-01T00:00:00"]],
        columns=["category_ind", "update_time"])
    target.to_sql(ts.article_categories.__tablename__,
                  con.engine,
                  if_exists='replace',
                  index=False)


def insert_catname(con):
    target = pd.DataFrame([[1, "エンタメ"], [2, "スポーツ"], [3, "おもしろ"], [4, "日本"],
                           [5, "海外"], [6, "コラム"], [7, "IT"], [8, "グルメ"]],
                          columns=["category_ind", "category_name"])
    target.to_sql(ts.article_categories_names.__tablename__,
                  con.engine,
                  if_exists='replace',
                  index=False)


if __name__ == '__main__':
    _p = drn(abp(__file__))
    with open(_p + '/user_info.json') as f:
        info = json.load(f)
    con = connectPSQL(info)
    con.create_tables()
    insert_cat(con)
    insert_catname(con)