Ejemplo n.º 1
0
def graticule(dpar=None, dmer=None, coord=None, local=None, **kwds):
    """Create a graticule, either on an existing mollweide map or not.

    Parameters:
      - dpar, dmer: interval in degrees between meridians and between parallels
      - coord: the coordinate system of the graticule (make rotation if needed,
               using coordinate system of the map if it is defined)
      - local: True if local graticule (no rotation is performed)
    Return:
      None
    """
    f = pylab.gcf()
    wasinteractive = pylab.isinteractive()
    pylab.ioff()
    try:
        if len(f.get_axes()) == 0:
            ax = PA.HpxMollweideAxes(f, (0.02, 0.05, 0.96, 0.9), coord=coord)
            f.add_axes(ax)
            ax.text(0.86,
                    0.05,
                    ax.proj.coordsysstr,
                    fontsize=14,
                    fontweight='bold',
                    transform=ax.transAxes)
        for ax in f.get_axes():
            if isinstance(ax, PA.SphericalProjAxes):
                ax.graticule(dpar=dpar,
                             dmer=dmer,
                             coord=coord,
                             local=local,
                             **kwds)
    finally:
        pylab.draw()
        if wasinteractive:
            pylab.ion()
Ejemplo n.º 2
0
def graticule(dpar=None, dmer=None, coord=None, local=None, **kwds):
    """Draw a graticule on the current Axes.

    Parameters
    ----------
    dpar, dmer : float, scalars
      Interval in degrees between meridians and between parallels
    coord : {'E', 'G', 'C'}
      The coordinate system of the graticule (make rotation if needed,
      using coordinate system of the map if it is defined).
    local : bool
      If True, draw a local graticule (no rotation is performed, useful for
      a gnomonic view, for example)

    Notes
    -----
    Other keyword parameters will be transmitted to the projplot function.

    See Also
    --------
    delgraticules
    """
    import pylab
    f = pylab.gcf()
    wasinteractive = pylab.isinteractive()
    pylab.ioff()
    try:
        if len(f.get_axes()) == 0:
            ax = PA.HpxMollweideAxes(f, (0.02, 0.05, 0.96, 0.9), coord=coord)
            f.add_axes(ax)
            ax.text(0.86,
                    0.05,
                    ax.proj.coordsysstr,
                    fontsize=14,
                    fontweight='bold',
                    transform=ax.transAxes)
        for ax in f.get_axes():
            if isinstance(ax, PA.SphericalProjAxes):
                ax.graticule(dpar=dpar,
                             dmer=dmer,
                             coord=coord,
                             local=local,
                             **kwds)
    finally:
        pylab.draw()
        if wasinteractive:
            pylab.ion()
