コード例 #1
0
    def plot(self,
             time,
             beam=None,
             maxground=2000,
             maxalt=500,
             step=1,
             showrefract=False,
             nr_cmap='jet_r',
             nr_lim=[0.8, 1.],
             raycolor='0.3',
             title=False,
             zorder=2,
             alpha=1,
             fig=None,
             rect=111,
             ax=None,
             aax=None):
        """Plot ray paths
        
        **Args**: 
            * **time** (datetime.datetime): time of rays
            * [**beam**]: beam number
            * [**maxground**]: maximum ground range [km]
            * [**maxalt**]: highest altitude limit [km]
            * [**step**]: step between each plotted ray (in number of ray steps)
            * [**showrefract**]: show refractive index along ray paths (supersedes raycolor)
            * [**nr_cmap**]: color map name for refractive index coloring
            * [**nr_lim**]: refractive index plotting limits
            * [**raycolor**]: color of ray paths
            * [**rect**]: subplot spcification
            * [**fig**]: A pylab.figure object (default to gcf)
            * [**title**]: Show default title
            * [**ax**]: Existing main axes
            * [**aax**]: Existing auxialary axes
        **Returns**:
            * **ax**: matplotlib.axes object containing formatting
            * **aax**: matplotlib.axes object containing data
            * **cbax**: matplotlib.axes object containing colorbar
        **Example**:
            ::

                # Show ray paths with colored refractive index along path
                import datetime as dt
                from models import raydarn
                sTime = dt.datetime(2012, 11, 18, 5)
                rto = raydarn.RtRun(sTime, rCode='bks', beam=12, title=True)
                rto.readRays() # read rays into memory
                ax, aax, cbax = rto.rays.plot(sTime, step=10, showrefract=True, nr_lim=[.85,1])
                ax.grid()
                
        written by Sebastien, 2013-04
        """
        from utils import plotUtils
        from matplotlib.collections import LineCollection
        import matplotlib.pyplot as plt
        import numpy as np
        from types import MethodType

        # Set up axes
        if not ax and not aax:
            ax, aax = plotUtils.curvedEarthAxes(fig=fig,
                                                rect=rect,
                                                maxground=maxground,
                                                maxalt=maxalt)
        else:
            ax = ax
            aax = aax
            if hasattr(ax, 'time'):
                time = ax.time
            if hasattr(ax, 'beam'):
                beam = ax.beam

        # make sure that the required time and beam are present
        assert (time in self.paths.keys()), 'Unkown time %s' % time
        if beam:
            assert (beam in self.paths[time].keys()), 'Unkown beam %s' % beam
        else:
            beam = self.paths[time].keys()[0]

        for ir, (el,
                 rays) in enumerate(sorted(self.paths[time][beam].items())):
            if not ir % step:
                if not showrefract:
                    aax.plot(rays['th'],
                             rays['r'] * 1e-3,
                             c=raycolor,
                             zorder=zorder,
                             alpha=alpha)
                else:
                    points = np.array([rays['th'],
                                       rays['r'] * 1e-3]).T.reshape(-1, 1, 2)
                    segments = np.concatenate([points[:-1], points[1:]],
                                              axis=1)
                    lcol = LineCollection(segments, zorder=zorder, alpha=alpha)
                    _ = lcol.set_cmap(nr_cmap)
                    _ = lcol.set_norm(plt.Normalize(*nr_lim))
                    _ = lcol.set_array(rays['nr'])
                    _ = aax.add_collection(lcol)

        # Plot title with date ut time and local time
        if title:
            stitle = _getTitle(time, beam, self.header, self.name)
            ax.set_title(stitle)

        # Add a colorbar when plotting refractive index
        if showrefract:
            cbax = plotUtils.addColorbar(lcol, ax)
            _ = cbax.set_ylabel("refractive index")
        else:
            cbax = None

        # Declare a new method to show range markers
        # This method is only available after rays have been plotted
        # This ensures that the markers match the plotted rays
        def showRange(self, markers=None, color='.8', s=2, zorder=3, **kwargs):
            """Plot ray paths
            
            **Args**: 
                * [**markers**]: range markers. Defaults to every 250 km
                * All other keywords are borrowed from :func:`matplotlib.pyplot.scatter`
            **Returns**:
                * **coll**: a collection of range markers
            **Example**:
                ::

                    # Add range markers to an existing ray plot
                    ax, aax, cbax = rto.rays.plot(sTime, step=10)
                    rto.rays.showRange()
                    
            written by Sebastien, 2013-04
            """

            if not markers:
                markers = np.arange(0, 5000, 250)

            x, y = [], []
            for el, rays in self.paths[time][beam].items():
                for rm in markers:
                    inds = (rays['gran'] * 1e-3 >= rm)
                    if inds.any():
                        x.append(rays['th'][inds][0])
                        y.append(rays['r'][inds][0] * 1e-3)
            coll = aax.scatter(x, y, color=color, s=s, zorder=zorder, **kwargs)

            return coll

        # End of new method

        # Assign new method
        self.showRange = MethodType(showRange, self)

        ax.beam = beam
        return ax, aax, cbax
コード例 #2
0
ファイル: rt.py プロジェクト: alexmorrisak/davitpy
    def plot(self, time, beam=None, maxground=2000, maxalt=500, step=1,
        showrefract=False, nr_cmap='jet_r', nr_lim=[0.8, 1.], 
        raycolor='0.4',  
        fig=None, rect=111):
        """Plot ray paths
        
        **Args**: 
            * **time** (datetime.datetime): time of rays
            * [**beam**]: beam number
            * [**maxground**]: maximum ground range [km]
            * [**maxalt**]: highest altitude limit [km]
            * [**step**]: step between each plotted ray (in number of ray steps)
            * [**showrefract**]: show refractive index along ray paths (supersedes raycolor)
            * [**nr_cmap**]: color map name for refractive index coloring
            * [**nr_lim**]: refractive index plotting limits
            * [**raycolor**]: color of ray paths
            * [**rect**]: subplot spcification
            * [**fig**]: A pylab.figure object (default to gcf)
        **Returns**:
            * **ax**: matplotlib.axes object containing formatting
            * **aax**: matplotlib.axes object containing data
            * **cbax**: matplotlib.axes object containing colorbar
        **Example**:
            ::

                # Show ray paths with colored refractive index along path
                import datetime as dt
                from models import raydarn
                sTime = dt.datetime(2012, 11, 18, 5)
                rto = raydarn.rtRun(sTime, rCode='bks', beam=12)
                rto.readRays() # read rays into memory
                ax, aax, cbax = rto.rays.plot(sTime, step=2, showrefract=True, nr_lim=[.85,1])
                ax.grid()
                
        written by Sebastien, 2013-04
        """
        from utils import plotUtils
        from mpl_toolkits.axes_grid1 import make_axes_locatable
        from matplotlib.collections import LineCollection
        import matplotlib.pyplot as plt
        import numpy as np

        ax, aax = plotUtils.curvedEarthAxes(fig=fig, rect=rect, 
            maxground=maxground, maxalt=maxalt)

        # make sure that the required time and beam are present
        assert (time in self.paths.keys()), 'Unkown time %s' % time
        if beam:
            assert (beam in self.paths[time].keys()), 'Unkown beam %s' % beam
        else:
            beam = self.paths[time].keys()[0]
        
        for ir, (el, rays) in enumerate( sorted(self.paths[time][beam].items()) ):
            if not ir % step:
                if not showrefract:
                    aax.plot(rays['th'], rays['r']*1e-3, c=raycolor, zorder=2)
                else:
                    points = np.array([rays['th'], rays['r']*1e-3]).T.reshape(-1, 1, 2)
                    segments = np.concatenate([points[:-1], points[1:]], axis=1)
                    lcol = LineCollection( segments )
                    lcol.set_cmap( nr_cmap )
                    lcol.set_norm( plt.Normalize(*nr_lim) )
                    lcol.set_array( rays['nr'] )
                    aax.add_collection( lcol )
        # Add a colorbar when plotting refractive index
        if showrefract:
            from mpl_toolkits.axes_grid1 import SubplotDivider, LocatableAxes, Size

            fig1 = ax.get_figure()
            divider = SubplotDivider(fig1, *ax.get_geometry(), aspect=True)

            # axes for colorbar
            cbax = LocatableAxes(fig1, divider.get_position())

            h = [Size.AxesX(ax), # main axes
                 Size.Fixed(0.1), # padding
                 Size.Fixed(0.2)] # colorbar
            v = [Size.AxesY(ax)]

            divider.set_horizontal(h)
            divider.set_vertical(v)

            ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
            cbax.set_axes_locator(divider.new_locator(nx=2, ny=0))

            fig1.add_axes(cbax)

            cbax.axis["left"].toggle(all=False)
            cbax.axis["top"].toggle(all=False)
            cbax.axis["bottom"].toggle(all=False)
            cbax.axis["right"].toggle(ticklabels=True, label=True)

            plt.colorbar(lcol, cax=cbax)
            cbax.set_ylabel("refractive index")

        return ax, aax, cbax
