File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed
src/hats/catalog/healpix_dataset Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -418,6 +418,27 @@ def has_healpix_column(self):
418418 return True
419419 return False
420420
421+ def get_pixel_paths (self ):
422+ """Generate paths to all pixel files.
423+
424+ Pixels will be traversed in "breadth-first" healpix order. If any spatial filters
425+ have been applied to this catalog, only those pixels that remain will be included.
426+
427+ Yields
428+ ------
429+ UPath
430+ Universal Pathlib pointing to either an npix directory, or to a single
431+ pixel partition data file.
432+ """
433+ if not self .on_disk :
434+ warnings .warn ("Calling read_pixel_to_pandas on an in-memory catalog. No results." )
435+ return
436+
437+ for pixel in self .get_healpix_pixels ():
438+ yield paths .pixel_catalog_file (
439+ self .catalog_base_dir , pixel , npix_suffix = self .catalog_info .npix_suffix
440+ )
441+
421442 def read_pixel_to_pandas (self , pixel : HealpixPixel , ** kwargs ) -> npd .NestedFrame :
422443 """Read the parquet file(s) for this pixel into a pandas dataframe.
423444
Original file line number Diff line number Diff line change @@ -125,10 +125,16 @@ def test_read_hats_nonstandard_npix_suffix(
125125 cat = read_hats (small_sky_npix_alt_suffix_dir )
126126 result = cat .read_pixel_to_pandas (cat .get_healpix_pixels ()[0 ])
127127 assert len (result ) == 131
128+ for path in cat .get_pixel_paths ():
129+ assert path .exists ()
130+ assert str (path ).endswith (".parq" )
128131
129132 cat = read_hats (small_sky_npix_as_dir_dir )
130133 result = cat .read_pixel_to_pandas (cat .get_healpix_pixels ()[0 ])
131134 assert len (result ) == 131
135+ for path in cat .get_pixel_paths ():
136+ assert path .exists ()
137+ assert path .is_dir ()
132138
133139
134140def test_read_hats_original_schema (small_sky_order1_dir ):
Original file line number Diff line number Diff line change @@ -235,6 +235,35 @@ def test_cone_filter(small_sky_order1_catalog):
235235 assert filtered_catalog .original_schema is not None
236236
237237
238+ def test_get_pixel_paths (small_sky_order1_catalog ):
239+ generator_length = 0
240+ for path in small_sky_order1_catalog .get_pixel_paths ():
241+ assert path .exists ()
242+ generator_length += 1
243+ assert generator_length == 4
244+
245+ ra = 315
246+ dec = - 66.443
247+ radius = 0.1
248+
249+ filtered_catalog = small_sky_order1_catalog .filter_by_cone (ra , dec , radius )
250+ generator_length = 0
251+ for path in filtered_catalog .get_pixel_paths ():
252+ assert path .exists ()
253+ generator_length += 1
254+ assert generator_length == 1
255+
256+
257+ def test_get_pixel_paths_in_memory (in_memory_catalog ):
258+ with pytest .warns (UserWarning , match = "in-memory" ):
259+ with pytest .raises (StopIteration ):
260+ next (in_memory_catalog .get_pixel_paths ())
261+
262+ with pytest .warns (UserWarning , match = "in-memory" ):
263+ for _ in in_memory_catalog .get_pixel_paths ():
264+ assert False , "Iterator should be empty."
265+
266+
238267def test_cone_filter_big (small_sky_order1_catalog ):
239268 filtered_catalog = small_sky_order1_catalog .filter_by_cone (315 , - 66.443 , 30 * 3600 )
240269 assert len (filtered_catalog .get_healpix_pixels ()) == 4
You can’t perform that action at this time.
0 commit comments