From c9aa6232740a5bc033d9af3440b5a13bfa36cd73 Mon Sep 17 00:00:00 2001 From: Eli Rykoff Date: Wed, 17 Apr 2024 09:40:49 -0700 Subject: [PATCH 1/2] Change test infrastructure to only use healpy for tests. --- .github/workflows/python-package-pr.yml | 2 +- .github/workflows/python-package-publish.yml | 2 +- .github/workflows/python-package-push.yml | 2 +- setup.cfg | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-package-pr.yml b/.github/workflows/python-package-pr.yml index 35343ee..b477a7f 100644 --- a/.github/workflows/python-package-pr.yml +++ b/.github/workflows/python-package-pr.yml @@ -24,7 +24,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[parquet,healpy,test] + pip install .[parquet,test,test_with_healpy] - name: Lint with flake8 run: | flake8 diff --git a/.github/workflows/python-package-publish.yml b/.github/workflows/python-package-publish.yml index e843990..b36d8f3 100644 --- a/.github/workflows/python-package-publish.yml +++ b/.github/workflows/python-package-publish.yml @@ -25,7 +25,7 @@ jobs: - name: Build and install run: | python -m pip install --upgrade pip setuptools - python -m pip install .[parquet,healpy,test] + python -m pip install .[parquet,test,test_with_healpy] - name: Run tests run: | cd tests diff --git a/.github/workflows/python-package-push.yml b/.github/workflows/python-package-push.yml index ea02034..83cdb28 100644 --- a/.github/workflows/python-package-push.yml +++ b/.github/workflows/python-package-push.yml @@ -24,7 +24,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install .[parquet,healpy,test] + python -m pip install .[parquet,test,test_with_healpy] - name: Lint with flake8 run: | flake8 diff --git a/setup.cfg b/setup.cfg index 93a1fbf..2c8b66e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ test = flake8 parquet = pyarrow>=5.0.0 -healpy = +test_with_healpy = healpy fitsio = fitsio From 07c805875fe668e0e82553dba7f4595528b53643 Mon Sep 17 00:00:00 2001 From: Eli Rykoff Date: Wed, 17 Apr 2024 09:41:10 -0700 Subject: [PATCH 2/2] Avoid use of healpy to read healpix maps. --- healsparse/io_map_fits.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/healsparse/io_map_fits.py b/healsparse/io_map_fits.py index e6be94f..1c1127d 100644 --- a/healsparse/io_map_fits.py +++ b/healsparse/io_map_fits.py @@ -90,20 +90,23 @@ def _read_map_fits(healsparse_class, filename, nside_coverage=None, pixels=None, _pix = data['PIXEL'] healsparse_map[_pix] = data[signal_column] elif hdr['INDXSCHM'].rstrip() == 'IMPLICIT': - try: - import healpy as hp - except ImportError: - raise RuntimeError("Cannot read full sky HEALPix maps without healpy.") - # This is an implicit (full) healpix map - # Figure out the datatype with HealSparseFits(filename) as fits: - row = fits.read_ext_data(1, row_range=[0, 1]) - dtype = row[0][0][0].dtype.type + data = fits.read_ext_data(1) + if "T" in data.dtype.names: + field_name = "T" + elif "TEMPERATURE" in data.dtype.names: + field_name = "TEMPERATURE" + else: + raise RuntimeError("Healpix file does not comply with standards.") + + # Ravel the data into one contiguous array. + data = data[field_name].ravel() + + if hdr["ORDERING"] == "RING": + data = hpg.reorder(data, ring_to_nest=True) - # Read in the map using healpy - healpix_map = hp.read_map(filename, nest=True, dtype=dtype) # Convert to healsparse format - healsparse_map = healsparse_class(healpix_map=healpix_map, + healsparse_map = healsparse_class(healpix_map=data, nside_coverage=nside_coverage, nest=True) else: @@ -111,7 +114,7 @@ def _read_map_fits(healsparse_class, filename, nside_coverage=None, pixels=None, if degrade_nside is not None: # Degrade this map. Note that this could not be done on read - # because healpy maps do not have that functionality. + # because healpix maps do not have that functionality. healsparse_map = healsparse_map.degrade(degrade_nside, reduction=reduction) if header: