hats.pixel_math.sparse_histogram#

Sparse 1-D histogram of healpix pixel counts.

Classes#

SparseHistogram

Wrapper around a naive sparse array, that is just non-zero indexes and counts.

HistogramAggregator

Utility for aggregating sparse histograms.

Module Contents#

class SparseHistogram(indexes, counts, order)[source]#

Wrapper around a naive sparse array, that is just non-zero indexes and counts.

e.g. for a dense 1-d numpy histogram of order 0, you might see:

[0, 4, 0, 0, 0, 0, 0, 0, 9, 0, 0]

There are only elements at [1, 8], and they have respective values [4, 9]. You would create the sparse histogram like:

SparseHistogram([1, 8], [4, 9], 0)
indexes[source]#
counts[source]#
order[source]#
to_array()[source]#

Convert the sparse array to a dense numpy array.

Returns:

dense 1-d numpy array.

to_file(file_name)[source]#

Persist the sparse array to disk.

NB: this saves as a sparse array, and so will likely have lower space requirements than saving the corresponding dense 1-d numpy array.

to_dense_file(file_name)[source]#

Persist the DENSE array to disk as a numpy array.

classmethod from_file(file_name)[source]#

Read sparse histogram from a file.

Returns:

new sparse histogram

class HistogramAggregator(order)[source]#

Utility for aggregating sparse histograms.

order[source]#
full_histogram[source]#
add(other)[source]#

Add in another sparse histogram, updating this wrapper’s array.

Parameters:

other (SparseHistogram) – the wrapper containing the addend

to_sparse()[source]#

Return a SparseHistogram, based on non-zero values in this aggregation.