Exemple #1
0
    def overlayMapFitVel(self, pltColBar=True, 
        overlayRadNames=True, annotateTime=True, 
        colorBarLabelSize=15., colMap=cm.jet):
        """Overlay fitted velocity vectors from mapex data
        
        Parameters
        ----------
        plotColBar : Optional[bool]

        overlayRadNames : Optional[bool]

        annotateTime : Optional[bool]

        colorBarLabelSize : Optional[bool]

        colMap : Optional[ ]

        Returns
        -------
            vectors of fitted convection velocities are overlayed on the map object.

        Note
        ----
        Belongs to class MapConv

        Example
        -------
            MapConv.overlayMapFitVel()

        """
        import matplotlib
        import datetime
        import numpy
        from davitpy.pydarn.plotting import overlayRadar

        norm = matplotlib.colors.Normalize(0, self.maxVelPlot) # the color maps work for [0, 1]

        # dateString to overlay date on plot
        dateStr = '{:%Y/%b/%d %H%M} - {:%H%M} UT'.format(
            self.mapData.sTime, self.mapData.eTime)

        # get the standard location parameters.
        # mlatsPlot = self.mapData.grid.vector.mlat
        # mlonsPlot = self.mapData.grid.vector.mlon
        stIds = self.mapData.grid.vector.stid

        # get the fitted mlat, mlon, velocity magnitude and azimuth from calcFitCnvVel() function
        ( mlatsPlot, mlonsPlot, velMagn, velAzm ) = self.calcFitCnvVel()

        self.mapFitPltStrt = []
        self.mapFitPltVec = []

        for nn in range( len(mlatsPlot) ):

            vecLen = velMagn[nn]*self.lenFactor/self.radEarth/1000.
            endLat = numpy.arcsin( numpy.sin(numpy.deg2rad( mlatsPlot[nn] ) )*numpy.cos(vecLen) \
                + numpy.cos( numpy.deg2rad( mlatsPlot[nn] ) )*numpy.sin(vecLen) \
                *numpy.cos(numpy.deg2rad( velAzm[nn] ) ) )
            endLat = numpy.degrees( endLat )
            
            delLon = ( numpy.arctan2( numpy.sin(numpy.deg2rad( velAzm[nn] ) ) \
                *numpy.sin(vecLen)*numpy.cos(numpy.deg2rad( mlatsPlot[nn] ) ), 
                numpy.cos(vecLen) - numpy.sin(numpy.deg2rad( mlatsPlot[nn] ) ) \
                *numpy.sin(numpy.deg2rad( endLat ) ) ) )
            
            if self.plotCoords == 'mag':
                endLon = mlonsPlot[nn] + numpy.degrees( delLon )
            elif self.plotCoords == 'mlt':
                endLon = ( mlonsPlot[nn] + numpy.degrees( delLon ) )/15.
            else:
                logging.warning('Check the coords.')
                
            
            xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn], 
                coords=self.plotCoords)
            xVecEnd, yVecEnd = self.mObj(endLon, endLat, 
                coords = self.plotCoords)

            self.mapFitPltStrt.append(self.mObj.scatter( xVecStrt, yVecStrt, 
                c=velMagn[nn], s=10.,
                vmin=0, vmax=self.maxVelPlot, 
                alpha=0.7, cmap=colMap, zorder=5., 
                edgecolor='none' ))

            self.mapFitPltVec.append(self.mObj.plot( [ xVecStrt, xVecEnd ], [ yVecStrt, yVecEnd ], 
                color = colMap(norm(velMagn[nn])) ))

        # Check and overlay colorbar
        if pltColBar:
            cbar = matplotlib.pyplot.colorbar(self.mapFitPltStrt[0], orientation='vertical')
            cbar.set_label('Velocity [m/s]', size = colorBarLabelSize)
        # Check and overlay radnames
        if overlayRadNames:
            overlayRadar( self.mObj, fontSize=12, ids= self.mapData.grid.stid )
        # Check and annotate time
        if annotateTime:
            self.axisHandle.annotate( dateStr, xy=(0.5, 1.), 
                fontsize=12, ha="center", xycoords="axes fraction",
                bbox=dict(boxstyle='round,pad=0.2', fc="w", alpha=0.3) )
Exemple #2
0
    def overlayMapFitVel(self,
                         pltColBar=True,
                         overlayRadNames=True,
                         annotateTime=True,
                         colorBarLabelSize=15.0,
                         colMap=cm.jet,
                         label_style="web"):
        """Overlay fitted velocity vectors from the map data
        
        Parameters
        ----------
        plotColBar : (bool)
            Add colorbar to plot (default=True)
        overlayRadNames : (bool)
            Overlay radar names (default=True)
        annotateTime : (bool)
            Add timestamp to axis (default=True)
        colorBarLabelSize : (float)
            Specify colorbar label size (default=15.0)
        colMap : (matplotlib.colors.LinearSegmentedColormap)
            Set color map (default=cm.jet)
        label_style : (str)
            Set colorbar label style.  'web'=[m/s]; 'agu'=[$m s^{-1}$]
            (default='web')

        Returns
        -------
            vectors of fitted convection velocities are overlayed on the map
            object.

        Note
        ----
        Belongs to class MapConv

        Example
        -------
            MapConv.overlayMapFitVel()
        """
        import matplotlib as mpl
        from davitpy.pydarn.plotting import overlayRadar

        # Test to make sure the necessary attributes have been set
        assert self.mapData is not None, logging.error("no map data available")
        assert self.mObj is not None, logging.error("no map available")
        assert self.axisHandle is not None, \
            logging.error("no axis handle available")

        # the color maps work for [0, 1]
        norm = mpl.colors.Normalize(self.min_vel, self.maxVelPlot)

        # dateString to overlay date on plot
        date_str = self.date_string("map", label_style=label_style)

        # get the fitted mlat, mlon, velocity magnitude and azimuth from
        # calcFitCnvVel() function
        (mlats_plot, mlons_plot, vel_mag, vel_azm) = self.calcFitCnvVel()

        self.mapFitPltStrt = []
        self.mapFitPltVec = []

        for nn, nn_mlats in enumerate(mlats_plot):
            vec_len = vel_mag[nn] * self.lenFactor / self.radEarth / 1000.0
            end_lat = np.arcsin(
                np.sin(np.deg2rad(nn_mlats)) * np.cos(vec_len) +
                np.cos(np.deg2rad(nn_mlats)) * np.sin(vec_len) *
                np.cos(np.deg2rad(vel_azm[nn])))
            end_lat = np.degrees(end_lat)

            del_lon = np.arctan2(
                np.sin(np.deg2rad(vel_azm[nn])) * np.sin(vec_len) *
                np.cos(np.deg2rad(nn_mlats)),
                np.cos(vec_len) -
                np.sin(np.deg2rad(nn_mlats)) * np.sin(np.deg2rad(end_lat)))

            end_lon = mlons_plot[nn] + np.degrees(del_lon)

            x_vec_strt, y_vec_strt = self.mObj(mlons_plot[nn],
                                               nn_mlats,
                                               coords='mag')
            x_vec_end, y_vec_end = self.mObj(end_lon, end_lat, coords='mag')

            self.mapFitPltStrt.append(
                self.mObj.scatter(x_vec_strt,
                                  y_vec_strt,
                                  c=vel_mag[nn],
                                  s=10.0,
                                  vmin=self.min_vel,
                                  vmax=self.maxVelPlot,
                                  alpha=0.7,
                                  cmap=colMap,
                                  zorder=5.0,
                                  edgecolor='none'))

            map_color = colMap(norm(vel_mag[nn]))
            self.mapFitPltVec.append(
                self.mObj.plot([x_vec_strt, x_vec_end],
                               [y_vec_strt, y_vec_end],
                               color=map_color))

        # Check and overlay colorbar
        if pltColBar:
            cbar = mpl.pyplot.colorbar(self.mapFitPltStrt[0],
                                       orientation='vertical')
            vlabel = "Velocity [m/s]" if label_style == "web" else \
                     "v [$m s^{-1}$]"
            cbar.set_label(vlabel, size=colorBarLabelSize)
        # Check and overlay radnames
        if overlayRadNames:
            overlayRadar(self.mObj, fontSize=12, ids=self.mapData.grid.stid)
        # Check and annotate time
        if annotateTime:
            self.axisHandle.set_title(date_str, fontsize="medium")
Exemple #3
0
    def overlayGridVel(self, pltColBar=True, overlayRadNames=True,
                       annotateTime=True, colorBarLabelSize=15.,
                       colMap=cm.jet):
        """Overlay Gridded LoS velocity data from grdex files

        Parameters
        ---------
        pltColBar : Optional[bool]

        overlayRadNames : Optional[bool]

        annotateTime : Optional[bool]

        colorBarLabelSize : Optional[float]

        colMap : Optional[ ]

        Note
        ----
        Belongs to class MapConv

        Returns
        -------
        Gridded LoS data is overlayed on the map object. HOW? OR IN WHAT
        VARIABLE?

        """
        import matplotlib
        import datetime
        import numpy
        from davitpy.pydarn.plotting import overlayRadar

        # the color maps work for [0, 1]
        norm = matplotlib.colors.Normalize(0, self.maxVelPlot)

        # dateString to overlay date on plot
        dateStr = '{:%Y/%b/%d %H%M} - {:%H%M} UT'.format(
            self.grdData.sTime, self.grdData.eTime)

        # get the standard location and LoS Vel parameters.
        mlatsPlot = self.grdData.vector.mlat
        mlonsPlot = self.grdData.vector.mlon
        velsPlot = self.grdData.vector.velmedian
        azmsPlot = self.grdData.vector.kvect
        stIds = self.grdData.vector.stid

        for nn in range(len(mlatsPlot)):

            # calculate stuff for plotting such as vector length, azimuth etc
            vecLen = velsPlot[nn] * self.lenFactor / self.radEarth / 1000.
            endLat = numpy.arcsin(numpy.sin(numpy.deg2rad(mlatsPlot[nn])) *
                                  numpy.cos(vecLen) +
                                  numpy.cos(numpy.deg2rad(mlatsPlot[nn])) *
                                  numpy.sin(vecLen) *
                                  numpy.cos(numpy.deg2rad(azmsPlot[nn])))
            endLat = numpy.degrees(endLat)
            delLon = (numpy.arctan2(numpy.sin(numpy.deg2rad(azmsPlot[nn])) *
                      numpy.sin(vecLen) *
                      numpy.cos(numpy.deg2rad(mlatsPlot[nn])),
                      numpy.cos(vecLen) -
                      numpy.sin(numpy.deg2rad(mlatsPlot[nn])) *
                      numpy.sin(numpy.deg2rad(endLat))))

            # depending on whether we have 'mag' or 'mlt' coords,
            # calculate endLon
            if self.plotCoords == 'mag':
                endLon = mlonsPlot[nn] + numpy.degrees(delLon)
            elif self.plotCoords == 'mlt':
                endLon = (mlonsPlot[nn] + numpy.degrees(delLon)) / 15.
            else:
                logging.warning('Check the coords')

            # get the start and end vecs
            xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn],
                                           coords=self.plotCoords)
            xVecEnd, yVecEnd = self.mObj(endLon, endLat,
                                         coords=self.plotCoords)

            # Plot the start point and then append the vector indicating magn.
            # and azimuth
            self.grdPltStrt = self.mObj.scatter(xVecStrt, yVecStrt,
                                                c=velsPlot[nn], s=10., vmin=0,
                                                vmax=self.maxVelPlot,
                                                alpha=0.7, cmap=colMap,
                                                zorder=5., edgecolor='none')
            self.grdPltVec = self.mObj.plot([ xVecStrt, xVecEnd ],
                                            [ yVecStrt, yVecEnd ],
                                            color=colMap(norm(velsPlot[nn])))

        # Check and overlay colorbar
        if pltColBar:
            cbar = matplotlib.pyplot.colorbar(self.grdPltStrt,
                                              orientation='vertical')
            cbar.set_label('Velocity [m/s]', size=colorBarLabelSize)
        # Check and overlay radnames
        if overlayRadNames:
            overlayRadar(self.mObj, fontSize=12, ids=self.grdData.stid)
        # Check and annotate time
        if annotateTime:
            self.axisHandle.annotate(dateStr, xy=(0.5, 1.), fontsize=12,
                                     ha="center", xycoords="axes fraction",
                                     bbox=dict(boxstyle='round,pad=0.2',
                                     fc="w", alpha=0.3))
Exemple #4
0
    def overlayGridVel(self,
                       pltColBar=True,
                       overlayRadNames=True,
                       annotateTime=True,
                       colorBarLabelSize=15.0,
                       colMap=cm.jet,
                       label_style="web"):
        """Overlay Gridded LoS velocity data from grd files

        Parameters
        ---------
        pltColBar : (bool)
            Add color bar for velocity (default=True)
        overlayRadNames : (bool)
            Add radar names (default=True)
        annotateTime : (bool)
            Add time to plot (default=True)
        colorBarLabelSize : (float)
            Set colorbar label size (default=15.0)
        colMap : (matplotlib.colors.LinearSegmentedColormap)
            Set color map (default=cm.jet)
        label_style : (str)
            Set colorbar label style.  'web'=[m/s]; 'agu'=[$m s^{-1}$]
            (default='web')

        Note
        ----
        Belongs to class MapConv

        Returns
        -------
        Gridded LoS data is overlayed on the subplot axis contained in the
        MapConv class object
        """
        import matplotlib as mpl
        from davitpy.pydarn.plotting import overlayRadar

        # Test to make sure the necessary attributes have been set
        assert self.grdData is not None, logging.error(
            "no grid data available")
        assert self.mObj is not None, logging.error("no map available")
        assert self.axisHandle is not None, \
            logging.error("no axis handle available")

        # the color maps work for [0, 1]
        norm = mpl.colors.Normalize(self.min_vel, self.maxVelPlot)

        # dateString to overlay date on plot
        date_str = self.date_string("grd", label_style=label_style)

        # get the standard location and LoS Vel parameters.
        mlats_plot = self.grdData.vector.mlat
        mlons_plot = self.grdData.vector.mlon
        vels_plot = self.grdData.vector.velmedian
        azms_plot = self.grdData.vector.kvect

        for nn, nn_mlats in enumerate(mlats_plot):
            # calculate stuff for plotting such as vector length, azimuth etc
            vec_len = (vels_plot[nn] * self.lenFactor / self.radEarth) / 1000.0
            end_lat = np.arcsin(
                np.sin(np.deg2rad(nn_mlats)) * np.cos(vec_len) +
                np.cos(np.deg2rad(nn_mlats)) * np.sin(vec_len) *
                np.cos(np.deg2rad(azms_plot[nn])))
            end_lat = np.degrees(end_lat)
            del_lon = np.arctan2(
                np.sin(np.deg2rad(azms_plot[nn])) * np.sin(vec_len) *
                np.cos(np.deg2rad(nn_mlats)),
                np.cos(vec_len) -
                np.sin(np.deg2rad(nn_mlats)) * np.sin(np.deg2rad(end_lat)))

            # depending on whether we have 'mag' or 'mlt' coords,
            # calculate the end longitude
            end_lon = mlons_plot[nn] + np.degrees(del_lon)

            # get the start and end vecs
            x_vec_strt, y_vec_strt = self.mObj(mlons_plot[nn],
                                               nn_mlats,
                                               coords='mag')
            x_vec_end, y_vec_end = self.mObj(end_lon, end_lat, coords='mag')

            # Plot the start point and then append the vector indicating magn.
            # and azimuth
            self.grdPltStrt = self.mObj.scatter(x_vec_strt,
                                                y_vec_strt,
                                                c=vels_plot[nn],
                                                s=10.0,
                                                vmin=self.min_vel,
                                                vmax=self.maxVelPlot,
                                                alpha=0.7,
                                                cmap=colMap,
                                                zorder=5.0,
                                                edgecolor='none')
            self.grdPltVec = self.mObj.plot([x_vec_strt, x_vec_end],
                                            [y_vec_strt, y_vec_end],
                                            color=colMap(norm(vels_plot[nn])))

        # Check and overlay colorbar
        if pltColBar:
            cbar = mpl.pyplot.colorbar(self.grdPltStrt, orientation='vertical')
            vlabel = "Velocity [m/s]" if label_style == "web" else \
                     "v [$m s^{-1}$]"
            cbar.set_label(vlabel, size=colorBarLabelSize)
        # Check and overlay radnames
        if overlayRadNames:
            overlayRadar(self.mObj, fontSize=12, ids=self.grdData.stid)
        # Check and annotate time
        if annotateTime:
            self.axisHandle.set_title(date_str, fontsize="medium")
