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 radec2pix for healpix pixel calculation. #438

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 6 additions & 10 deletions src/hats_import/catalog/map_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,16 @@ def _iterate_input_file(
else:
# Set up the pixel data
if isinstance(data, pd.DataFrame):
mapped_pixels = hp.ang2pix(
2**highest_order,
mapped_pixels = hp.radec2pix(
highest_order,
data[ra_column].to_numpy(copy=False, dtype=float),
data[dec_column].to_numpy(copy=False, dtype=float),
lonlat=True,
nest=True,
)
else:
mapped_pixels = hp.ang2pix(
2**highest_order,
mapped_pixels = hp.radec2pix(
highest_order,
data[ra_column].to_numpy(),
data[dec_column].to_numpy(),
lonlat=True,
nest=True,
)
yield chunk_number, data, mapped_pixels

Expand Down Expand Up @@ -299,8 +295,8 @@ def reduce_pixel_shards(
SPATIAL_INDEX_COLUMN,
[
pixel_math.compute_spatial_index(
merged_table[ra_column].to_numpy(),
merged_table[dec_column].to_numpy(),
merged_table[ra_column].to_numpy().astype(np.float64),
merged_table[dec_column].to_numpy().astype(np.float64),
)
],
).sort_by(SPATIAL_INDEX_COLUMN)
Expand Down
7 changes: 3 additions & 4 deletions src/hats_import/hipscat_conversion/run_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile
from typing import no_type_check

import hats.pixel_math.healpix_shim as healpix
import healpy as hp
import numpy as np
import pyarrow.parquet as pq
Expand Down Expand Up @@ -128,12 +129,10 @@ def _convert_partition_file(pixel, args, schema, ra_column, dec_column):
0,
"_healpix_29",
[
hp.ang2pix(
2**29,
healpix.radec2pix(
29,
table[ra_column].to_numpy(),
table[dec_column].to_numpy(),
nest=True,
lonlat=True,
)
],
)
Expand Down
6 changes: 2 additions & 4 deletions src/hats_import/margin_cache/margin_cache_map_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ def map_pixel_shards(
f"margin_pixel >= {margin_pixel_range_start} and margin_pixel < {margin_pixel_range_end}"
)

margin_pixel_list = hp.ang2pix(
2**margin_order,
margin_pixel_list = hp.radec2pix(
margin_order,
data[ra_column].values,
data[dec_column].values,
lonlat=True,
nest=True,
)
margin_pixel_filter = pd.DataFrame(
{"margin_pixel": margin_pixel_list, "filter_value": np.arange(0, len(margin_pixel_list))}
Expand Down
6 changes: 2 additions & 4 deletions tests/hats_import/catalog/test_map_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,10 @@ def test_reduce_with_sorting_complex(assert_parquet_file_ids, tmp_path):
file2_data.to_parquet(shard_dir / "file_2_shard_1.parquet")

combined_data = pd.concat([file1_data, file2_data])
combined_data["norder19_healpix"] = hp.ang2pix(
2**19,
combined_data["norder19_healpix"] = hp.radec2pix(
19,
combined_data["ra"].values,
combined_data["dec"].values,
lonlat=True,
nest=True,
)
## Use this to prune generated columns like Norder, Npix, and _healpix_29
comparison_columns = ["source_id", "object_id", "time", "ra", "dec"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_reduce_margin_shards(tmp_path):
hats_indexes = pixel_math.compute_spatial_index(ras, dec)
margin_order = np.full(360, 0)
margin_dir = np.full(360, 0)
margin_pixels = hp.ang2pix(2**3, ras, dec, lonlat=True, nest=True)
margin_pixels = hp.radec2pix(3, ras, dec)

test_df = pd.DataFrame(
data=zip(hats_indexes, ras, dec, norder, ndir, npix, margin_order, margin_dir, margin_pixels),
Expand Down