Skip to content

Commit

Permalink
Merge pull request #285 from astronomy-commons/update-margin-cache-info
Browse files Browse the repository at this point in the history
Derive `MarginCacheCatalogInfo` from `CatalogInfo`
  • Loading branch information
camposandro authored Jun 6, 2024
2 parents 696db00 + fb85774 commit 6d427ac
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/hipscat/catalog/margin_cache/margin_cache_catalog_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from dataclasses import dataclass

from hipscat.catalog.catalog_info import CatalogInfo
from hipscat.catalog.catalog_type import CatalogType
from hipscat.catalog.dataset.base_catalog_info import BaseCatalogInfo


@dataclass
class MarginCacheCatalogInfo(BaseCatalogInfo):
class MarginCacheCatalogInfo(CatalogInfo):
"""Catalog Info for a HiPSCat Margin Cache table"""

primary_catalog: str = None
Expand All @@ -16,7 +16,7 @@ class MarginCacheCatalogInfo(BaseCatalogInfo):
margin_threshold: float = None
"""Threshold of the pixel boundary, expressed in arcseconds."""

required_fields = BaseCatalogInfo.required_fields + [
required_fields = CatalogInfo.required_fields + [
"primary_catalog",
"margin_threshold",
]
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def margin_cache_catalog_info_data() -> dict:
"catalog_name": "test_margin",
"catalog_type": "margin",
"total_rows": 100,
"epoch": "J2000",
"ra_column": "ra",
"dec_column": "dec",
"primary_catalog": "test_name",
"margin_threshold": 0.5,
}
Expand Down
3 changes: 3 additions & 0 deletions tests/data/almanac/small_sky_order1_margin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ catalog_info:
catalog_name: small_sky_order1_margin
catalog_type: margin
total_rows: 28
epoch: J2000
ra_column: ra
dec_column: dec
primary_catalog: small_sky_order1
margin_threshold: 7200
primary: small_sky_order1
3 changes: 3 additions & 0 deletions tests/data/almanac_exception/margin_missing_primary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ catalog_info:
catalog_name: margin_cache
catalog_type: margin
total_rows: 100
epoch: J2000
ra_column: ra
dec_column: dec
primary_catalog: NOT_A_CATALOG
margin_threshold: 0.5
3 changes: 3 additions & 0 deletions tests/data/info_only/margin_cache/catalog_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"catalog_name": "margin_cache",
"catalog_type": "margin",
"total_rows": 100,
"epoch": "J2000",
"ra_column": "ra",
"dec_column": "dec",
"primary_catalog": "catalog",
"margin_threshold": 0.5
}
3 changes: 3 additions & 0 deletions tests/data/small_sky_order1_margin/catalog_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"catalog_name": "small_sky_order1_margin",
"catalog_type": "margin",
"total_rows": 28,
"epoch": "J2000",
"ra_column": "ra",
"dec_column": "dec",
"primary_catalog": "small_sky_order1",
"margin_threshold": 7200
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def test_read_from_file(margin_cache_catalog_info_file, assert_catalog_info_matc
"catalog_name",
"catalog_type",
"total_rows",
"epoch",
"ra_column",
"dec_column",
"primary_catalog",
"margin_threshold",
]:
Expand Down Expand Up @@ -58,7 +61,8 @@ def test_type_missing(margin_cache_catalog_info_data):

def test_wrong_type(margin_cache_catalog_info_data, catalog_info_data):
with pytest.raises(TypeError, match="unexpected"):
MarginCacheCatalogInfo(**catalog_info_data)
unexpected_info = {**catalog_info_data, "invalid_key": "unknown"}
MarginCacheCatalogInfo(**unexpected_info)

with pytest.raises(ValueError, match=f"{CatalogType.MARGIN}"):
init_data = margin_cache_catalog_info_data.copy()
Expand Down
3 changes: 3 additions & 0 deletions tests/hipscat/catalog/margin_cache/test_margin_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def test_read_from_file(margin_catalog_path, margin_catalog_pixels):
info = catalog.catalog_info
assert info.catalog_name == "small_sky_order1_margin"
assert info.catalog_type == CatalogType.MARGIN
assert info.epoch == "J2000"
assert info.ra_column == "ra"
assert info.dec_column == "dec"
assert info.primary_catalog == "small_sky_order1"
assert info.margin_threshold == 7200

Expand Down

0 comments on commit 6d427ac

Please sign in to comment.