Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a naive sparse histogram. #534

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/lsdb/io/to_hats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

import dask
import hats as hc
import hats.pixel_math.healpix_shim as hp
import nested_pandas as npd
import numpy as np
from hats.catalog import PartitionInfo
from hats.catalog.healpix_dataset.healpix_dataset import HealpixDataset as HCHealpixDataset
from hats.pixel_math import HealpixPixel, spatial_index_to_healpix
from hats.pixel_math.sparse_histogram import SparseHistogram
from hats.pixel_math.sparse_histogram import HistogramAggregator, SparseHistogram
from upath import UPath

if TYPE_CHECKING:
Expand Down Expand Up @@ -116,11 +115,11 @@ def to_hats(
)
new_hc_structure.catalog_info.to_properties_file(base_catalog_path)
# Save the point distribution map
full_histogram = np.zeros(hp.order2npix(histogram_order))
total_histogram = HistogramAggregator(histogram_order)
for partition_hist in histograms:
full_histogram += partition_hist.to_array()
total_histogram.add(partition_hist)
point_map_path = hc.io.paths.get_point_map_file_pointer(base_catalog_path)
hc.io.file_io.write_fits_image(full_histogram, point_map_path)
hc.io.file_io.write_fits_image(total_histogram.full_histogram, point_map_path)


def write_partitions(
Expand Down
28 changes: 28 additions & 0 deletions tests/lsdb/catalog/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,34 @@ def test_save_catalog_when_catalog_is_empty(small_sky_order1_catalog, tmp_path):
cone_search_catalog.to_hats(base_catalog_path)


def test_save_big_catalog(tmp_path):
"""Load a catalog with many partitions, and save with to_hats."""
mock_partition_df = pd.DataFrame(
{
"ra": np.linspace(0, 360, 100_000),
"dec": np.linspace(-90, 90, 100_000),
"id": np.arange(100_000, 200_000),
}
)

base_catalog_path = tmp_path / "big_sky"

kwargs = {
"catalog_name": "big_sky",
"catalog_type": "object",
"lowest_order": 6,
"highest_order": 10,
"threshold": 500,
}

catalog = lsdb.from_dataframe(mock_partition_df, margin_threshold=None, **kwargs)

catalog.to_hats(base_catalog_path)

read_catalog = hc.read_hats(base_catalog_path)
assert len(read_catalog.get_healpix_pixels()) == len(catalog.get_healpix_pixels())


def test_save_catalog_with_some_empty_partitions(small_sky_order1_catalog, tmp_path):
base_catalog_path = tmp_path / "small_sky"

Expand Down
Loading