def _compute_Q4_matrix(self, divisions):
     """
     Computes Q4 matrix
     """
     self.divide_in_circles(divisions)
     subdivision = self._actual_subdivision
     Q4_subsystems = []
     for subsystem_ in subdivision:
             subsystem = methods.decompress_state(subsystem_)
             Q4 = [subsystem.center[0], subsystem.center[1]]
             Q4.append(subsystem.Q4)
             Q4_subsystems.append(methods.compress_state(Q4))
     return Q4_subsystems
 def _create_subgroups_matrix(self, divisions):
     """
         Put subsystems in a matrix form.
     """
     if divisions != self._divisions:
         self._reset()
     if not len(self._subdivision_centers):
         self.divide_in_circles(divisions)
         act_sub = self._actual_subdivision
         actual_y = methods.decompress_state(act_sub[0]).center[1]
         row = []
         subgroups_matrix = []
         for index in range(len(act_sub)):
             element = methods.decompress_state(act_sub[index])
             element_y = element.center[1]
             if element_y != actual_y:
                 subgroups_matrix.append(row)
                 row = []
                 actual_y = element_y
             row.append(element)
         subgroups_matrix.append(row)
         act_sub = None
         self._subdivision_centers = methods.compress_state(subgroups_matrix)
 def Q2_plot_matrix(self, divisions):
     """
         Returns values for plotting Q2 matrix.
     """
     x_values = []
     y_values = []
     z_values = []
     Q2_subsystems = self._compute_Q2_matrix(divisions)
     for subsystem_ in Q2_subsystems:
         subsystem = methods.decompress_state(subsystem_)
         [x_val, y_val, z_val] = subsystem
         x_values.append(x_val)
         y_values.append(y_val)
         z_values.append(z_val)
     return x_values, y_values, z_values
 def _compute_density_matrix(self, divisions, normalized=False):
     """
         Computes density matrix of the system.
     """
     self.divide_in_circles(divisions)
     density = []
     subdivision = self._actual_subdivision
     for subsystem_ in subdivision:
         subsystem = methods.decompress_state(subsystem_)
         dens = subsystem.density
         if normalized:
             dens /= self.number_of_rods
         subdensity = [subsystem.center[0], subsystem.center[1]]
         subdensity.append(dens)
         density.append(subdensity)
     subdivision = None
     return density
 def subgroups_matrix(self, divisions):
     """
         Returns subgroups matrix
     """
     self._create_subgroups_matrix(divisions)
     return methods.decompress_state(self._subdivision_centers)
def create_rods_with_length(folder="./", length=10, length_error=.3, real_kappas=10,
                radius_correction_ratio=0.1, file_range=[]):
    """
    Create rods using rod length instead of kappa.
    """
    print "--"*(len(inspect.stack())-2)+">"+"["+str(inspect.stack()[1][3])+"]->["+str(inspect.stack()[0][3])+"]: " + "Importing data"
    names = methods.get_file_names(folder=folder)
    if len(file_range) != 0:
        try:
            names = names[file_range[0]:file_range[1]]
        except:
            pass
    num_of_files = len(names)
    if not num_of_files:
        print "No files to import.\n\n"
        raise ValueError
    states = [None for dummy_ in range(num_of_files)]
    processes = []
    states_queue = mp.Queue()
    for index in range(num_of_files):
        process = mp.Process(target=create_rods_with_length_process,
                            args=(length, length_error, real_kappas,
                            radius_correction_ratio, names,
                            index, states_queue))
        processes.append(process)
    num_processes = len(processes)
    running, processes_left = methods.run_processes(processes)
    finished_ = 0
    previous_time = datetime.datetime.now()
    counter = 0
    time_left = None
    times = []
    print " "
    empty_states = []
    while finished_ < num_processes:
        counter += 1
        finished_ += 1
        previous_time, counter, time_left, times = methods.print_progress(finished_, num_processes,
                                counter, times, time_left, previous_time)
        [index, state] = states_queue.get()
        if state is not None:
            states[index] = state
        else:
            empty_states.append(index)
        if len(processes_left):
            new_process = processes_left.pop(0)
            time.sleep(settings.waiting_time)
            new_process.start()
    for process in processes:
        if process.is_alive():
            process.terminate()
    for empty_state in empty_states:
        diff = 1
        while True:
            new_state = empty_state - diff
            if states[new_state] is not None:
                break
            diff += 1
        new_state = methods.decompress_state(states[new_state]).clone
        states[empty_state] = methods.compress_state(new_state)
    print(CURSOR_UP_ONE + ERASE_LINE + CURSOR_UP_ONE)
    return names, states