Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

V1 properties data assemblies and stimulus sets #33

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Empty file.
46 changes: 46 additions & 0 deletions mkgu_packaging/dicarlo/marques/marques_devalois1982a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import numpy as np
import pandas as pd
from marques_utils import gen_sample
from brainio_collection.packaging import package_data_assembly
from brainio_base.assemblies import DataAssembly

DATA_DIR = '/braintree/data2/active/users/tmarques/bs_datasets/or_po_DeValois1982.csv'
ASSEMBLY_NAME = 'dicarlo.Marques_devalois1982a'
mschrimpf marked this conversation as resolved.
Show resolved Hide resolved
ORIENTATION_STIM_NAME = 'dicarlo.Marques2020_orientation'


def collect_data(data_dir):
devalois1982a = pd.read_csv(data_dir, header=None)

# Preferred orientation data
pref_or_hist = np.squeeze(np.fliplr(np.roll(devalois1982a[[1]].values.T, 1)))
pref_or_bins = np.linspace(-22.5, 157.5, 5)

pref_or = gen_sample(pref_or_hist, pref_or_bins)

# Create DataAssembly with single neuronal properties and bin information
assembly = DataAssembly(pref_or, coords={'neuroid_id': ('neuroid', range(pref_or.shape[0])),
'region': ('neuroid', ['V1'] * pref_or.shape[0]),
'neuronal_property': ['pref_or']},
mschrimpf marked this conversation as resolved.
Show resolved Hide resolved
dims=['neuroid', 'neuronal_property'])

assembly.attrs['number_of_trials'] = 20

for p in assembly.coords['properties'].values:
assembly.attrs[p+'_bins'] = eval(p+'_bins')

return assembly


def main():
assembly = collect_data(DATA_DIR)
assembly.name = ASSEMBLY_NAME
print('Packaging assembly')
package_data_assembly(assembly, assembly_identifier=assembly.name, stimulus_set_identifier=ORIENTATION_STIM_NAME,
assembly_class='PropertiyAssembly', bucket_name='brainio.dicarlo')
mschrimpf marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == '__main__':
main()

58 changes: 58 additions & 0 deletions mkgu_packaging/dicarlo/marques/marques_gen_stim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import numpy as np
from mkgu_packaging.dicarlo.marques.marques_stim_common import gen_grating_stim, gen_blank_stim, load_stim_info
from brainio_collection.packaging import package_stimulus_set

BLANK_STIM_NAME = 'dicarlo.Marques2020_blank'
RF_STIM_NAME = 'dicarlo.Marques2020_rf'
mschrimpf marked this conversation as resolved.
Show resolved Hide resolved
ORIENTATION_STIM_NAME = 'dicarlo.Marques2020_orientation'
SF_STIM_NAME = 'dicarlo.Marques2020_sf'
mschrimpf marked this conversation as resolved.
Show resolved Hide resolved
SIZE_STIM_NAME = 'dicarlo.Marques2020_size'

DATA_DIR = '/braintree/data2/active/users/tmarques/bs_stimuli'
DEGREES = 12
SIZE_PX = 672

## All parameters
RF_POS = np.linspace(-2.5, 2.5, 21, endpoint=True)
STIM_POS = np.array([0.5])
RADIUS = np.logspace(-3 + 0.75, 4 - 0.75, 12, endpoint=True, base=2) / 2
SF = np.logspace(-1.5 + 0.125, 4 - 0.125, 22, endpoint=True, base=2)
ORIENTATION = np.linspace(0, 165, 12, endpoint=True)
PHASE = np.linspace(0, 315, 8, endpoint=True)

STIM_NAMES = [RF_STIM_NAME, ORIENTATION_STIM_NAME, SF_STIM_NAME, SIZE_STIM_NAME]

POS_DICT = {RF_STIM_NAME: RF_POS, ORIENTATION_STIM_NAME: STIM_POS, SF_STIM_NAME: STIM_POS, SIZE_STIM_NAME: STIM_POS}
RADIUS_DICT = {RF_STIM_NAME: np.array([1/6]), ORIENTATION_STIM_NAME: np.array([0.25, 0.5, 1]),
SF_STIM_NAME: np.array([0.75, 2.25]), SIZE_STIM_NAME: RADIUS}
SF_DICT = {RF_STIM_NAME: np.array([3]), ORIENTATION_STIM_NAME: np.array([1, 2, 4]), SF_STIM_NAME: SF,
SIZE_STIM_NAME: np.array([1, 2, 4])}
ORIENTATION_DICT = {RF_STIM_NAME: ORIENTATION[[0, 3, 6, 9]], ORIENTATION_STIM_NAME: ORIENTATION,
SF_STIM_NAME: ORIENTATION[[0, 2, 4, 6, 8, 10]], SIZE_STIM_NAME: ORIENTATION[[0, 2, 4, 6, 8, 10]]}
PHASE_DICT = {RF_STIM_NAME: PHASE[[0, 4]], ORIENTATION_STIM_NAME: PHASE, SF_STIM_NAME: PHASE, SIZE_STIM_NAME: PHASE}


