Skip to content

Commit

Permalink
Use different methods for healpix manipulation. (#436)
Browse files Browse the repository at this point in the history
* Remove margin fine filtering.

* Use different methods for healpix manipulation.

* Optional dependency for older healpy fits files.

* Allow import of map types. (#437)

* Accomodate changes in cds-healpix.
  • Loading branch information
delucchi-cmu authored Nov 21, 2024
1 parent 1c5acb5 commit 61d7d52
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ full = [
"fsspec[full]", # complete file system specs.
"ipykernel", # Support for Jupyter notebooks
"ipywidgets", # useful for tqdm in notebooks.
"healpy", # used only in hipscat conversion
]

[build-system]
Expand Down
4 changes: 2 additions & 2 deletions src/hats_import/catalog/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def _check_arguments(self):
raise ValueError("pixel_threshold should be between 100 and 1,000,000,000")
self.mapping_healpix_order = self.highest_healpix_order

if self.catalog_type not in ("source", "object"):
raise ValueError("catalog_type should be one of `source` or `object`")
if self.catalog_type not in ("source", "object", "map"):
raise ValueError("catalog_type should be one of `source`, `object`, or `map`")

if self.file_reader is None:
raise ValueError("file_reader is required")
Expand Down
11 changes: 3 additions & 8 deletions src/hats_import/hipscat_conversion/run_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile
from typing import no_type_check

import hats.pixel_math.healpix_shim as hp
import healpy as hp
import numpy as np
import pyarrow.parquet as pq
from dask.distributed import as_completed, get_worker
Expand Down Expand Up @@ -169,11 +169,6 @@ def _write_nested_fits_map(input_dir, output_dir):
map_fits_image = hp.read_map(_tmp_file.name)
else:
map_fits_image = map_fits_image[0]
map_fits_image = map_fits_image.astype(np.int32)

output_file = output_dir / "point_map.fits"
with tempfile.NamedTemporaryFile() as _tmp_file:
with output_file.open("wb") as _map_file:
hp.write_map(
_tmp_file.name, map_fits_image, overwrite=True, dtype=np.int32, nest=True, coord="CEL"
)
_map_file.write(_tmp_file.read())
file_io.write_fits_image(map_fits_image, output_dir / "point_map.fits")
4 changes: 1 addition & 3 deletions src/hats_import/margin_cache/margin_cache_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def _check_arguments(self):
"margin_order must be of a higher order than the highest order catalog partition pixel."
)

margin_pixel_nside = hp.order2nside(self.margin_order)
margin_pixel_avgsize = hp.nside2resol(margin_pixel_nside, arcmin=True)
margin_pixel_mindist = hp.avgsize2mindist(margin_pixel_avgsize)
margin_pixel_mindist = hp.order2mindist(self.margin_order)
if margin_pixel_mindist * 60.0 < self.margin_threshold:
raise ValueError("margin pixels must be larger than margin_threshold")

Expand Down
5 changes: 2 additions & 3 deletions src/hats_import/soap/resume_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import hats.pixel_math.healpix_shim as hp
import numpy as np
from hats import read_hats
from hats import pixel_math, read_hats
from hats.catalog import Catalog
from hats.io import file_io
from hats.pixel_math.healpix_pixel import HealpixPixel
Expand Down Expand Up @@ -193,8 +193,7 @@ def source_to_object_map(object_catalog, source_catalog):

for source, objects in source_to_object.items():
# get all neighboring pixels
nside = hp.order2nside(source.order)
neighbors = hp.get_all_neighbours(nside, source.pixel, nest=True)
neighbors = pixel_math.get_margin(source.order, source.pixel, 0)

## get rid of -1s and normalize to max order
explosion_factor = 4 ** (max_order - source.order)
Expand Down

0 comments on commit 61d7d52

Please sign in to comment.