コード例 #3
0
    def plot(self,
             time,
             beam=None,
             maxground=2000,
             maxalt=500,
             iscat=True,
             gscat=True,
             title=False,
             weighted=False,
             cmap='hot_r',
             fig=None,
             rect=111,
             ax=None,
             aax=None,
             zorder=4):
        """Plot scatter on ground/altitude profile
        
        **Args**: 
            * **time** (datetime.datetime): time of profile
            * [**beam**]: beam number
            * [**iscat**] (bool): show ionospheric scatter
            * [**gscat**] (bool): show ground scatter
            * [**maxground**]: maximum ground range [km]
            * [**maxalt**]: highest altitude limit [km]
            * [**rect**]: subplot spcification
            * [**fig**]: A pylab.figure object (default to gcf)
            * [**ax**]: Existing main axes
            * [**aax**]: Existing auxialary axes
            * [**title**]: Show default title
            * [**weighted**] (bool): plot ionospheric scatter relative strength (based on background density and range)
            * [**cmap**]: colormap used for weighted ionospheric scatter
        **Returns**:
            * **ax**: matplotlib.axes object containing formatting
            * **aax**: matplotlib.axes object containing data
            * **cbax**: matplotlib.axes object containing colorbar
        **Example**:
            ::

                # Show ionospheric scatter
                import datetime as dt
                from models import raydarn
                sTime = dt.datetime(2012, 11, 18, 5)
                rto = raydarn.RtRun(sTime, rCode='bks', beam=12)
                rto.readRays() # read rays into memory
                ax, aax, cbax = rto.rays.plot(sTime, title=True)
                rto.readScatter() # read scatter into memory
                rto.scatter.plot(sTime, ax=ax, aax=aax)
                ax.grid()
                
        written by Sebastien, 2013-04
        """
        from utils import plotUtils
        from matplotlib.collections import LineCollection
        import matplotlib.pyplot as plt
        import numpy as np

        # Set up axes
        if not ax and not aax:
            ax, aax = plotUtils.curvedEarthAxes(fig=fig,
                                                rect=rect,
                                                maxground=maxground,
                                                maxalt=maxalt)
        else:
            ax = ax
            aax = aax
            if hasattr(ax, 'beam'):
                beam = ax.beam

        # make sure that the required time and beam are present
        assert (time in self.isc.keys()
                or time in self.gsc.keys()), 'Unkown time %s' % time
        if beam:
            assert (beam in self.isc[time].keys()), 'Unkown beam %s' % beam
        else:
            beam = self.isc[time].keys()[0]

        if gscat and time in self.gsc.keys():
            for ir, (el,
                     rays) in enumerate(sorted(self.gsc[time][beam].items())):
                if len(rays['r']) == 0: continue
                _ = aax.scatter(rays['th'],
                                ax.Re * np.ones(rays['th'].shape),
                                color='0',
                                zorder=zorder)

        if iscat and time in self.isc.keys():
            if weighted:
                wmin = np.min([
                    r['w'].min() for r in self.isc[time][beam].values()
                    if r['nstp'] > 0
                ])
                wmax = np.max([
                    r['w'].max() for r in self.isc[time][beam].values()
                    if r['nstp'] > 0
                ])

            for ir, (el,
                     rays) in enumerate(sorted(self.isc[time][beam].items())):
                if rays['nstp'] == 0: continue
                t = rays['th']
                r = rays['r'] * 1e-3
                spts = np.array([t, r]).T.reshape(-1, 1, 2)
                h = rays['h'] * 1e-3
                rel = np.radians(rays['rel'])
                r = np.sqrt(r**2 + h**2 + 2 * r * h * np.sin(rel))
                t = t + np.arcsin(h / r * np.cos(rel))
                epts = np.array([t, r]).T.reshape(-1, 1, 2)
                segments = np.concatenate([spts, epts], axis=1)
                lcol = LineCollection(segments, zorder=zorder)
                if weighted:
                    _ = lcol.set_cmap(cmap)
                    _ = lcol.set_norm(plt.Normalize(0, 1))
                    _ = lcol.set_array((rays['w'] - wmin) / wmax)
                else:
                    _ = lcol.set_color('0')
                _ = aax.add_collection(lcol)

            # Plot title with date ut time and local time
            if title:
                stitle = _getTitle(time, beam, self.header, None)
                ax.set_title(stitle)

            # If weighted, plot ionospheric scatter with colormap
            if weighted:
                # Add a colorbar
                cbax = plotUtils.addColorbar(lcol, ax)
                _ = cbax.set_ylabel("Ionospheric Scatter")
            else:
                cbax = None

        ax.beam = beam
        return ax, aax, cbax
