-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b692476
commit 63d1622
Showing
13 changed files
with
145 additions
and
15 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
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,7 @@ | ||
{ | ||
"catalog_name": "small_sky_xmatch_margin", | ||
"catalog_type": "margin", | ||
"total_rows": 26, | ||
"primary_catalog": "small_sky_xmatch", | ||
"margin_threshold": 7200 | ||
} |
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,28 @@ | ||
{ | ||
"catalog_name": "small_sky_xmatch_margin", | ||
"catalog_type": "margin", | ||
"total_rows": 26, | ||
"primary_catalog": "data/small_sky_xmatch", | ||
"margin_threshold": 7200, | ||
"version": "0.1.8", | ||
"generation_date": "2024.01.11", | ||
"tool_args": { | ||
"tool_name": "hipscat_import", | ||
"version": "0.1.3.dev12+gf50adee", | ||
"runtime_args": { | ||
"catalog_name": "small_sky_xmatch_margin", | ||
"output_path": "data/small_sky_xmatch_margin", | ||
"output_artifact_name": "small_sky_xmatch_margin", | ||
"tmp_dir": "", | ||
"overwrite": false, | ||
"dask_tmp": "", | ||
"dask_n_workers": 1, | ||
"dask_threads_per_worker": 1, | ||
"catalog_path": "data/small_sky_xmatch_margin/small_sky_xmatch_margin", | ||
"tmp_path": "data/small_sky_xmatch_margin/small_sky_xmatch_margin/intermediate", | ||
"input_catalog_path": "data/small_sky_xmatch", | ||
"margin_threshold": 7200, | ||
"margin_order": 2 | ||
} | ||
} | ||
} |
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
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,77 @@ | ||
import json | ||
import os | ||
|
||
import pytest | ||
|
||
from hipscat.catalog import MarginCatalog, CatalogType, PartitionInfo | ||
from hipscat.pixel_tree.pixel_node_type import PixelNodeType | ||
|
||
|
||
def test_init_catalog(margin_catalog_info, margin_catalog_pixels): | ||
catalog = MarginCatalog( | ||
margin_catalog_info, margin_catalog_pixels | ||
) | ||
assert catalog.catalog_name == margin_catalog_info.catalog_name | ||
assert catalog.get_healpix_pixels() == margin_catalog_pixels | ||
assert catalog.catalog_info == margin_catalog_info | ||
|
||
assert len(catalog.get_healpix_pixels()) == len(margin_catalog_pixels) | ||
for hp_pixel in catalog.get_healpix_pixels(): | ||
assert hp_pixel in margin_catalog_pixels | ||
assert hp_pixel in catalog.pixel_tree | ||
assert catalog.pixel_tree[hp_pixel].node_type == PixelNodeType.LEAF | ||
|
||
|
||
def test_wrong_catalog_type(margin_catalog_info, margin_catalog_pixels): | ||
margin_catalog_info.catalog_type = CatalogType.OBJECT | ||
with pytest.raises(ValueError, match="catalog_type"): | ||
MarginCatalog(margin_catalog_info, margin_catalog_pixels) | ||
|
||
|
||
def test_wrong_catalog_info_type(catalog_info, margin_catalog_pixels): | ||
catalog_info.catalog_type = CatalogType.MARGIN | ||
with pytest.raises(TypeError, match="catalog_info"): | ||
MarginCatalog(catalog_info, margin_catalog_pixels) | ||
|
||
|
||
def test_read_from_file(margin_catalog_path, margin_catalog_pixels): | ||
catalog = MarginCatalog.read_from_hipscat(margin_catalog_path) | ||
assert catalog.on_disk | ||
assert catalog.catalog_path == margin_catalog_path | ||
assert len(catalog.get_healpix_pixels()) == len(margin_catalog_pixels) | ||
assert catalog.get_healpix_pixels() == margin_catalog_pixels | ||
|
||
info = catalog.catalog_info | ||
assert info.catalog_name == "small_sky_xmatch_margin" | ||
assert info.catalog_type == CatalogType.MARGIN | ||
assert info.primary_catalog == "small_sky_xmatch" | ||
assert info.margin_threshold == 7200 | ||
|
||
|
||
def test_empty_directory(tmp_path, margin_cache_catalog_info_data, margin_catalog_pixels): | ||
"""Test loading empty or incomplete data""" | ||
## Path doesn't exist | ||
with pytest.raises(FileNotFoundError): | ||
MarginCatalog.read_from_hipscat(os.path.join("path", "empty")) | ||
|
||
catalog_path = os.path.join(tmp_path, "empty") | ||
os.makedirs(catalog_path, exist_ok=True) | ||
|
||
## Path exists but there's nothing there | ||
with pytest.raises(FileNotFoundError, match="catalog info"): | ||
MarginCatalog.read_from_hipscat(catalog_path) | ||
|
||
## catalog_info file exists - getting closer | ||
file_name = os.path.join(catalog_path, "catalog_info.json") | ||
with open(file_name, "w", encoding="utf-8") as metadata_file: | ||
metadata_file.write(json.dumps(margin_cache_catalog_info_data)) | ||
|
||
with pytest.raises(FileNotFoundError, match="metadata"): | ||
MarginCatalog.read_from_hipscat(catalog_path) | ||
|
||
## Now we create the needed _metadata and everything is right. | ||
part_info = PartitionInfo.from_healpix(margin_catalog_pixels) | ||
part_info.write_to_metadata_files(catalog_path=catalog_path) | ||
|
||
catalog = MarginCatalog.read_from_hipscat(catalog_path) | ||
assert catalog.catalog_name == margin_cache_catalog_info_data["catalog_name"] |