pixel_clusterizer/clusterizer.py
def cluster_hits(self, hits, noisy_pixels=None, disabled_pixels=None):
        ''' Cluster given hit array.

        The noisy_pixels and disabled_pixels parameters are iterables of column/row index pairs, e.g. [[column_1, row_1], [column_2, row_2], ...].
        The noisy_pixels parameter allows for removing clusters that consist of a single noisy pixels. Clusters with 2 or more noisy pixels are not removed.
        The disabled_pixels parameter allows for ignoring pixels.
        '''
        # Jitting a second time to workaround different bahavior of the installation methods on different platforms (pip install vs. python setup.py).
        # In some circumstances, the Numba compiler can't compile functions that were pickled previously.
        self.cluster_functions._end_of_cluster_function = self._jitted(self._end_of_cluster_function)
        self.cluster_functions._end_of_event_function = self._jitted(self._end_of_event_function)

        n_hits = hits.shape[0]  # Set n_hits to new size

        if (n_hits < int(0.5 * self._cluster_hits.size)) or (n_hits > self._cluster_hits.size):
            self._init_arrays(size=int(1.1 * n_hits))  # oversize buffer slightly to reduce allocations
        else:
            self._assigned_hit_array.fill(0)  # The hit indices of the actual cluster, 0 means not assigned
            self._cluster_hit_indices.fill(-1)  # The hit indices of the actual cluster, -1 means not assigned

        self._clusters.dtype.names = self._unmap_cluster_field_names(self._clusters.dtype.names)  # Reset the data fields from previous renaming
        self._cluster_hits.dtype.names = self._unmap_hit_field_names(self._cluster_hits.dtype.names)  # Reset the data fields from previous renaming
        self._check_struct_compatibility(hits)

        # The hit info is extended by the cluster info; this is only possible by creating a new hit info array and copy data
        for field_name in hits.dtype.fields:
            if field_name in self._hit_fields_mapping_inverse:
                cluster_hits_field_name = self._hit_fields_mapping_inverse[field_name]
            else:
                cluster_hits_field_name = field_name
            if cluster_hits_field_name in self._cluster_hits.dtype.fields:
                self._cluster_hits[cluster_hits_field_name][:n_hits] = hits[field_name]

        noisy_pixels_array = np.array([]) if noisy_pixels is None else np.array(noisy_pixels)
        if noisy_pixels_array.shape[0] != 0:
            noisy_pixels_max_range = np.array([max(0, np.max(noisy_pixels_array[:, 0])), max(0, np.max(noisy_pixels_array[:, 1]))])
            noisy_pixels = np.zeros(noisy_pixels_max_range + 1, dtype=np.bool)
            noisy_pixels[noisy_pixels_array[:, 0], noisy_pixels_array[:, 1]] = 1
        else:
            noisy_pixels = np.zeros((0, 0), dtype=np.bool)

        disabled_pixels_array = np.array([]) if disabled_pixels is None else np.array(disabled_pixels)
        if disabled_pixels_array.shape[0] != 0:
            disabled_pixels_max_range = np.array([np.max(disabled_pixels_array[:, 0]), np.max(disabled_pixels_array[:, 1])])
            disabled_pixels = np.zeros(disabled_pixels_max_range + 1, dtype=np.bool)
            disabled_pixels[disabled_pixels_array[:, 0], disabled_pixels_array[:, 1]] = 1
        else:
            disabled_pixels = np.zeros((0, 0), dtype=np.bool)

