-
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.
Merge pull request #44 from astronomy-commons/delucchi/issue/39
Use hive formatting for directory/catalog path.
- Loading branch information
Showing
16 changed files
with
158 additions
and
59 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
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,44 @@ | ||
"""Container class to hold per-partition metadata""" | ||
|
||
import os | ||
|
||
import pandas as pd | ||
|
||
from hipscat.io import paths | ||
|
||
|
||
class PartitionInfo: | ||
"""Container class for per-partition info.""" | ||
|
||
METADATA_ORDER_COLUMN_NAME = "Norder" | ||
METADATA_DIR_COLUMN_NAME = "Dir" | ||
METADATA_PIXEL_COLUMN_NAME = "Npix" | ||
|
||
def __init__(self, catalog_path=None): | ||
self.catalog_path = catalog_path | ||
|
||
partition_info_filename = os.path.join(self.catalog_path, "partition_info.csv") | ||
if not os.path.exists(partition_info_filename): | ||
raise FileNotFoundError( | ||
f"No partition info found where expected: {partition_info_filename}" | ||
) | ||
|
||
self.data_frame = pd.read_csv(partition_info_filename) | ||
|
||
def get_file_names(self): | ||
"""Get file handles for all partition files in the catalog | ||
Returns: | ||
one-dimensional array of strings, where each string is a partition file | ||
""" | ||
file_names = [] | ||
for _, partition in self.data_frame.iterrows(): | ||
file_names.append( | ||
paths.pixel_catalog_file( | ||
self.catalog_path, | ||
partition[self.METADATA_ORDER_COLUMN_NAME], | ||
partition[self.METADATA_PIXEL_COLUMN_NAME], | ||
) | ||
) | ||
|
||
return file_names |
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
File renamed without changes.
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,2 +1,2 @@ | ||
order,pixel,num_objects | ||
0,11,131 | ||
Norder,Dir,Npix,num_rows | ||
0,0,11,131 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,5 +1,5 @@ | ||
order,pixel,num_objects | ||
1,44,42 | ||
1,45,29 | ||
1,46,42 | ||
1,47,18 | ||
Norder,Dir,Npix,num_rows | ||
1,0,44,42 | ||
1,0,45,29 | ||
1,0,46,42 | ||
1,0,47,18 |
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,27 @@ | ||
"""Tests of partition info functionality""" | ||
|
||
import os | ||
|
||
from hipscat.catalog import PartitionInfo | ||
|
||
|
||
def test_load_partition_info_small_sky(small_sky_dir): | ||
"""Instantiate the partition info for catalog with 1 pixel""" | ||
partitions = PartitionInfo(small_sky_dir) | ||
|
||
partition_file_list = partitions.get_file_names() | ||
assert len(partition_file_list) == 1 | ||
|
||
for parquet_file in partition_file_list: | ||
assert os.path.exists(parquet_file) | ||
|
||
|
||
def test_load_partition_info_small_sky_order1(small_sky_order1_dir): | ||
"""Instantiate the partition info for catalog with 4 pixels""" | ||
partitions = PartitionInfo(small_sky_order1_dir) | ||
|
||
partition_file_list = partitions.get_file_names() | ||
assert len(partition_file_list) == 4 | ||
|
||
for parquet_file in partition_file_list: | ||
assert os.path.exists(parquet_file) |
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