Ejemplo n.º 1
0
    for key in electrodes_read_area.keys():
        if electrodes_read_area[key] == electrodes_read_area[1]:
            electrodes_area = electrodes_read_area[1]
        else:
            electrodes = None
            print("Electrode mismatch in ERP data files")
            break

    electrode_indices = select_electrodes(
        parameters["hemispheres"], parameters["sites"], parameters["locations"], electrodes_area
    )[4]

    for key1 in ERP_area.keys():
        for key2 in ERP_area[key1].keys():
            # NOTE: Copy is done inside perform_scaling
            ERP_area_scaled[key1][key2] = perform_scaling(ERP_area[key1][key2], electrode_indices)
            # TODO: This should be done as a unit test probably
            if test_scaling(ERP_area_scaled[key1][key2], electrode_indices):
                print("A problem with scaling has been detected")


if parameters["todo_test_assumptions_data"]:
    print("Performing assumption tests on ERP data")

    # This is temporary, but works
    data1 = ERP_area["old"]["300-500"]
    data2 = ERP_area["new"]["300-500"]

    test_assumptions(
        parameters["hemispheres"],
        parameters["sites"],
Ejemplo n.º 2
0
    def run(self, run_generators=True, run_noise=True, run_reference=True):
        smallest_p = create_scaled_data_structure([])
        sig_p_count = create_scaled_data_structure(0)
        sig_p_count_interaction = create_scaled_data_structure(0)

        for simulation_number in range(self.number_of_simulations):
            if run_generators:
                if simulation_number == 0 or self.configuration == 'random':
                    gen_conf_1 = self.condition_1_gen_conf()
                    gen_conf_2 = self.condition_2_gen_conf(gen_conf_1)
                
                if self.configuration == 'uandk':
                    gen_conf_1 = [{'depth': 7.0,\
                                   'magnitude': -1050.0,\
                                   'orientation': 0.0,\
                                   'orientation_phi':  0.0,\
                                   'phi': -0.65,\
                                   'theta': 0.6}]
                    #print('Ran from here')
                    [gen_conf_1, magnitude_stddev] =\
                            scale_generator_configuration(gen_conf_1, 3.5, 2)
                    #print('STOP')
                    #print('HUUUUUGE FAILLLL!')
                    #print magnitude_stddev
                    gen_conf_2 = self.condition_2_gen_conf(gen_conf_1)
                    
                if simulation_number == 0 or self.configuration == 'random' or \
                   self.generator_magnitude_stddev != 0:
                    [simulated_gen_1, gen_conf_1, simulated_gen_2, gen_conf_2, 
                     electrodes] = self.simulate_sources(gen_conf_1, gen_conf_2)
                    self.electrodes = electrodes
            else:
                simulated_gen_1 = deepcopy(self.simulated_gen_1[simulation_number])
                simulated_gen_2 = deepcopy(self.simulated_gen_2[simulation_number])
                gen_conf_1 = deepcopy(self.gen_conf_1[simulation_number])
                gen_conf_2 = deepcopy(self.gen_conf_2[simulation_number])
            
            simulated_data_1 = deepcopy(simulated_gen_1)
            simulated_data_2 = deepcopy(simulated_gen_2)
            
            if run_noise:
                [normal_noise_1, topographic_noise_1, 
                 normal_noise_2, topographic_noise_2, constant_noise] =\
                        self.simulate_noise(simulated_gen_1.shape)
            else:
                normal_noise_1 = deepcopy(self.normal_noise_1[simulation_number])
                normal_noise_2 = deepcopy(self.normal_noise_2[simulation_number])
                topographic_noise_1 = deepcopy(self.topographic_noise_1[simulation_number])
                topographic_noise_2 = deepcopy(self.topographic_noise_2[simulation_number])
                constant_noise = deepcopy(self.constant_noise[simulation_number])

            if normal_noise_1 != None and normal_noise_2 != None:
                simulated_data_1 += normal_noise_1 
                simulated_data_2 += normal_noise_2
            
            if constant_noise != None:
                simulated_data_1 += constant_noise
                simulated_data_2 += constant_noise

            if topographic_noise_1 != None and topographic_noise_2 != None:
                simulated_data_1 += topographic_noise_1 
                simulated_data_2 += topographic_noise_2  

            if run_reference and self.reference != 'none':
                [simulated_data_1, simulated_data_2] =\
                        self.rereference(simulated_data_1, simulated_data_2, 
                                         self.electrodes)

            electrode_indices = select_electrodes(self.hemispheres, 
                                                  self.sites, 
                                                  self.locations,
                                                  self.electrodes)[4]
            simulated_data_1_scaled = perform_scaling(simulated_data_1,
                                                      electrode_indices)
            simulated_data_2_scaled = perform_scaling(simulated_data_2,
                                                      electrode_indices)
            self.electrode_indices = electrode_indices
            
            anova_results_scaled = \
                create_scaled_data_structure(None)

            [anova_results, electrode_indices] = \
                run_anova(self.hemispheres, self.sites, 
                          self.locations, simulated_data_1,
                          simulated_data_2, self.electrodes,
                          self.doElectrodesAsFactor, printResults=False,
                          name='testu_sim')
            p = self.find_smallest_interaction_p(anova_results)
            smallest_p['Unrescaled'].append(p)
            if p < 0.05:
                found_interaction_on_unrescaled = True
                sig_p_count['Unrescaled'] += 1
            else:
                found_interaction_on_unrescaled = False
            
            for key1 in anova_results_scaled.keys():
                if key1 == 'Unrescaled':
                    break
                for key2 in anova_results_scaled[key1].keys():
                    for key3 in anova_results_scaled[key1][key2].keys():
                        anova_results_scaled[key1][key2][key3] = \
                            run_anova(self.hemispheres, self.sites, 
                                      self.locations,
                                      simulated_data_1_scaled[key1][key2][key3],
                                      simulated_data_2_scaled[key1][key2][key3],
                                      self.electrodes, self.doElectrodesAsFactor,
                                      printResults=False,
                                      name='testu_sim_scaled')[0]
                        p = self.find_smallest_interaction_p\
                                (anova_results_scaled[key1][key2][key3])
                        smallest_p[key1][key2][key3].append(p)
                        if p <0.05:
                            sig_p_count[key1][key2][key3] += 1
                            if found_interaction_on_unrescaled:
                                sig_p_count_interaction[key1][key2][key3] += 1
            
            if self.collect:
                if len(self.gen_conf_1) == self.number_of_simulations:
                    self.gen_conf_1[simulation_number] = gen_conf_1
                    self.gen_conf_2[simulation_number] = gen_conf_2
                    self.simulated_gen_1[simulation_number] = simulated_gen_1
                    self.simulated_gen_2[simulation_number] = simulated_gen_2
                    self.normal_noise_1[simulation_number] = normal_noise_1
                    self.normal_noise_2[simulation_number] = normal_noise_2
                    self.constant_noise[simulation_number] = constant_noise
                    self.topographic_noise_1[simulation_number] = topographic_noise_1
                    self.topographic_noise_2[simulation_number] = topographic_noise_2
                    self.simulated_data_1[simulation_number] = simulated_data_1
                    self.simulated_data_2[simulation_number] = simulated_data_2
                    if self.electrodes == None:
                        self.electrodes = electrodes
                    self.sig_p_count[simulation_number] = sig_p_count
                    self.sig_p_count_interaction[simulation_number] = sig_p_count_interaction
                if not (len(self.gen_conf_1) == self.number_of_simulations):
                    self.gen_conf_1.append(gen_conf_1)
                    self.gen_conf_2.append(gen_conf_2)
                    self.simulated_gen_1.append(simulated_gen_1)
                    self.simulated_gen_2.append(simulated_gen_2)
                    self.normal_noise_1.append(normal_noise_1)
                    self.normal_noise_2.append(normal_noise_2)
                    self.constant_noise.append(constant_noise)
                    self.topographic_noise_1.append(topographic_noise_1)
                    self.topographic_noise_2.append(topographic_noise_2)
                    self.simulated_data_1.append(simulated_data_1)
                    self.simulated_data_2.append(simulated_data_2)
                    if self.electrodes == None:
                        self.electrodes = electrodes
                    self.sig_p_count.append(sig_p_count)
                    self.sig_p_count_interaction.append(sig_p_count_interaction)
        
        self.print_stats(sig_p_count, sig_p_count_interaction)
        
        return [simulated_data_1, simulated_data_2, simulated_data_1_scaled,
                simulated_data_2_scaled, gen_conf_1, gen_conf_2, smallest_p,
                sig_p_count, topographic_noise_1, topographic_noise_2,
                constant_noise]