示例#1
0
def plotopticsonly(allsky_data,plotdir,m,ax,fig,latlim,lonlim):
    """ Make a set of pots when only all sky is avalible."""
    maxplot = len(allsky_data.times)
    strlen = int(sp.ceil(sp.log10(maxplot))+1)
    fmstr = '{0:0>'+str(strlen)+'}_'
    optictimes = allsky_data.times
    plotnum=0
    firstbar = True
    optbnds = [300,1100]
    for iop in range(len(optictimes)):
        (slice3,cbar3) = slice2DGD(allsky_data,'alt',150,optbnds,title='',
                            time = iop,cmap='gray',gkey = 'image',fig=fig,ax=ax,cbar=True,m=m)

        slice3.set_norm(colors.PowerNorm(gamma=0.6,vmin=optbnds[0],vmax=optbnds[1]))
        if firstbar:
            firstbar=False
            cbaras = plt.colorbar(slice3,ax=ax,orientation='horizontal')
            cbaras.set_label('All Sky Scale')

        plt.title(insertinfo('All Sky $tmdy $thmsehms',posix=allsky_data.times[iop,0],posixend=allsky_data.times[iop,1]))
        print('Ploting {0} of {1} plots'.format(plotnum,maxplot))
        plt.savefig(os.path.join(plotdir,fmstr.format(plotnum)+'ASonly.png'))

        plotnum+=1
        slice3.remove()
示例#2
0
def plotting(risr_classred,risr_class,omti_class,reglistfinal,odir=None):

    figcount = 0
    for iomti,ilist in enumerate(reglistfinal):
        for irisr in ilist:
            omtitime = iomti
            risrtime =  irisr

            try:
                mfig = mlab.figure(fgcolor=(1, 1, 1), bgcolor=(1, 1, 1))
                surflist1 = plot3Dslice(omti_class, omtislices, vbounds[0],
                            time = omtitime,cmap='gray',gkey = 'optical',fig=mfig)
                arr = plot3Dslice(risr_classred, risrslices, vbounds[1],
                            time = risrtime,cmap='jet',gkey = 'ne',fig=mfig,units = 'm^{-3}',colorbar = True,view=[50,60],outimage=True)
                titlestr1 = '$N_e$ and OMTI at $thm'
                newtitle = insertinfo(titlestr1,'',risr_classred.times[risrtime,0],risr_classred.times[risrtime,1])
            except Exception as e:
                logging.error('trouble with 3D plot  {}'.format(e))

            (figmplf, [[ax1,ax2],[ax3,ax4]]) = plt.subplots(2, 2,figsize=(16, 12), facecolor='w')

            try:
                ax1.imshow(arr)
                ax1.set_title(newtitle)
                ax1.axis('off')
            except:
                pass

            (slice2,cbar2) = slice2DGD(risr_classred,'z',400,vbounds[1],title='$N_e$ at $thm',
                        time = risrtime,cmap='jet',gkey = 'ne',fig=figmplf,ax=ax2)
            cbar2.set_label('$N_e$ in $m^{-3}$')

            (slice3,cbar3) = slice2DGD(omti_class,'z',omtislices[-1][0],vbounds[0],title='OMTI at $thm',
                        time = omtitime,cmap='Greys',gkey = 'optical',fig=figmplf,ax=ax3,cbar=False)
            plt.hold(True)

            (slice4,cbar4) = contourGD(risr_classred,'z',400,vbounds[1],title='$N_e$ at $thm',
                        time = risrtime,cmap='jet',gkey = 'ne',fig=figmplf,ax=ax3)
            cbar4.set_label('$N_e$ in $m^{-3}$')
            bmpos = plotbeamposGD(risr_class)

            if odir is not None:
                figname = os.path.join(odir,'figure{0:0>2}.png'.format(figcount))
                figmplf.savefig(figname,format='png',dpi = 400)
                plt.close(figmplf)
                figcount=figcount+1
示例#3
0
def plotgpswoptics(allsky_data,TEClist,allskylist,gpslist,plotdir,m,ax,fig,latlim,lonlim):
    """ Make a set of plots when given both all sky ad GPS are given.
        Inputs
            allsky_data - The all sky data as a GeoData object.
            TEClist - The of GeoData objects derived from the ionofiles.
            allskylist - A list of list which determines which allsky times are used."""
    maxplot = len(allsky_data.times)
    maxplot = sp.array([len(i) for i in allskylist]).sum()
    strlen = int(sp.ceil(sp.log10(maxplot))+1)
    fmstr = '{0:0>'+str(strlen)+'}_'
    plotnum=0
    firstbar = True
    optbnds = [300,1100]
    for (optic_times,gps_cur)in zip(allskylist,gpslist):
        gpshands = []
        gpsmin = sp.inf
        gpsmax = -sp.inf
        for igpsn, (igps,igpslist) in enumerate(zip(TEClist,gps_cur)):
            print('Plotting GPS data from rec {0} of {1}'.format(igpsn,len(gps_cur)))
            # check if there's anything to plot
            if len(igpslist)==0:
                continue

            (sctter,scatercb) = scatterGD(igps,'alt',3.5e5,vbounds=[0,20],time = igpslist,gkey = 'vTEC',cmap='plasma',fig=fig,
                  ax=ax,title='',cbar=True,err=.1,m=m)
            gpsmin = sp.minimum(igps.times[igpslist,0].min(),gpsmin)
            gpsmax = sp.maximum(igps.times[igpslist,0].max(),gpsmax)
            gpshands.append(sctter)
        scatercb.set_label('vTEC in TECu')
        #change he z order
        minz = gpshands[0].get_zorder()
        for i in reversed(gpshands):
            i.set_zorder(i.get_zorder()+1)

        for iop in optic_times:
            (slice3,cbar3) = slice2DGD(allsky_data,'alt',150,optbnds,title='',
                                time = iop,cmap='gray',gkey = 'image',fig=fig,ax=ax,cbar=False,m=m)
            slice3.set_norm(colors.PowerNorm(gamma=0.6,vmin=optbnds[0],vmax=optbnds[1]))

            if firstbar:
                firstbar=False
                cbaras = plt.colorbar(slice3,ax=ax,orientation='horizontal')
                cbaras.set_label('All Sky Scale')
            slice3.set_zorder(minz)
            plt.title(insertinfo('GPS $tmdy $thmsehms',posix=gpsmin,posixend=gpsmax)+'\n'+insertinfo('All Sky $tmdy $thmsehms',posix=allsky_data.times[iop,0],posixend=allsky_data.times[iop,1]))
            print('Ploting {0} of {1} plots'.format(plotnum,maxplot))
            plt.savefig(os.path.join(plotdir,fmstr.format(plotnum)+'ASwGPS.png'))

            plotnum+=1
            slice3.remove()
        for i in reversed(gpshands):
            i.remove()
示例#4
0
def getSRIhdf5(filename,times,pnheights,xycoords,newcordname,vbounds,pltdir =None):
    """ Plots a set of ISR data in SRI's data format."""
    paramstr = ['Ne','Ti','Te']
    SRIh5 = GeoData(readSRI_h5,(filename,paramstr))
    (dt1,dt2) = parser.parse(times[0]),parser.parse(times[1])
    dt1 =dt1.replace(tzinfo=pytz.utc)
    dt2 = dt2.replace(tzinfo=pytz.utc)
    dt1ts = (dt1 -datetime(1970,1,1,0,0,0,tzinfo=pytz.utc)).total_seconds()
    dt2ts = (dt2 -datetime(1970,1,1,0,0,0,tzinfo=pytz.utc)).total_seconds()

    timelist = sp.where((SRIh5.times[:,0]>=dt1ts)&(SRIh5.times[:,0]<=dt2ts))[0]

    if len(timelist)==0:
        return

    SRIh5 = SRIh5.timeslice(timelist)

    hset = sp.array([i[1] for i in pnheights])
    uh,uhs =sp.unique(hset,return_inverse=True)

        # interpolation
    ncoords = xycoords.shape[0]
    uhall = sp.repeat(uh,ncoords)

    coords = sp.tile(xycoords,(len(uh),1))
    coords = sp.column_stack((coords,uhall))


    SRIh5.interpolate(coords,newcordname,method='linear')


    maxplot = len(timelist)
    strlen = int(sp.ceil(sp.log10(maxplot))+1)
    fmstr = '{0:0>'+str(strlen)+'}_'
    for itn in range(len(timelist)):
        fig, axmat = plt.subplots(nrows=len(pnheights),ncols=1)
        axvec = axmat.flatten()


        for icase,(iparam,iheight) in enumerate(pnheights):
           (plth,cbh) =  slice2DGD(SRIh5,'z',uhs[icase],vbounds=vbounds[icase],time = itn,gkey = iparam,cmap='jet',fig=fig,
                  ax=axvec[icase],title=iparam + ' at {0} km'.format(iheight),cbar=True)
           if iparam.lower()!='ne':
               ntics = sp.linspace(vbounds[icase][0],vbounds[icase][1],5)
               cbh.set_ticks(ntics)
               cbh.formatter.fmt = '%d'
               cbh.update_ticks()
           else:
               ntics = sp.linspace(vbounds[icase][0],vbounds[icase][1],5)
               cbh.set_ticks(ntics)
               cbh.formatter.fmt = '%.1e'
               cbh.update_ticks()
        outstr = insertinfo('ISR Data at $tmdy $thmsehms',posix=SRIh5.times[itn,0],posixend = SRIh5.times[itn,1])
        plt.suptitle(outstr)
        fname = 'SRIData'+fmstr.format(itn)+'.png'
        plt.tight_layout()
        plt.subplots_adjust(top=0.85)
        if not pltdir is None:
            fname=os.path.join(pltdir,fname)
        print('saving {}'.format(fname))
        plt.savefig(fname)
        plt.close(fig)
