Example #1
0
    def superimpose_polygon_outline(self, vertices, label, color='red',
                                    coord_in='C', cbar=True):
        '''Superimpose an outline of a survey given input vertices

        Parameters
        ----------
        vertices: array-like (nvtxs, 2)
            The vertices of the polygon

        label : string
            The label for the survey

        color : string or array-like with shape (3,)
            The color to use when overlaying the survey footprint. Either a
            string or rgb triplet.

        coord_in : 'C', 'E', or 'G'
            The coordinate system for the input vertices

        cbar : boolean
            Whether to add a colorbar corresponding to this polygon or not
        '''

        lons = vertices[:, 0]
        lats = vertices[:, 1]

        if np.abs(lons[-1] - 180.0) > 0.01:
            lons = np.append(lons, lons[0])
            lats = np.append(lats, lats[0])

        #Convert coordinate system for the outline to the one used in the
        #plot
        r = H.rotator.Rotator(coord=[coord_in, self.coord_plot])
        r = H.rotator.Rotator(coord=[coord_in, coord_in])
        lonsp = []
        latsp = []
        for lon, lat in zip(lons, lats):
            theta = np.radians(90 - lat)
            phi = np.radians(lon)
            thetap, phip = r(theta, phi)
            lonsp.append(np.degrees(phip))
            latsp.append(90 - np.degrees(thetap))

        lons = lonsp
        lats = latsp

        nvertices = len(lons)

        # Loop over all vertices and generate lines between adjacent vertices
        # in list. This is to ensure the lines are drawn.
        linelon = np.array([])
        linelat = np.array([])
        for i in range(nvertices-1):
            tmplon = np.linspace(lons[i], lons[i+1], num=1000)
            tmplat = np.linspace(lats[i], lats[i+1], num=1000)
            linelon = np.append(linelon, tmplon)
            linelat = np.append(linelat, tmplat)

        H.projplot(linelon, linelat, lonlat=True, markersize=1,
                   color=color, coord=coord_in)

        if cbar:
            # Temporary axis with a Healpix map so I can get the correct color
            # for the colorbar
            cm1 = util.get_color_map(color)
            coord = [coord_in, self.coord_plot]
            hpx_map = np.ones(12*32**2)
            self.mapview(hpx_map, title='', coord=coord,
                         cbar=True, fig=self.fig.number, cmap=cm1,
                         notext=True, flip='astro', **self.kwds)
            self.fig.delaxes(self.fig.axes[-1])

            # First add the new colorbar axis to the figure
            im0 = self.fig.axes[-1].get_images()[0]
            box = self.fig.axes[0].get_position()
            ax_color = pl.axes([len(self.cbs), box.y0-0.1, 0.05, 0.05])
            self.fig.colorbar(im0, cax=ax_color, orientation='horizontal',
                              label=label, values=[1, 1])

            self.cbs.append(ax_color)

            # Delete the temporary map
            self.fig.delaxes(self.fig.axes[-2])

            # Readjust the location of every colorbar
            ncb = len(self.cbs)

            left = 1.0 / (2.0*ncb) - 0.025
            for ax_tmp in self.cbs:
                ax_tmp.set_position([left, box.y0-0.1, 0.05, 0.05])
                left += 1.0 / ncb
Example #2
0
    def superimpose_hpxmap_contour(self, hpx_map, label, color='red',
                                   coord_in='C', cbar=True, frac=0.85,
                                   smooth_map=None):
        '''Superimpose a contour of an input healpix map.

        Parameters
        ----------
        hpx_map : array-like
            The input healpix map

        label : string
            The name to use as a label for the input map

        color : string or array-like with shape (3,), optional
            The color to use when overlaying the survey footprint. Either a
            string or rgb triplet. Default = 'red'

        coord_in : 'C', 'E', or 'G', optional
            The coordinate system of the input map. Default = 'C'.

        cbar : boolean, optional
            Whether to add a colorbar labeling the input map. Default = true.

        frac : float, optional
            The contour level will be drawn containing `frac' levels
            of observation time.

        smooth_map : float
            FWHM to smooth the input map (in arcminutes)
        '''

        idx_nan = (hpx_map == 0)

        # Smoothing makes it more likely that contours don't have holes,
        # but it takes some time to smooth each map
        if smooth_map:
            hpx_map = H.smoothing(hpx_map, fwhm=np.radians(smooth_map/60.0),
                                  verbose=False)

        hpx_map /= np.max(hpx_map)
        hpx_map[idx_nan] = np.NaN

        cm1 = util.get_color_map(color)

        coord = [coord_in, self.coord_plot]

        level = determine_level(hpx_map, frac)

        if self.partialmap:
            # Colorbar is added to this and then deleted to make sure there is
            # room at the bottom of the map for the labels. Margins are to make
            # sure the title is not partially off the figure for a square map
            sub = (1, 1, 1)
            margins = (0.01, 0.025, 0.01, 0.03)
            map_tmp = H.cartcontour(hpx_map, 5, title='', coord=coord,
                                    fig=self.fig.number, cmap=cm1, notext=True,
                                    flip='astro', latra=self.latra,
                                    lonra=self.lonra, sub=sub, margins=margins,
                                    return_projected_map=True, **self.kwds)
            idx = np.isfinite(map_tmp)
            if cbar:
                cbar = len(map_tmp[idx]) > 0
        else:
            self.mapcontour(hpx_map, [-0.1, level], title='', coord=coord,
                            cbar=True, fig=self.fig.number, cmap=cm1,
                            notext=True, flip='astro', **self.kwds)
        self.fig.delaxes(self.fig.axes[-1])

        if cbar:
            # Temporary axis with a Healpix map so I can get the correct color
            # for the colorbar
            cm1 = util.get_color_map(color)
            coord = [coord_in, self.coord_plot]
            hpx_map = np.ones(12*32**2)
            self.mapview(hpx_map, title='', coord=coord,
                         cbar=None, fig=self.fig.number, cmap=cm1,
                         notext=True, flip='astro', **self.kwds)

            # First add the new colorbar axis to the figure
            im0 = self.fig.axes[-1].get_images()[0]
            box = self.fig.axes[0].get_position()
            ax_color = pl.axes([len(self.cbs), box.y0-0.1, 0.05, 0.05])
            self.fig.colorbar(im0, cax=ax_color, orientation='horizontal',
                              label=label, values=[1, 1])

            self.cbs.append(ax_color)

            self.fig.delaxes(self.fig.axes[-2])

            # Readjust the location of every colorbar
            ncb = len(self.cbs)

            left = 1.0 / (2.0*ncb) - 0.025
            for ax_tmp in self.cbs:
                ax_tmp.set_position([left, box.y0-0.1, 0.05, 0.05])
                left += 1.0 / ncb
Example #3
0
    def superimpose_hpxmap(self, hpx_map, label, color='red', coord_in='C',
                           cbar=True):
        '''Superimpose a Healpix map on the background map.

        Parameters
        ----------
        hpx_map : array-like
            The hpx_map to superimpose upon the background.

        label : string
            The label to put on the colorbar for this footprint.

        color : string or array-like with shape (3,)
            The color to use when overlaying the survey footprint. Either a
            string or rgb triplet.

        coord_in : 'C', 'G', or 'E'
            The coordinate system of the input healpix map.

        Notes
        -----
        The input healpix map will have zeros replaced with NaNs to make
        those points completely transparent.
        '''

        idx_nan = (hpx_map == 0)
        hpx_map /= np.max(hpx_map)
        hpx_map[idx_nan] = np.NaN

        cm1 = util.get_color_map(color)

        coord = [coord_in, self.coord_plot]

        if self.partialmap:
            # Colorbar is added to this and then deleted to make sure there is
            # room at the bottom of the map for the labels. Margins are to make
            # sure the title is not partially off the figure for a square map
            sub = (1, 1, 1)
            margins = (0.01, 0.025, 0.01, 0.03)
            map_tmp = H.cartview(hpx_map, title='',
                                 coord=coord, fig=self.fig.number, cmap=cm1,
                                 notext=True, flip='astro', sub=sub,
                                 margins=margins, return_projected_map=True,
                                 **self.kwds)
            idx = np.isfinite(map_tmp)
            cbar = len(map_tmp[idx]) > 0
        else:
            self.mapview(hpx_map, title='', coord=coord,
                         cbar=True, fig=self.fig.number, cmap=cm1,
                         notext=True, flip='astro', **self.kwds)
        self.fig.delaxes(self.fig.axes[-1])

        if cbar:
            # First add the new colorbar axis to the figure
            im0 = self.fig.axes[-1].get_images()[0]
            box = self.fig.axes[0].get_position()
            ax_color = pl.axes([len(self.cbs), box.y0-0.1, 0.05, 0.05])
            self.fig.colorbar(im0, cax=ax_color, orientation='horizontal',
                              label=label, values=[1, 1])

            self.cbs.append(ax_color)

            # Read just the location of every colorbar
            ncb = len(self.cbs)

            left = 1.0 / (2.0*ncb) - 0.025
            for ax_tmp in self.cbs:
                ax_tmp.set_position([left, box.y0-0.1, 0.05, 0.05])
                left += 1.0 / ncb
Example #4
0
    def superimpose_polygon_outline(self,
                                    vertices,
                                    label,
                                    color='red',
                                    coord_in='C',
                                    cbar=True):
        '''Superimpose an outline of a survey given input vertices

        Parameters
        ----------
        vertices: array-like (nvtxs, 2)
            The vertices of the polygon

        label : string
            The label for the survey

        color : string or array-like with shape (3,)
            The color to use when overlaying the survey footprint. Either a
            string or rgb triplet.

        coord_in : 'C', 'E', or 'G'
            The coordinate system for the input vertices

        cbar : boolean
            Whether to add a colorbar corresponding to this polygon or not
        '''

        lons = vertices[:, 0]
        lats = vertices[:, 1]

        if np.abs(lons[-1] - 180.0) > 0.01:
            lons = np.append(lons, lons[0])
            lats = np.append(lats, lats[0])

        #Convert coordinate system for the outline to the one used in the
        #plot
        r = H.rotator.Rotator(coord=[coord_in, self.coord_plot])
        r = H.rotator.Rotator(coord=[coord_in, coord_in])
        lonsp = []
        latsp = []
        for lon, lat in zip(lons, lats):
            theta = np.radians(90 - lat)
            phi = np.radians(lon)
            thetap, phip = r(theta, phi)
            lonsp.append(np.degrees(phip))
            latsp.append(90 - np.degrees(thetap))

        lons = lonsp
        lats = latsp

        nvertices = len(lons)

        # Loop over all vertices and generate lines between adjacent vertices
        # in list. This is to ensure the lines are drawn.
        linelon = np.array([])
        linelat = np.array([])
        for i in range(nvertices - 1):
            tmplon = np.linspace(lons[i], lons[i + 1], num=1000)
            tmplat = np.linspace(lats[i], lats[i + 1], num=1000)
            linelon = np.append(linelon, tmplon)
            linelat = np.append(linelat, tmplat)

        H.projplot(linelon,
                   linelat,
                   lonlat=True,
                   markersize=1,
                   color=color,
                   coord=coord_in)

        if cbar:
            # Temporary axis with a Healpix map so I can get the correct color
            # for the colorbar
            cm1 = util.get_color_map(color)
            coord = [coord_in, self.coord_plot]
            hpx_map = np.ones(12 * 32**2)
            self.mapview(hpx_map,
                         title='',
                         coord=coord,
                         cbar=True,
                         fig=self.fig.number,
                         cmap=cm1,
                         notext=True,
                         flip='astro',
                         **self.kwds)
            self.fig.delaxes(self.fig.axes[-1])

            # First add the new colorbar axis to the figure
            im0 = self.fig.axes[-1].get_images()[0]
            box = self.fig.axes[0].get_position()
            ax_color = pl.axes([len(self.cbs), box.y0 - 0.1, 0.05, 0.05])
            self.fig.colorbar(im0,
                              cax=ax_color,
                              orientation='horizontal',
                              label=label,
                              values=[1, 1])

            self.cbs.append(ax_color)

            # Delete the temporary map
            self.fig.delaxes(self.fig.axes[-2])

            # Readjust the location of every colorbar
            ncb = len(self.cbs)

            left = 1.0 / (2.0 * ncb) - 0.025
            for ax_tmp in self.cbs:
                ax_tmp.set_position([left, box.y0 - 0.1, 0.05, 0.05])
                left += 1.0 / ncb
Example #5
0
    def superimpose_hpxmap_contour(self,
                                   hpx_map,
                                   label,
                                   color='red',
                                   coord_in='C',
                                   cbar=True,
                                   frac=0.85,
                                   smooth_map=None):
        '''Superimpose a contour of an input healpix map.

        Parameters
        ----------
        hpx_map : array-like
            The input healpix map

        label : string
            The name to use as a label for the input map

        color : string or array-like with shape (3,), optional
            The color to use when overlaying the survey footprint. Either a
            string or rgb triplet. Default = 'red'

        coord_in : 'C', 'E', or 'G', optional
            The coordinate system of the input map. Default = 'C'.

        cbar : boolean, optional
            Whether to add a colorbar labeling the input map. Default = true.

        frac : float, optional
            The contour level will be drawn containing `frac' levels
            of observation time.

        smooth_map : float
            FWHM to smooth the input map (in arcminutes)
        '''

        idx_nan = (hpx_map == 0)

        # Smoothing makes it more likely that contours don't have holes,
        # but it takes some time to smooth each map
        if smooth_map:
            hpx_map = H.smoothing(hpx_map,
                                  fwhm=np.radians(smooth_map / 60.0),
                                  verbose=False)

        hpx_map /= np.max(hpx_map)
        hpx_map[idx_nan] = np.NaN

        cm1 = util.get_color_map(color)

        coord = [coord_in, self.coord_plot]

        level = determine_level(hpx_map, frac)

        if self.partialmap:
            # Colorbar is added to this and then deleted to make sure there is
            # room at the bottom of the map for the labels. Margins are to make
            # sure the title is not partially off the figure for a square map
            sub = (1, 1, 1)
            margins = (0.01, 0.025, 0.01, 0.03)
            map_tmp = H.cartcontour(hpx_map,
                                    5,
                                    title='',
                                    coord=coord,
                                    fig=self.fig.number,
                                    cmap=cm1,
                                    notext=True,
                                    flip='astro',
                                    latra=self.latra,
                                    lonra=self.lonra,
                                    sub=sub,
                                    margins=margins,
                                    return_projected_map=True,
                                    **self.kwds)
            idx = np.isfinite(map_tmp)
            if cbar:
                cbar = len(map_tmp[idx]) > 0
        else:
            self.mapcontour(hpx_map, [-0.1, level],
                            title='',
                            coord=coord,
                            cbar=True,
                            fig=self.fig.number,
                            cmap=cm1,
                            notext=True,
                            flip='astro',
                            **self.kwds)
        self.fig.delaxes(self.fig.axes[-1])

        if cbar:
            # Temporary axis with a Healpix map so I can get the correct color
            # for the colorbar
            cm1 = util.get_color_map(color)
            coord = [coord_in, self.coord_plot]
            hpx_map = np.ones(12 * 32**2)
            self.mapview(hpx_map,
                         title='',
                         coord=coord,
                         cbar=None,
                         fig=self.fig.number,
                         cmap=cm1,
                         notext=True,
                         flip='astro',
                         **self.kwds)

            # First add the new colorbar axis to the figure
            im0 = self.fig.axes[-1].get_images()[0]
            box = self.fig.axes[0].get_position()
            ax_color = pl.axes([len(self.cbs), box.y0 - 0.1, 0.05, 0.05])
            self.fig.colorbar(im0,
                              cax=ax_color,
                              orientation='horizontal',
                              label=label,
                              values=[1, 1])

            self.cbs.append(ax_color)

            self.fig.delaxes(self.fig.axes[-2])

            # Readjust the location of every colorbar
            ncb = len(self.cbs)

            left = 1.0 / (2.0 * ncb) - 0.025
            for ax_tmp in self.cbs:
                ax_tmp.set_position([left, box.y0 - 0.1, 0.05, 0.05])
                left += 1.0 / ncb
Example #6
0
    def superimpose_hpxmap(self,
                           hpx_map,
                           label,
                           color='red',
                           coord_in='C',
                           cbar=True):
        '''Superimpose a Healpix map on the background map.

        Parameters
        ----------
        hpx_map : array-like
            The hpx_map to superimpose upon the background.

        label : string
            The label to put on the colorbar for this footprint.

        color : string or array-like with shape (3,)
            The color to use when overlaying the survey footprint. Either a
            string or rgb triplet.

        coord_in : 'C', 'G', or 'E'
            The coordinate system of the input healpix map.

        Notes
        -----
        The input healpix map will have zeros replaced with NaNs to make
        those points completely transparent.
        '''

        idx_nan = (hpx_map == 0)
        hpx_map /= np.max(hpx_map)
        hpx_map[idx_nan] = np.NaN

        cm1 = util.get_color_map(color)

        coord = [coord_in, self.coord_plot]

        if self.partialmap:
            # Colorbar is added to this and then deleted to make sure there is
            # room at the bottom of the map for the labels. Margins are to make
            # sure the title is not partially off the figure for a square map
            sub = (1, 1, 1)
            margins = (0.01, 0.025, 0.01, 0.03)
            map_tmp = H.cartview(hpx_map,
                                 title='',
                                 coord=coord,
                                 fig=self.fig.number,
                                 cmap=cm1,
                                 notext=True,
                                 flip='astro',
                                 sub=sub,
                                 margins=margins,
                                 return_projected_map=True,
                                 **self.kwds)
            idx = np.isfinite(map_tmp)
            cbar = len(map_tmp[idx]) > 0
        else:
            self.mapview(hpx_map,
                         title='',
                         coord=coord,
                         cbar=True,
                         fig=self.fig.number,
                         cmap=cm1,
                         notext=True,
                         flip='astro',
                         **self.kwds)
        self.fig.delaxes(self.fig.axes[-1])

        if cbar:
            # First add the new colorbar axis to the figure
            im0 = self.fig.axes[-1].get_images()[0]
            box = self.fig.axes[0].get_position()
            ax_color = pl.axes([len(self.cbs), box.y0 - 0.1, 0.05, 0.05])
            self.fig.colorbar(im0,
                              cax=ax_color,
                              orientation='horizontal',
                              label=label,
                              values=[1, 1])

            self.cbs.append(ax_color)

            # Read just the location of every colorbar
            ncb = len(self.cbs)

            left = 1.0 / (2.0 * ncb) - 0.025
            for ax_tmp in self.cbs:
                ax_tmp.set_position([left, box.y0 - 0.1, 0.05, 0.05])
                left += 1.0 / ncb