def create_downsampled_data(params):
maxsamples = <NUM_LIT:1><EOL>for data_type in ['<STR_LIT>','<STR_LIT>']:<EOL><INDENT>if RANK == <NUM_LIT:0>:<EOL><INDENT>if not os.path.isdir(os.path.join(params.savefolder, '<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>os.mkdir((os.path.join(params.savefolder,'<STR_LIT>','<STR_LIT>')))<EOL><DEDENT><DEDENT>COMM.Barrier()<EOL>try:<EOL><INDENT>assert(ana_params.scaling <= params.recordSingleContribFrac)<EOL><DEDENT>except AssertionError as ae:<EOL><INDENT>raise ae('<STR_LIT>')<EOL><DEDENT>samples = int(<NUM_LIT:1.> / ana_params.scaling)<EOL>if samples > maxsamples:<EOL><INDENT>samples = maxsamples<EOL><DEDENT>COUNTER = <NUM_LIT:0><EOL>for j, layer in enumerate(params.y_in_Y): <EOL><INDENT>for k, pop in enumerate(layer): <EOL><INDENT>for i, y in enumerate(pop): <EOL><INDENT>if COUNTER % SIZE == RANK:<EOL><INDENT>fname = os.path.join(params.savefolder, '<STR_LIT>', '<STR_LIT>'% (y, data_type))<EOL>f = h5py.File(fname)<EOL>print('<STR_LIT>' % str(f.filename))<EOL>raw_data = f['<STR_LIT:data>'].value<EOL>srate = f['<STR_LIT>'].value<EOL>f.close()<EOL>N = int(params.N_y[np.array(params.y) == y]*ana_params.scaling)<EOL>try:<EOL><INDENT>assert(N <= raw_data.shape[<NUM_LIT:0>])<EOL><DEDENT>except AssertionError as ae:<EOL><INDENT>raise ae('<STR_LIT>')<EOL><DEDENT>for sample in range(samples): <EOL><INDENT>data = raw_data[sample*N:(sample+<NUM_LIT:1>)*N]<EOL>fname = os.path.join(params.savefolder,'<STR_LIT>','<STR_LIT>',<EOL>'<STR_LIT>'% (y, data_type, ana_params.scaling*<NUM_LIT:100>, sample))<EOL>f = h5py.File(fname, '<STR_LIT:w>')<EOL>print('<STR_LIT>' % str(f.filename))<EOL>f['<STR_LIT:data>'] = data<EOL>f['<STR_LIT>'] = srate<EOL>f.close()<EOL>fname = os.path.join(params.savefolder,'<STR_LIT>','<STR_LIT>',<EOL>'<STR_LIT>'% (y,data_type,ana_params.scaling*<NUM_LIT:100>,sample))<EOL>f = h5py.File(fname, '<STR_LIT:w>')<EOL>print('<STR_LIT>' % str(f.filename))<EOL>f['<STR_LIT:data>'] = data.sum(axis=<NUM_LIT:0>)<EOL>f['<STR_LIT>'] = srate<EOL>f.close()<EOL><DEDENT><DEDENT>COUNTER += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>COMM.Barrier()<EOL>f = h5py.File(os.path.join(params.savefolder,'<STR_LIT>', '<STR_LIT>' % (y,data_type)), '<STR_LIT:r>')<EOL>datashape = f['<STR_LIT:data>'].shape<EOL>f.close()<EOL>COUNTER = <NUM_LIT:0><EOL>for sample in range(samples): <EOL><INDENT>if COUNTER % SIZE == RANK:<EOL><INDENT>data_full = np.zeros(datashape[<NUM_LIT:1>:])<EOL>for j,layer in enumerate(params.y_in_Y): <EOL><INDENT>for k,pop in enumerate(layer): <EOL><INDENT>data_Y = np.zeros(datashape[<NUM_LIT:1>:])<EOL>for i,y in enumerate(pop): <EOL><INDENT>fname = os.path.join(params.savefolder, '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>'% (y, data_type, ana_params.scaling*<NUM_LIT:100>,<EOL>sample))<EOL>f = h5py.File(fname, '<STR_LIT:r>')    <EOL>data_Y += f['<STR_LIT:data>'].value<EOL>srate = f['<STR_LIT>'].value<EOL>f.close()<EOL><DEDENT>fname = os.path.join(params.savefolder,'<STR_LIT>','<STR_LIT>',<EOL>'<STR_LIT>'% (params.Y[<NUM_LIT:2>*j+k], data_type,<EOL>ana_params.scaling*<NUM_LIT:100>, sample))<EOL>f = h5py.File(fname,'<STR_LIT:w>')<EOL>print('<STR_LIT>' % str(f.filename))<EOL>f['<STR_LIT:data>'] = data_Y<EOL>f['<STR_LIT>'] = srate<EOL>f.close() <EOL>data_full += data_Y<EOL><DEDENT><DEDENT>fname = os.path.join(params.savefolder,'<STR_LIT>','<STR_LIT>',<EOL>'<STR_LIT>' % (data_type,ana_params.scaling*<NUM_LIT:100>,sample))<EOL>f = h5py.File(fname,'<STR_LIT:w>')<EOL>print('<STR_LIT>' % str(f.filename))<EOL>f['<STR_LIT:data>'] = data_full<EOL>f['<STR_LIT>'] = srate<EOL>f.close()<EOL><DEDENT>COUNTER += <NUM_LIT:1><EOL><DEDENT>COMM.Barrier()<EOL><DEDENT>
Creates one CSD or LFP file with downsampled data per cell type