2929}
3030
3131
32- def read_hats (catalog_path : str | Path | UPath ) -> CatalogCollection | Dataset :
32+ def read_hats (
33+ catalog_path : str | Path | UPath , * , single_catalog : bool | None = None , read_moc : bool = True
34+ ) -> CatalogCollection | Dataset :
3335 """Reads a HATS Catalog from a HATS directory
3436
3537 Parameters
3638 ----------
3739 catalog_path : str | Path | UPath
3840 path to the root directory of the catalog
41+ single_catalog: bool
42+ If you happen to already know that the `catalog_path` points to a
43+ single catalog, instead of a catalog collection, this flag can
44+ save a few file read operations.
45+ read_moc: bool
46+ If you happen to know that your catalog does not have a MOC (or if
47+ you know that your use case will not utilize a MOC), then you can
48+ skip the file read and memory load of the MOC.
3949
4050 Returns
4151 -------
@@ -50,20 +60,26 @@ def read_hats(catalog_path: str | Path | UPath) -> CatalogCollection | Dataset:
5060 catalog = hats.read_hats(UPath(..., anon=True))
5161 """
5262 path = file_io .get_upath (catalog_path )
63+ if single_catalog is not None :
64+ if single_catalog :
65+ return _load_catalog (path , read_moc = read_moc )
66+ return _load_collection (path , read_moc = read_moc )
5367 if (path / "hats.properties" ).exists () or (path / "properties" ).exists ():
54- return _load_catalog (path )
68+ return _load_catalog (path , read_moc = read_moc )
5569 if (path / "collection.properties" ).exists ():
56- return _load_collection (path )
70+ return _load_collection (path , read_moc = read_moc )
5771 raise FileNotFoundError (f"Failed to read HATS at location { catalog_path } " )
5872
5973
60- def _load_collection (collection_path : UPath ) -> CatalogCollection :
74+ def _load_collection (collection_path : UPath , read_moc : bool = True ) -> CatalogCollection :
6175 collection_properties = CollectionProperties .read_from_dir (collection_path )
62- main_catalog = _load_catalog (collection_path / collection_properties .hats_primary_table_url )
76+ main_catalog = _load_catalog (
77+ collection_path / collection_properties .hats_primary_table_url , read_moc = read_moc
78+ )
6379 return CatalogCollection (collection_path , collection_properties , main_catalog )
6480
6581
66- def _load_catalog (catalog_path : UPath ) -> Dataset :
82+ def _load_catalog (catalog_path : UPath , read_moc : bool = True ) -> Dataset :
6783 properties = TableProperties .read_from_dir (catalog_path )
6884 dataset_type = properties .catalog_type
6985 if dataset_type not in DATASET_TYPE_TO_CLASS :
@@ -78,7 +94,8 @@ def _load_catalog(catalog_path: UPath) -> Dataset:
7894 }
7995 if _is_healpix_dataset (dataset_type ):
8096 kwargs ["pixels" ] = PartitionInfo .read_from_dir (catalog_path )
81- kwargs ["moc" ] = _read_moc_from_point_map (catalog_path )
97+ if read_moc :
98+ kwargs ["moc" ] = _read_moc_from_point_map (catalog_path )
8299 return loader (** kwargs )
83100
84101
@@ -95,7 +112,7 @@ def _is_healpix_dataset(dataset_type):
95112def _read_moc_from_point_map (catalog_base_dir : str | Path | UPath ) -> MOC | None :
96113 """Reads a MOC object from the `point_map.fits` file if it exists in the catalog directory"""
97114 point_map_path = paths .get_point_map_file_pointer (catalog_base_dir )
98- if not file_io . does_file_or_directory_exist ( point_map_path ):
115+ if not point_map_path . exists ( ):
99116 return None
100117 fits_image = file_io .read_fits_image (point_map_path )
101118 order = hp .npix2order (len (fits_image ))
0 commit comments