Exemple #5
0
    def overlayGridVel(self, pltColBar=True, 
        overlayRadNames=True, annotateTime=True, 
        colorBarLabelSize = 15., colMap = cm.jet):
        """Overlay Gridded LoS velocity data from grdex files
        
        **Belongs to**: :class:`MapConv`

        **Returns**:
            Gridded LoS data is overlayed on the map object.
        """
        import matplotlib
        import datetime
        import numpy
        from davitpy.pydarn.plotting import overlayRadar

        norm = matplotlib.colors.Normalize(0, self.maxVelPlot) # the color maps work for [0, 1]

        # dateString to overlay date on plot
        dateStr = '{:%Y/%b/%d %H%M} - {:%H%M} UT'.format(
            self.grdData.sTime, self.grdData.eTime)

        # get the standard location and LoS Vel parameters.
        mlatsPlot = self.grdData.vector.mlat
        mlonsPlot = self.grdData.vector.mlon
        velsPlot = self.grdData.vector.velmedian
        azmsPlot = self.grdData.vector.kvect
        stIds = self.grdData.vector.stid

        for nn in range( len(mlatsPlot) ) :
    
            # calculate stuff for plotting such as vector length, azimuth etc 
            vecLen = velsPlot[nn]*self.lenFactor/self.radEarth/1000.
            endLat = numpy.arcsin( numpy.sin(numpy.deg2rad( mlatsPlot[nn] ) )*numpy.cos(vecLen) + \
                numpy.cos( numpy.deg2rad( mlatsPlot[nn] ) )*numpy.sin(vecLen) \
                *numpy.cos(numpy.deg2rad( azmsPlot[nn] ) ) )
            endLat = numpy.degrees( endLat )
            delLon = ( numpy.arctan2( numpy.sin(numpy.deg2rad( azmsPlot[nn] ) ) \
                *numpy.sin(vecLen)*numpy.cos(numpy.deg2rad( mlatsPlot[nn] ) ), 
                numpy.cos(vecLen) - numpy.sin(numpy.deg2rad( mlatsPlot[nn] ) ) \
                *numpy.sin(numpy.deg2rad( endLat ) ) ) )
                        
            # depending on whether we have 'mag' or 'mlt' coords, calculate endLon
            if self.plotCoords == 'mag' :
                endLon = mlonsPlot[nn] + numpy.degrees( delLon )
            elif self.plotCoords == 'mlt' :
                endLon = ( mlonsPlot[nn] + numpy.degrees( delLon ) )/15.
            else :
                print 'Check the coords'

            # get the start and end vecs
            xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn], coords=self.plotCoords )
            xVecEnd, yVecEnd = self.mObj(endLon, endLat, coords=self.plotCoords )
            
            # Plot the start point and then append the vector indicating magn. and azimuth
            self.grdPltStrt = self.mObj.scatter( xVecStrt, yVecStrt, 
                c=velsPlot[nn], s=10., vmin=0, vmax=self.maxVelPlot,
                alpha=0.7, cmap=colMap, zorder=5., edgecolor='none' )
            self.grdPltVec = self.mObj.plot( [ xVecStrt, xVecEnd ], [ yVecStrt, yVecEnd ], 
                color = colMap(norm(velsPlot[nn])) )

        # Check and overlay colorbar
        if pltColBar :
            cbar = matplotlib.pyplot.colorbar(self.grdPltStrt, orientation='vertical')
            cbar.set_label('Velocity [m/s]', size = colorBarLabelSize)
        # Check and overlay radnames
        if overlayRadNames :
            overlayRadar( self.mObj, fontSize=12, ids= self.grdData.stid )
        # Check and annotate time
        if annotateTime :
            self.axisHandle.annotate( dateStr, 
                xy=(0.5, 1.), fontsize=12, 
                ha="center", xycoords="axes fraction",
                bbox=dict(boxstyle='round,pad=0.2', 
                fc="w", alpha=0.3) )
