Exemplo n.º 1
0
def main():
    parser.description = 'Sparsenoise stimulus generator.'
    parser.add_argument(
        'fraction_on',
        type=float,
        nargs='*',
        help='fraction of pixels on per presentation frame (between 0 and 1)')
    parser.add_argument('--frames_per_run',
                        type=int,
                        help='number of frames per run presentation',
                        default=60000)
    args = parser.parse_args()
    fracs = args.fraction_on
    frames_total = args.nframes
    frames_per_run = args.frames_per_run
    n_runs = -(-frames_total // frames_per_run)  # ceiling division.
    assert n_runs > len(fracs)
    if n_runs > (frames_total // frames_per_run):
        print(
            'WARNING: {} frames were requested, but {} frames will be presented due to rounding.'
            .format(frames_total, n_runs * frames_per_run))
    if n_runs < len(fracs) * 2:
        print(
            'WARNING: each sparsity fraction will be presented in only one contiguous run of {} frames'
            .format(frames_per_run))
    runs_per_frac = -(-n_runs // len(fracs))  # ceiling division
    print('Running each sparsity fraction {} times...'.format(runs_per_frac))
    frac_list_weighted = []
    for frac in fracs:  # check to make sure fractions are valid.
        if frac > 1. or frac < 0.:
            errst = 'Fraction argument must be between 0 and 1.'
            raise ValueError(errst)
        else:
            frac_list_weighted.extend([frac] * runs_per_frac)
    frac_list_permuted = np.random.permutation(frac_list_weighted)
    savefile_base, _ = os.path.splitext(args.savefile)
    presented = 0
    for i in range(n_runs):
        savefile_str = "{}_r{:03d}.h5".format(savefile_base, i)
        print('Starting run number {} of {}.'.format(i + 1, n_runs))
        frac = frac_list_permuted[i]
        seq_gen = sparsenoise_function_generator(frac)
        presented += frames_per_run
        run_presentations(frames_per_run,
                          savefile_str,
                          seq_gen,
                          file_overwrite=args.overwrite,
                          seq_debug=False,
                          image_scale=args.scale,
                          picture_time=args.pic_time,
                          mask_filepath=args.maskfile)
Exemplo n.º 2
0
def main():
    parser.description = 'Whitenoise (50%) stimulus generator.'
    parser.add_argument(
        '--debug',
        action='store_true',
        help='display sequential numbers on DMD to debug sequence and saving')
    args = parser.parse_args()
    run_presentations(args.nframes,
                      args.savefile,
                      generate_whitenoise_sequence,
                      file_overwrite=args.overwrite,
                      seq_debug=args.debug,
                      picture_time=args.pic_time,
                      mask_filepath=args.maskfile,
                      image_scale=args.scale)
Exemplo n.º 3
0
def main():
    parser.description = 'Sparsenoise stimulus generator.'
    parser.add_argument(
        'fraction_on',
        type=float,
        help='fraction of pixels on per presentation frame (between 0 and 1)')
    args = parser.parse_args()
    frac = args.fraction_on
    if frac > 1. or frac < 0.:
        errst = 'Fraction argument must be between 0 and 1.'
        raise ValueError(errst)
    else:
        generate_sparsenoise_sequences = sparsenoise_function_generator(frac)
        run_presentations(args.nframes,
                          args.savefile,
                          generate_sparsenoise_sequences,
                          file_overwrite=args.overwrite,
                          seq_debug=False,
                          image_scale=args.scale,
                          picture_time=args.pic_time,
                          mask_filepath=args.maskfile)
Exemplo n.º 4
0
    seq_array[:] *= mask  # mask is 1 in areas we want to stimulate and 0 otherwise. This is faster than alternatives.


def main():
    parser.description = 'Whitenoise (50%) stimulus generator.'
    parser.add_argument(
        '--debug',
        action='store_true',
        help='display sequential numbers on DMD to debug sequence and saving')
    args = parser.parse_args()
    run_presentations(args.nframes,
                      args.savefile,
                      generate_whitenoise_sequence,
                      file_overwrite=args.overwrite,
                      seq_debug=args.debug,
                      picture_time=args.pic_time,
                      mask_filepath=args.maskfile,
                      image_scale=args.scale)


if __name__ == '__main__':
    pth = r"D:\patters\test22.h5"
    mskfile = r"D:\patters\mouse_11103\sess_001\mask.npy"
    run_presentations(1 * 10**6,
                      pth,
                      generate_whitenoise_sequence,
                      file_overwrite=False,
                      picture_time=10 * 1000,
                      mask_filepath=mskfile,
                      image_scale=8)
Exemplo n.º 5
0
    else:
        generate_sparsenoise_sequences = sparsenoise_function_generator(frac)
        run_presentations(args.nframes,
                          args.savefile,
                          generate_sparsenoise_sequences,
                          file_overwrite=args.overwrite,
                          seq_debug=False,
                          image_scale=args.scale,
                          picture_time=args.pic_time,
                          mask_filepath=args.maskfile)


if __name__ == '__main__':
    import os
    d = r"D:"
    pth = os.path.join(d, 'test.h5')
    # mskfile = os.path.join(d, 'mask.npy')
    mskfile = r"D:\patters\mouse_11113\sess_001\mask.npy"
    if os.path.exists(d) and os.path.exists(
            mskfile) and not os.path.exists(pth):
        generate_sparsenoise_sequences = sparsenoise_function_generator(.005)
        run_presentations(.7 * 10**6,
                          pth,
                          file_overwrite=False,
                          seq_debug=False,
                          picture_time=10 * 1000,
                          mask_filepath=mskfile)
    elif not os.path.exists(mskfile):
        raise FileNotFoundError('Mask file not found ({})'.format(mskfile))
    elif os.path.exists(pth):
        raise FileExistsError("Patterns file already exists {}.".format(pth))