Ejemplo n.º 3
0
def mollzoom(map=None,
             fig=None,
             rot=None,
             coord=None,
             unit='',
             xsize=800,
             title='Mollweide view',
             nest=False,
             min=None,
             max=None,
             flip='astro',
             remove_dip=False,
             remove_mono=False,
             gal_cut=0,
             format='%g',
             cmap=None,
             norm=None,
             hold=False,
             margins=None,
             sub=None):
    """Interactive mollweide plot with zoomed gnomview.
    
    Parameters:
    -----------
    map : float, array-like shape (Npix,)
      if None, use map with inf value (white map), useful for
      overplotting
    fig : a figure number. 
      Default: create a new figure
    rot : scalar or sequence, optional
      Describe the rotation to apply.
      In the form (lon, lat, psi) (unit: degrees) : the point at
      longitude *lon* and latitude *lat* will be at the center. An additional rotation
      of angle *psi* around this direction is applied.
    coord : sequence of character, optional
      Either one of 'G', 'E' or 'C' to describe the coordinate
      system of the map, or a sequence of 2 of these to rotate
      the map from the first to the second coordinate system.
    unit : str, optional
      A text describing the unit of the data. Default: ''
    xsize : int, optional
      The size of the image. Default: 800
    title : str, optional
      The title of the plot. Default: 'Mollweide view'
    nest : bool, optional
      If True, ordering scheme is NESTED. Default: False (RING)
    min : float, optional
      The minimum range value
    max : float, optional
      The maximum range value
    flip : {'astro', 'geo'}, optional
      Defines the convention of projection : 'astro' (default, east towards left, west towards right)
      or 'geo' (east towards roght, west towards left)
    remove_dip : bool, optional
      If :const:`True`, remove the dipole+monopole
    remove_mono : bool, optional
      If :const:`True`, remove the monopole
    gal_cut : float, scalar, optional
      Symmetric galactic cut for the dipole/monopole fit.
      Removes points in latitude range [-gal_cut, +gal_cut]
    format : str, optional
      The format of the scale label. Default: '%g'
    """
    # create the figure (if interactive, it will open the window now)
    f = pylab.figure(fig, figsize=(10.5, 5.4))
    extent = (0.02, 0.25, 0.56, 0.72)
    # Starting to draw : turn interactive off
    wasinteractive = pylab.isinteractive()
    pylab.ioff()
    try:
        if map is None:
            map = np.zeros(12) + np.inf
        ax = PA.HpxMollweideAxes(f,
                                 extent,
                                 coord=coord,
                                 rot=rot,
                                 format=format,
                                 flipconv=flip)
        f.add_axes(ax)
        if remove_dip:
            map = pixelfunc.remove_dipole(map,
                                          gal_cut=gal_cut,
                                          nest=nest,
                                          copy=True,
                                          verbose=True)
        elif remove_mono:
            map = pixelfunc.remove_monopole(map,
                                            gal_cut=gal_cut,
                                            nest=nest,
                                            copy=True,
                                            verbose=True)
        ax.projmap(map,
                   nest=nest,
                   xsize=xsize,
                   coord=coord,
                   vmin=min,
                   vmax=max,
                   cmap=cmap,
                   norm=norm)
        im = ax.get_images()[0]
        b = im.norm.inverse(np.linspace(0, 1, im.cmap.N + 1))
        v = np.linspace(im.norm.vmin, im.norm.vmax, im.cmap.N)
        if matplotlib.__version__ >= '0.91.0':
            cb = f.colorbar(ax.get_images()[0],
                            ax=ax,
                            orientation='horizontal',
                            shrink=0.5,
                            aspect=25,
                            ticks=PA.BoundaryLocator(),
                            pad=0.05,
                            fraction=0.1,
                            boundaries=b,
                            values=v)
        else:
            # for older matplotlib versions, no ax kwarg
            cb = f.colorbar(ax.get_images()[0],
                            orientation='horizontal',
                            shrink=0.5,
                            aspect=25,
                            ticks=PA.BoundaryLocator(),
                            pad=0.05,
                            fraction=0.1,
                            boundaries=b,
                            values=v)
        ax.set_title(title)
        ax.text(0.86,
                0.05,
                ax.proj.coordsysstr,
                fontsize=14,
                fontweight='bold',
                transform=ax.transAxes)
        cb.ax.text(1.05,
                   0.30,
                   unit,
                   fontsize=14,
                   fontweight='bold',
                   transform=cb.ax.transAxes,
                   ha='left',
                   va='center')
        f.sca(ax)

        ## Gnomonic axes
        #extent = (0.02,0.25,0.56,0.72)
        g_xsize = 600
        g_reso = 1.
        extent = (0.60, 0.04, 0.38, 0.94)
        g_ax = PA.HpxGnomonicAxes(f,
                                  extent,
                                  coord=coord,
                                  rot=rot,
                                  format=format,
                                  flipconv=flip)
        f.add_axes(g_ax)
        if remove_dip:
            map = pixelfunc.remove_dipole(map,
                                          gal_cut=gal_cut,
                                          nest=nest,
                                          copy=True)
        elif remove_mono:
            map = pixelfunc.remove_monopole(map,
                                            gal_cut=gal_cut,
                                            nest=nest,
                                            copy=True)
        g_ax.projmap(map,
                     nest=nest,
                     coord=coord,
                     vmin=min,
                     vmax=max,
                     xsize=g_xsize,
                     ysize=g_xsize,
                     reso=g_reso,
                     cmap=cmap,
                     norm=norm)
        im = g_ax.get_images()[0]
        b = im.norm.inverse(np.linspace(0, 1, im.cmap.N + 1))
        v = np.linspace(im.norm.vmin, im.norm.vmax, im.cmap.N)
        if matplotlib.__version__ >= '0.91.0':
            cb = f.colorbar(g_ax.get_images()[0],
                            ax=g_ax,
                            orientation='horizontal',
                            shrink=0.5,
                            aspect=25,
                            ticks=PA.BoundaryLocator(),
                            pad=0.08,
                            fraction=0.1,
                            boundaries=b,
                            values=v)
        else:
            cb = f.colorbar(g_ax.get_images()[0],
                            orientation='horizontal',
                            shrink=0.5,
                            aspect=25,
                            ticks=PA.BoundaryLocator(),
                            pad=0.08,
                            fraction=0.1,
                            boundaries=b,
                            values=v)
        g_ax.set_title(title)
        g_ax.text(-0.07,
                  0.02,
                  "%g '/pix,   %dx%d pix" %
                  (g_ax.proj.arrayinfo['reso'], g_ax.proj.arrayinfo['xsize'],
                   g_ax.proj.arrayinfo['ysize']),
                  fontsize=12,
                  verticalalignment='bottom',
                  transform=g_ax.transAxes,
                  rotation=90)
        g_ax.text(-0.07,
                  0.8,
                  g_ax.proj.coordsysstr,
                  fontsize=14,
                  fontweight='bold',
                  rotation=90,
                  transform=g_ax.transAxes)
        lon, lat = np.around(g_ax.proj.get_center(lonlat=True),
                             g_ax._coordprec)
        g_ax.text(0.5,
                  -0.03,
                  'on (%g,%g)' % (lon, lat),
                  verticalalignment='center',
                  horizontalalignment='center',
                  transform=g_ax.transAxes)
        cb.ax.text(1.05,
                   0.30,
                   unit,
                   fontsize=14,
                   fontweight='bold',
                   transform=cb.ax.transAxes,
                   ha='left',
                   va='center')
        # Add graticule info axes
        grat_ax = pylab.axes([0.25, 0.02, 0.22, 0.25])
        grat_ax.axis('off')
        # Add help text
        help_ax = pylab.axes([0.02, 0.02, 0.22, 0.25])
        help_ax.axis('off')
        t = help_ax.transAxes
        help_ax.text(0.1,
                     0.8,
                     'r/t .... zoom out/in',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.65,
                     'p/v .... print coord/val',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.5,
                     'c ...... go to center',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.35,
                     'f ...... next color scale',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.2,
                     'k ...... save current scale',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.05,
                     'g ...... toggle graticule',
                     transform=t,
                     va='baseline')
        f.sca(g_ax)
        # Set up the zoom capability
        zt = ZoomTool(map,
                      fig=f.number,
                      nest=nest,
                      cmap=cmap,
                      norm=norm,
                      coord=coord)
    finally:
        pylab.draw()
        if wasinteractive:
            pylab.ion()
