How to use the healpy.mollview function in healpy

To help you get started, we’ve selected a few healpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github healpy / healpy / test / test_fit_dipole.py View on Github external
print 'ini: mono=%s, dipole=%s'%(c,d)
mono,dipole = H.pixelfunc.fit_dipole(sig)
print 'fit: mono=%s, dipole=%s'%(mono,dipole)

resfit = dot(vec.T,dipole)+mono

diff = sig.copy()
diff[sig != H.UNSEEN] -= resfit[sig != H.UNSEEN]

H.mollview(diff)

# use remove_dipole
m2 = H.pixelfunc.remove_dipole(sig)
m3 = H.pixelfunc.remove_monopole(sig)

H.mollview(m2)
H.mollview(m3)
github telegraphic / PyGSM / pygsm / pygsm.py View on Github external
ra_rad, dec_rad = self.radec_of(0, np.pi / 2)
        ra_deg  = ra_rad / np.pi * 180
        dec_deg = dec_rad / np.pi * 180

        # Apply rotation
        derotate = hp.Rotator(rot=[ra_deg, dec_deg])
        g0, g1 = derotate(self._theta, self._phi)
        pix0 = hp.ang2pix(self._n_side, g0, g1)
        sky = sky[pix0]

        coordrotate = hp.Rotator(coord=['C', 'G'], inv=True)
        g0, g1 = coordrotate(self._theta, self._phi)
        pix0 = hp.ang2pix(self._n_side, g0, g1)
        sky = sky[pix0]

        hp.mollview(sky, coord='G', **kwargs)

        if show:
            if not plt:
                import pylab as plt
            plt.show()

        return sky
github DarkEnergySurvey / ugali / ugali / scratch / PlotManglePolygon.py View on Github external
usage = "Usage: %prog  [options] mangle1.ply [mangle2.ply ...]"
    description = "python script"
    parser = OptionParser(usage=usage,description=description)
    (opts, args) = parser.parse_args()

    nside = 2**8
    print("Creating ra, dec...")
    pix = np.arange(healpy.nside2npix(nside))
    ra,dec = pixToAng(nside,pix)

    for infile in args:
        print("Testing %i HEALPix pixels ..."%len(pix))
        inside = inMangle(infile,ra,dec)

        print("Plotting...")
        healpy.mollview(inside)

        outfile = infile.replace('.ply','.png')
        print("Writing %s"%outfile)
        plt.savefig(outfile)
github LSSTDESC / NaMaster / sandbox_validation / data / get_lss_contaminants.py View on Github external
starmap=hp.read_map("star_template.fits",verbose=False)
    starmap[starmap<=0]=1E-15
    starmap_low=hp.smoothing(hp.ud_grade(hp.ud_grade(starmap,nside_out=64),nside_out=o.nside_out),fwhm=3.5*np.pi/180,verbose=False) #Smooth out the star map to 3.5deg FWHM
    r_starmap=starmap_low/np.amax(starmap_low[msk>0]) #Normalize by maximum value
    shotnoise_factor=(r_starmap-4)/(2*r_starmap-4) #Compute shot noise factor. This interpolates between 1 (no stars) and 1.5 (lots of stars)

    #Now, impose additional depth variations on scales of 3.5 degrees
    cl_extravar=np.exp(-larr*(larr+1)*(3.5*np.pi/180/2.355)**2)
    norm=0.67E-3/np.sum(cl_extravar*(2*larr+1)/4/np.pi); cl_extravar*=norm; #This yields <10% variations
    depth_factor=1+hp.synfast(cl_extravar,o.nside_out,new=True,verbose=False);

    #This total map corresponds to the relative variation in the shot-noise variance
    snvmap=shotnoise_factor*depth_factor*msk

    if o.plot_stuff :
        hp.mollview(snvmap,min=0.9,title='Relative local shot noise variance');
        plt.show()

    hp.write_map("cont_lss_nvar_ns%d.fits"%o.nside_out,snvmap,overwrite=True)