Exemple #6
0
    def overlayMapFitVel(self, pltColBar=True, 
        overlayRadNames=True, annotateTime=True, 
        colorBarLabelSize=15., colMap=cm.jet):
        """Overlay fitted velocity vectors from mapex data
        
        **Belongs to**: :class:`MapConv`

        **Returns**:
            vectors of fitted convection velocities are overlayed on the map object.
        **Example**:
            ::

                MapConv.overlayMapFitVel()
        """
        import matplotlib
        import datetime
        import numpy
        from davitpy.pydarn.plotting import overlayRadar

        norm = matplotlib.colors.Normalize(0, self.maxVelPlot) # the color maps work for [0, 1]

        # dateString to overlay date on plot
        dateStr = '{:%Y/%b/%d %H%M} - {:%H%M} UT'.format(
            self.mapData.sTime, self.mapData.eTime)

        # get the standard location parameters.
        # mlatsPlot = self.mapData.grid.vector.mlat
        # mlonsPlot = self.mapData.grid.vector.mlon
        stIds = self.mapData.grid.vector.stid

        # get the fitted mlat, mlon, velocity magnitude and azimuth from calcFitCnvVel() function
        ( mlatsPlot, mlonsPlot, velMagn, velAzm ) = self.calcFitCnvVel()

        self.mapFitPltStrt = []
        self.mapFitPltVec = []

        for nn in range( len(mlatsPlot) ) :

            vecLen = velMagn[nn]*self.lenFactor/self.radEarth/1000.
            endLat = numpy.arcsin( numpy.sin(numpy.deg2rad( mlatsPlot[nn] ) )*numpy.cos(vecLen) \
                + numpy.cos( numpy.deg2rad( mlatsPlot[nn] ) )*numpy.sin(vecLen) \
                *numpy.cos(numpy.deg2rad( velAzm[nn] ) ) )
            endLat = numpy.degrees( endLat )
            
            delLon = ( numpy.arctan2( numpy.sin(numpy.deg2rad( velAzm[nn] ) ) \
                *numpy.sin(vecLen)*numpy.cos(numpy.deg2rad( mlatsPlot[nn] ) ), 
                numpy.cos(vecLen) - numpy.sin(numpy.deg2rad( mlatsPlot[nn] ) ) \
                *numpy.sin(numpy.deg2rad( endLat ) ) ) )
            
            if self.plotCoords == 'mag' :
                endLon = mlonsPlot[nn] + numpy.degrees( delLon )
            elif self.plotCoords == 'mlt' :
                endLon = ( mlonsPlot[nn] + numpy.degrees( delLon ) )/15.
            else :
                print 'Check the coords.'
                
            
            xVecStrt, yVecStrt = self.mObj(mlonsPlot[nn], mlatsPlot[nn], 
                coords=self.plotCoords)
            xVecEnd, yVecEnd = self.mObj(endLon, endLat, 
                coords = self.plotCoords)

            self.mapFitPltStrt.append(self.mObj.scatter( xVecStrt, yVecStrt, 
                c=velMagn[nn], s=10.,
                vmin=0, vmax=self.maxVelPlot, 
                alpha=0.7, cmap=colMap, zorder=5., 
                edgecolor='none' ))

            self.mapFitPltVec.append(self.mObj.plot( [ xVecStrt, xVecEnd ], [ yVecStrt, yVecEnd ], 
                color = colMap(norm(velMagn[nn])) ))

        # Check and overlay colorbar
        if pltColBar :
            cbar = matplotlib.pyplot.colorbar(self.mapFitPltStrt[0], orientation='vertical')
            cbar.set_label('Velocity [m/s]', size = colorBarLabelSize)
        # Check and overlay radnames
        if overlayRadNames :
            overlayRadar( self.mObj, fontSize=12, ids= self.mapData.grid.stid )
        # Check and annotate time
        if annotateTime :
            self.axisHandle.annotate( dateStr, xy=(0.5, 1.), 
                fontsize=12, ha="center", xycoords="axes fraction",
                bbox=dict(boxstyle='round,pad=0.2', fc="w", alpha=0.3) )
Exemple #7
0
    def overlayMapFitVel(self, pltColBar=True, overlayRadNames=True,
                         annotateTime=True, colorBarLabelSize=15.0,
                         colMap=cm.jet, label_style="web"):
        """Overlay fitted velocity vectors from the map data
        
        Parameters
        ----------
        plotColBar : (bool)
            Add colorbar to plot (default=True)
        overlayRadNames : (bool)
            Overlay radar names (default=True)
        annotateTime : (bool)
            Add timestamp to axis (default=True)
        colorBarLabelSize : (float)
            Specify colorbar label size (default=15.0)
        colMap : (matplotlib.colors.LinearSegmentedColormap)
            Set color map (default=cm.jet)
        label_style : (str)
            Set colorbar label style.  'web'=[m/s]; 'agu'=[$m s^{-1}$]
            (default='web')

        Returns
        -------
            vectors of fitted convection velocities are overlayed on the map
            object.

        Note
        ----
        Belongs to class MapConv

        Example
        -------
            MapConv.overlayMapFitVel()
        """
        import matplotlib as mpl
        from davitpy.pydarn.plotting import overlayRadar

        # Test to make sure the necessary attributes have been set
        assert self.mapData is not None, logging.error("no map data available")
        assert self.mObj is not None, logging.error("no map available")
        assert self.axisHandle is not None, \
            logging.error("no axis handle available")

        # the color maps work for [0, 1]
        norm = mpl.colors.Normalize(self.min_vel, self.maxVelPlot)

        # dateString to overlay date on plot
        date_str = self.date_string("map", label_style=label_style)

        # get the fitted mlat, mlon, velocity magnitude and azimuth from
        # calcFitCnvVel() function
        (mlats_plot, mlons_plot, vel_mag, vel_azm) = self.calcFitCnvVel()

        self.mapFitPltStrt = []
        self.mapFitPltVec = []

        for nn, nn_mlats in enumerate(mlats_plot):
            vec_len = vel_mag[nn] * self.lenFactor / self.radEarth / 1000.0
            end_lat = np.arcsin(np.sin(np.deg2rad(nn_mlats)) * np.cos(vec_len) +
                               np.cos(np.deg2rad(nn_mlats)) * np.sin(vec_len) *
                               np.cos(np.deg2rad(vel_azm[nn])))
            end_lat = np.degrees(end_lat)
            
            del_lon = np.arctan2(np.sin(np.deg2rad(vel_azm[nn])) *
                                 np.sin(vec_len) * np.cos(np.deg2rad(nn_mlats)),
                                 np.cos(vec_len) - np.sin(np.deg2rad(nn_mlats))
                                 * np.sin(np.deg2rad(end_lat)))

            end_lon = mlons_plot[nn] + np.degrees(del_lon)

            x_vec_strt, y_vec_strt = self.mObj(mlons_plot[nn], nn_mlats,
                                           coords='mag')
            x_vec_end, y_vec_end = self.mObj(end_lon, end_lat, coords='mag')

            self.mapFitPltStrt.append(self.mObj.scatter(x_vec_strt, y_vec_strt, 
                                                        c=vel_mag[nn], s=10.0,
                                                        vmin=self.min_vel,
                                                        vmax=self.maxVelPlot, 
                                                        alpha=0.7, cmap=colMap,
                                                        zorder=5.0,
                                                        edgecolor='none'))

            map_color = colMap(norm(vel_mag[nn]))
            self.mapFitPltVec.append(self.mObj.plot([x_vec_strt, x_vec_end],
                                                    [y_vec_strt, y_vec_end], 
                                                    color=map_color))

        # Check and overlay colorbar
        if pltColBar:
            cbar = mpl.pyplot.colorbar(self.mapFitPltStrt[0],
                                       orientation='vertical')
            vlabel = "Velocity [m/s]" if label_style == "web" else \
                     "v [$m s^{-1}$]"
            cbar.set_label(vlabel, size=colorBarLabelSize)
        # Check and overlay radnames
        if overlayRadNames:
            overlayRadar(self.mObj, fontSize=12, ids=self.mapData.grid.stid)
        # Check and annotate time
        if annotateTime:
            self.axisHandle.set_title(date_str, fontsize="medium")