Ejemplo n.º 4
0
def mollzoom(map=None,
             fig=None,
             rot=None,
             coord=None,
             unit='',
             xsize=800,
             title='Mollweide view',
             nest=False,
             min=None,
             max=None,
             flip='astro',
             remove_dip=False,
             remove_mono=False,
             gal_cut=0,
             format='%g',
             cmap=None,
             norm=None,
             hold=False,
             margins=None,
             sub=None):
    """Plot an healpix map (given as an array) in Mollweide projection,
    with a gnomview zone showing a zoomed region.
    
    Input:
      - map : an ndarray containing the map
              if None, use map with inf value (white map), useful for
              overplotting
    Parameters:
      - fig: a figure number. Default: create a new figure
      - rot: rotation, either 1,2 or 3 angles describing the rotation
             Default: None
      - coord: either one of 'G', 'E' or 'C' to describe the coordinate
               system of the map, or a sequence of 2 of these to make
               rotation from the first to the second coordinate system.
               Default: None
      - unit: a text describing the unit. Default: ''
      - xsize: the size of the image. Default: 800
      - title: the title of the plot. Default: 'Mollweide view'
      - nest: if True, ordering scheme is NEST. Default: False (RING)
      - min: the minimum range value
      - max: the maximum range value
      - flip: 'astro' (default, east towards left, west towards right) or 'geo'
      - remove_dip: if True, remove the dipole+monopole
      - remove_mono: if True, remove the monopole
      - gal_cut: galactic cut for the dipole/monopole fit
      - format: the format of the scale. Default: '%g'
    """
    # create the figure (if interactive, it will open the window now)
    f = pylab.figure(fig, figsize=(10.5, 5.4))
    extent = (0.02, 0.25, 0.56, 0.72)
    # Starting to draw : turn interactive off
    wasinteractive = pylab.isinteractive()
    pylab.ioff()
    try:
        if map is None:
            map = npy.zeros(12) + npy.inf
        ax = PA.HpxMollweideAxes(f,
                                 extent,
                                 coord=coord,
                                 rot=rot,
                                 format=format,
                                 flipconv=flip)
        f.add_axes(ax)
        if remove_dip:
            map = pixelfunc.remove_dipole(map,
                                          gal_cut=gal_cut,
                                          nest=nest,
                                          copy=True,
                                          verbose=True)
        elif remove_mono:
            map = pixelfunc.remove_monopole(map,
                                            gal_cut=gal_cut,
                                            nest=nest,
                                            copy=True,
                                            verbose=True)
        ax.projmap(map,
                   nest=nest,
                   xsize=xsize,
                   coord=coord,
                   vmin=min,
                   vmax=max,
                   cmap=cmap,
                   norm=norm)
        im = ax.get_images()[0]
        b = im.norm.inverse(npy.linspace(0, 1, im.cmap.N + 1))
        v = npy.linspace(im.norm.vmin, im.norm.vmax, im.cmap.N)
        if matplotlib.__version__ >= '0.91.0':
            cb = f.colorbar(ax.get_images()[0],
                            ax=ax,
                            orientation='horizontal',
                            shrink=0.5,
                            aspect=25,
                            ticks=PA.BoundaryLocator(),
                            pad=0.05,
                            fraction=0.1,
                            boundaries=b,
                            values=v)
        else:
            # for older matplotlib versions, no ax kwarg
            cb = f.colorbar(ax.get_images()[0],
                            orientation='horizontal',
                            shrink=0.5,
                            aspect=25,
                            ticks=PA.BoundaryLocator(),
                            pad=0.05,
                            fraction=0.1,
                            boundaries=b,
                            values=v)
        ax.set_title(title)
        ax.text(0.86,
                0.05,
                ax.proj.coordsysstr,
                fontsize=14,
                fontweight='bold',
                transform=ax.transAxes)
        cb.ax.text(1.05,
                   0.30,
                   unit,
                   fontsize=14,
                   fontweight='bold',
                   transform=cb.ax.transAxes,
                   ha='left',
                   va='center')
        f.sca(ax)

        ## Gnomonic axes
        #extent = (0.02,0.25,0.56,0.72)
        g_xsize = 600
        g_reso = 1.
        extent = (0.60, 0.04, 0.38, 0.94)
        g_ax = PA.HpxGnomonicAxes(f,
                                  extent,
                                  coord=coord,
                                  rot=rot,
                                  format=format,
                                  flipconv=flip)
        f.add_axes(g_ax)
        if remove_dip:
            map = pixelfunc.remove_dipole(map,
                                          gal_cut=gal_cut,
                                          nest=nest,
                                          copy=True)
        elif remove_mono:
            map = pixelfunc.remove_monopole(map,
                                            gal_cut=gal_cut,
                                            nest=nest,
                                            copy=True)
        g_ax.projmap(map,
                     nest=nest,
                     coord=coord,
                     vmin=min,
                     vmax=max,
                     xsize=g_xsize,
                     ysize=g_xsize,
                     reso=g_reso,
                     cmap=cmap,
                     norm=norm)
        im = g_ax.get_images()[0]
        b = im.norm.inverse(npy.linspace(0, 1, im.cmap.N + 1))
        v = npy.linspace(im.norm.vmin, im.norm.vmax, im.cmap.N)
        if matplotlib.__version__ >= '0.91.0':
            cb = f.colorbar(g_ax.get_images()[0],
                            ax=g_ax,
                            orientation='horizontal',
                            shrink=0.5,
                            aspect=25,
                            ticks=PA.BoundaryLocator(),
                            pad=0.08,
                            fraction=0.1,
                            boundaries=b,
                            values=v)
        else:
            cb = f.colorbar(g_ax.get_images()[0],
                            orientation='horizontal',
                            shrink=0.5,
                            aspect=25,
                            ticks=PA.BoundaryLocator(),
                            pad=0.08,
                            fraction=0.1,
                            boundaries=b,
                            values=v)
        g_ax.set_title(title)
        g_ax.text(-0.07,
                  0.02,
                  "%g '/pix,   %dx%d pix" %
                  (g_ax.proj.arrayinfo['reso'], g_ax.proj.arrayinfo['xsize'],
                   g_ax.proj.arrayinfo['ysize']),
                  fontsize=12,
                  verticalalignment='bottom',
                  transform=g_ax.transAxes,
                  rotation=90)
        g_ax.text(-0.07,
                  0.8,
                  g_ax.proj.coordsysstr,
                  fontsize=14,
                  fontweight='bold',
                  rotation=90,
                  transform=g_ax.transAxes)
        lon, lat = npy.around(g_ax.proj.get_center(lonlat=True),
                              g_ax._coordprec)
        g_ax.text(0.5,
                  -0.03,
                  'on (%g,%g)' % (lon, lat),
                  verticalalignment='center',
                  horizontalalignment='center',
                  transform=g_ax.transAxes)
        cb.ax.text(1.05,
                   0.30,
                   unit,
                   fontsize=14,
                   fontweight='bold',
                   transform=cb.ax.transAxes,
                   ha='left',
                   va='center')
        # Add graticule info axes
        grat_ax = pylab.axes([0.25, 0.02, 0.22, 0.25])
        grat_ax.axis('off')
        # Add help text
        help_ax = pylab.axes([0.02, 0.02, 0.22, 0.25])
        help_ax.axis('off')
        t = help_ax.transAxes
        help_ax.text(0.1,
                     0.8,
                     'r/t .... zoom out/in',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.65,
                     'p/v .... print coord/val',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.5,
                     'c ...... go to center',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.35,
                     'f ...... next color scale',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.2,
                     'k ...... save current scale',
                     transform=t,
                     va='baseline')
        help_ax.text(0.1,
                     0.05,
                     'g ...... toggle graticule',
                     transform=t,
                     va='baseline')
        f.sca(g_ax)
        # Set up the zoom capability
        zt = ZoomTool(map,
                      fig=f.number,
                      nest=nest,
                      cmap=cmap,
                      norm=norm,
                      coord=coord)
    finally:
        pylab.draw()
        if wasinteractive:
            pylab.ion()
