Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make get_map return healpix map #1

Open
SergeiDBykov opened this issue Jun 30, 2021 · 0 comments
Open

Make get_map return healpix map #1

SergeiDBykov opened this issue Jun 30, 2021 · 0 comments

Comments

@SergeiDBykov
Copy link

SergeiDBykov commented Jun 30, 2021

Hi!
I think it would be very handy and cool to have a healpix map returned when one uses plot_map function from 'data' module. Also the hires data should be included if needed.

it requires a modification only of a few lines in core.py, as below


    @classmethod
    def plot_map(cls, map_name, plotname=None, hires=False):
        """
        Full-sky plot (mollweide projection) of the map.

        **Note:** this method needs ``healpy`` and ``matplotlib``.

        Parameters
        ----------
        map_name : ``str``
            Name of the map to be plotted. Use ``show_maps`` method
            to see a list of all available maps.
        plotname : ``str`` or ``None``, optional
            Name of the file where the plot will be saved. If ``None``,
            the plot is shown but not saved. Defaults to ``None``.
        hires : bool
            whether to use high resolution map
        Returns
        -------
        plot : ``numpy.ndarray``
            2D numpy array with the plot.
        hpmap : ``numpy.ndarray``
            1D numpy array with the healpix map being plot.
        """
        import healpy as hp
        import matplotlib.pyplot as plt

        cls._check_map(map_name)

        if not hires:
            hpmapfile = "{}_{}_healpix_lowres.fits".format(
                cls._map_type, map_name)
        else:
            hpmapfile = "{}_{}_healpix_hires.fits".format(
                cls._map_type, map_name)

        hpmapfile = os.path.join(cls._data_path, hpmapfile)
        hpmap = hp.read_map(hpmapfile)

        title = "{} ({})".format(map_name, cls._maps[map_name])
        if cls._map_type == "h1_nh":
            unit_label = "cm-2"
            minval, maxval = 1e19, 3e22
        else:
            unit_label = "mag"
            minval, maxval = 0, hpmap.max()

        plot = hp.mollview(
            hpmap,
            title=title,
            norm="hist",
            min=minval,
            max=maxval,
            unit=unit_label,
            return_projected_map=True,
        )

        if plotname is None:
            plt.show()
        else:
            plt.savefig(plotname)

        return plot, hpmap

And for this reason, returning low/hi resolution map should be an argument.
Healpix NH maps are useful for creating masks for, say, X-ray surveys.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant