hats.pixel_math.sparse_histogram#
Sparse 1-D histogram of healpix pixel counts.
Classes#
Wrapper around a naive sparse array, that is just non-zero indexes and counts. |
|
Utility for aggregating sparse histograms. |
Functions#
|
Specialized method for getting a histogram of some supplemental count, |
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)
- to_array()[source]#
Convert the sparse array to a dense numpy array.
- Returns:
- np.ndarray
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.
- Parameters:
- file_namepath-like
intended file to save to
- to_dense_file(file_name)[source]#
Persist the DENSE array to disk as a numpy array.
- Parameters:
- file_namepath-like
intended file to save to
- class HistogramAggregator(order)[source]#
Utility for aggregating sparse histograms.
- supplemental_count_histogram(mapped_pixels, supplemental_count, highest_order)[source]#
Specialized method for getting a histogram of some supplemental count, collating according to the pixels in the first argument.
Typically used during import, when you wish to partition according to some supplemental data, such as in-memory size, or length of a nested column.
- Parameters:
- mapped_pixelsarray_like of int
1-D array of healpix pixel IDs. Values will be aggregated by pixel to produce the row-count histogram.
- supplemental_countNone or array_like of int
Optional 1-D array of supplemental counts (for example per-row memory sizes or nested-column lengths). If
None, no supplemental histogram will be produced and the returned second element will beNone.- highest_orderint
Healpix order used for the histograms.
- Returns:
- tuple
(row_count_histo, supplemental_count_histo)where both elements areSparseHistogram.row_count_histocontains counts of rows per pixel.supplemental_count_histocontains the sum of the supplemental counts per pixel, orNoneifsupplemental_countwasNone.