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

Cleanups. #115

Merged
merged 3 commits into from
Jul 20, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def _get_partition_join_info_from_pixels(
raise TypeError("join_pixels must be of type PartitionJoinInfo or DataFrame")

@classmethod
def _read_args(
cls, catalog_base_dir: FilePointer
) -> Tuple[CatalogInfoClass, JoinPixelInputTypes]:
def _read_args(cls, catalog_base_dir: FilePointer) -> Tuple[CatalogInfoClass, JoinPixelInputTypes]:
args = super()._read_args(catalog_base_dir)
partition_join_info_file = paths.get_partition_join_info_pointer(catalog_base_dir)
partition_join_info = PartitionJoinInfo.read_from_file(partition_join_info_file)
Expand Down
19 changes: 8 additions & 11 deletions src/hipscat/inspection/visualize_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from matplotlib import pyplot as plt

from hipscat.catalog import Catalog, PartitionInfo
from hipscat.catalog import Catalog
from hipscat.io import file_io, paths


Expand Down Expand Up @@ -55,23 +55,20 @@ def plot_pixels(catalog: Catalog, projection="moll", draw_map=True):
- cart - Cartesian projection
- orth - Orthographic projection
"""
pixels = catalog.get_pixels()

catalog_orders = pixels[PartitionInfo.METADATA_ORDER_COLUMN_NAME].unique()
catalog_orders.sort()
max_order = catalog_orders[-1]
pixels = catalog.partition_info.get_healpix_pixels()
max_order = catalog.partition_info.get_highest_order()

order_map = np.full(hp.order2npix(max_order), hp.pixelfunc.UNSEEN)

for _, pixel in pixels.iterrows():
explosion_factor = 4 ** (max_order - pixel[PartitionInfo.METADATA_ORDER_COLUMN_NAME])
for pixel in pixels:
explosion_factor = 4 ** (max_order - pixel.order)
exploded_pixels = [
*range(
pixel[PartitionInfo.METADATA_PIXEL_COLUMN_NAME] * explosion_factor,
(pixel[PartitionInfo.METADATA_PIXEL_COLUMN_NAME] + 1) * explosion_factor,
pixel.pixel * explosion_factor,
(pixel.pixel + 1) * explosion_factor,
)
]
order_map[exploded_pixels] = pixel[PartitionInfo.METADATA_ORDER_COLUMN_NAME]
order_map[exploded_pixels] = pixel.order
_plot_healpix_map(
order_map,
projection,
Expand Down
8 changes: 2 additions & 6 deletions src/hipscat/pixel_math/healpix_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ def convert_to_higher_order(self, delta_order: int) -> List[HealpixPixel]:
pixels cannot be generated. Or if delta_order is negative
"""
if self.order + delta_order > HIPSCAT_ID_HEALPIX_ORDER:
raise ValueError(
f"Pixel Order cannot be above maximum order {HIPSCAT_ID_HEALPIX_ORDER}"
)
raise ValueError(f"Pixel Order cannot be above maximum order {HIPSCAT_ID_HEALPIX_ORDER}")
if delta_order < 0:
raise ValueError("delta order cannot be below zero")
pixels = []
new_order = self.order + delta_order
for new_pixel in range(
self.pixel * 4**delta_order, (self.pixel + 1) * 4**delta_order
):
for new_pixel in range(self.pixel * 4**delta_order, (self.pixel + 1) * 4**delta_order):
pixels.append(HealpixPixel(new_order, new_pixel))
return pixels
23 changes: 12 additions & 11 deletions src/hipscat/pixel_tree/pixel_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class PixelAlignment:
and 7, would result in the smaller order 1 pixels in the aligned tree.
alignment_type: The type of alignment describing how to handle nodes which exist in one tree
but not the other. Options are:
inner - only use pixels that appear in both catalogs
left - use all pixels that appear in the left catalog and any overlapping from the right
right - use all pixels that appear in the right catalog and any overlapping from the
left
outer - use all pixels from both catalogs

- inner - only use pixels that appear in both catalogs
- left - use all pixels that appear in the left catalog and any overlapping from the right
- right - use all pixels that appear in the right catalog and any overlapping from the left
- outer - use all pixels from both catalogs
"""

PRIMARY_ORDER_COLUMN_NAME = "primary_Norder"
Expand Down Expand Up @@ -73,11 +73,12 @@ def align_trees(
right: The right tree to align
alignment_type: The type of alignment describing how to handle nodes which exist in one tree
but not the other. Options are:
inner - only use pixels that appear in both catalogs
left - use all pixels that appear in the left catalog and any overlapping from the right
right - use all pixels that appear in the right catalog and any overlapping from the
left
outer - use all pixels from both catalogs

- inner - only use pixels that appear in both catalogs
- left - use all pixels that appear in the left catalog and any overlapping from the right
- right - use all pixels that appear in the right catalog and any overlapping from the left
- outer - use all pixels from both catalogs

Returns:
The `PixelAlignment` object with the alignment from the two trees
"""
Expand Down Expand Up @@ -214,5 +215,5 @@ def _generate_pixel_mapping_from_tree(left: PixelTree, right: PixelTree, aligned
right_pixel = right_node.hp_pixel if right_node is not None else None
pixel_mapping_dict[PixelAlignment.JOIN_ORDER_COLUMN_NAME].append(right_order)
pixel_mapping_dict[PixelAlignment.JOIN_PIXEL_COLUMN_NAME].append(right_pixel)
pixel_mapping = pd.DataFrame.from_dict(pixel_mapping_dict)
pixel_mapping = pd.DataFrame.from_dict(pixel_mapping_dict).astype(pd.Int64Dtype())
return pixel_mapping
4 changes: 2 additions & 2 deletions src/hipscat/pixel_tree/pixel_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def get_leaf_nodes_at_healpix_pixel(self, pixel: HealpixInputTypes) -> List[Pixe

- Exact matches will return a list with only the matching pixel
- A pixel that is within a lower order pixel in the tree will return a list with the lower
order pixel
order pixel
- A pixel that has higher order pixels within found in the tree will return a list with all
higher order pixels
higher order pixels
- A pixel with no matching leaf nodes in the tree will return an empty list

Args:
Expand Down
13 changes: 10 additions & 3 deletions tests/hipscat/pixel_math/test_healpix_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ def test_pixel_str_and_repr():


def test_convert_lower_order():
test_cases = [(3,10,2,2),(6,1033,5,258),(4,0,3,0),(5,400,2,6),(2,4,0,0),(3,10,3,10)]
test_cases = [
(3, 10, 2, 2),
(6, 1033, 5, 258),
(4, 0, 3, 0),
(5, 400, 2, 6),
(2, 4, 0, 0),
(3, 10, 3, 10),
]
for order, pixel, final_order, final_pixel in test_cases:
delta = order - final_order
pixel = HealpixPixel(order, pixel)
Expand All @@ -68,11 +75,11 @@ def test_convert_lower_order_fails_negative():


def test_convert_higher_order():
test_cases = [(3,10,1),(6,1033,3),(4,0,1),(5,400,2),(2,4,0),(0,10,2)]
test_cases = [(3, 10, 1), (6, 1033, 3), (4, 0, 1), (5, 400, 2), (2, 4, 0), (0, 10, 2)]
for order, pixel, delta_order in test_cases:
converted_pixels = HealpixPixel(order, pixel).convert_to_higher_order(delta_order)
final_order = order + delta_order
for final_pixel in range(pixel * 4**delta_order, (pixel+1) * 4**delta_order):
for final_pixel in range(pixel * 4**delta_order, (pixel + 1) * 4**delta_order):
assert HealpixPixel(final_order, final_pixel) in converted_pixels


Expand Down