#         col_dtype = self._cluster_hits.dtype.fields["column"][0]
#         row_dtype = self._cluster_hits.dtype.fields["row"][0]
#         mask_dtype = {"names": ["column", "row"],
#                       "formats": [col_dtype, row_dtype]}
#         noisy_pixels = np.recarray(noisy_pixels_array.shape[0], dtype=mask_dtype)
#         noisy_pixels[:] = [(item[0], item[1]) for item in noisy_pixels_array]
#         disabled_pixels = np.recarray(disabled_pixels_array.shape[0], dtype=mask_dtype)
#         disabled_pixels[:] = [(item[0], item[1]) for item in disabled_pixels_array]

        n_clusters = self.cluster_functions._cluster_hits(  # Set n_clusters to new size
            hits=self._cluster_hits[:n_hits],
            clusters=self._clusters[:n_hits],
            assigned_hit_array=self._assigned_hit_array[:n_hits],
            cluster_hit_indices=self._cluster_hit_indices[:n_hits],
            column_cluster_distance=self._column_cluster_distance,
            row_cluster_distance=self._row_cluster_distance,
            frame_cluster_distance=self._frame_cluster_distance,
            min_hit_charge=self._min_hit_charge,
            max_hit_charge=self._max_hit_charge,
            ignore_same_hits=self._ignore_same_hits,
            noisy_pixels=noisy_pixels,
            disabled_pixels=disabled_pixels)

        self._cluster_hits.dtype.names = self._map_hit_field_names(self._cluster_hits.dtype.names)  # Rename the data fields for the result
        self._clusters.dtype.names = self._map_cluster_field_names(self._clusters.dtype.names)  # Rename the data fields for the result

        return self._cluster_hits[:n_hits], self._clusters[:n_clusters]
def cluster_hits(self, hits, noisy_pixels=None, disabled_pixels=None):
        ''' Cluster given hit array.

        The noisy_pixels and disabled_pixels parameters are iterables of column/row index pairs, e.g. [[column_1, row_1], [column_2, row_2], ...].
        The noisy_pixels parameter allows for removing clusters that consist of a single noisy pixels. Clusters with 2 or more noisy pixels are not removed.
        The disabled_pixels parameter allows for ignoring pixels.
        '''
        # Jitting a second time to workaround different bahavior of the installation methods on different platforms (pip install vs. python setup.py).
        # In some circumstances, the Numba compiler can't compile functions that were pickled previously.
        self.cluster_functions._end_of_cluster_function = self._jitted(self._end_of_cluster_function)
        self.cluster_functions._end_of_event_function = self._jitted(self._end_of_event_function)

        n_hits = hits.shape[0]  # Set n_hits to new size

        if (n_hits < int(0.5 * self._cluster_hits.size)) or (n_hits > self._cluster_hits.size):
            self._init_arrays(size=int(1.1 * n_hits))  # oversize buffer slightly to reduce allocations
        else:
            self._assigned_hit_array.fill(0)  # The hit indices of the actual cluster, 0 means not assigned
            self._cluster_hit_indices.fill(-1)  # The hit indices of the actual cluster, -1 means not assigned

        self._clusters.dtype.names = self._unmap_cluster_field_names(self._clusters.dtype.names)  # Reset the data fields from previous renaming
        self._cluster_hits.dtype.names = self._unmap_hit_field_names(self._cluster_hits.dtype.names)  # Reset the data fields from previous renaming
        self._check_struct_compatibility(hits)

        # The hit info is extended by the cluster info; this is only possible by creating a new hit info array and copy data
        for field_name in hits.dtype.fields:
            if field_name in self._hit_fields_mapping_inverse:
                cluster_hits_field_name = self._hit_fields_mapping_inverse[field_name]
            else:
                cluster_hits_field_name = field_name
            if cluster_hits_field_name in self._cluster_hits.dtype.fields:
                self._cluster_hits[cluster_hits_field_name][:n_hits] = hits[field_name]

        noisy_pixels_array = np.array([]) if noisy_pixels is None else np.array(noisy_pixels)
        if noisy_pixels_array.shape[0] != 0:
            noisy_pixels_max_range = np.array([max(0, np.max(noisy_pixels_array[:, 0])), max(0, np.max(noisy_pixels_array[:, 1]))])
            noisy_pixels = np.zeros(noisy_pixels_max_range + 1, dtype=np.bool)
            noisy_pixels[noisy_pixels_array[:, 0], noisy_pixels_array[:, 1]] = 1
        else:
            noisy_pixels = np.zeros((0, 0), dtype=np.bool)

        disabled_pixels_array = np.array([]) if disabled_pixels is None else np.array(disabled_pixels)
        if disabled_pixels_array.shape[0] != 0:
            disabled_pixels_max_range = np.array([np.max(disabled_pixels_array[:, 0]), np.max(disabled_pixels_array[:, 1])])
            disabled_pixels = np.zeros(disabled_pixels_max_range + 1, dtype=np.bool)
            disabled_pixels[disabled_pixels_array[:, 0], disabled_pixels_array[:, 1]] = 1
        else:
            disabled_pixels = np.zeros((0, 0), dtype=np.bool)

#         col_dtype = self._cluster_hits.dtype.fields["column"][0]
#         row_dtype = self._cluster_hits.dtype.fields["row"][0]
#         mask_dtype = {"names": ["column", "row"],
#                       "formats": [col_dtype, row_dtype]}
#         noisy_pixels = np.recarray(noisy_pixels_array.shape[0], dtype=mask_dtype)
#         noisy_pixels[:] = [(item[0], item[1]) for item in noisy_pixels_array]
#         disabled_pixels = np.recarray(disabled_pixels_array.shape[0], dtype=mask_dtype)
#         disabled_pixels[:] = [(item[0], item[1]) for item in disabled_pixels_array]

        n_clusters = self.cluster_functions._cluster_hits(  # Set n_clusters to new size
            hits=self._cluster_hits[:n_hits],
            clusters=self._clusters[:n_hits],
            assigned_hit_array=self._assigned_hit_array[:n_hits],
            cluster_hit_indices=self._cluster_hit_indices[:n_hits],
            column_cluster_distance=self._column_cluster_distance,
            row_cluster_distance=self._row_cluster_distance,
            frame_cluster_distance=self._frame_cluster_distance,
            min_hit_charge=self._min_hit_charge,
            max_hit_charge=self._max_hit_charge,
            ignore_same_hits=self._ignore_same_hits,
            noisy_pixels=noisy_pixels,
            disabled_pixels=disabled_pixels)

        self._cluster_hits.dtype.names = self._map_hit_field_names(self._cluster_hits.dtype.names)  # Rename the data fields for the result
        self._clusters.dtype.names = self._map_cluster_field_names(self._clusters.dtype.names)  # Rename the data fields for the result

        return self._cluster_hits[:n_hits], self._clusters[:n_clusters]
def cluster_hits ( self , hits , noisy_pixels = None , disabled_pixels = None ) : # Jitting a second time to workaround different bahavior of the installation methods on different platforms (pip install vs. python setup.py). # In some circumstances, the Numba compiler can't compile functions that were pickled previously. self . cluster_functions . _end_of_cluster_function = self . _jitted ( self . _end_of_cluster_function ) self . cluster_functions . _end_of_event_function = self . _jitted ( self . _end_of_event_function ) n_hits = hits . shape [ 0 ] # Set n_hits to new size if ( n_hits < int ( 0.5 * self . _cluster_hits . size ) ) or ( n_hits > self . _cluster_hits . size ) : self . _init_arrays ( size = int ( 1.1 * n_hits ) ) # oversize buffer slightly to reduce allocations else : self . _assigned_hit_array . fill ( 0 ) # The hit indices of the actual cluster, 0 means not assigned self . _cluster_hit_indices . fill ( - 1 ) # The hit indices of the actual cluster, -1 means not assigned self . _clusters . dtype . names = self . _unmap_cluster_field_names ( self . _clusters . dtype . names ) # Reset the data fields from previous renaming self . _cluster_hits . dtype . names = self . _unmap_hit_field_names ( self . _cluster_hits . dtype . names ) # Reset the data fields from previous renaming self . _check_struct_compatibility ( hits ) # The hit info is extended by the cluster info; this is only possible by creating a new hit info array and copy data for field_name in hits . dtype . fields : if field_name in self . _hit_fields_mapping_inverse : cluster_hits_field_name = self . _hit_fields_mapping_inverse [ field_name ] else : cluster_hits_field_name = field_name if cluster_hits_field_name in self . _cluster_hits . dtype . fields : self . _cluster_hits [ cluster_hits_field_name ] [ : n_hits ] = hits [ field_name ] noisy_pixels_array = np . array ( [ ] ) if noisy_pixels is None else np . array ( noisy_pixels ) if noisy_pixels_array . shape [ 0 ] != 0 : noisy_pixels_max_range = np . array ( [ max ( 0 , np . max ( noisy_pixels_array [ : , 0 ] ) ) , max ( 0 , np . max ( noisy_pixels_array [ : , 1 ] ) ) ] ) noisy_pixels = np . zeros ( noisy_pixels_max_range + 1 , dtype = np . bool ) noisy_pixels [ noisy_pixels_array [ : , 0 ] , noisy_pixels_array [ : , 1 ] ] = 1 else : noisy_pixels = np . zeros ( ( 0 , 0 ) , dtype = np . bool ) disabled_pixels_array = np . array ( [ ] ) if disabled_pixels is None else np . array ( disabled_pixels ) if disabled_pixels_array . shape [ 0 ] != 0 : disabled_pixels_max_range = np . array ( [ np . max ( disabled_pixels_array [ : , 0 ] ) , np . max ( disabled_pixels_array [ : , 1 ] ) ] ) disabled_pixels = np . zeros ( disabled_pixels_max_range + 1 , dtype = np . bool ) disabled_pixels [ disabled_pixels_array [ : , 0 ] , disabled_pixels_array [ : , 1 ] ] = 1 else : disabled_pixels = np . zeros ( ( 0 , 0 ) , dtype = np . bool ) #         col_dtype = self._cluster_hits.dtype.fields["column"][0] #         row_dtype = self._cluster_hits.dtype.fields["row"][0] #         mask_dtype = {"names": ["column", "row"], #                       "formats": [col_dtype, row_dtype]} #         noisy_pixels = np.recarray(noisy_pixels_array.shape[0], dtype=mask_dtype) #         noisy_pixels[:] = [(item[0], item[1]) for item in noisy_pixels_array] #         disabled_pixels = np.recarray(disabled_pixels_array.shape[0], dtype=mask_dtype) #         disabled_pixels[:] = [(item[0], item[1]) for item in disabled_pixels_array] n_clusters = self . cluster_functions . _cluster_hits ( # Set n_clusters to new size hits = self . _cluster_hits [ : n_hits ] , clusters = self . _clusters [ : n_hits ] , assigned_hit_array = self . _assigned_hit_array [ : n_hits ] , cluster_hit_indices = self . _cluster_hit_indices [ : n_hits ] , column_cluster_distance = self . _column_cluster_distance , row_cluster_distance = self . _row_cluster_distance , frame_cluster_distance = self . _frame_cluster_distance , min_hit_charge = self . _min_hit_charge , max_hit_charge = self . _max_hit_charge , ignore_same_hits = self . _ignore_same_hits , noisy_pixels = noisy_pixels , disabled_pixels = disabled_pixels ) self . _cluster_hits . dtype . names = self . _map_hit_field_names ( self . _cluster_hits . dtype . names ) # Rename the data fields for the result self . _clusters . dtype . names = self . _map_cluster_field_names ( self . _clusters . dtype . names ) # Rename the data fields for the result return self . _cluster_hits [ : n_hits ] , self . _clusters [ : n_clusters ]
Cluster given hit array.

        The noisy_pixels and disabled_pixels parameters are iterables of column/row index pairs, e.g. [[column_1, row_1], [column_2, row_2], ...].
        The noisy_pixels parameter allows for removing clusters that consist of a single noisy pixels. Clusters with 2 or more noisy pixels are not removed.
        The disabled_pixels parameter allows for ignoring pixels.
Cluster given hit array .