-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from ykwang1/issue/237/select_pixel_order
Filter based on HEALpix order
- Loading branch information
Showing
26 changed files
with
220 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .cone_search import ConeSearch | ||
from .index_search import IndexSearch | ||
from .order_search import OrderSearch | ||
from .polygon_search import PolygonSearch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from typing import List | ||
|
||
import pandas as pd | ||
from hipscat.pixel_math import HealpixPixel | ||
|
||
from lsdb.core.search.abstract_search import AbstractSearch | ||
|
||
|
||
class OrderSearch(AbstractSearch): | ||
"""Filter the catalog by HEALPix order. | ||
Filters partitions in the catalog to those that are in the orders specified. | ||
Does not filter points inside those partitions. | ||
""" | ||
|
||
def __init__(self, min_order: int = 0, max_order: int | None = None): | ||
if max_order and min_order > max_order: | ||
raise ValueError("The minimum order should be lower than or equal to the maximum order") | ||
self.min_order = min_order | ||
self.max_order = max_order | ||
|
||
def search_partitions(self, pixels: List[HealpixPixel]) -> List[HealpixPixel]: | ||
"""Determine the target partitions for further filtering.""" | ||
max_catalog_order = max(pixel.order for pixel in pixels) | ||
max_order = max_catalog_order if self.max_order is None else self.max_order | ||
if self.min_order > max_order: | ||
raise ValueError("The minimum order is higher than the catalog's maximum order") | ||
return [pixel for pixel in pixels if self.min_order <= pixel.order <= max_order] | ||
|
||
def search_points(self, frame: pd.DataFrame, _) -> pd.DataFrame: | ||
"""Determine the search results within a data frame.""" | ||
return frame |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"catalog_name": "small_sky_source", | ||
"catalog_type": "source", | ||
"total_rows": 17161, | ||
"epoch": "J2000", | ||
"ra_column": "source_ra", | ||
"dec_column": "source_dec" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Norder,Npix,Dir | ||
0,4,0 | ||
1,47,0 | ||
2,176,0 | ||
2,177,0 | ||
2,178,0 | ||
2,179,0 | ||
2,180,0 | ||
2,181,0 | ||
2,182,0 | ||
2,183,0 | ||
2,184,0 | ||
2,185,0 | ||
2,186,0 | ||
2,187,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"catalog_name": "small_sky_source", | ||
"catalog_type": "source", | ||
"total_rows": 17161, | ||
"epoch": "J2000", | ||
"ra_column": "source_ra", | ||
"dec_column": "source_dec", | ||
"version": "0.2.8", | ||
"generation_date": "2024.03.15", | ||
"tool_args": { | ||
"tool_name": "hipscat_import", | ||
"version": "0.2.5.dev8+g9d0bfc4", | ||
"runtime_args": { | ||
"catalog_name": "small_sky_source", | ||
"output_path": ".", | ||
"output_artifact_name": "small_sky_source", | ||
"tmp_dir": "/var/folders/x4/rmzh8l_s0zxc74nwr72z12340000gn/T/tmpax37bk_h", | ||
"overwrite": true, | ||
"dask_tmp": "", | ||
"dask_n_workers": 1, | ||
"dask_threads_per_worker": 1, | ||
"catalog_path": "./small_sky_source", | ||
"tmp_path": "/var/folders/x4/rmzh8l_s0zxc74nwr72z12340000gn/T/tmpax37bk_h/small_sky_source/intermediate", | ||
"epoch": "J2000", | ||
"catalog_type": "source", | ||
"input_path": null, | ||
"input_paths": [ | ||
"raw/small_sky_source/small_sky_source.csv" | ||
], | ||
"input_file_list": [ | ||
"raw/small_sky_source/small_sky_source.csv" | ||
], | ||
"ra_column": "source_ra", | ||
"dec_column": "source_dec", | ||
"use_hipscat_index": false, | ||
"sort_columns": null, | ||
"constant_healpix_order": -1, | ||
"highest_healpix_order": 2, | ||
"pixel_threshold": 3000, | ||
"mapping_healpix_order": 2, | ||
"debug_stats_only": false, | ||
"file_reader_info": { | ||
"input_reader_type": "CsvReader", | ||
"chunksize": 500000, | ||
"header": "infer", | ||
"schema_file": null, | ||
"separator": ",", | ||
"column_names": null, | ||
"type_map": {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from lsdb.core.search import OrderSearch | ||
|
||
|
||
def test_order_search_filters_correct_pixels(small_sky_source_catalog, assert_divisions_are_correct): | ||
order_search_catalog = small_sky_source_catalog.order_search(min_order=1, max_order=1) | ||
pixel_orders = [pixel.order for pixel in order_search_catalog.get_healpix_pixels()] | ||
assert all(order == 1 for order in pixel_orders) | ||
assert_divisions_are_correct(order_search_catalog) | ||
|
||
order_search_catalog = small_sky_source_catalog.order_search(min_order=1, max_order=2) | ||
pixel_orders = [pixel.order for pixel in order_search_catalog.get_healpix_pixels()] | ||
assert all(1 <= order <= 2 for order in pixel_orders) | ||
assert_divisions_are_correct(order_search_catalog) | ||
|
||
order_search_catalog = small_sky_source_catalog.order_search(min_order=1) | ||
pixel_orders = [pixel.order for pixel in order_search_catalog.get_healpix_pixels()] | ||
assert all(1 <= order <= 2 for order in pixel_orders) | ||
assert_divisions_are_correct(order_search_catalog) | ||
|
||
order_search_catalog = small_sky_source_catalog.order_search(max_order=1) | ||
pixel_orders = [pixel.order for pixel in order_search_catalog.get_healpix_pixels()] | ||
assert all(0 <= order <= 1 for order in pixel_orders) | ||
assert_divisions_are_correct(order_search_catalog) | ||
|
||
|
||
def test_order_search_keeps_all_points(small_sky_source_catalog): | ||
metadata = small_sky_source_catalog.hc_structure | ||
partition_df = small_sky_source_catalog._ddf.partitions[0].compute() | ||
search = OrderSearch(min_order=1, max_order=2) | ||
filtered_df = search.search_points(partition_df, metadata) | ||
pd.testing.assert_frame_equal(partition_df, filtered_df) | ||
|
||
|
||
def test_order_search_invalid_args(small_sky_source_catalog): | ||
with pytest.raises(ValueError, match="lower than or equal to the maximum order"): | ||
small_sky_source_catalog.order_search(min_order=2, max_order=1) | ||
with pytest.raises(ValueError, match="minimum order is higher than"): | ||
small_sky_source_catalog.order_search(min_order=3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters