Skip to content

Commit c39621d

Browse files
authored
Create new catalog type: map (#429)
* Initial work on map type. * Use importer to create map type.
1 parent 635816f commit c39621d

25 files changed

+86
-3
lines changed

src/hats/catalog/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
from .catalog_type import CatalogType
77
from .dataset.dataset import Dataset
88
from .dataset.table_properties import TableProperties
9+
from .map.map_catalog import MapCatalog
910
from .margin_cache.margin_catalog import MarginCatalog
1011
from .partition_info import PartitionInfo

src/hats/catalog/catalog_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class CatalogType(str, Enum):
99
ASSOCIATION = "association"
1010
INDEX = "index"
1111
MARGIN = "margin"
12+
MAP = "map"
1213

1314
@classmethod
1415
def all_types(cls):

src/hats/catalog/dataset/table_properties.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
],
2626
CatalogType.INDEX: ["primary_catalog", "indexing_column", "extra_columns"],
2727
CatalogType.MARGIN: ["primary_catalog", "margin_threshold", "ra_column", "dec_column", "default_columns"],
28+
CatalogType.MAP: ["default_columns"],
2829
}
2930

3031
## catalog_name, catalog_type, and total_rows are required for ALL types
@@ -40,6 +41,7 @@
4041
],
4142
CatalogType.INDEX: ["primary_catalog", "indexing_column"],
4243
CatalogType.MARGIN: ["primary_catalog", "margin_threshold"],
44+
CatalogType.MAP: [],
4345
}
4446

4547
# All additional properties in the HATS recommendation.

src/hats/catalog/map/__init__.py

Whitespace-only changes.

src/hats/catalog/map/map_catalog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from __future__ import annotations
2+
3+
from hats.catalog.healpix_dataset.healpix_dataset import HealpixDataset
4+
5+
6+
class MapCatalog(HealpixDataset):
7+
"""A HATS table to represent non-point-source data in a continuous map."""

src/hats/loaders/read_hats.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from upath import UPath
1010

1111
import hats.pixel_math.healpix_shim as hp
12-
from hats.catalog import AssociationCatalog, Catalog, CatalogType, Dataset, MarginCatalog
12+
from hats.catalog import AssociationCatalog, Catalog, CatalogType, Dataset, MapCatalog, MarginCatalog
1313
from hats.catalog.association_catalog.partition_join_info import PartitionJoinInfo
1414
from hats.catalog.dataset.table_properties import TableProperties
1515
from hats.catalog.index.index_catalog import IndexCatalog
@@ -23,6 +23,7 @@
2323
CatalogType.ASSOCIATION: AssociationCatalog,
2424
CatalogType.INDEX: IndexCatalog,
2525
CatalogType.MARGIN: MarginCatalog,
26+
CatalogType.MAP: MapCatalog,
2627
}
2728

2829

@@ -63,6 +64,7 @@ def _is_healpix_dataset(dataset_type):
6364
CatalogType.SOURCE,
6465
CatalogType.ASSOCIATION,
6566
CatalogType.MARGIN,
67+
CatalogType.MAP,
6668
)
6769

6870

tests/data/generate_data.ipynb

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,49 @@
297297
" runner.pipeline_with_client(args, client)"
298298
]
299299
},
300+
{
301+
"cell_type": "code",
302+
"execution_count": null,
303+
"metadata": {},
304+
"outputs": [],
305+
"source": [
306+
"import pandas as pd\n",
307+
"import numpy as np\n",
308+
"from hats.pixel_math.spatial_index import healpix_to_spatial_index\n",
309+
"\n",
310+
"target_pixels = np.arange(0, 12)\n",
311+
"\n",
312+
"healpix_29 = healpix_to_spatial_index(0, target_pixels)\n",
313+
"\n",
314+
"square_vals = target_pixels * target_pixels\n",
315+
"value_frame = pd.DataFrame({\"_healpix_29\": healpix_29, \"star_count\": square_vals})"
316+
]
317+
},
318+
{
319+
"cell_type": "code",
320+
"execution_count": null,
321+
"metadata": {},
322+
"outputs": [],
323+
"source": [
324+
"with tempfile.TemporaryDirectory() as pipeline_tmp:\n",
325+
" csv_file = Path(pipeline_tmp) / \"square_map.csv\"\n",
326+
" value_frame.to_csv(csv_file, index=False)\n",
327+
" args = ImportArguments(\n",
328+
" constant_healpix_order=1,\n",
329+
" catalog_type=\"map\",\n",
330+
" use_healpix_29=True,\n",
331+
" ra_column=None,\n",
332+
" dec_column=None,\n",
333+
" file_reader=\"csv\",\n",
334+
" input_file_list=[csv_file],\n",
335+
" output_artifact_name=\"square_map\",\n",
336+
" output_path=\".\",\n",
337+
" tmp_dir=pipeline_tmp,\n",
338+
" )\n",
339+
"\n",
340+
" runner.pipeline_with_client(args, client)"
341+
]
342+
},
300343
{
301344
"cell_type": "code",
302345
"execution_count": null,
@@ -317,7 +360,7 @@
317360
],
318361
"metadata": {
319362
"kernelspec": {
320-
"display_name": "env",
363+
"display_name": "demo",
321364
"language": "python",
322365
"name": "python3"
323366
},
@@ -331,7 +374,7 @@
331374
"name": "python",
332375
"nbconvert_exporter": "python",
333376
"pygments_lexer": "ipython3",
334-
"version": "3.9.12"
377+
"version": "3.12.3"
335378
}
336379
},
337380
"nbformat": 4,
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.
1.57 KB
Binary file not shown.
8.57 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Norder,Npix
2+
1,0
3+
1,4
4+
1,8
5+
1,12
6+
1,16
7+
1,20
8+
1,24
9+
1,28
10+
1,32
11+
1,36
12+
1,40
13+
1,44

tests/data/square_map/point_map.fits

8.44 KB
Binary file not shown.

tests/data/square_map/properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#HATS catalog
2+
obs_collection=square_map
3+
dataproduct_type=map
4+
hats_nrows=12
5+
hats_max_rows=1000000
6+
hats_order=1
7+
moc_sky_fraction=0.25000
8+
hats_builder=hats-import v0.4.1
9+
hats_creation_date=2024-11-20T19\:32UTC
10+
hats_estsize=52
11+
hats_release_date=2024-09-18
12+
hats_version=v0.1

tests/hats/catalog/loaders/test_read_hats.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ def test_read_hats_branches(
88
small_sky_source_object_index_dir,
99
margin_catalog_path,
1010
small_sky_source_dir,
11+
test_data_dir,
1112
):
1213
read_hats(small_sky_dir)
1314
read_hats(small_sky_order1_dir)
1415
read_hats(association_catalog_path)
1516
read_hats(small_sky_source_object_index_dir)
1617
read_hats(margin_catalog_path)
1718
read_hats(small_sky_source_dir)
19+
read_hats(test_data_dir / "square_map")

0 commit comments

Comments
 (0)