def format_data(self, data): """ This accepts data input in the form: ***** (observation) ***** {"density": {"mean": "XX 1000/mm3", "std": "YY 1000/mm3"}} ***** (prediction) ***** {"density": {"value": "ZZ 1000/mm3"}} It splits the values of mean, std, value to numeric quantities and their units (via quantities package). """ for key, val in data["density"].items(): try: quantity_parts = val.split(" ") number = float(quantity_parts[0]) units_str = " ".join(quantity_parts[1:]) assert (units_str == self.units.symbol) data["density"][key] = quantities.Quantity(number, self.units) except AssertionError: raise sciunit.Error( "Values not in appropriate format. Required units: ", self.units.symbol) except: raise sciunit.Error("Values not in appropriate format.") return data
def format_data(self, data): """ This accepts data input in the form: ***** (observation) ***** {'Layer 1': {'height': {'mean': 'X0 um', 'std': 'Y0 um'}}, 'Layer 2/3': {'height': {'mean': 'X1 um', 'std': 'Y1 um'}}, ... } ***** (prediction) ***** { 'Layer 1': {'height': {'value': 'X0 um'}}, 'Layer 2/3': {'height': {'value': 'X1 um'}}, ... } and splits the values of mean and std to numeric quantities and their units (via quantities package). """ for key0 in data.keys(): for key, val in data[key0]["height"].items(): try: quantity_parts = val.split(" ") number = float(quantity_parts[0]) units_str = " ".join(quantity_parts[1:]) assert (units_str == self.units.symbol) data[key0]["height"][key] = quantities.Quantity( number, self.units) except AssertionError: raise sciunit.Error( "Values not in appropriate format. Required units: ", self.units.symbol) except: raise sciunit.Error("Values not in appropriate format.") return data
def format_data(self, data): """ This accepts data input in the form: ***** (observation) ***** list of Nunit neo.SpikeTrains with annotations 'exc', 'inh' ***** (prediction) ***** list of Nunit neo.SpikeTrains with annotations 'exc', 'inh' """ neu_types = [] for st in data: try: # neo SpikeTrains? assert type(st) is neo.core.spiketrain.SpikeTrain except: raise sciunit.Error("List elements are not " + "neo.core.spiketrain.SpikeTrains.") try: # has neu_type annotations? assert 'neu_type' in st.annotations except: raise sciunit.Error("SpikeTrain has no neu_type annotation.") neu_types.append(st.annotations['neu_type']) neu_types = set(neu_types) try: assert any('exc' == s for s in neu_types) except: raise sciunit.Error("There are no exc units.") try: assert any('inh' == s for s in neu_types) except: raise sciunit.Error("There are no inh units.") pass
def format_data(self, data): """ This accepts data input in the form: ***** (observation) ***** {"cell_kind": { "cell_part_1": {'morph_feature_name_11': {'mean value': 'X11_mean units_str', 'std': 'X11_std units_str'}, 'morph_feature_name_12': {'mean value': 'X12_mean units_str', 'std': 'X12_std units_str'}, ... }, "cell_part_2": {'morph_feature_name_21': {'mean value': 'X21_mean units_str', 'std': 'X21_std units_str'}, 'morph_feature_name_22': {'mean value': 'X22_mean units_str', 'std': 'X22_std units_str'}, ... }, ... } } ***** (prediction) ***** {"cell1_ID": { 'cell_part_1': {'morph_feature_name_11': {'value': 'X11 units_str'}, 'morph_feature_name_12': {'value': 'X12 units_str'}, ... }, 'cell_part_2': {'morph_feature_name_21': {'value': 'X21 units_str'}, 'morph_feature_name_22': {'value': 'X22 units_str'}, ... }, ... } "cell2_ID": { 'cell_part_1': {'morph_feature_name_11': {'value': 'Y11 units_str'}, 'morph_feature_name_12': {'value': 'Y12 units_str'}, ... }, 'cell_part_2': {'morph_feature_name_21': {'value': 'Y21 units_str'}, 'morph_feature_name_22': {'value': 'Y22 units_str'}, ... }, ... } ... } It splits the values of mean, std and value to numeric quantities and their units (via quantities package) """ dim_non = ['order', 'number', 'asymmetry', 'rate'] dim_um = ['radii', 'length', 'distance', 'extent'] dim_umSq = ['area'] dim_umCb = ['volume'] dim_deg = ['angle'] for dict1 in data.values( ): # Dict. with cell's part-features dictionary pairs for each cell for dict2 in dict1.values( ): # Dict. with feature name-value pairs for each cell part: # neuron, apical_dendrite, basal_dendrite or axon for dict3 in dict2.values( ): # Dict. with 'value', 'mean' and 'std' values for key, val in dict3.items(): quantity_parts = val.split() number, units_str = float(quantity_parts[0]), " ".join( quantity_parts[1:]) try: if any(sub_str in key for sub_str in dim_um): assert (units_str == quantities.um | units_str == quantities.mm), \ sciunit.Error("Values not in appropriate format. Required units: mm or um") elif any(sub_str in key for sub_str in dim_non): assert (units_str == quantities.dimensionless), \ sciunit.Error("Values not in appropriate format. Required units: ", quantities.dimensionless) finally: dict3[key] = quantities.Quantity(number, units_str) return data
def validate_observation(self, observation): # Checking format of the observation data for dict1 in observation.values( ): # Dict. with cell's part-features dictionary pairs for each cell for dict2 in dict1.values( ): # Dict. with feature name-value pairs for each cell part: # neuron, apical_dendrite, basal_dendrite or axon for dict3 in dict2.values( ): # Dict. with 'value' or 'mean' and 'std' values for val in dict3.values(): assert type(val) is quantities.Quantity, \ sciunit.Error(("Observation must be of the form " "{'mean': 'XX units_str','std': 'YY units_str'}"))
def format_data(self, data): """ This accepts data input in the form: ***** (observation) ***** { "AA":{ "SO": {"mean": "X0"}, "SP": {"mean": "X1"}, "SR": {"mean": "X2"}, "SLM":{"mean": "X3"} }, "BP": {...}, "BS": {...}, "CCKBC":{...}, "Ivy":{...}, "OLM":{...}, "PC":{...}, "PPA":{...}, "SCA":{...}, "Tri":{...} } ***** (prediction) ***** { "AA":{ "SO": {"value": "X0"}, "SP": {"value": "X1"}, "SR": {"value": "X2"}, "SLM":{"value": "X3"}, "OUT":{"value": "X4"} }, "BP": {...}, "BS": {...}, "CCKBC":{...}, "Ivy":{...}, "OLM":{...}, "PC":{...}, "PPA":{...}, "SCA":{...}, "Tri":{...} } Returns a new dictionary of the form { "AA":[X0, X1, X2, X3, X4], "BP":[...] , "BS":[...], "CCKBC":[...], "Ivy":[...], "OLM":[...], "PC":[...], "PPA":[...], "SCA":[...], "Tri":[...] } """ data_new_dict = dict() for key0, dict0 in data.items( ): # dict0: a dictionary containing the synapses fraction in each of the # Hippocampus CA1 layers (SO, SP, SR, SLM) and OUT (for prediction data only) # for each m-type cell (AA, BP, BS, CCKBC, Ivy, OLM, PC, PPA, SCA, Tri) data_list_1 = list() for dict1 in dict0.values(): # dict1: a dictionary of the form # {"mean": "X0"} (observation) or {"value": "X"} (prediction) try: synapses_fraction = float(dict1.values()[0]) assert (synapses_fraction <= 1.0) data_list_1.extend([synapses_fraction]) except: raise sciunit.Error( "Values not in appropriate format. Synapses fraction of an m-type cell" "must be dimensionless and not larger than 1.0") if "OUT" not in dict0.keys(): data_list_1.extend([0.0]) # observation data data_list_1_q = quantities.Quantity(data_list_1, self.units) data_new_dict[key0] = data_list_1_q return data_new_dict