Exemplo n.º 1
0
def main():
    """The program."""
    parser = OptionParser(usage="%prog [-n SAMPLING] ROTATIONS_FILE OUTPUT_FILE")
    parser.add_option("-n", action="store", dest="n", type="int", default=None,
                      help="Density of sphere sampling if different from the rotation sampling.")
    parser.add_option("-w", action="store_false", dest="use_weights", help="Use weights.")
    options, args = parser.parse_args()

    rotations_file = args[0]
    output_file = args[1]

    quaternions, weights = read_rotations(rotations_file)

    if options.n is None:
        number_of_rotations = len(quaternions)
        n_sampling = rotations.rots_to_n(number_of_rotations)
    else:
        n_sampling = options.n

    if not options.use_weights:
        weights = None

    table, table_weights = calculate_table(n_sampling, quaternions, weights)

    save_table(output_file, table, table_weights)
Exemplo n.º 2
0
def main():
    """The program."""
    parser = OptionParser(
        usage="%prog [-n SAMPLING] ROTATIONS_FILE OUTPUT_FILE")
    parser.add_option(
        "-n",
        action="store",
        dest="n",
        type="int",
        default=None,
        help=
        "Density of sphere sampling if different from the rotation sampling.")
    parser.add_option("-w",
                      action="store_false",
                      dest="use_weights",
                      help="Use weights.")
    options, args = parser.parse_args()

    rotations_file = args[0]
    output_file = args[1]

    quaternions, weights = read_rotations(rotations_file)

    if options.n is None:
        number_of_rotations = len(quaternions)
        n_sampling = rotations.rots_to_n(number_of_rotations)
    else:
        n_sampling = options.n

    if not options.use_weights:
        weights = None

    table, table_weights = calculate_table(n_sampling, quaternions, weights)

    save_table(output_file, table, table_weights)
Exemplo n.º 3
0
 def get_single_rotation_values(self, iteration, image_number):
     """Get the rotation distribution of a single image"""
     self.check_ready()
     try:
         resp_handle = h5py.File('output/responsabilities_%.4d.h5' % iteration)
         resp = resp_handle['data'][image_number, :]
         resp_handle.close()
     except IOError:
         self.read_error.emit()
     if len(resp) != self._number_of_rotations:
         self._number_of_rotations = len(resp)
         self._rotations_n = rotations.rots_to_n(self._number_of_rotations)
         self.properties_changed.emit()
     self._rotation_sphere_bins[:] = 0.
     for i, resp in enumerate(resp):
         self._rotation_sphere_bins[self._rotation_mapping_table[i]] += resp
     self._rotation_sphere_bins[self._rotation_sphere_good_indices] /= \
         self._rotation_sphere_weights[self._rotation_sphere_good_indices]
     return self._rotation_sphere_bins
Exemplo n.º 4
0
 def get_average_rotation_values(self, iteration):
     """Get the average rotation distribution of all images"""
     self.check_ready()
     try:
         #average_resp = loadtxt('output/average_resp_%.4d.data' % iteration)
         average_resp = self._read_average_resp(iteration)
     except IOError:
         self.read_error.emit()
         return self._rotation_sphere_bins
     if len(average_resp) != self._number_of_rotations:
         self._number_of_rotations = len(average_resp)
         self._rotations_n = rotations.rots_to_n(self._number_of_rotations)
         self.properties_changed.emit()
     self._rotation_sphere_bins[:] = 0.
     for i, resp in enumerate(average_resp):
         self._rotation_sphere_bins[self._rotation_mapping_table[i]] += resp
     self._rotation_sphere_bins[self._rotation_sphere_good_indices] /= \
         self._rotation_sphere_weights[self._rotation_sphere_good_indices]
     #return float32(self._rotation_sphere_weights) # debug line
     return self._rotation_sphere_bins
Exemplo n.º 5
0
    def setup_rotations(self):
        """Read the appropriate quaternion list and calculate a table for projecting."""
        self._number_of_rotations = len(self._read_average_resp(0))
        self._rotations_n = rotations.rots_to_n(self._number_of_rotations)

        if self._rotation_sphere_coordinates is None:
            raise RuntimeError("Must call set_sampling_coordinates before setting up rotations")

        filename = "{directory}/data/rotations_table_n{n}.h5".format(directory=os.path.split(__file__)[0], n=self._rotations_n)
        print filename
        with h5py.File(filename, "r") as file_handle:
            self._rotation_sphere_weights = file_handle['weights'][...]
            self._rotation_mapping_table = file_handle['table'][...]

        self._rotation_sphere_good_indices = self._rotation_sphere_weights > 0.

        self._number_of_bins = len(self._rotation_sphere_weights)
        self._rotation_sphere_bins = numpy.zeros(self._number_of_bins)

        self._setup_done = True