if not os.path.isfile("cont_lss_star_ns%d.fits"%o.nside_out) :
    starmap=hp.ud_grade(hp.read_map("star_template.fits",verbose=False),nside_out=o.nside_out)
    starmap[starmap<=0]=1E-15
    starmap=-np.log(starmap) #Contaminant will be proportional to log(n_star)
    mean=np.sum(starmap*msk)/np.sum(msk)

    clcont=hp.anafast((starmap-mean)*msk)/fsky
    nflat=np.mean(clcont[max(2,o.nside_out//3-50):o.nside_out//3+50])*np.ones_like(clcont); #Add extra fluctuations beyond ell~nside/3 with flat power spectrum
    dstar=hp.synfast(nflat,o.nside_out,new=True,verbose=False)
    starmap_b=np.maximum(starmap+dstar,0)
    clcont_b=hp.anafast((starmap_b-mean)*msk)/fsky
    ratio=-np.sqrt(0.03*np.sum(cltt[max(2,o.nside_out//3-50):o.nside_out//3+50])/np.sum(clcont_b[max(2,o.nside_out//3-50):o.nside_out//3+50])) #3% contamination at ell~nside/3
github healpy / healpy / doc / create_images.py View on Github external
import healpy as hp
import numpy as np
import matplotlib.pyplot as plt

SIZE = 400
DPI = 60

m = np.arange(hp.nside2npix(32))
hp.mollview(m, nest=True, xsize=SIZE, title="Mollview image NESTED")
plt.savefig("static/moll_nside32_nest.png", dpi=DPI)

hp.mollview(m, nest=False, xsize=SIZE, title="Mollview image RING")
plt.savefig("static/moll_nside32_ring.png", dpi=DPI)

wmap_map_I = hp.read_map("../healpy/test/data/wmap_band_imap_r9_7yr_W_v4.fits")

hp.mollview(
    wmap_map_I,
    coord=["G", "E"],
    title="Histogram equalized Ecliptic",
    unit="mK",
    norm="hist",
    min=-1,
    max=1,
    xsize=SIZE,
github telegraphic / PyGSM / pygsm / pygsm2016.py View on Github external
"""

        if self.generated_map_data is None:
            raise RuntimeError("No GSM map has been generated yet. Run generate() first.")

        if self.generated_map_data.ndim == 2:
            gmap = self.generated_map_data[idx]
            freq = self.generated_map_freqs[idx]
        else:
            gmap = self.generated_map_data
            freq = self.generated_map_freqs

        if logged:
            gmap = np.log2(gmap)

        hp.mollview(gmap, coord='G',
                    title='Global Sky Model %s %s' % (str(freq), self.unit))
        if not plt:
            import pylab as plt
        plt.show()
github astroML / astroML / examples / datasets / plot_wmap_raw.py View on Github external
from matplotlib import pyplot as plt

# warning: due to a bug in healpy, importing it before pylab can cause
#  a segmentation fault in some circumstances.
import healpy as hp

from astroML.datasets import fetch_wmap_temperatures

#------------------------------------------------------------
# Fetch the wmap data
wmap_unmasked = fetch_wmap_temperatures(masked=False)

#------------------------------------------------------------
# plot the unmasked map
fig = plt.figure(1)
hp.mollview(wmap_unmasked, min=-1, max=1, title='Raw WMAP data',
            fig=1, cmap=plt.cm.jet, unit=r'$\Delta$T (mK)')
plt.show()
github cosmo-ethz / seek / seek / utils / plotting.py View on Github external
def mollview(hpmap, mark_unseen=True, radiosrc=True, cmap=None, **kwargs):
    if cmap is None:
        cmap = cubehelix_palette()
    
    if mark_unseen:
        hpmap = hpmap.copy()
        hpmap[hpmap==0] = hp.UNSEEN

    figsize = kwargs.pop("figsize", (15,10))
    fig, ax = plt.subplots(figsize=figsize)

    title = kwargs.pop("title", "")

    hp.mollview(hpmap, coord="C",
                hold=True, 
                cmap=cmap,
                title=title,
                **kwargs)
    
    hp.graticule(coord="g", verbose=False)
    
    if radiosrc:
        ax=hp.projaxes.HpxMollweideAxes(fig, (0.02,0.05,0.96,0.9),coord="g")
        fig.add_axes(ax)
    
        def add_radiosrc(ra, dec):
            hpmollaxes = fig.axes[-1]
            phi = sphere.ra2phi(ra * 2 * np.pi / 25)
            theta = sphere.dec2theta(np.radians(dec))
            scatter_kwargs = dict(marker="o", facecolors='none', edgecolors='r', linewidth=2.)
github LSSTDESC / NaMaster / sandbox_validation / data / plot_mock_data.py View on Github external
ax2.set_xlim([rb/2,2*nside_lss])
    ax3.set_xlim([rb/2,2*nside_lss])
    plt.savefig("../plots_paper/cls_cont_lss.pdf",bbox_inches='tight')
    plt.show()
    
if (o.whichfig==5) or (o.whichfig==-1) :
    #Plotting CMB stuff
    msk_s=hp.read_map("mask_cmb_ns%d.fits"%nside_cmb,verbose=False)
    fmi,msk_f=fm.read_flat_map("mask_cmb_flat.fits")
    fdum,[cq_f,cu_f]=fm.read_flat_map("cont_cmb_flat.fits",i_map=-1)
    cq_s,cu_s=hp.read_map("cont_cmb_ns%d.fits"%nside_cmb,field=[0,1],verbose=False)
    tonull_s=np.where(msk_s==0)
    tonull_f=np.where(msk_f==0)
    plt.figure(figsize=(12,9.75))
    ax=plt.subplot(321); mpp=msk_s.copy();
    hp.mollview(mpp,hold=True,notext=True,coord=['G','C'],title='Mask',cbar=False)
    ax=plt.subplot(322,projection=fmi.wcs); mpp=msk_f.copy();
    fmi.view_map(mpp,ax=ax,addColorbar=False,title="Mask",xlabel="")
    ax=plt.subplot(323); mpp=msk_s*cq_s;
    hp.mollview(mpp,hold=True,notext=True,coord=['G','C'],title='$Q_{\\rm FG}$',cbar=False)
    ax=plt.subplot(324,projection=fmi.wcs); mpp=msk_f*cq_f;
    fmi.view_map(mpp,ax=ax,addColorbar=False,title="$Q_{\\rm FG}$",xlabel="")
    ax=plt.subplot(325); mpp=msk_s*cu_s;
    hp.mollview(mpp,hold=True,notext=True,coord=['G','C'],title='$U_{\\rm FG}$',cbar=False)
    ax=plt.subplot(326,projection=fmi.wcs); mpp=msk_f*cu_f;
    fmi.view_map(mpp,ax=ax,addColorbar=False,title="$U_{\\rm FG}$")
    plt.savefig("../plots_paper/maps_cmb.pdf",bbox_inches='tight')
    plt.show()

if (o.whichfig==6) or (o.whichfig==-1) :
    lmax=7000
    def read_cl_camb(fname) :