From 84583ff3fbc89d8ca748b27eaa78edbbba6ac9b2 Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Wed, 28 Feb 2024 17:02:00 -0500 Subject: [PATCH 1/2] refactor filter_from_pixel_list to healpix_dataset.py --- src/hipscat/catalog/catalog.py | 14 -------------- .../catalog/healpix_dataset/healpix_dataset.py | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/hipscat/catalog/catalog.py b/src/hipscat/catalog/catalog.py index edfb0ca2..88460308 100644 --- a/src/hipscat/catalog/catalog.py +++ b/src/hipscat/catalog/catalog.py @@ -2,7 +2,6 @@ from __future__ import annotations -import dataclasses from typing import Any, Dict, List, Tuple, Union import healpy as hp @@ -121,19 +120,6 @@ def filter_by_polygon(self, vertices: List[SphericalCoordinates] | List[Cartesia validate_polygon(vertices) return self.filter_from_pixel_list(filter_pixels_by_polygon(self.pixel_tree, vertices)) - def filter_from_pixel_list(self, pixels: List[HealpixPixel]) -> Catalog: - """Filter the pixels in the catalog to only include the requested pixels. - - Args: - pixels (List[HealpixPixels]): the pixels to include - - Returns: - A new catalog with only those pixels. Note that we reset the total_rows - to None, instead of performing a scan over the new pixel sizes. - """ - filtered_catalog_info = dataclasses.replace(self.catalog_info, total_rows=None) - return Catalog(filtered_catalog_info, pixels) - def generate_negative_tree_pixels(self) -> List[HealpixPixel]: """Get the leaf nodes at each healpix order that have zero catalog data. diff --git a/src/hipscat/catalog/healpix_dataset/healpix_dataset.py b/src/hipscat/catalog/healpix_dataset/healpix_dataset.py index dffd4eed..61f62a8a 100644 --- a/src/hipscat/catalog/healpix_dataset/healpix_dataset.py +++ b/src/hipscat/catalog/healpix_dataset/healpix_dataset.py @@ -1,7 +1,8 @@ +import dataclasses from typing import Any, Dict, List, Tuple, Union import pandas as pd -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, Self from hipscat.catalog.dataset import BaseCatalogInfo, Dataset from hipscat.catalog.partition_info import PartitionInfo @@ -102,3 +103,16 @@ def _check_files_exist(cls, catalog_base_dir: FilePointer, storage_options: dict raise FileNotFoundError( f"_metadata or partition info file is required in catalog directory {catalog_base_dir}" ) + + def filter_from_pixel_list(self, pixels: List[HealpixPixel]) -> Self: + """Filter the pixels in the catalog to only include the requested pixels. + + Args: + pixels (List[HealpixPixels]): the pixels to include + + Returns: + A new catalog with only those pixels. Note that we reset the total_rows + to None, instead of performing a scan over the new pixel sizes. + """ + filtered_catalog_info = dataclasses.replace(self.catalog_info, total_rows=None) + return self.__class__(filtered_catalog_info, pixels) From 4c383dbe78d21d8679116b2ff9f0e8bec5e38ca3 Mon Sep 17 00:00:00 2001 From: Sean McGuire Date: Wed, 28 Feb 2024 17:07:22 -0500 Subject: [PATCH 2/2] isort --- src/hipscat/catalog/healpix_dataset/healpix_dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hipscat/catalog/healpix_dataset/healpix_dataset.py b/src/hipscat/catalog/healpix_dataset/healpix_dataset.py index 61f62a8a..3608529d 100644 --- a/src/hipscat/catalog/healpix_dataset/healpix_dataset.py +++ b/src/hipscat/catalog/healpix_dataset/healpix_dataset.py @@ -2,7 +2,7 @@ from typing import Any, Dict, List, Tuple, Union import pandas as pd -from typing_extensions import TypeAlias, Self +from typing_extensions import Self, TypeAlias from hipscat.catalog.dataset import BaseCatalogInfo, Dataset from hipscat.catalog.partition_info import PartitionInfo