コード例 #4
0
    def plot(self,
             time,
             beam=None,
             maxground=2000,
             maxalt=500,
             nel_cmap='jet',
             nel_lim=[10, 12],
             title=False,
             fig=None,
             rect=111,
             ax=None,
             aax=None):
        """Plot electron density profile
        
        **Args**: 
            * **time** (datetime.datetime): time of profile
            * [**beam**]: beam number
            * [**maxground**]: maximum ground range [km]
            * [**maxalt**]: highest altitude limit [km]
            * [**nel_cmap**]: color map name for electron density index coloring
            * [**nel_lim**]: electron density index plotting limits
            * [**rect**]: subplot spcification
            * [**fig**]: A pylab.figure object (default to gcf)
            * [**ax**]: Existing main axes
            * [**aax**]: Existing auxialary axes
            * [**title**]: Show default title
        **Returns**:
            * **ax**: matplotlib.axes object containing formatting
            * **aax**: matplotlib.axes object containing data
            * **cbax**: matplotlib.axes object containing colorbar
        **Example**:
            ::

                # Show electron density profile
                import datetime as dt
                from models import raydarn
                sTime = dt.datetime(2012, 11, 18, 5)
                rto = raydarn.RtRun(sTime, rCode='bks', beam=12)
                rto.readEdens() # read electron density into memory
                ax, aax, cbax = rto.ionos.plot(sTime, title=True)
                ax.grid()
                
        written by Sebastien, 2013-04
        """
        from utils import plotUtils
        from matplotlib.collections import LineCollection
        import matplotlib.pyplot as plt
        import numpy as np

        # Set up axes
        if not ax and not aax:
            ax, aax = plotUtils.curvedEarthAxes(fig=fig,
                                                rect=rect,
                                                maxground=maxground,
                                                maxalt=maxalt)
        else:
            ax = ax
            aax = aax
            if hasattr(ax, 'time'):
                time = ax.time
            if hasattr(ax, 'beam'):
                beam = ax.beam

        # make sure that the required time and beam are present
        assert (time in self.edens.keys()), 'Unkown time %s' % time
        if beam:
            assert (beam in self.edens[time].keys()), 'Unkown beam %s' % beam
        else:
            beam = self.edens[time].keys()[0]

        X, Y = np.meshgrid(self.edens[time][beam]['th'],
                           ax.Re + np.linspace(60, 560, 250))
        im = aax.pcolormesh(X,
                            Y,
                            np.log10(self.edens[time][beam]['nel']),
                            vmin=nel_lim[0],
                            vmax=nel_lim[1],
                            cmap=nel_cmap)

        # Plot title with date ut time and local time
        if title:
            stitle = _getTitle(time, beam, self.header, None)
            ax.set_title(stitle)

        # Add a colorbar
        cbax = plotUtils.addColorbar(im, ax)
        _ = cbax.set_ylabel(r"N$_{el}$ [$\log_{10}(m^{-3})$]")

        ax.beam = beam
        return ax, aax, cbax