Ejemplo n.º 5
0
def mollview(map=None,
             fig=None,
             rot=None,
             coord=None,
             unit='',
             xsize=800,
             title='Mollweide view',
             nest=False,
             min=None,
             max=None,
             flip='astro',
             remove_dip=False,
             remove_mono=False,
             gal_cut=0,
             format='%g',
             format2='%g',
             cbar=True,
             cmap=None,
             notext=False,
             norm=None,
             hold=False,
             margins=None,
             sub=None):
    """Plot an healpix map (given as an array) in Mollweide projection.
    
    Input:
      - map : an ndarray containing the map
              if None, use map with inf value (white map), useful for
              overplotting
    Parameters:
      - fig: a figure number. Default: create a new figure
      - rot: rotation, either 1,2 or 3 angles describing the rotation
             Default: None
      - coord: either one of 'G', 'E' or 'C' to describe the coordinate
               system of the map, or a sequence of 2 of these to make
               rotation from the first to the second coordinate system.
               Default: None
      - unit: a text describing the unit. Default: ''
      - xsize: the size of the image. Default: 800
      - title: the title of the plot. Default: 'Mollweide view'
      - nest: if True, ordering scheme is NEST. Default: False (RING)
      - min: the minimum range value
      - max: the maximum range value
      - flip: 'astro' (default, east towards left, west towards right) or 'geo'
      - remove_dip: if True, remove the dipole+monopole
      - remove_mono: if True, remove the monopole
      - gal_cut: galactic cut for the dipole/monopole fit
      - format: the format of the scale label. Default: '%g'
      - format2: format of the pixel value under mouse. Default: '%g'
      - cbar: display the colorbar. Default: True
      - notext: if True, no text is printed around the map
      - norm: color normalization, hist= histogram equalized color mapping, log=
              logarithmic color mapping, default: None (linear color mapping)
      - hold: if True, replace the current Axes by a MollweideAxes.
              use this if you want to have multiple maps on the same
              figure. Default: False
      - sub: use a part of the current figure (same syntax as subplot).
             Default: None
      - margins: either None, or a sequence (left,bottom,right,top)
                 giving the margins on left,bottom,right and top
                 of the axes. Values are relative to figure (0-1).
                 Default: None
    """
    # Create the figure
    if not (hold or sub):
        f = pylab.figure(fig, figsize=(8.5, 5.4))
        extent = (0.02, 0.05, 0.96, 0.9)
    elif hold:
        f = pylab.gcf()
        left, bottom, right, top = npy.array(f.gca().get_position()).ravel()
        extent = (left, bottom, right - left, top - bottom)
        f.delaxes(f.gca())
    else:  # using subplot syntax
        f = pylab.gcf()
        if hasattr(sub, '__len__'):
            nrows, ncols, idx = sub
        else:
            nrows, ncols, idx = sub / 100, (sub % 100) / 10, (sub % 10)
        if idx < 1 or idx > ncols * nrows:
            raise ValueError('Wrong values for sub: %d, %d, %d' %
                             (nrows, ncols, idx))
        c, r = (idx - 1) % ncols, (idx - 1) / ncols
        if not margins:
            margins = (0.01, 0.0, 0.0, 0.02)
        extent = (c * 1. / ncols + margins[0],
                  1. - (r + 1) * 1. / nrows + margins[1],
                  1. / ncols - margins[2] - margins[0],
                  1. / nrows - margins[3] - margins[1])
        extent = (extent[0] + margins[0], extent[1] + margins[1],
                  extent[2] - margins[2] - margins[0],
                  extent[3] - margins[3] - margins[1])
        #extent = (c*1./ncols, 1.-(r+1)*1./nrows,1./ncols,1./nrows)
    #f=pylab.figure(fig,figsize=(8.5,5.4))

    # Starting to draw : turn interactive off
    wasinteractive = pylab.isinteractive()
    pylab.ioff()
    try:
        if map is None:
            map = npy.zeros(12) + npy.inf
            cbar = False
        ax = PA.HpxMollweideAxes(f,
                                 extent,
                                 coord=coord,
                                 rot=rot,
                                 format=format2,
                                 flipconv=flip)
        f.add_axes(ax)
        if remove_dip:
            map = pixelfunc.remove_dipole(map,
                                          gal_cut=gal_cut,
                                          nest=nest,
                                          copy=True,
                                          verbose=True)
        elif remove_mono:
            map = pixelfunc.remove_monopole(map,
                                            gal_cut=gal_cut,
                                            nest=nest,
                                            copy=True,
                                            verbose=True)
        ax.projmap(map,
                   nest=nest,
                   xsize=xsize,
                   coord=coord,
                   vmin=min,
                   vmax=max,
                   cmap=cmap,
                   norm=norm)
        if cbar:
            im = ax.get_images()[0]
            b = im.norm.inverse(npy.linspace(0, 1, im.cmap.N + 1))
            v = npy.linspace(im.norm.vmin, im.norm.vmax, im.cmap.N)
            if matplotlib.__version__ >= '0.91.0':
                cb = f.colorbar(ax.get_images()[0],
                                ax=ax,
                                orientation='horizontal',
                                shrink=0.5,
                                aspect=25,
                                ticks=PA.BoundaryLocator(),
                                pad=0.05,
                                fraction=0.1,
                                boundaries=b,
                                values=v,
                                format=format)
            else:
                # for older matplotlib versions, no ax kwarg
                cb = f.colorbar(ax.get_images()[0],
                                orientation='horizontal',
                                shrink=0.5,
                                aspect=25,
                                ticks=PA.BoundaryLocator(),
                                pad=0.05,
                                fraction=0.1,
                                boundaries=b,
                                values=v,
                                format=format)
        ax.set_title(title)
        if not notext:
            ax.text(0.86,
                    0.05,
                    ax.proj.coordsysstr,
                    fontsize=14,
                    fontweight='bold',
                    transform=ax.transAxes)
        if cbar:
            cb.ax.text(0.5,
                       -1.0,
                       unit,
                       fontsize=14,
                       transform=cb.ax.transAxes,
                       ha='center',
                       va='center')
        f.sca(ax)
    finally:
        pylab.draw()
        if wasinteractive:
            pylab.ion()
Ejemplo n.º 6
0
def mollview(map=None,
             fig=None,
             rot=None,
             coord=None,
             unit='',
             xsize=800,
             title='Mollweide view',
             nest=False,
             min=None,
             max=None,
             flip='astro',
             remove_dip=False,
             remove_mono=False,
             gal_cut=0,
             format='%g',
             format2='%g',
             cbar=True,
             cmap=None,
             notext=False,
             norm=None,
             hold=False,
             margins=None,
             sub=None):
    """Plot an healpix map (given as an array) in Mollweide projection.
    
    Parameters
    ----------
    map : float, array-like or None
      An array containing the map, supports masked maps, see the `ma` function.
      If None, will display a blank map, useful for overplotting.
    fig : int or None, optional
      The figure number to use. Default: create a new figure
    rot : scalar or sequence, optional
      Describe the rotation to apply.
      In the form (lon, lat, psi) (unit: degrees) : the point at
      longitude *lon* and latitude *lat* will be at the center. An additional rotation
      of angle *psi* around this direction is applied.
    coord : sequence of character, optional
      Either one of 'G', 'E' or 'C' to describe the coordinate
      system of the map, or a sequence of 2 of these to rotate
      the map from the first to the second coordinate system.
    unit : str, optional
      A text describing the unit of the data. Default: ''
    xsize : int, optional
      The size of the image. Default: 800
    title : str, optional
      The title of the plot. Default: 'Mollweide view'
    nest : bool, optional
      If True, ordering scheme is NESTED. Default: False (RING)
    min : float, optional
      The minimum range value
    max : float, optional
      The maximum range value
    flip : {'astro', 'geo'}, optional
      Defines the convention of projection : 'astro' (default, east towards left, west towards right)
      or 'geo' (east towards roght, west towards left)
    remove_dip : bool, optional
      If :const:`True`, remove the dipole+monopole
    remove_mono : bool, optional
      If :const:`True`, remove the monopole
    gal_cut : float, scalar, optional
      Symmetric galactic cut for the dipole/monopole fit.
      Removes points in latitude range [-gal_cut, +gal_cut]
    format : str, optional
      The format of the scale label. Default: '%g'
    format2 : str, optional
      Format of the pixel value under mouse. Default: '%g'
    cbar : bool, optional
      Display the colorbar. Default: True
    notext : bool, optional
      If True, no text is printed around the map
    norm : {'hist', 'log', None}
      Color normalization, hist= histogram equalized color mapping,
      log= logarithmic color mapping, default: None (linear color mapping)
    hold : bool, optional
      If True, replace the current Axes by a MollweideAxes.
      use this if you want to have multiple maps on the same
      figure. Default: False
    sub : int, scalar or sequence, optional
      Use only a zone of the current figure (same syntax as subplot).
      Default: None
    margins : None or sequence, optional
      Either None, or a sequence (left,bottom,right,top)
      giving the margins on left,bottom,right and top
      of the axes. Values are relative to figure (0-1).
      Default: None

    See Also
    --------
    gnomview, cartview
    """
    # Create the figure
    import pylab
    if not (hold or sub):
        f = pylab.figure(fig, figsize=(8.5, 5.4))
        extent = (0.02, 0.05, 0.96, 0.9)
    elif hold:
        f = pylab.gcf()
        left, bottom, right, top = np.array(f.gca().get_position()).ravel()
        extent = (left, bottom, right - left, top - bottom)
        f.delaxes(f.gca())
    else:  # using subplot syntax
        f = pylab.gcf()
        if hasattr(sub, '__len__'):
            nrows, ncols, idx = sub
        else:
            nrows, ncols, idx = sub / 100, (sub % 100) / 10, (sub % 10)
        if idx < 1 or idx > ncols * nrows:
            raise ValueError('Wrong values for sub: %d, %d, %d' %
                             (nrows, ncols, idx))
        c, r = (idx - 1) % ncols, (idx - 1) / ncols
        if not margins:
            margins = (0.01, 0.0, 0.0, 0.02)
        extent = (c * 1. / ncols + margins[0],
                  1. - (r + 1) * 1. / nrows + margins[1],
                  1. / ncols - margins[2] - margins[0],
                  1. / nrows - margins[3] - margins[1])
        extent = (extent[0] + margins[0], extent[1] + margins[1],
                  extent[2] - margins[2] - margins[0],
                  extent[3] - margins[3] - margins[1])
        #extent = (c*1./ncols, 1.-(r+1)*1./nrows,1./ncols,1./nrows)
    #f=pylab.figure(fig,figsize=(8.5,5.4))

    # Starting to draw : turn interactive off
    wasinteractive = pylab.isinteractive()
    pylab.ioff()
    try:
        if map is None:
            map = np.zeros(12) + np.inf
            cbar = False
        map = pixelfunc.ma_to_array(map)
        ax = PA.HpxMollweideAxes(f,
                                 extent,
                                 coord=coord,
                                 rot=rot,
                                 format=format2,
                                 flipconv=flip)
        f.add_axes(ax)
        if remove_dip:
            map = pixelfunc.remove_dipole(map,
                                          gal_cut=gal_cut,
                                          nest=nest,
                                          copy=True,
                                          verbose=True)
        elif remove_mono:
            map = pixelfunc.remove_monopole(map,
                                            gal_cut=gal_cut,
                                            nest=nest,
                                            copy=True,
                                            verbose=True)
        ax.projmap(map,
                   nest=nest,
                   xsize=xsize,
                   coord=coord,
                   vmin=min,
                   vmax=max,
                   cmap=cmap,
                   norm=norm)
        if cbar:
            im = ax.get_images()[0]
            b = im.norm.inverse(np.linspace(0, 1, im.cmap.N + 1))
            v = np.linspace(im.norm.vmin, im.norm.vmax, im.cmap.N)
            if matplotlib.__version__ >= '0.91.0':
                cb = f.colorbar(im,
                                ax=ax,
                                orientation='horizontal',
                                shrink=0.5,
                                aspect=25,
                                ticks=PA.BoundaryLocator(),
                                pad=0.05,
                                fraction=0.1,
                                boundaries=b,
                                values=v,
                                format=format)
            else:
                # for older matplotlib versions, no ax kwarg
                cb = f.colorbar(im,
                                orientation='horizontal',
                                shrink=0.5,
                                aspect=25,
                                ticks=PA.BoundaryLocator(),
                                pad=0.05,
                                fraction=0.1,
                                boundaries=b,
                                values=v,
                                format=format)
        ax.set_title(title)
        if not notext:
            ax.text(0.86,
                    0.05,
                    ax.proj.coordsysstr,
                    fontsize=14,
                    fontweight='bold',
                    transform=ax.transAxes)
        if cbar:
            cb.ax.text(0.5,
                       -1.0,
                       unit,
                       fontsize=14,
                       transform=cb.ax.transAxes,
                       ha='center',
                       va='center')
        f.sca(ax)
    finally:
        pylab.draw()
        if wasinteractive:
            pylab.ion()