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.
43 changes: 43 additions & 0 deletions mkgu_packaging/dicarlo/marques/marques_devalois1982a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

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

ASSEMBLY_NAME = 'devalois.DeValois1982a'
ORIENTATION_STIM_NAME = 'dicarlo.Marques2020_orientation'


def collect_data():
# Preferred orientation data
preferred_orientation_hist = np.array([77, 49, 66, 54])
preferred_orientation_bins = np.linspace(-22.5, 157.5, 5)

preferred_orientation = gen_sample(preferred_orientation_hist, preferred_orientation_bins, scale='linear')

# Create DataAssembly with single neuronal properties and bin information
assembly = DataAssembly(preferred_orientation, coords={'neuroid_id': ('neuroid',
range(preferred_orientation.shape[0])),
'region': ('neuroid', ['V1'] * preferred_orientation.shape[0]),
'neuronal_property': ['preferred_orientation']},
dims=['neuroid', 'neuronal_property'])

assembly.attrs['number_of_trials'] = 20

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

return assembly


def main():
assembly = collect_data()
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.contrib')


if __name__ == '__main__':
main()

47 changes: 47 additions & 0 deletions mkgu_packaging/dicarlo/marques/marques_devalois1982b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

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

ASSEMBLY_NAME = 'devalois.DeValois1982b'
SPATIAL_FREQUENCY_STIM_NAME = 'dicarlo.Marques2020_spatial_frequency'


def collect_data():
# Peak spatial frequency data
peak_spatial_frequency_bins = np.array([0.35, 0.5, 0.7, 1.0, 1.4, 2.0, 2.8, 4.0, 5.6, 8.0, 11.2, 16.0, 22.4])
peak_spatial_frequency_simple_hist = np.array([0, 4, 4, 8, 25, 33, 26, 28, 12, 5, 2, 1])
peak_spatial_frequency_complex_hist = np.array([0, 0, 0, 9, 9, 7, 10, 23, 12, 8, 3, 3])
peak_spatial_frequency_hist = (peak_spatial_frequency_simple_hist + peak_spatial_frequency_complex_hist)

peak_spatial_frequency = gen_sample(peak_spatial_frequency_hist, peak_spatial_frequency_bins, scale='log2')

# Create DataAssembly with single neuronal properties and bin information
assembly = DataAssembly(peak_spatial_frequency, coords={'neuroid_id': ('neuroid',
range(peak_spatial_frequency.shape[0])),
'region': ('neuroid', ['V1'] *
peak_spatial_frequency.shape[0]),
'neuronal_property': ['peak_spatial_frequency']},
dims=['neuroid', 'neuronal_property'])

assembly.attrs['number_of_trials'] = 20

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

return assembly


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


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_receptive_field'
ORIENTATION_STIM_NAME = 'dicarlo.Marques2020_orientation'
SF_STIM_NAME = 'dicarlo.Marques2020_spatial_frequency'
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()
94 changes: 94 additions & 0 deletions mkgu_packaging/dicarlo/marques/marques_ringach2002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

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 = 'shapley.Ringach2002'
ORIENTATION_STIM_NAME = 'dicarlo.Marques2020_orientation'

PROPERTY_NAMES = ['baseline', 'max_dc', 'min_dc', 'max_ac', 'modulation_ratio', 'circular_variance', 'bandwidth',
mschrimpf marked this conversation as resolved.
Show resolved Hide resolved
'orthogonal_preferred_ratio', 'orientation_selective', 'circular_variance_bandwith_ratio',
'orthogonal_preferred_ratio_circular_variance_difference',
'orthogonal_preferred_ratio_bandwith_ratio']


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]

max_dc = or_data['maxdc'][0, 0].T
min_dc = or_data['mindc'][0, 0].T
max_ac = or_data['maxfirst'][0, 0].T
modulation_ratio = max_ac / max_dc

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

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

# Orientation tuning properties covariances
circular_variance_bandwith_ratio = circular_variance / bandwidth
orthogonal_preferred_ratio_circular_variance_difference = orthogonal_preferred_ratio - circular_variance
orthogonal_preferred_ratio_bandwith_ratio = orthogonal_preferred_ratio/bandwidth

# Bins
max_dc_bins = np.logspace(0, 3, 10, base=10)
max_ac_bins = np.logspace(0, 3, 10, base=10)
min_dc_bins = np.logspace(-1-1/3, 2, 11, base=10)
baseline_bins = np.logspace(-1-1/3, 2, 11, base=10)
modulation_ratio_bins = np.linspace(0, 2, 11)

circular_variance_bins = np.linspace(0, 1, num=14)
bandwidth_bins = np.linspace(0, 90, num=18)
orthogonal_preferred_ratio_bins = np.linspace(0, 1, num=14)
orientation_selective_bins = np.linspace(0, 1, num=3)

circular_variance_bandwith_ratio_bins = np.logspace(-3, 0, num=16, base=10)
orthogonal_preferred_ratio_bandwith_ratio_bins = np.logspace(-3, 0, num=16, base=10)
orthogonal_preferred_ratio_circular_variance_difference_bins = np.linspace(-1, 1, num=20)

# Create DataAssembly with single neuronal properties and bin information
assembly = np.concatenate((baseline, max_dc, min_dc, max_ac, modulation_ratio, circular_variance, bandwidth,
orthogonal_preferred_ratio, orientation_selective,
circular_variance_bandwith_ratio,
orthogonal_preferred_ratio_circular_variance_difference,
orthogonal_preferred_ratio_bandwith_ratio), axis=1)

# Filters neurons with weak responses
good_neuroids = max_dc > 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.contrib')


if __name__ == '__main__':
main()

54 changes: 54 additions & 0 deletions mkgu_packaging/dicarlo/marques/marques_schiller1976c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

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

ASSEMBLY_NAME = 'schiller.Schiller1976c'
SPATIAL_FREQUENCY_STIM_NAME = 'dicarlo.Marques2020_spatial_frequency'


def collect_data():
# Spatial frequency bandwidth data
spatial_frequency_bandwidth_bins = np.linspace(0, 100, num=11)
spatial_frequency_bandwidth_simple_hist = np.array([0, 0, 0, 6, 5, 10, 7, 2, 0, 0])
spatial_frequency_bandwidth_complex_hist = np.array([0, 3, 4, 10, 17, 6, 2, 1, 0, 0])
spatial_frequency_bandwidth_hist = (spatial_frequency_bandwidth_simple_hist +
spatial_frequency_bandwidth_complex_hist)
spatial_frequency_bandwidth = gen_sample(spatial_frequency_bandwidth_hist, spatial_frequency_bandwidth_bins,
scale='linear')
# Spatial frequency selective data
spatial_frequency_selective_bins = np.linspace(0, 1, num=3)
spatial_frequency_selective_hist = np.array([14, spatial_frequency_bandwidth_hist.sum()])
spatial_frequency_selective = np.concatenate((np.zeros(spatial_frequency_selective_hist[0]),
np.ones(spatial_frequency_selective_hist[1]))).reshape((-1,1))

# Create DataAssembly with single neuronal properties and bin information
assembly = np.concatenate((spatial_frequency_bandwidth, spatial_frequency_selective), axis=1)

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

assembly.attrs['number_of_trials'] = 20

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

return assembly


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


if __name__ == '__main__':
main()

Loading