Skip to content

focus() before healpix() blows up memory #32

@monodera

Description

@monodera

The density map generated with skymapper does not seem to follow the resolution set by the nside parameter with healpy.

I run the following code with nside=32 (resolution of 110 arcmin) and nside=1024 (resolution of 3.4 arcmin), the resolution (or pixel size) of the output density map.

import healpy as hp
import numpy as np
import skymapper as skm

np.random.seed(42)


def getCatalog(size=10000, survey=None):
    # dummy catalog: uniform on sphere
    # Marsaglia (1972)
    xyz = np.random.normal(size=(size, 3))
    r = np.sqrt((xyz**2).sum(axis=1))
    dec = np.arccos(xyz[:, 2] / r) / skm.DEG2RAD - 90
    ra = 180 - np.arctan2(xyz[:, 0], xyz[:, 1]) / skm.DEG2RAD

    # survey selection
    if survey is not None:
        inside = survey.contains(ra, dec)
        ra = ra[inside]
        dec = dec[inside]
    return ra, dec


class TestSurvey(skm.survey.Survey):
    def contains(self, ra, dec):
        return ((dec > 65) & (dec < 68)) & ((ra > 265) & (ra < 275))


if __name__ == "__main__":

    # load RA/Dec from catalog
    size = 300000
    survey = TestSurvey()
    ra, dec = getCatalog(size, survey=survey)

    # 1) construct a projection, here Albers
    # define the optimal projection for set of coordinates
    # by minimizing the variation in distortion
    crit = skm.stdDistortion
    proj = skm.Albers.optimize(ra, dec, crit=crit)

    # 2) construct map: will hold figure and projection
    # the outline of the sphere can be styled with kwargs for matplotlib Polygon
    map = skm.Map(proj)

    # 3) add graticules, separated by 15 deg
    # the lines can be styled with kwargs for matplotlib Line2D
    # additional arguments for formatting the graticule labels
    sep = 1
    map.grid(sep=sep)

    # 4) add data to the map, e.g.
    # make density plot
    nside = 32
    # nside = 1024

    print(f"nside = {nside}")
    # print(f"{hp.nside2npix(nside)} pixels")
    print(f"{hp.nside2resol(nside, arcmin=True)=} arcmin")
    # print(f"{hp.nside2resol(nside, arcmin=True)/60} deg")

    mappable = map.density(ra, dec, nside=nside, vmin=0, vmax=0.005)
    cb = map.colorbar(mappable, cb_label="$n_g$ [arcmin$^{-2}$]")

    # add scatter plot
    map.scatter(ra, dec, s=10**2, edgecolor="k", facecolor="None")

    # focus on relevant region
    map.focus(ra, dec)

    map.title(f"{nside=}")

    map.savefig(f"readme_example_{nside}.png", bbox_inches="tight", dpi=300)

readme_example_32
readme_example_1024

I'd expect that the pixel size is that defined by nside in Healpix (hp.nside2resol()), but it seems not.

My python environment is the following:

  • Python 3.11.9
  • Numpy 1.26.4
  • Healpy 1.17.3
  • Matplotlib 3.9.2
  • Skymapper 0.4.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions