Beispiel #1
0
    def show(self, **kwargs):
        """ show coverage

        Parameters
        ----------

        typ : string
            'pr' | 'sinr' | 'capacity' | 'loss' | 'best' | 'egd' | 'ref'
        grid : boolean
        polar : string
            'o' | 'p'
        best : boolean
            draw best server contour if True
        f : int
            frequency index
        a : int
            access point index (-1 all access point)

        Examples
        --------

        .. plot::
            :include-source:

            >>> from pylayers.antprop.coverage import *
            >>> C = Coverage()
            >>> C.cover()
            >>> f,a = C.show(typ='pr',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='best',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='loss',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='sinr',figsize=(10,8))
            >>> plt.show()

        See Also
        --------

        pylayers.gis.layout.Layout.showG

        """
        defaults = {
            'typ': 'pr',
            'grid': False,
            'polar': 'p',
            'scale': 30,
            'f': 0,
            'a': -1,
            'db': True,
            'cmap': cm.jet,
            'best': False,
            'title': ''
        }

        for k in defaults:
            if k not in kwargs:
                kwargs[k] = defaults[k]

        title = self.dap[list(
            self.dap.keys())[0]].s.name + ' : ' + kwargs['title'] + " :"
        polar = kwargs['polar']
        best = kwargs['best']
        scale = kwargs['scale']

        assert polar in ['p', 'o'], "polar wrongly defined in show coverage"

        if 'fig' in kwargs:
            if 'ax' in kwargs:
                fig, ax = self.L.showG('s', fig=kwargs['fig'], ax=kwargs['ax'])
            else:
                fig, ax = self.L.showG('s', fig=kwargs['fig'])
        else:
            if 'figsize' in kwargs:
                fig, ax = self.L.showG('s', figsize=kwargs['figsize'])
            else:
                fig, ax = self.L.showG('s')

        # plot the grid
        if kwargs['grid']:
            for k in self.dap:
                p = self.dap[k].p
                ax.plot(p[0], p[1], 'or')

        f = kwargs['f']
        a = kwargs['a']
        typ = kwargs['typ']
        assert typ in [
            'best', 'egd', 'sinr', 'snr', 'capacity', 'pr', 'loss', 'ref'
        ], "typ unknown in show coverage"
        best = kwargs['best']

        dB = kwargs['db']

        # setting the grid

        l = self.grid[0, 0]
        r = self.grid[-1, 0]
        b = self.grid[0, 1]
        t = self.grid[-1, -1]

        if typ == 'best' and self.best:
            title = title + 'Best server' + ' fc = ' + str(
                self.fGHz[f]) + ' GHz' + ' polar : ' + polar
            for ka in range(self.na):
                if polar == 'p':
                    bestsv = self.bestsvp[f, :, ka]
                if polar == 'o':
                    bestsv = self.bestsvo[f, :, ka]
                m = np.ma.masked_where(bestsv == 0, bestsv)
                if self.mode != 'file':
                    W = m.reshape(self.nx, self.ny).T
                    ax.imshow(W,
                              extent=(l, r, b, t),
                              origin='lower',
                              vmin=1,
                              vmax=self.na + 1)
                else:
                    ax.scatter(self.grid[:, 0],
                               self.grid[:, 1],
                               c=m,
                               s=scale,
                               linewidth=0)
            ax.set_title(title)
        else:
            if typ == 'egd':
                title = title + 'excess group delay : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                V = self.Ed
                dB = False
                legcb = 'Delay (ns)'
            if typ == 'sinr':
                title = title + 'SINR : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar == 'o':
                    V = self.sinro
                if polar == 'p':
                    V = self.sinrp
            if typ == 'snr':
                title = title + 'SNR : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar == 'o':
                    V = self.snro
                if polar == 'p':
                    V = self.snrp
            if typ == 'capacity':
                title = title + 'Capacity : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                legcb = 'Mbit/s'
                if polar == 'o':
                    V = self.bmhz.T[np.newaxis, :] * np.log(
                        1 + self.sinro) / np.log(2)
                if polar == 'p':
                    V = self.bmhz.T[np.newaxis, :] * np.log(
                        1 + self.sinrp) / np.log(2)
            if typ == "pr":
                title = title + 'Pr : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dBm'
                else:
                    lgdcb = 'mW'
                if polar == 'o':
                    V = self.CmWo
                if polar == 'p':
                    V = self.CmWp

            if typ == "ref":
                title = kwargs['title']
                V = 10**(self.ref / 10)
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'

            if typ == "loss":
                title = title + 'Loss : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar == 'o':
                    V = self.Lwo * self.freespace
                if polar == 'p':
                    V = self.Lwp * self.freespace

            if a == -1:
                V = np.max(V[f, :, :], axis=1)
            else:
                V = V[f, :, a]

            # reshaping the data on the grid
            if self.mode != 'file':
                U = V.reshape((self.nx, self.ny)).T
            else:
                U = V

            if dB:
                U = 10 * np.log10(U)

            if 'vmin' in kwargs:
                vmin = kwargs['vmin']
            else:
                vmin = U.min()

            if 'vmax' in kwargs:
                vmax = kwargs['vmax']
            else:
                vmax = U.max()

            if self.mode != 'file':
                img = ax.imshow(U,
                                extent=(l, r, b, t),
                                origin='lower',
                                vmin=vmin,
                                vmax=vmax,
                                cmap=kwargs['cmap'])
            else:
                img = ax.scatter(self.grid[:, 0],
                                 self.grid[:, 1],
                                 c=U,
                                 s=scale,
                                 linewidth=0,
                                 cmap=kwargs['cmap'],
                                 vmin=vmin,
                                 vmax=vmax)

            # for k in range(self.na):
            #     ax.annotate(str(k),xy=(self.pa[0,k],self.pa[1,k]))
            for k in self.dap.keys():
                ax.annotate(str(self.dap[k]['name']),
                            xy=(self.dap[k]['p'][0], self.dap[k]['p'][1]))
            ax.set_title(title)

            divider = make_axes_locatable(ax)
            cax = divider.append_axes("right", size="5%", pad=0.05)
            clb = fig.colorbar(img, cax)
            clb.set_label(legcb)
            if best:
                if self.mode != 'file':
                    if polar == 'o':
                        ax.contour(np.sum(self.bestsvo, axis=2)[f, :].reshape(
                            self.nx, self.ny).T,
                                   extent=(l, r, b, t),
                                   linestyles='dotted')
                    if polar == 'p':
                        ax.contour(np.sum(self.bestsvp, axis=2)[f, :].reshape(
                            self.nx, self.ny).T,
                                   extent=(l, r, b, t),
                                   linestyles='dotted')

        # display access points
        if a == -1:
            ax.scatter(self.pa[0, :],
                       self.pa[1, :],
                       s=scale + 10,
                       c='r',
                       linewidth=0)
        else:
            ax.scatter(self.pa[0, a],
                       self.pa[1, a],
                       s=scale + 10,
                       c='r',
                       linewidth=0)
        plt.tight_layout()
        return (fig, ax)
Beispiel #2
0
    def show(self,**kwargs):
        """ show coverage

        Parameters
        ----------

        typ : string
            'pr' | 'sinr' | 'capacity' | 'loss' | 'best'
        grid : boolean
        best : boolean
            draw best server contour if True
        f : int
            frequency index
        a : int
            access point index (-1 all access point)

        Examples
        --------

        .. plot::
            :include-source:

            >>> from pylayers.antprop.coverage import *
            >>> C = Coverage()
            >>> C.cover(polar='o')
            >>> f,a = C.show(typ='pr')
            >>> plt.show()
            >>> f,a = C.show(typ='best')
            >>> plt.show()
            >>> f,a = C.show(typ='loss')
            >>> plt.show()
            >>> f,a = C.show(typ='sinr')
            >>> plt.show()

        """
        defaults = { 'typ': 'pr',
                     'grid': False,
                     'f' : 0,
                     'a' :-1,
                     'db':True,
                     'cmap' :cm.jet,
                     'best':True
                   }

        title = self.dap[0].s.name+ ' : '
        for k in defaults:
            if k not in kwargs:
                kwargs[k]=defaults[k]

        if 'fig' in kwargs:
            fig,ax=self.L.showG('s',fig=kwargs['fig'])
        else:
            fig,ax=self.L.showG('s')

        # plot the grid
        if kwargs['grid']:
            for k in self.dap:
                p = self.dap[k].p
                ax.plot(p[0],p[1],'or')

        f = kwargs['f']
        a = kwargs['a']
        typ = kwargs['typ']
        best = kwargs['best']

        dB = kwargs['db']

        # setting the grid

        l = self.grid[0,0]
        r = self.grid[-1,0]
        b = self.grid[0,1]
        t = self.grid[-1,-1]

        if typ=='best':
            title = title + 'Best server'+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+self.polar
            for ka in range(self.na):
                bestsv =  self.bestsv[f,:,ka]
                m = np.ma.masked_where(bestsv == 0,bestsv)
                W = m.reshape(self.nx,self.ny).T
                ax.imshow(W, extent=(l,r,b,t),
                            origin='lower',
                            vmin=1,
                            vmax=self.na+1)
            ax.set_title(title)
        else:
            if typ=='sinr':
                title = title + 'SINR : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+self.polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                V = self.sinr

            if typ=='snr':
                title = title + 'SNR : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+self.polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                V = self.snr

            if typ=='capacity':
                title = title + 'Capacity : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+self.polar
                legcb = 'Mbit/s'
                V = self.bmhz[np.newaxis,np.newaxis,:]*np.log(1+self.sinr)/np.log(2)

            if typ=='pr':
                title = title + 'Pr : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+self.polar
                if dB:
                    legcb = 'dBm'
                else:
                    lgdcb = 'mW'
                V = self.CmW

            if typ=='loss':
                title = title + 'Loss : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+self.polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'

                V = self.Lw*self.freespace

            if a == -1:
                V = np.max(V[f,:,:],axis=1)
            else:
                V = V[f,:,a]

            # reshaping the data on the grid
            U = V.reshape((self.nx,self.ny)).T
            if dB:
                U = 10*np.log10(U)

            if 'vmin' in kwargs:
                vmin = kwargs['vmin']
            else:
                vmin = U.min()

            if 'vmax' in kwargs:
                vmax = kwargs['vmax']
            else:
                vmax = U.max()

            img = ax.imshow(U,
                            extent=(l,r,b,t),
                            origin='lower',
                            vmin = vmin,
                            vmax = vmax,
                            cmap = kwargs['cmap'])

            for k in range(self.na):
                ax.annotate(str(k),xy=(self.pa[0,k],self.pa[1,k]))
            ax.set_title(title)

            divider = make_axes_locatable(ax)
            cax = divider.append_axes("right", size="5%", pad=0.05)
            clb = fig.colorbar(img,cax)
            clb.set_label(legcb)
            if best:
                ax.contour(np.sum(self.bestsv,axis=2)[f,:].reshape(self.nx,self.ny).T,extent=(l,r,b,t),linestyles='dotted')

        # display access points
        ax.scatter(self.pa[0,:],self.pa[1,:],s=10,c='k',linewidth=0)

        return(fig,ax)
Beispiel #3
0
    def show(self,**kwargs):
        """ show coverage

        Parameters
        ----------

        typ : string
            'pr' | 'sinr' | 'capacity' | 'loss' | 'best' | 'egd'
        grid : boolean
        polar : string
            'o' | 'p'
        best : boolean
            draw best server contour if True
        f : int
            frequency index
        a : int
            access point index (-1 all access point)

        Examples
        --------

        .. plot::
            :include-source:

            >>> from pylayers.antprop.coverage import *
            >>> C = Coverage()
            >>> C.cover()
            >>> f,a = C.show(typ='pr',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='best',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='loss',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='sinr',figsize=(10,8))
            >>> plt.show()

        See Also
        --------

        pylayers.gis.layout.Layout.showG

        """
        defaults = { 'typ': 'pr',
                     'grid': False,
                     'polar':'p',
                     'f' : 0,
                     'a' :-1,
                     'db':True,
                     'cmap' :cm.jet,
                     'best':True
                   }

        title = self.dap[self.dap.keys()[0]].s.name+ ' : '

        for k in defaults:
            if k not in kwargs:
                kwargs[k]=defaults[k]
        polar = kwargs['polar']
        assert polar in ['p','o'],"polar wrongly defined in show coverage"

        if 'fig' in kwargs:
            if 'ax' in kwargs:
                fig,ax=self.L.showG('s',fig=kwargs['fig'],ax=kwargs['ax'])
            else:
                fig,ax=self.L.showG('s',fig=kwargs['fig'])
        else:
            if 'figsize' in kwargs:
                fig,ax=self.L.showG('s',figsize=kwargs['figsize'])
            else:
                fig,ax=self.L.showG('s')

        # plot the grid
        if kwargs['grid']:
            for k in self.dap:
                p = self.dap[k].p
                ax.plot(p[0],p[1],'or')

        f = kwargs['f']
        a = kwargs['a']
        typ = kwargs['typ']
        assert typ in ['best','egd','sinr','snr','capacity','pr','loss'],"typ unknown in show coverage"
        best = kwargs['best']

        dB = kwargs['db']

        # setting the grid

        l = self.grid[0,0]
        r = self.grid[-1,0]
        b = self.grid[0,1]
        t = self.grid[-1,-1]

        if typ=='best':
            title = title + 'Best server'+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+polar
            for ka in range(self.na):
                if polar=='p':
                    bestsv =  self.bestsvp[f,:,ka]
                if polar=='o':    
                    bestsv =  self.bestsvo[f,:,ka]
                m = np.ma.masked_where(bestsv == 0,bestsv)
                if self.mode<>'file':
                    W = m.reshape(self.nx,self.ny).T
                    ax.imshow(W, extent=(l,r,b,t),
                            origin='lower',
                            vmin=1,
                            vmax=self.na+1)
                else:
                    ax.scatter(self.grid[:,0],self.grid[:,1],c=m,s=20,linewidth=0)
            ax.set_title(title)
        else:
            if typ=='egd':
                title = title + 'excess group delay : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+polar
                V = self.Ed
                dB = False
                legcb =  'Delay (ns)'
            if typ=='sinr':
                title = title + 'SINR : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar=='o':        
                    V = self.sinro
                if polar=='p':    
                    V = self.sinrp
            if typ=='snr':
                title = title + 'SNR : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar=='o':
                    V = self.snro
                if polar=='p':
                    V = self.snrp
            if typ=='capacity':
                title = title + 'Capacity : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+polar
                legcb = 'Mbit/s'
                if polar=='o':
                    V = self.bmhz.T[np.newaxis,:]*np.log(1+self.sinro)/np.log(2)
                if polar=='p':
                    V = self.bmhz.T[np.newaxis,:]*np.log(1+self.sinrp)/np.log(2)
            if typ=='pr':
                title = title + 'Pr : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+polar
                if dB:
                    legcb = 'dBm'
                else:
                    lgdcb = 'mW'
                if polar=='o':
                    V = self.CmWo
                if polar=='p':
                    V = self.CmWp

            if typ=='loss':
                title = title + 'Loss : '+' fc = '+str(self.fGHz[f])+' GHz'+ ' polar : '+polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar=='o':
                    V = self.Lwo*self.freespace
                if polar=='p':
                    V = self.Lwp*self.freespace

            if a == -1:
                V = np.max(V[f,:,:],axis=1)
            else:
                V = V[f,:,a]

            # reshaping the data on the grid
            if self.mode!='file':
                U = V.reshape((self.nx,self.ny)).T
            else:
                U = V

            if dB:
                U = 10*np.log10(U)

            if 'vmin' in kwargs:
                vmin = kwargs['vmin']
            else:
                vmin = U.min()

            if 'vmax' in kwargs:
                vmax = kwargs['vmax']
            else:
                vmax = U.max()

            if self.mode!='file':
                img = ax.imshow(U,
                            extent=(l,r,b,t),
                            origin='lower',
                            vmin = vmin,
                            vmax = vmax,
                            cmap = kwargs['cmap'])
            else:
                img=ax.scatter(self.grid[:,0],
                               self.grid[:,1],
                               c=U,
                               s=20,
                               linewidth=0,
                               cmap=kwargs['cmap'],
                               vmin=vmin,
                               vmax=vmax)

            for k in range(self.na):
                ax.annotate(str(k),xy=(self.pa[0,k],self.pa[1,k]))
            ax.set_title(title)

            divider = make_axes_locatable(ax)
            cax = divider.append_axes("right", size="5%", pad=0.05)
            clb = fig.colorbar(img,cax)
            clb.set_label(legcb)
            if best:
                if self.mode<>'file':
                    if polar=='o':
                        ax.contour(np.sum(self.bestsvo,axis=2)[f,:].reshape(self.nx,self.ny).T,extent=(l,r,b,t),linestyles='dotted')
                    if polar=='p':
                        ax.contour(np.sum(self.bestsvp,axis=2)[f,:].reshape(self.nx,self.ny).T,extent=(l,r,b,t),linestyles='dotted')

        # display access points
        if a==-1:
            ax.scatter(self.pa[0,:],self.pa[1,:],s=30,c='r',linewidth=0)
        else:
            ax.scatter(self.pa[0,a],self.pa[1,a],s=30,c='r',linewidth=0)
        plt.tight_layout()
        return(fig,ax)
Beispiel #4
0
    def show(self, **kwargs):
        """ show coverage

        Parameters
        ----------

        typ : string
            'pr' | 'sinr' | 'capacity' | 'loss' | 'best' | 'egd'
        grid : boolean
        polar : string
            'o' | 'p'
        best : boolean
            draw best server contour if True
        f : int
            frequency index
        a : int
            access point index (-1 all access point)

        Examples
        --------

        .. plot::
            :include-source:

            >>> from pylayers.antprop.coverage import *
            >>> C = Coverage()
            >>> C.cover(polar='o')
            >>> f,a = C.show(typ='pr',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='best',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='loss',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='sinr',figsize=(10,8))
            >>> plt.show()

        See Also
        --------

        pylayers.gis.layout.Layout.showG

        """
        defaults = {"typ": "pr", "grid": False, "polar": "p", "f": 0, "a": -1, "db": True, "cmap": cm.jet, "best": True}

        title = self.dap[1].s.name + " : "

        for k in defaults:
            if k not in kwargs:
                kwargs[k] = defaults[k]
        polar = kwargs["polar"]
        if "fig" in kwargs:
            if "ax" in kwargs:
                fig, ax = self.L.showG("s", fig=kwargs["fig"], ax=kwargs["ax"])
            else:
                fig, ax = self.L.showG("s", fig=kwargs["fig"])
        else:
            if "figsize" in kwargs:
                fig, ax = self.L.showG("s", figsize=kwargs["figsize"])
            else:
                fig, ax = self.L.showG("s")

        # plot the grid
        if kwargs["grid"]:
            for k in self.dap:
                p = self.dap[k].p
                ax.plot(p[0], p[1], "or")

        f = kwargs["f"]
        a = kwargs["a"]
        typ = kwargs["typ"]
        best = kwargs["best"]

        dB = kwargs["db"]

        # setting the grid

        l = self.grid[0, 0]
        r = self.grid[-1, 0]
        b = self.grid[0, 1]
        t = self.grid[-1, -1]

        if typ == "best":
            title = title + "Best server" + " fc = " + str(self.fGHz[f]) + " GHz" + " polar : " + polar
            for ka in range(self.na):
                if polar == "p":
                    bestsv = self.bestsvp[f, :, ka]
                if polar == "o":
                    bestsv = self.bestsvo[f, :, ka]
                m = np.ma.masked_where(bestsv == 0, bestsv)
                if self.mode <> "file":
                    W = m.reshape(self.nx, self.ny).T
                    ax.imshow(W, extent=(l, r, b, t), origin="lower", vmin=1, vmax=self.na + 1)
                else:
                    ax.scatter(self.grid[:, 0], self.grid[:, 1], c=m, s=20, linewidth=0)
            ax.set_title(title)
        else:
            if typ == "egd":
                title = title + "excess group delay : " + " fc = " + str(self.fGHz[f]) + " GHz" + " polar : " + polar
                V = self.Ed
                dB = False
                legcb = "Delay (ns)"
            if typ == "sinr":
                title = title + "SINR : " + " fc = " + str(self.fGHz[f]) + " GHz" + " polar : " + polar
                if dB:
                    legcb = "dB"
                else:
                    legcb = "Linear scale"
                if polar == "o":
                    V = self.sinro
                if polar == "p":
                    V = self.sinrp
            if typ == "snr":
                title = title + "SNR : " + " fc = " + str(self.fGHz[f]) + " GHz" + " polar : " + polar
                if dB:
                    legcb = "dB"
                else:
                    legcb = "Linear scale"
                if polar == "o":
                    V = self.snro
                if polar == "p":
                    V = self.snrp
            if typ == "capacity":
                title = title + "Capacity : " + " fc = " + str(self.fGHz[f]) + " GHz" + " polar : " + polar
                legcb = "Mbit/s"
                if polar == "o":
                    V = self.bmhz.T[np.newaxis, :] * np.log(1 + self.sinro) / np.log(2)
                if polar == "p":
                    V = self.bmhz.T[np.newaxis, :] * np.log(1 + self.sinrp) / np.log(2)
            if typ == "pr":
                title = title + "Pr : " + " fc = " + str(self.fGHz[f]) + " GHz" + " polar : " + polar
                if dB:
                    legcb = "dBm"
                else:
                    lgdcb = "mW"
                if polar == "o":
                    V = self.CmWo
                if polar == "p":
                    V = self.CmWp

            if typ == "loss":
                title = title + "Loss : " + " fc = " + str(self.fGHz[f]) + " GHz" + " polar : " + polar
                if dB:
                    legcb = "dB"
                else:
                    legcb = "Linear scale"
                if polar == "o":
                    V = self.Lwo * self.freespace
                if polar == "p":
                    V = self.Lwp * self.freespace

            if a == -1:
                V = np.max(V[f, :, :], axis=1)
            else:
                V = V[f, :, a]

            # reshaping the data on the grid
            if self.mode != "file":
                U = V.reshape((self.nx, self.ny)).T
            else:
                U = V

            if dB:
                U = 10 * np.log10(U)

            if "vmin" in kwargs:
                vmin = kwargs["vmin"]
            else:
                vmin = U.min()

            if "vmax" in kwargs:
                vmax = kwargs["vmax"]
            else:
                vmax = U.max()

            if self.mode != "file":
                img = ax.imshow(U, extent=(l, r, b, t), origin="lower", vmin=vmin, vmax=vmax, cmap=kwargs["cmap"])
            else:
                img = ax.scatter(self.grid[:, 0], self.grid[:, 1], c=U, s=20, linewidth=0)

            for k in range(self.na):
                ax.annotate(str(k), xy=(self.pa[0, k], self.pa[1, k]))
            ax.set_title(title)

            divider = make_axes_locatable(ax)
            cax = divider.append_axes("right", size="5%", pad=0.05)
            clb = fig.colorbar(img, cax)
            clb.set_label(legcb)
            if best:
                if self.mode <> "file":
                    if polar == "o":
                        ax.contour(
                            np.sum(self.bestsvo, axis=2)[f, :].reshape(self.nx, self.ny).T,
                            extent=(l, r, b, t),
                            linestyles="dotted",
                        )
                    if polar == "p":
                        ax.contour(
                            np.sum(self.bestsvp, axis=2)[f, :].reshape(self.nx, self.ny).T,
                            extent=(l, r, b, t),
                            linestyles="dotted",
                        )

        # display access points
        if a == -1:
            ax.scatter(self.pa[0, :], self.pa[1, :], s=30, c="r", linewidth=0)
        else:
            ax.scatter(self.pa[0, a], self.pa[1, a], s=30, c="r", linewidth=0)
        plt.tight_layout()
        return (fig, ax)