示例#5
0
    def plotsingle(self,m,ax,fig,timenum=0,icase=0,cbarax=[]):
        """ Make single plot given the desired time and number associated with
            the desired ISR param.
            Inputs
                m - The map handle that is used to plot everything.
                fig - The figure handle for the plots.
                ax - The axes handle that the map will be plotted over.
                timenum - The of GeoData objects derived from the ionofiles.
                icase - A list of list which determines which allsky times are used.
                cbarax - The list of color bar axes.
            Outputs
                allhands - The list handles of the plotted data.
                cbarax - A list of
        """


        optbnds = self.params['aslim']
        gam=self.params['asgamma']

        curwin=self.Regdict['Time'][timenum]

        allhands = [[]]

        titlelist = []
        if len(cbarax)==0:
            wid = .3/self.numGD
            cbarax=[fig.add_axes([.7+i*wid,.3,wid/2.,.4]) for i in range(self.numGD)]
            fig.tight_layout(rect=[0,.05,.7,.95])
        cbcur=0
        if not self.GDGPS is None:
            gpshands = []
            gpsbounds = self.params['gpslim']
            for igps,igpslist in zip(self.GDGPS,self.Regdict['TEC'][timenum]):
                # check if there's anything to plot
                if len(igpslist)==0:
                    continue
                (sctter,scatercb) = scatterGD(igps,'alt',1.5e5,vbounds=gpsbounds,time = igpslist,gkey = 'TEC',cmap=defmap,fig=fig, ax=ax,title='',cbar=False,err=.1,m=m)

                gpshands.append(sctter)
                """
		Plot Position of Mah8
                y = 64.971
		x = 212.567-360
		xd,yd = m(x,y)
		gpshands.append(ax.plot(xd,yd,'rx',markersize=15)[0])
		"""
                if('lol' in igps.data):
                    for i in igpslist:
                        if(igps.data['lol'][i].any()):
                            ydata = igps.dataloc[i][0]
                            xdata = igps.dataloc[i][1]
                            Xdata,Ydata = m(xdata,ydata)
                            gpshands.append(ax.plot(Xdata,Ydata,'kx',markersize=12)[0])


            # If no gps data plots dont try to plot the color bar
            if len(gpshands)>0:
                scatercb = plt.colorbar(sctter,cax=cbarax[cbcur])

                scatercb.set_label('vTEC in TECu')
            cbcur+=1
            allhands[0]=gpshands
            titlelist.append( insertinfo('GPS $tmdy $thmsehms',posix=curwin[0],posixend=curwin[1]))
            #change he z order

            allhands[0]=gpshands

        if not self.GDAS is None:

            iop = self.Regdict['AS'][timenum]
            (slice3,cbar3) = slice2DGD(self.GDAS,'alt',150,optbnds,title='',
                                time = iop,cmap='gray',gkey = 'image',fig=fig,ax=ax,cbar=False,m=m)
            slice3.set_norm(colors.PowerNorm(gamma=gam,vmin=optbnds[0],vmax=optbnds[1]))
            titlelist.append(insertinfo('All Sky $tmdy $thmsehms',posix=self.GDAS.times[iop,0],posixend=self.GDAS.times[iop,1]))
            cbaras = plt.colorbar(slice3,cax=cbarax[cbcur])
            cbcur+=1
            cbaras.set_label('All Sky Scale')
            minz=slice3.get_zorder()
            for i in reversed(allhands[0]):
                minz=sp.minimum(minz,i.get_zorder())
                i.set_zorder(i.get_zorder()+1)
            slice3.set_zorder(minz)
            allhands.append(slice3)
        if not self.GDISR is None:
            itn=self.Regdict['ISR'][timenum]
            curph=self.params['paramheight'][icase]
            vbounds = self.params['paramlim']
            iparam=curph[0]
            if iparam.lower()!='ne':
                levels = sp.logspace(sp.log10(vbounds[icase][0]),sp.log10(vbounds[icase][1]),5)
            else:
                levels = sp.linspace(vbounds[icase][0],vbounds[icase][1],5)
            (plth,cbh) =  contourGD(self.GDISR,'alt',curph[1],vbounds=vbounds[icase],time = itn,gkey = iparam,cmap='jet',fig=fig,
                  ax=ax,cbar=False,m=m,levels = levels)
            cbh = plt.colorbar(plth,cax=cbarax[cbcur])
            cbh.set_label(iparam)
            if iparam.lower()!='ne':

                fmt= '%d'


            else:

                plth.set_norm(colors.LogNorm(vmin=vbounds[icase][0],vmax=vbounds[icase][1]))
                fmt = '%.1e'
            titlelist.append( insertinfo('ISR Data at $tmdy $thmsehms',posix=self.GDISR.times[itn,0],posixend = self.GDISR.times[itn,1]))