Exemple #8
0
    def overlayGridVel(self, pltColBar=True, overlayRadNames=True,
                       annotateTime=True, colorBarLabelSize=15.0,
                       colMap=cm.jet, label_style="web"):
        """Overlay Gridded LoS velocity data from grd files

        Parameters
        ---------
        pltColBar : (bool)
            Add color bar for velocity (default=True)
        overlayRadNames : (bool)
            Add radar names (default=True)
        annotateTime : (bool)
            Add time to plot (default=True)
        colorBarLabelSize : (float)
            Set colorbar label size (default=15.0)
        colMap : (matplotlib.colors.LinearSegmentedColormap)
            Set color map (default=cm.jet)
        label_style : (str)
            Set colorbar label style.  'web'=[m/s]; 'agu'=[$m s^{-1}$]
            (default='web')

        Note
        ----
        Belongs to class MapConv

        Returns
        -------
        Gridded LoS data is overlayed on the subplot axis contained in the
        MapConv class object
        """
        import matplotlib as mpl
        from davitpy.pydarn.plotting import overlayRadar

        # Test to make sure the necessary attributes have been set
        assert self.grdData is not None, logging.error("no grid data available")
        assert self.mObj is not None, logging.error("no map available")
        assert self.axisHandle is not None, \
            logging.error("no axis handle available")

        # the color maps work for [0, 1]
        norm = mpl.colors.Normalize(self.min_vel, self.maxVelPlot)

        # dateString to overlay date on plot
        date_str = self.date_string("grd", label_style=label_style)

        # get the standard location and LoS Vel parameters.
        mlats_plot = self.grdData.vector.mlat
        mlons_plot = self.grdData.vector.mlon
        vels_plot = self.grdData.vector.velmedian
        azms_plot = self.grdData.vector.kvect

        for nn, nn_mlats in enumerate(mlats_plot):
            # calculate stuff for plotting such as vector length, azimuth etc
            vec_len = (vels_plot[nn] * self.lenFactor / self.radEarth) / 1000.0
            end_lat = np.arcsin(np.sin(np.deg2rad(nn_mlats)) * np.cos(vec_len) +
                                np.cos(np.deg2rad(nn_mlats)) * np.sin(vec_len) *
                                np.cos(np.deg2rad(azms_plot[nn])))
            end_lat = np.degrees(end_lat)
            del_lon = np.arctan2(np.sin(np.deg2rad(azms_plot[nn])) *
                                 np.sin(vec_len) * np.cos(np.deg2rad(nn_mlats)),
                                 np.cos(vec_len) - np.sin(np.deg2rad(nn_mlats))
                                 * np.sin(np.deg2rad(end_lat)))

            # depending on whether we have 'mag' or 'mlt' coords,
            # calculate the end longitude
            end_lon = mlons_plot[nn] + np.degrees(del_lon)

            # get the start and end vecs
            x_vec_strt, y_vec_strt = self.mObj(mlons_plot[nn], nn_mlats,
                                               coords='mag')
            x_vec_end, y_vec_end = self.mObj(end_lon, end_lat, coords='mag')

            # Plot the start point and then append the vector indicating magn.
            # and azimuth
            self.grdPltStrt = self.mObj.scatter(x_vec_strt, y_vec_strt,
                                                c=vels_plot[nn], s=10.0,
                                                vmin=self.min_vel,
                                                vmax=self.maxVelPlot,
                                                alpha=0.7, cmap=colMap,
                                                zorder=5.0, edgecolor='none')
            self.grdPltVec = self.mObj.plot([x_vec_strt, x_vec_end],
                                            [y_vec_strt, y_vec_end],
                                            color=colMap(norm(vels_plot[nn])))

        # Check and overlay colorbar
        if pltColBar:
            cbar = mpl.pyplot.colorbar(self.grdPltStrt, orientation='vertical')
            vlabel = "Velocity [m/s]" if label_style == "web" else \
                     "v [$m s^{-1}$]"
            cbar.set_label(vlabel, size=colorBarLabelSize)
        # Check and overlay radnames
        if overlayRadNames:
            overlayRadar(self.mObj, fontSize=12, ids=self.grdData.stid)
        # Check and annotate time
        if annotateTime:
            self.axisHandle.set_title(date_str, fontsize="medium")