Beispiel #5
0
    def show(self, **kwargs):
        """ show coverage
        Parameters
        ----------
        typ : string
            'pr' | 'sinr' | 'capacity' | 'loss' | 'best' | 'egd'
        grid : boolean
        polar : string
            'o' | 'p'
        best : boolean
            draw best server contour if True
        f : int
            frequency index
        a : int
            access point index (-1 all access point)
        Examples
        --------
        .. plot::
            :include-source:
            >>> from pylayers.antprop.coverage import *
            >>> C = Coverage()
            >>> C.cover()
            >>> f,a = C.show(typ='pr',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='best',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='loss',figsize=(10,8))
            >>> plt.show()
            >>> f,a = C.show(typ='sinr',figsize=(10,8))
            >>> plt.show()
        See Also
        --------
        pylayers.gis.layout.Layout.showG
        """
        defaults = {
            'typ': 'pr',
            'grid': False,
            'polar': 'p',
            'f': 0,
            'a': -1,
            'db': True,
            'cmap': cm.jet,
            'best': True
        }

        title = self.dap[self.dap.keys()[0]].s.name + ' : '

        for k in defaults:
            if k not in kwargs:
                kwargs[k] = defaults[k]
        polar = kwargs['polar']
        assert polar in ['p', 'o'], "polar wrongly defined in show coverage"

        if 'fig' in kwargs:
            if 'ax' in kwargs:
                fig, ax = self.L.showG('s', fig=kwargs['fig'], ax=kwargs['ax'])
            else:
                fig, ax = self.L.showG('s', fig=kwargs['fig'])
        else:
            if 'figsize' in kwargs:
                fig, ax = self.L.showG('s', figsize=kwargs['figsize'])
            else:
                fig, ax = self.L.showG('s')

        # plot the grid
        self.typ = kwargs['typ']
        typ = kwargs['typ']
        if kwargs['grid']:
            for k in self.dap:
                p = self.dap[k].p
                ax.plot(p[0], p[1], 'or')

        f = kwargs['f']
        a = kwargs['a']
        assert typ in [
            'best', 'egd', 'sinr', 'snr', 'capacity', 'pr', 'loss',
            'intensity', 'losssombreamento', 'prsombreamento',
            'snrsombreamento'
        ], "typ unknown in show coverage"
        best = kwargs['best']

        dB = kwargs['db']

        # setting the grid

        l = self.grid[0, 0]
        r = self.grid[-1, 0]
        b = self.grid[0, 1]
        t = self.grid[-1, -1]

        arq = open('cobertura.txt', 'w')
        texto = '''dBm e V/m \n'''
        arq.write(texto)
        arq.close()

        if typ == 'best':
            title = title + 'Best server' + ' fc = ' + str(
                self.fGHz[f]) + ' GHz' + ' polar : ' + polar
            for ka in range(self.na):
                if polar == 'p':
                    bestsv = self.bestsvp[f, :, ka]
                if polar == 'o':
                    bestsv = self.bestsvo[f, :, ka]
                m = np.ma.masked_where(bestsv == 0, bestsv)
                if self.mode <> 'file':
                    W = m.reshape(self.nx, self.ny).T
                    ax.imshow(W,
                              extent=(l, r, b, t),
                              origin='lower',
                              vmin=1,
                              vmax=self.na + 1)
                else:
                    ax.scatter(self.grid[:, 0],
                               self.grid[:, 1],
                               c=m,
                               s=20,
                               linewidth=0)
            ax.set_title(title)
        else:
            if typ == 'egd':
                title = title + 'excess group delay : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                V = self.Ed
                dB = False
                legcb = 'Delay (ns)'
            if typ == 'sinr':
                title = title + 'SINR : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar == 'o':
                    V = self.sinro
                if polar == 'p':
                    V = self.sinrp
            if typ == 'snr':
                title = title + 'SNR : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar == 'o':
                    V = self.snro
                if polar == 'p':
                    V = self.snrp
            if typ == 'capacity':
                title = title + 'Capacity : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                legcb = 'Mbit/s'
                if polar == 'o':
                    V = self.bmhz.T[np.newaxis, :] * np.log(
                        1 + self.sinro) / np.log(2)
                if polar == 'p':
                    V = self.bmhz.T[np.newaxis, :] * np.log(
                        1 + self.sinrp) / np.log(2)

            if typ == 'pr':
                title = title + 'Pr : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dBm'
                else:
                    lgdcb = 'mW'
                if polar == 'o':
                    V = self.CmWo
                if polar == 'p':
                    V = self.CmWp

            if typ == 'loss':
                title = title + 'Loss : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dB'
                else:
                    legcb = 'Linear scale'
                if polar == 'o':
                    V = self.Lwo * self.freespace
                if polar == 'p':
                    V = self.Lwp * self.freespace

            if typ == 'losssombreamento':
                #relaxa que esse so muda no final
                title = title + 'Loss Log : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dB'
                else:
                    lgdcb = 'Linear scale'
                if polar == 'o':
                    V = self.CmWo
                if polar == 'p':
                    V = self.CmWp

            if typ == 'prsombreamento':
                #relaxa que esse so muda no final
                title = title + 'Pr Log : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dBm'
                else:
                    lgdcb = 'Linear scale'
                if polar == 'o':
                    V = self.CmWo
                if polar == 'p':
                    V = self.CmWp

            if typ == 'snrsombreamento':
                #relaxa que esse so muda no final
                title = title + 'SNR Log : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                if dB:
                    legcb = 'dB'
                else:
                    lgdcb = 'Linear scale'
                if polar == 'o':
                    V = self.CmWo
                if polar == 'p':
                    V = self.CmWp

            if typ == 'intensity':
                title = title + 'Intensity : ' + ' fc = ' + str(
                    self.fGHz[f]) + ' GHz' + ' polar : ' + polar
                legcb = 'V/m'
                if polar == 'o':
                    V = np.power(10, (
                        (self.CmWo + 20 * np.log10(self.fGHz[f] * 1000) + 77.2)
                        / 20)) * 0.000001
                if polar == 'p':
                    V = np.power(10, (
                        (self.CmWp + 20 * np.log10(self.fGHz[f] * 1000) + 77.2)
                        / 20)) * 0.000001

            if a == -1:
                V = np.max(V[f, :, :], axis=1)
            else:
                V = V[f, :, a]

            # reshaping the data on the grid
            if self.mode != 'file':
                U = V.reshape((self.nx, self.ny)).T
            else:
                U = V

            if dB and typ != 'intensity':
                if typ == 'losssombreamento' or typ == 'prsombreamento' or typ == 'snrsombreamento':
                    f = self.fGHz[f] * 1000
                    Lf = self.PtDB - self.Prdo + self.Gt + self.Gr

                    medidas1 = []

                    dx = np.linspace(0, self.xt, self.nx)
                    dy = np.linspace(0, self.yt, self.ny)

                    for i in range(self.ny):
                        medidas1.append([])

                    for i in range(self.ny):
                        for j in range(self.nx):
                            medidas1[i].append(
                                np.sqrt(
                                    np.power(dx[j] - self.x0, 2) +
                                    np.power(dy[i] - self.y0, 2)) / 1000)

                    desvio = 0

                    X = np.random.normal(0, self.desviopadrao, len(medidas1))

                    PL2 = []
                    maior, menor = 0, 100

                    for i in range(self.ny):
                        PL2.append([])

                    for i in range(self.ny):
                        for j in range(self.nx):
                            oi = Lf + 10 * self.n * np.log10(
                                medidas1[i][j] / self.do) + X[i]
                            PL2[i].append(oi)
                            if (maior < oi):
                                maior = oi
                            if (menor > oi):
                                menor = oi

                    menor = np.floor(menor / 10) * 10
                    maior = np.ceil(maior / 10) * 10

                    if typ == 'prsombreamento':
                        maior, menor = -100, 0
                        pr = []
                        for i in range(self.ny):
                            pr.append([])

                        for i in range(self.ny):
                            for j in range(self.nx):
                                oi = self.PtDB - PL2[i][j]
                                pr[i].append(oi)
                                if (maior < oi):
                                    maior = oi
                                if (menor > oi):
                                    menor = oi
                        menor = np.floor(menor / 10) * 10
                        maior = np.ceil(maior / 10) * 10
                        U = pr
                    elif typ == 'snrsombreamento':
                        maior, menor = -100, 100
                        pr = []
                        for i in range(self.ny):
                            pr.append([])

                        for i in range(self.ny):
                            for j in range(self.nx):
                                oi = PL2[i][j] / self.pnw[0][0]
                                pr[i].append(oi)
                                if (maior < oi):
                                    maior = oi
                                if (menor > oi):
                                    menor = oi
                        menor = np.floor(menor / 10) * 10
                        maior = np.ceil(maior / 10) * 10
                        U = pr
                    else:
                        U = PL2
                else:
                    U = 10 * np.log10(U)
                #print U

            arq = open('cobertura.txt', 'w')
            texto = []
            for linha in U:
                texto.append(str(linha) + '\n')
            arq.writelines(texto)
            arq.close()

            if 'vmin' in kwargs:
                vmin = kwargs['vmin']
            else:
                if typ == 'losssombreamento' or typ == 'prsombreamento' or typ == 'snrsombreamento':
                    vmin = menor
                else:
                    vmin = U.min()

            if 'vmax' in kwargs:
                vmax = kwargs['vmax']
            else:
                if typ == 'losssombreamento' or typ == 'prsombreamento' or typ == 'snrsombreamento':
                    vmax = maior
                else:
                    vmax = U.max()

            if self.mode != 'file':
                img = ax.imshow(U,
                                extent=(l, r, b, t),
                                origin='lower',
                                vmin=vmin,
                                vmax=vmax,
                                cmap=kwargs['cmap'])
            else:
                img = ax.scatter(self.grid[:, 0],
                                 self.grid[:, 1],
                                 c=U,
                                 s=20,
                                 linewidth=0,
                                 cmap=kwargs['cmap'],
                                 vmin=vmin,
                                 vmax=vmax)

            for k in range(self.na):
                ax.annotate(str(k), xy=(self.pa[0, k], self.pa[1, k]))
            ax.set_title(title)

            divider = make_axes_locatable(ax)
            cax = divider.append_axes("right", size="5%", pad=0.05)
            clb = fig.colorbar(img, cax)
            clb.set_label(legcb)
            if typ == 'losssombreamento' or typ == 'prsombreamento' or typ == 'snrsombreamento':
                print 'Modelo do Sombreamento Log Normal'
            else:
                if best:
                    if self.mode <> 'file':
                        if polar == 'o':
                            ax.contour(np.sum(self.bestsvo,
                                              axis=2)[f, :].reshape(
                                                  self.nx, self.ny).T,
                                       extent=(l, r, b, t),
                                       linestyles='dotted')
                        if polar == 'p':
                            ax.contour(np.sum(self.bestsvp,
                                              axis=2)[f, :].reshape(
                                                  self.nx, self.ny).T,
                                       extent=(l, r, b, t),
                                       linestyles='dotted')

        # display access points
        if a == -1:
            ax.scatter(self.pa[0, :], self.pa[1, :], s=30, c='r', linewidth=0)
        else:
            ax.scatter(self.pa[0, a], self.pa[1, a], s=30, c='r', linewidth=0)
        plt.tight_layout()
        return (fig, ax)