#            minz=plth.get_zorder()
#            for i in reversed(allhands[0]):
#                minz=sp.minimum(minz,i.get_zorder)
#                i.set_zorder(i.get_zorder()+1)
#            plth.set_zorder(minz)
            cbh = plt.colorbar(plth,cax=cbarax[cbcur],format=fmt)
            cbh.set_label(iparam)
            allhands.append(plth)
        ax.set_title('\n'.join(titlelist) )
        return allhands,cbarax
示例#6
0
def plotting(risr_classred, risr_class, omti_class, reglistfinal, odir=None):

    figcount = 0
    for iomti, ilist in enumerate(reglistfinal):
        for irisr in ilist:
            omtitime = iomti
            risrtime = irisr

            try:
                mfig = mlab.figure(fgcolor=(1, 1, 1), bgcolor=(1, 1, 1))
                surflist1 = plot3Dslice(omti_class,
                                        omtislices,
                                        vbounds[0],
                                        time=omtitime,
                                        cmap='gray',
                                        gkey='optical',
                                        fig=mfig)
                arr = plot3Dslice(risr_classred,
                                  risrslices,
                                  vbounds[1],
                                  time=risrtime,
                                  cmap='jet',
                                  gkey='ne',
                                  fig=mfig,
                                  units='m^{-3}',
                                  colorbar=True,
                                  view=[50, 60],
                                  outimage=True)
                titlestr1 = '$N_e$ and OMTI at $thm'
                newtitle = insertinfo(titlestr1, '',
                                      risr_classred.times[risrtime, 0],
                                      risr_classred.times[risrtime, 1])
            except Exception as e:
                logging.error('trouble with 3D plot  {}'.format(e))

            (figmplf, [[ax1, ax2], [ax3,
                                    ax4]]) = plt.subplots(2,
                                                          2,
                                                          figsize=(16, 12),
                                                          facecolor='w')

            try:
                ax1.imshow(arr)
                ax1.set_title(newtitle)
                ax1.axis('off')
            except:
                pass

            (slice2, cbar2) = slice2DGD(risr_classred,
                                        'z',
                                        400,
                                        vbounds[1],
                                        title='$N_e$ at $thm',
                                        time=risrtime,
                                        cmap='jet',
                                        gkey='ne',
                                        fig=figmplf,
                                        ax=ax2)
            cbar2.set_label('$N_e$ in $m^{-3}$')

            (slice3, cbar3) = slice2DGD(omti_class,
                                        'z',
                                        omtislices[-1][0],
                                        vbounds[0],
                                        title='OMTI at $thm',
                                        time=omtitime,
                                        cmap='Greys',
                                        gkey='optical',
                                        fig=figmplf,
                                        ax=ax3,
                                        cbar=False)
            plt.hold(True)

            (slice4, cbar4) = contourGD(risr_classred,
                                        'z',
                                        400,
                                        vbounds[1],
                                        title='$N_e$ at $thm',
                                        time=risrtime,
                                        cmap='jet',
                                        gkey='ne',
                                        fig=figmplf,
                                        ax=ax3)
            cbar4.set_label('$N_e$ in $m^{-3}$')
            bmpos = plotbeamposGD(risr_class)

            if odir is not None:
                figname = os.path.join(odir,
                                       'figure{0:0>2}.png'.format(figcount))
                figmplf.savefig(figname, format='png', dpi=400)
                plt.close(figmplf)
                figcount = figcount + 1