def main():
blank_dir = DATA_DIR + os.sep + BLANK_STIM_NAME
if not (os.path.isdir(blank_dir)):
gen_blank_stim(degrees=DEGREES, size_px=448, save_dir=blank_dir)
stimuli = load_stim_info(BLANK_STIM_NAME, blank_dir)
print('Packaging stimuli:' + stimuli.identifier)
package_stimulus_set(stimuli, stimulus_set_identifier=stimuli.identifier, bucket_name='brainio.dicarlo')

for stim_name in STIM_NAMES:
stim_dir = DATA_DIR + os.sep + stim_name
if not (os.path.isdir(stim_dir)):
gen_grating_stim(degrees=DEGREES, size_px=SIZE_PX, stim_name=stim_name, grat_contrast=[1],
grat_pos=POS_DICT[stim_name], grat_rad=RADIUS_DICT[stim_name], grat_sf=SF_DICT[stim_name],
grat_orientation=ORIENTATION_DICT[stim_name], grat_phase=PHASE_DICT[stim_name],
save_dir=stim_dir)
stimuli = load_stim_info(stim_name, stim_dir)
print('Packaging stimuli:' + stimuli.identifier)
package_stimulus_set(stimuli, stimulus_set_identifier=stimuli.identifier, bucket_name='brainio.dicarlo')
return


if __name__ == '__main__':
main()
88 changes: 88 additions & 0 deletions mkgu_packaging/dicarlo/marques/marques_ringach2002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

import numpy as np
from brainio_collection.packaging import package_data_assembly
import scipy.io as sio
from brainio_base.assemblies import DataAssembly

DATA_DIR = '/braintree/data2/active/users/tmarques/bs_datasets/Ringach2002.mat'
ASSEMBLY_NAME = 'dicarlo.Marques2020_Ringach2002'
mschrimpf marked this conversation as resolved.
Show resolved Hide resolved
ORIENTATION_STIM_NAME = 'dicarlo.Marques2020_orientation'
PROPERTY_NAMES = ['baseline', 'maxdc', 'mindc', 'maxac', 'mod_ratio', 'circ_var', 'bandwidth', 'orth_pref_ratio',
'or_sel', 'cv_bw_ratio', 'opr_cv_diff', 'opr_bw_ratio']
mschrimpf marked this conversation as resolved.
Show resolved Hide resolved


def collect_data(data_dir):
ringach2002 = sio.loadmat(data_dir)
or_data = ringach2002['db']

# Response magnitudes
baseline = or_data['spont'][0, 0].T
n_neuroids = baseline.shape[0]

maxdc = or_data['maxdc'][0, 0].T
mindc = or_data['mindc'][0, 0].T
maxac = or_data['maxfirst'][0, 0].T
mod_ratio = maxac / maxdc

# Orientation tuning properties
circ_var = or_data['orivar'][0, 0].T
bandwidth = or_data['bw'][0, 0].T
bandwidth[bandwidth > 90] = np.nan
orth_pref_ratio = or_data['po'][0, 0].T

or_sel = np.ones((n_neuroids, 1))
or_sel[np.isnan(bandwidth)] = 0

# Orientation tuning properties covariances
cv_bw_ratio = circ_var / bandwidth
opr_cv_diff = orth_pref_ratio - circ_var
opr_bw_ratio = orth_pref_ratio/bandwidth

# Bins
maxdc_bins = np.logspace(0, 3, 10, base=10)
maxac_bins = np.logspace(0, 3, 10, base=10)
mindc_bins = np.logspace(-1-1/3, 2, 11, base=10)
baseline_bins = np.logspace(-1-1/3, 2, 11, base=10)
mod_ratio_bins = np.linspace(0, 2, 11)

circ_var_bins = np.linspace(0, 1, num=14)
bandwidth_bins = np.linspace(0, 90, num=18)
orth_pref_ratio_bins = np.linspace(0, 1, num=14)
or_sel_bins = np.linspace(0, 1, num=3)

cv_bw_ratio_bins = np.logspace(-3, 0, num=16, base=10)
opr_bw_ratio_bins = np.logspace(-3, 0, num=16, base=10)
opr_cv_diff_bins = np.linspace(-1, 1, num=20)

# Create DataAssembly with single neuronal properties and bin information
assembly = np.concatenate((baseline, maxdc, mindc, maxac, mod_ratio, circ_var, bandwidth, orth_pref_ratio, or_sel,
cv_bw_ratio, opr_cv_diff, opr_bw_ratio), axis=1)

# Filters neurons with weak responses
good_neuroids = maxdc > baseline + 5
assembly = assembly[np.argwhere(good_neuroids)[:, 0], :]

assembly = DataAssembly(assembly, coords={'neuroid_id': ('neuroid', range(assembly.shape[0])),
'region': ('neuroid', ['V1'] * assembly.shape[0]),
'neuronal_property': PROPERTY_NAMES},
dims=['neuroid', 'neuronal_property'])

assembly.attrs['number_of_trials'] = 40

for p in assembly.coords['neuronal_property'].values:
assembly.attrs[p+'_bins'] = eval(p+'_bins')

return assembly


def main():
assembly = collect_data(DATA_DIR)
assembly.name = ASSEMBLY_NAME
print('Packaging assembly')
package_data_assembly(assembly, assembly_identifier=assembly.name, stimulus_set_identifier=ORIENTATION_STIM_NAME,
assembly_class='PropertyAssembly', bucket_name='brainio.dicarlo')


if __name__ == '__main__':
main()

Loading