コード例 #5
0
ファイル: rt.py プロジェクト: DeepHorizons/davitpy
    def plot(self, time, beam=None, 
        maxground=2000, maxalt=500, step=1,
        showrefract=False, nr_cmap='jet_r', nr_lim=[0.8, 1.], 
        raycolor='0.3', title=False, zorder=2, alpha=1, 
        fig=None, rect=111, ax=None, aax=None):
        """Plot ray paths
        
        **Args**: 
            * **time** (datetime.datetime): time of rays
            * [**beam**]: beam number
            * [**maxground**]: maximum ground range [km]
            * [**maxalt**]: highest altitude limit [km]
            * [**step**]: step between each plotted ray (in number of ray steps)
            * [**showrefract**]: show refractive index along ray paths (supersedes raycolor)
            * [**nr_cmap**]: color map name for refractive index coloring
            * [**nr_lim**]: refractive index plotting limits
            * [**raycolor**]: color of ray paths
            * [**rect**]: subplot spcification
            * [**fig**]: A pylab.figure object (default to gcf)
            * [**title**]: Show default title
            * [**ax**]: Existing main axes
            * [**aax**]: Existing auxialary axes
        **Returns**:
            * **ax**: matplotlib.axes object containing formatting
            * **aax**: matplotlib.axes object containing data
            * **cbax**: matplotlib.axes object containing colorbar
        **Example**:
            ::

                # Show ray paths with colored refractive index along path
                import datetime as dt
                from models import raydarn
                sTime = dt.datetime(2012, 11, 18, 5)
                rto = raydarn.RtRun(sTime, rCode='bks', beam=12, title=True)
                rto.readRays() # read rays into memory
                ax, aax, cbax = rto.rays.plot(sTime, step=10, showrefract=True, nr_lim=[.85,1])
                ax.grid()
                
        written by Sebastien, 2013-04
        """
        from utils import plotUtils
        from matplotlib.collections import LineCollection
        import matplotlib.pyplot as plt
        import numpy as np
        from types import MethodType

        # Set up axes
        if not ax and not aax:
            ax, aax = plotUtils.curvedEarthAxes(fig=fig, rect=rect, 
                maxground=maxground, maxalt=maxalt)
        else:
            ax = ax
            aax = aax
            if hasattr(ax, 'time'):
                time = ax.time
            if hasattr(ax, 'beam'):
                beam = ax.beam

        # make sure that the required time and beam are present
        assert (time in self.paths.keys()), 'Unkown time %s' % time
        if beam:
            assert (beam in self.paths[time].keys()), 'Unkown beam %s' % beam
        else:
            beam = self.paths[time].keys()[0]
        
        for ir, (el, rays) in enumerate( sorted(self.paths[time][beam].items()) ):
            if not ir % step:
                if not showrefract:
                    aax.plot(rays['th'], rays['r']*1e-3, c=raycolor, 
                        zorder=zorder, alpha=alpha)
                else:
                    points = np.array([rays['th'], rays['r']*1e-3]).T.reshape(-1, 1, 2)
                    segments = np.concatenate([points[:-1], points[1:]], axis=1)
                    lcol = LineCollection( segments, zorder=zorder, alpha=alpha)
                    _ = lcol.set_cmap( nr_cmap )
                    _ = lcol.set_norm( plt.Normalize(*nr_lim) )
                    _ = lcol.set_array( rays['nr'] )
                    _ = aax.add_collection( lcol )

        # Plot title with date ut time and local time
        if title:
            stitle = _getTitle(time, beam, self.header, self.name)
            ax.set_title( stitle )

        # Add a colorbar when plotting refractive index
        if showrefract:
            cbax = plotUtils.addColorbar(lcol, ax)
            _ = cbax.set_ylabel("refractive index")
        else: cbax = None

        # Declare a new method to show range markers
        # This method is only available after rays have been plotted
        # This ensures that the markers match the plotted rays
        def showRange(self, markers=None, 
            color='.8', s=2, zorder=3, 
            **kwargs):
            """Plot ray paths
            
            **Args**: 
                * [**markers**]: range markers. Defaults to every 250 km
                * All other keywords are borrowed from :func:`matplotlib.pyplot.scatter`
            **Returns**:
                * **coll**: a collection of range markers
            **Example**:
                ::

                    # Add range markers to an existing ray plot
                    ax, aax, cbax = rto.rays.plot(sTime, step=10)
                    rto.rays.showRange()
                    
            written by Sebastien, 2013-04
            """

            if not markers:
                markers = np.arange(0, 5000, 250)
            
            x, y = [], []
            for el, rays in self.paths[time][beam].items():
                for rm in markers:
                    inds = (rays['gran']*1e-3 >= rm)
                    if inds.any():
                        x.append( rays['th'][inds][0] )
                        y.append( rays['r'][inds][0]*1e-3 )
            coll = aax.scatter(x, y, 
                color=color, s=s, zorder=zorder, **kwargs)

            return coll
        # End of new method

        # Assign new method
        self.showRange = MethodType(showRange, self)

        ax.beam = beam
        return ax, aax, cbax
コード例 #6
0
ファイル: rt.py プロジェクト: DeepHorizons/davitpy
    def plot(self, time, beam=None, maxground=2000, maxalt=500,
        iscat=True, gscat=True, title=False, weighted=False, cmap='hot_r', 
        fig=None, rect=111, ax=None, aax=None, zorder=4):
        """Plot scatter on ground/altitude profile
        
        **Args**: 
            * **time** (datetime.datetime): time of profile
            * [**beam**]: beam number
            * [**iscat**] (bool): show ionospheric scatter
            * [**gscat**] (bool): show ground scatter
            * [**maxground**]: maximum ground range [km]
            * [**maxalt**]: highest altitude limit [km]
            * [**rect**]: subplot spcification
            * [**fig**]: A pylab.figure object (default to gcf)
            * [**ax**]: Existing main axes
            * [**aax**]: Existing auxialary axes
            * [**title**]: Show default title
            * [**weighted**] (bool): plot ionospheric scatter relative strength (based on background density and range)
            * [**cmap**]: colormap used for weighted ionospheric scatter
        **Returns**:
            * **ax**: matplotlib.axes object containing formatting
            * **aax**: matplotlib.axes object containing data
            * **cbax**: matplotlib.axes object containing colorbar
        **Example**:
            ::

                # Show ionospheric scatter
                import datetime as dt
                from models import raydarn
                sTime = dt.datetime(2012, 11, 18, 5)
                rto = raydarn.RtRun(sTime, rCode='bks', beam=12)
                rto.readRays() # read rays into memory
                ax, aax, cbax = rto.rays.plot(sTime, title=True)
                rto.readScatter() # read scatter into memory
                rto.scatter.plot(sTime, ax=ax, aax=aax)
                ax.grid()
                
        written by Sebastien, 2013-04
        """
        from utils import plotUtils
        from matplotlib.collections import LineCollection
        import matplotlib.pyplot as plt
        import numpy as np

        # Set up axes
        if not ax and not aax:
            ax, aax = plotUtils.curvedEarthAxes(fig=fig, rect=rect, 
                maxground=maxground, maxalt=maxalt)
        else:
            ax = ax
            aax = aax
            if hasattr(ax, 'beam'):
                beam = ax.beam

        # make sure that the required time and beam are present
        assert (time in self.isc.keys() or time in self.gsc.keys()), 'Unkown time %s' % time
        if beam:
            assert (beam in self.isc[time].keys()), 'Unkown beam %s' % beam
        else:
            beam = self.isc[time].keys()[0]

        if gscat and time in self.gsc.keys():
            for ir, (el, rays) in enumerate( sorted(self.gsc[time][beam].items()) ):
                if len(rays['r']) == 0: continue
                _ = aax.scatter(rays['th'], ax.Re*np.ones(rays['th'].shape), 
                    color='0', zorder=zorder)

        if iscat and time in self.isc.keys():
            if weighted:
                wmin = np.min( [ r['w'].min() for r in self.isc[time][beam].values() if r['nstp'] > 0] )
                wmax = np.max( [ r['w'].max() for r in self.isc[time][beam].values() if r['nstp'] > 0] )

            for ir, (el, rays) in enumerate( sorted(self.isc[time][beam].items()) ):
                if rays['nstp'] == 0: continue
                t = rays['th']
                r = rays['r']*1e-3
                spts = np.array([t, r]).T.reshape(-1, 1, 2)
                h = rays['h']*1e-3
                rel = np.radians( rays['rel'] )
                r = np.sqrt( r**2 + h**2 + 2*r*h*np.sin( rel ) )
                t = t + np.arcsin( h/r * np.cos( rel ) )
                epts = np.array([t, r]).T.reshape(-1, 1, 2)
                segments = np.concatenate([spts, epts], axis=1)
                lcol = LineCollection( segments, zorder=zorder )
                if weighted:
                    _ = lcol.set_cmap( cmap )
                    _ = lcol.set_norm( plt.Normalize(0, 1) )
                    _ = lcol.set_array( ( rays['w'] - wmin ) / wmax )
                else:
                    _ = lcol.set_color('0')
                _ = aax.add_collection( lcol )

            # Plot title with date ut time and local time
            if title:
                stitle = _getTitle(time, beam, self.header, None)
                ax.set_title( stitle )

            # If weighted, plot ionospheric scatter with colormap
            if weighted:
                # Add a colorbar
                cbax = plotUtils.addColorbar(lcol, ax)
                _ = cbax.set_ylabel("Ionospheric Scatter")
            else: cbax = None

        ax.beam = beam
        return ax, aax, cbax
コード例 #7
0
ファイル: rt.py プロジェクト: DeepHorizons/davitpy
    def plot(self, time, beam=None, maxground=2000, maxalt=500,
        nel_cmap='jet', nel_lim=[10, 12], title=False, 
        fig=None, rect=111, ax=None, aax=None):
        """Plot electron density profile
        
        **Args**: 
            * **time** (datetime.datetime): time of profile
            * [**beam**]: beam number
            * [**maxground**]: maximum ground range [km]
            * [**maxalt**]: highest altitude limit [km]
            * [**nel_cmap**]: color map name for electron density index coloring
            * [**nel_lim**]: electron density index plotting limits
            * [**rect**]: subplot spcification
            * [**fig**]: A pylab.figure object (default to gcf)
            * [**ax**]: Existing main axes
            * [**aax**]: Existing auxialary axes
            * [**title**]: Show default title
        **Returns**:
            * **ax**: matplotlib.axes object containing formatting
            * **aax**: matplotlib.axes object containing data
            * **cbax**: matplotlib.axes object containing colorbar
        **Example**:
            ::

                # Show electron density profile
                import datetime as dt
                from models import raydarn
                sTime = dt.datetime(2012, 11, 18, 5)
                rto = raydarn.RtRun(sTime, rCode='bks', beam=12)
                rto.readEdens() # read electron density into memory
                ax, aax, cbax = rto.ionos.plot(sTime, title=True)
                ax.grid()
                
        written by Sebastien, 2013-04
        """
        from utils import plotUtils
        from matplotlib.collections import LineCollection
        import matplotlib.pyplot as plt
        import numpy as np

        # Set up axes
        if not ax and not aax:
            ax, aax = plotUtils.curvedEarthAxes(fig=fig, rect=rect, 
                maxground=maxground, maxalt=maxalt)
        else:
            ax = ax
            aax = aax
            if hasattr(ax, 'time'):
                time = ax.time
            if hasattr(ax, 'beam'):
                beam = ax.beam

        # make sure that the required time and beam are present
        assert (time in self.edens.keys()), 'Unkown time %s' % time
        if beam:
            assert (beam in self.edens[time].keys()), 'Unkown beam %s' % beam
        else:
            beam = self.edens[time].keys()[0]

        X, Y = np.meshgrid(self.edens[time][beam]['th'], ax.Re + np.linspace(60,560,250))
        im = aax.pcolormesh(X, Y, np.log10( self.edens[time][beam]['nel'] ), 
            vmin=nel_lim[0], vmax=nel_lim[1], cmap=nel_cmap)

        # Plot title with date ut time and local time
        if title:
            stitle = _getTitle(time, beam, self.header, None)
            ax.set_title( stitle )

        # Add a colorbar
        cbax = plotUtils.addColorbar(im, ax)
        _ = cbax.set_ylabel(r"N$_{el}$ [$\log_{10}(m^{-3})$]")

        ax.beam = beam
        return ax, aax, cbax