def fit2geodata(inputfile):
    Ionoin = IonoContainer.readh5(inputfile)
    keep = ["Ne", "Te", "Ti"]
    GD = GeoData(readIono, [Ionoin])
    for ikey in GD.data.keys():
        if ikey not in keep:
            del GD.data[ikey]
    indir, fnameall = os.path.split(inputfile)
    fname = os.path.splitext(fnameall)[0]
    GD.write_h5(os.path.join(indir, fname + "GEOD.h5"))
    print("Saved " + os.path.join(indir, fname + ".h5"))
def plotdata(ionofile_in,ionofile_fit,madfile,time1):


    fig1,axmat =plt.subplots(2,2,facecolor='w',figsize=(10,10))
    axvec = axmat.flatten()
    paramlist = ['ne','te','ti','vo']
    paramlisti = ['Ne','Te','Ti','Vi']
    paramlistiname = ['$N_e$','$T_e$','$T_i$','$V_i$']
    paramunit = ['$m^{-3}$','$^\circ$ K','$^\circ$ K','m/s']
    boundlist = [[0.,7e11],[500.,3200.],[500.,2500.],[-500.,500.]]
    IonoF = IonoContainer.readh5(ionofile_fit)
    IonoI = IonoContainer.readh5(ionofile_in)
    gfit = GeoData(readIono,[IonoF,'spherical'])
    ginp = GeoData(readIono,[IonoI,'spherical'])
    data1 = GeoData(readMad_hdf5,[madfile,['nel','te','ti','vo','dnel','dte','dti','dvo']])
    data1.data['ne']=sp.power(10.,data1.data['nel'])
    data1.data['dne']=sp.power(10.,data1.data['dnel'])
    
    t1,t2 = data1.timelisting()[340]
    handlist = []
    for inum,iax in enumerate(axvec):
        ploth = rangevsparam(data1,data1.dataloc[0,1:],time1,gkey=paramlist[inum],fig=fig1,ax=iax,it=False)
        handlist.append(ploth[0])
        ploth = rangevsparam(ginp,ginp.dataloc[0,1:],0,gkey=paramlisti[inum],fig=fig1,ax=iax,it=False)
        handlist.append(ploth[0])
        ploth = rangevsparam(gfit,gfit.dataloc[0,1:],0,gkey=paramlisti[inum],fig=fig1,ax=iax,it=False)
        handlist.append(ploth[0])
        iax.set_xlim(boundlist[inum])
        iax.set_ylabel('Altitude in km')
        iax.set_xlabel(paramlistiname[inum]+' in '+paramunit[inum])
    # with error bars
    plt.tight_layout()
    fig1.suptitle('Comparison Without Error Bars\nPFISR Data Times: {0} to {1}'.format(t1,t2))
    plt.subplots_adjust(top=0.9)
    plt.figlegend( handlist[:3], ['PFISR', 'SimISR Input','SimISR Fit'], loc = 'lower center', ncol=5, labelspacing=0. )
    fig2,axmat2 =plt.subplots(2,2,facecolor='w',figsize=(10,10))
    axvec2 = axmat2.flatten()
    handlist2 = []
    for inum,iax in enumerate(axvec2):
        ploth = rangevsparam(data1,data1.dataloc[0,1:],time1,gkey=paramlist[inum],gkeyerr='d'+paramlist[inum],fig=fig2,ax=iax,it=False)
        handlist2.append(ploth[0])
        ploth = rangevsparam(ginp,ginp.dataloc[0,1:],0,gkey=paramlisti[inum],fig=fig2,ax=iax,it=False)
        handlist2.append(ploth[0])
        ploth = rangevsparam(gfit,gfit.dataloc[0,1:],0,gkey=paramlisti[inum],gkeyerr='n'+paramlisti[inum],fig=fig2,ax=iax,it=False)
        handlist2.append(ploth[0])
        iax.set_xlim(boundlist[inum])
        iax.set_ylabel('Altitude in km')
        iax.set_xlabel(paramlistiname[inum]+' in '+paramunit[inum])
    plt.tight_layout()
    fig2.suptitle('Comparison With Error Bars\nPFISR Data Times: {0} to {1}'.format(t1,t2))
    plt.subplots_adjust(top=0.9)
    plt.figlegend( handlist2[:3], ['PFISR', 'SimISR Input','SimISR Fit'], loc = 'lower center', ncol=5, labelspacing=0. )
    return (fig1,axvec,handlist,fig2,axvec2,handlist2)
예제 #3
0
    def GPSRead(self,GPSloc):
        """ This function will read in the GPS data from ionofiles. It will assign
            the class variable GDGPS to the resultant GeoData object.
            Input
                GPSloc - The directory that holds all of the iono/h5 GeoData files.
                    Can also be the filename of a mahali gps file
        """
        self.numGD+=1
        if GPSloc is None:
            return

        GPSloc = Path(GPSloc).expanduser()

        timelim=self.params['timebounds']
        TEClist = []
        ish5file = GPSloc.is_file() and GPSloc.suffix=='.h5'
        if ish5file:
            print('Reading in GPS Data')
            f = h5py.File(GPSloc, "r", libver='latest')
            siteinfo = f['sites'].value
            GPSNames = [i[0] for i in siteinfo]
            for isite in GPSNames:
                try:
                    TECGD = GeoData(readMahalih5,(GPSloc,isite))
                except Exception:
                    TECGD =  read_h5(os.path.join(GPSloc,isite))
                if timelim is not None:
                    TECGD.timereduce(timelim)

                if len(TECGD.times)==0:
                    continue
                TEClist.append(TECGD)
            self.GPSNames = GPSNames
            self.GDGPS = TEClist
            print('Finished Reading in GPS Data')
        elif GPSloc.is_dir():
            print('Reading in GPS Data')
            # Read in either iono files or h5 files
            TECfiles = GPSloc.glob('*.iono')
            funcname = readIonofiles
            if len(TECfiles) == 0:
                TECfiles = GPSloc.glob('*.h5')
                funcname = read_h5_main
            for ifile in TECfiles:
                TECGD = GeoData(funcname, str(ifile))
                if timelim is not None:
                    TECGD.timereduce(timelim)

                if len(TECGD.times)==0:
                    continue
                TEClist.append(TECGD)

            # Determine the receiver names
            self.GPSNames = [os.path.splitext(os.path.split(i)[-1])[0].split('-')[0] for i in TECfiles]
            self.GDGPS = TEClist
            print('Finished Reading in GPS Data')
        else:
            print('GPS path is not a directory')
            return
예제 #4
0
def plotparams(datapath,indch):
    # read in the files
    geofile = os.path.join(datapath,'Fitted','fitteddataGEOD.h5')
    acffile = os.path.join(datapath,'ACF','00lags.h5')
    geod = GeoData.read_h5(geofile)
    acfIono = IonoContainer.readh5(acffile)
    picklefile = os.path.join(datapath,'config.ini')
    (sensdict,simparams) = readconfigfile(picklefile)
    #determine the ind
    dataloc = geod.dataloc
    rngloc = 210
    ind = sp.argmin(sp.absolute(dataloc[:,0]-rngloc))
    #
    Ne = geod.data['Ne'][ind]
    Ti = geod.data['Ti'][ind]
    Te = geod.data['Te'][ind]


    #make a spectrum
    npts = 128
    datablock = sp.array([[Ne[indch],Ti[indch]],[Ne[indch],Te[indch]]])
    specobj = ISRSpectrum(centerFrequency =sensdict['fc'],nspec = npts,sampfreq=sensdict['fs'])
    (omeg,specexample,rcs) = specobj.getspecsep(datablock,simparams['species'],rcsflag=True)
    specexample = rcs*npts*specexample/sp.absolute(specexample).sum()
    acf = acfIono.Param_List[ind,indch]
    origspec = scfft.fftshift(scfft.fft(acf,n=npts)).real
    (figmplf, [[ax1,ax2],[ax3,ax4]]) = plt.subplots(2, 2,figsize=(16, 12), facecolor='w')


    ax1.plot(sp.arange(len(Ne)),Ne)
    ax1.set_title('$N_e$')
    ax2.plot(sp.arange(len(Ti)),Ti)
    ax2.set_title('$T_i$')
    ax3.plot(sp.arange(len(Te)),Te)
    ax3.set_title('$T_e$');
    spec1 = ax4.plot(omeg*1e-3,origspec,label='Measured')
    spec2 = ax4.plot(omeg*1e-3,specexample,label='Fitted')
    ax4.set_title('Measured and Fitted Spectrums')
    ax4.set_xlabel('Frequency KHz')
    ax4.legend(loc = 1)

#    Nevals = sp.linspace(5e10,5e11,10)
#    Tivals = sp.linspace(1e3,2e5,10)
#    Tevals = sp.linspace(1e3,2e5,10)
#    xlist = [[1],Tivals,Nevals,Tevals,[0]]
#    outsurf = makefitsurf(xlist,acf,sensdict,simparams)
    return(figmplf)
예제 #5
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)
예제 #6
0
def main(allskydir,ionofdir,plotdir,latlim2,lonlim2,wl,tint,reinterp=False,timelim=[-sp.infty,sp.infty]):
    """ This is the main function for plot data. This function will determine what is to be plotted
    and call all of the spatial and time regestration programs from GeoData.
    Inputs
        allskydir - The directory that holds the FITS files for the allsky data.
            If a None is passed then a the allsky is not plotted.
        ionofdir - The directory that holds all of the ionofiles. If a None is
            passed then a the allsky is not plotted.
        plotdir - The directory where the plots are stored.
        wl - The wavelength of the allsky light
        tint - The number of minutes the GPS data is plotted over. Default is 5.
        reinterp - A bool that determines if the GeoData files for the optical data
            should be remade.
        timelim - A list that shows the time boundaries in posix."""

    wl = str(int(wl))
#%% Make map
    fig,ax,m=setupmap(latlim2,lonlim2)

    isallsky=False
    isgps = False
    TECtime = None

    if ionofdir is not None:
        isgps=True
        TEClist = []
        TECfiles = glob.glob(os.path.join(ionofdir,'*.iono'))
        if not TECfiles:
            raise IOError('found no TEC files in {}'.format(ionofdir))
        print('found {} .iono files in {}'.format(len(TECfiles),ionofdir))

        for i,ifile in enumerate(TECfiles):
            print('processing {}/{} {}  '.format(i+1,len(TECfiles),ifile))
            TECGD = GeoData(readIonofiles,(ifile,))
            if timelim is not None:
                TECGD.timereduce(timelim)

            if len(TECGD.times)==0:
                continue
            TEClist.append(TECGD)

            if TECtime is not None:
                TECtime[0] = min(TECGD.times[:,0].min(), TECtime[0])
                TECtime[1] = max(TECGD.times[:,0].max(), TECtime[1])
            else:
                TECtime = [TECGD.times[:,0].min(), TECGD.times[:,0].max()]
    if allskydir is not None:
        isallsky=True

        wlstr ='*_0'+wl+'_*.FITS'
        interpsavedfile = os.path.join(allskydir,'interp'+wl+'.h5')
        if reinterp or (not os.path.isfile(interpsavedfile)):
            flist558 = glob.glob(os.path.join(allskydir,wlstr))
            if not flist558:
                raise IOError('no allsky files found in {}'.format(allskydir))
            print(('{} allsky files found in {}'.format(len(flist558),allskydir)))

            allsky_data = GeoData(readAllskyFITS,
                                  (flist558,
                                   ('PKR_20111006_AZ_10deg.FITS','PKR_20111006_EL_10deg.FITS'),
                                   150.))
            if timelim is not None:
                allsky_data.timereduce(timelim)
                # reduce the size of the allskydata
            allskytime = allsky_data.times[:,0]
            allsky_data=allsky_data.timeslice(sp.where((allskytime>=TECtime[0]) & (allskytime<TECtime[1]))[0])
            allskytime=allsky_data.times[:,0]

            xcoords = allsky_data.__changecoords__('WGS84')
            latlim=[xcoords[:,0].min(),xcoords[:,0].max()]
            lonlim=[xcoords[:,1].min(),xcoords[:,1].max()]
            nlat = 256
            nlon = 256

            latvec = sp.linspace(latlim[0],latlim[1],nlat)
            lonvec = sp.linspace(lonlim[0],lonlim[1],nlon)
            [LATM,LONM] = sp.meshgrid(latvec,lonvec)

            newcoords = sp.column_stack((LATM.ravel(),LONM.ravel(),150.*sp.ones(LONM.size)))
            allsky_data.interpolate(newcoords,'WGS84',method='linear',twodinterp=True)
            print('writing {}'.format(interpsavedfile))
            allsky_data.write_h5(interpsavedfile)
        else:
            allsky_data = GeoData.read_h5(interpsavedfile)
            if timelim is not None:
                allsky_data.timereduce(timelim)
            allskytime=allsky_data.times[:,0]


    #%% make lists for plotting
    tectime = sp.arange(TECtime[0],TECtime[1],60.*tint)
    nptimes= tectime.size

    if isallsky and isgps:
        allskylist = []
        gpslist = []
        tlistkeep = sp.zeros(nptimes-1,dtype=bool)
        for itasn in range(nptimes-1):
            techlist = []
            tlistemp=True
            itback=tectime[itasn]
            itfor = tectime[itasn+1]
            itas = sp.where((allskytime>=itback) &  (allskytime<itfor))[0]
            if len(itas)==0:
                itas = sp.where(allskytime<=itback)[0]
                if len(itas)==0:
                    continue
                itas = [itas[-1]]

            for k in range(len(TEClist)):
                Geoone=TEClist[k];
                timevec = Geoone.times[:,0];

                itgps = sp.where((timevec>=itback) & (timevec<itfor))[0]
                if len(itgps)>0:
                    tlistemp=False
                techlist.append(itgps)
            if tlistemp:
                continue
            allskylist.append(itas)
            gpslist.append(techlist)
            tlistkeep[itasn]=True

        plotgpswoptics(allsky_data,TEClist,allskylist,gpslist,plotdir,m,ax,fig,latlim2,lonlim2)
    elif isgps:
        gpslist = []
        tlistkeep = sp.zeros(nptimes-1,dtype=bool)
        for itasn in range(nptimes-1):
            techlist = []
            tlistemp=True
            itback=tectime[itasn]
            itfor = tectime[itasn+1]

            for k in range(len(TEClist)):
                Geoone=TEClist[k];
                timevec = Geoone.times[:,0];

                itgps = sp.where((timevec>=itback)& (timevec<itfor))[0]
                if len(itgps)>0:
                    tlistemp=False
                techlist.append(itgps)
            if tlistemp:
                continue
            gpslist.append(techlist)
            tlistkeep[itasn]=True
        plotgpsonly(TEClist,gpslist,plotdir,m,ax,fig,latlim2,lonlim2)
    elif isallsky:
        plotopticsonly(allsky_data,plotdir,m,ax,fig,latlim2,lonlim2)

    plt.close(fig)
@author: John Swoboda
"""
import os, glob
from SimISR.IonoContainer import IonoContainer
from GeoData.GeoData import GeoData
from GeoData.utilityfuncs import readIono

if __name__ == "__main__":
    inputdir = "/Users/Bodangles/Documents/Python/PhantomProc/Origparams"
    outdir = "/Users/Bodangles/Documents/MATLAB/phantoms/Origparams"
    dirlist = glob.glob(os.path.join(inputdir, "*.mat"))
    keep = ["Ne", "Te", "Ti"]
    for ifile in dirlist:
        Ionoin = IonoContainer.readmat(ifile)
        GD = GeoData(readIono, [Ionoin])
        for ikey in GD.data.keys():
            if ikey not in keep:
                del GD.data[ikey]
        fname = os.path.splitext(os.path.split(ifile)[1])[0]
        GD.write_h5(os.path.join(outdir, fname + ".h5"))
        print("Saved " + os.path.join(outdir, fname + ".h5"))


def fit2geodata(inputfile):
    Ionoin = IonoContainer.readh5(inputfile)
    keep = ["Ne", "Te", "Ti"]
    GD = GeoData(readIono, [Ionoin])
    for ikey in GD.data.keys():
        if ikey not in keep:
            del GD.data[ikey]
예제 #8
0
def plotgradlines(inputlist,fitiono,alt,times,paramlist=['Ne','Te','Ti']):
    """
    Plots the values along a specific alittude. 
    """
    inputiono = makeionocombined(inputlist)
    Iono1 = GeoData(readIono,[inputiono])
    fitiono = IonoContainer.readh5(fitiono)
    fitGeo = GeoData(readIono,[fitiono])
    
    paramlist = ['Ne','Te','Ti']
    (x,y,z) = inputiono.Cart_Coords.transpose()
    r = sp.sqrt(x**2+y**2)*sp.sign(y)
    incoords = sp.column_stack((r,z,sp.ones_like(z)))
    ru,zu =[ sp.unique(r),sp.unique(z)]
    Rmat,Zmat = sp.meshgrid(ru,zu)
    zinput = sp.argmin(sp.absolute(zu-alt))
    
    (xf,yf,zf) = fitiono.Cart_Coords.transpose()
    rf = sp.sqrt(xf**2+yf**2)*sp.sign(yf)
    outcoords = sp.column_stack((rf,zf,sp.ones_like(zf)))
    rfu,zfu =[ sp.unique(rf),sp.unique(zf)]
    Rfmat,Zfmat = sp.meshgrid(rfu,zfu)
    zoutput = sp.argmin(sp.absolute(zfu-alt))
    
    fitGeo.interpolate(incoords,Iono1.coordnames,method='linear',fill_value=sp.nan,twodinterp = True,oldcoords=outcoords)

    uz = sp.unique(z)
    ur = sp.unique(r)
    (rmat,zmat) = sp.meshgrid(ur,uz)
    
    inputdata = {}
    for iparm in paramlist:
        if iparm =='Nepow':
            iparm='Ne'
        curdata = Iono1.data[iparm][:,times[0]]
        
        inputdata[iparm] = sp.reshape(curdata,Rmat.shape)[zinput]

    outputdata = {}
    for iparm in paramlist:
        curdata = fitGeo.data[iparm][:, times[1]]
        outputdata[iparm] = sp.reshape(curdata,Rmat.shape)[zinput]
    
    fig, axvec = plt.subplots(len(paramlist),1,sharey=False,figsize=(12,5*len(paramlist)))
    
    for ipn,iparam in enumerate(paramlist):
        ax = axvec[ipn]
        ax2 = ax.twinx()
        p1, = ax.plot(ru,inputdata[iparam],'b-',label='In',linewidth=3)
        p2, = ax.plot(ru,outputdata[iparam],'b--',label='Out',linewidth=3)
        ax.set_title(iparam)
        ax.set_xlabel('X Plane in km')
        gi = sp.gradient(inputdata[iparam])/sp.gradient(ru)
        go = sp.gradient(outputdata[iparam])/sp.gradient(ru)
        p3, = ax2.plot(ru,gi,'g-',label='Grad In',linewidth=3)
        p4, = ax2.plot(ru,go,'g--',label='Grad Out',linewidth=3)
        ax.yaxis.label.set_color(p1.get_color())
        ax2.yaxis.label.set_color(p3.get_color())
        lines = [p1,p2,p3,p4]
        ax.legend(lines,[l.get_label() for l in lines])
    
    plt.tight_layout()    
    return(fig)
예제 #9
0
class PlotClass(object):
    """ This class will handle all of the reading , registration and plotting of data
    related to the mahali project. This is ment to be both the back end to a gui and
    the basic code used to run a whole set of data. The class will be given an
    ini file and location of data sets. The ini file will hold information regaurding
    the plotting and data registration.
    Variables:
        inifile - The name of the ini file used for the the parameters.
        params - A dixtionary that holds all of the parameters. The list INIOPTIONS
            holds all of the keys for this dicitonary.
        GDISR - A GeodData object for the ISR data. The default value is None.
        GDGPS - A GeodData object for the GPS data. The default value is None.
        GDAS - A GeodData object for the AllSky data. The default value is None.
        numGD - The number of Sensor classes avalible.
        GPSNames - The names of the GPS receivers.
        Regdict - A dictionary used to order all of the data. The keys are
            TEC, AS, Time ISR. """
    def __init__(self,inifile,GPSloc=None,ASloc=None,ISRloc=None,nointerp=False):
        """ This will create an instance of a PlotClass object.
            Inputs
            inifile - The name of the ini file used for the the parameters.
            GPSloc - The directory that holds all of the iono files.
            ASloc - This can be either a directory holding the FITS files or a
                h5 file thats been pre interpolated.
            ISRloc - This can be either a file from SRI or an h5 file
                thats been pre interpolated."""
        self.nointerp = nointerp
        self.inifile = inifile
        self.params = readini(inifile)
        # GeoData objects
        self.GDISR = None
        self.GDGPS = None
        self.GPSNames = None
        self.GDAS = None
        self.numGD = 0
        # Read in GeoData objects
        self.GPSRead(GPSloc)
        self.ASRead(ASloc)
        self.ISRRead(ISRloc)
        # Time Register everyting
        self.RegisterData()


  #%% Read in data
    def GPSRead(self,GPSloc):
        """ This function will read in the GPS data from ionofiles. It will assign
            the class variable GDGPS to the resultant GeoData object.
            Input
                GPSloc - The directory that holds all of the iono/h5 GeoData files.
                    Can also be the filename of a mahali gps file
        """
        self.numGD+=1
        if GPSloc is None:
            return

        GPSloc = Path(GPSloc).expanduser()

        timelim=self.params['timebounds']
        TEClist = []
        ish5file = GPSloc.is_file() and GPSloc.suffix=='.h5'
        if ish5file:
            print('Reading in GPS Data')
            f = h5py.File(GPSloc, "r", libver='latest')
            siteinfo = f['sites'].value
            GPSNames = [i[0] for i in siteinfo]
            for isite in GPSNames:
                try:
                    TECGD = GeoData(readMahalih5,(GPSloc,isite))
                except Exception:
                    TECGD =  read_h5(os.path.join(GPSloc,isite))
                if timelim is not None:
                    TECGD.timereduce(timelim)

                if len(TECGD.times)==0:
                    continue
                TEClist.append(TECGD)
            self.GPSNames = GPSNames
            self.GDGPS = TEClist
            print('Finished Reading in GPS Data')
        elif GPSloc.is_dir():
            print('Reading in GPS Data')
            # Read in either iono files or h5 files
            TECfiles = GPSloc.glob('*.iono')
            funcname = readIonofiles
            if len(TECfiles) == 0:
                TECfiles = GPSloc.glob('*.h5')
                funcname = read_h5_main
            for ifile in TECfiles:
                TECGD = GeoData(funcname, str(ifile))
                if timelim is not None:
                    TECGD.timereduce(timelim)

                if len(TECGD.times)==0:
                    continue
                TEClist.append(TECGD)

            # Determine the receiver names
            self.GPSNames = [os.path.splitext(os.path.split(i)[-1])[0].split('-')[0] for i in TECfiles]
            self.GDGPS = TEClist
            print('Finished Reading in GPS Data')
        else:
            print('GPS path is not a directory')
            return


    def ASRead(self,ASloc):
        """ This function will read in the All sky data from FITS files or structured
            h5 files for GeoData.
            Input
                ASloc - This can be either a directory holding the FITS files or a
                h5 file thats been pre interpolated. It will assign the class variable GDAS to the
            resultant GeoData object."""

        if ASloc is None:
            return

        ASloc = Path(ASloc).expanduser()

        if not ASloc.is_dir() and not ASloc.is_file():
            print('All Sky Data cannot be read')
            return

        self.numGD+=1
        print('Reading in All sky data')
        wl = str(int(self.params['wl']))
        wlstr ='*_0'+wl+'_*.FITS'
        interpsavedfile = ASloc/('interp'+wl+'.h5')
        reinterp=self.params['reinterp']
        timelim=self.params['timebounds']

        if self.nointerp:
            flist558 = sorted(ASloc.glob(wlstr))
            self.GDAS =  GeoData(readAllskyFITS,(flist558,
                                                 ('PKR_DASC_20110112_AZ_10deg.FITS',
                                                  'PKR_DASC_20110112_EL_10deg.FITS'),
                                                 150.,timelim))
            return

        if reinterp or not ASloc.is_file():
           # pfalla = sp.array([65.136667,-147.447222,689.])

            flist558 = sorted(ASloc.glob(wlstr))
            if not flist558:
                return

            allsky_data = GeoData(readAllskyFITS,(flist558,('PKR_DASC_20110112_AZ_10deg.FITS','PKR_DASC_20110112_EL_10deg.FITS'),150.,timelim))
            if timelim is not None:
                allsky_data.timereduce(timelim)


            xcoords = allsky_data.__changecoords__('WGS84')
            latlim=[xcoords[:,0].min(),xcoords[:,0].max()]
            lonlim=[xcoords[:,1].min(),xcoords[:,1].max()]
            nlat = 256
            nlon = 256

            latvec = sp.linspace(latlim[0],latlim[1],nlat)
            lonvec = sp.linspace(lonlim[0],lonlim[1],nlon)
            [LATM,LONM] = sp.meshgrid(latvec,lonvec)

            newcoords = sp.column_stack((LATM.flatten(),LONM.flatten(),150.*sp.ones(LONM.size)))
            allsky_data.interpolate(newcoords,'WGS84',method='linear',twodinterp=True)
            allsky_data.write_h5(interpsavedfile)
        else:
            allsky_data = GeoData.read_h5(ASloc)
            if timelim is not None:
                allsky_data.timereduce(timelim)

        self.GDAS = allsky_data
        print('Finished Reading in Allsky Data')
    def ISRRead(self,ISRloc):
        """ This function will read in the ISR data from SRI files or structured
            h5 files for GeoData. It will assign the class variable GDISR to the
            resultant GeoData object.
            Input
                ISRloc - This can be either a file from SRI or an h5 file
                thats been pre interpolated. """
        if ISRloc is None:
            return

        ISRloc = Path(ISRloc).expanduser()

        if not ISRloc.is_file():
            print('ISR Data is not a file')
            return
        self.numGD+=1
        print('Reading in ISR Data')
        pnheights= self.params['paramheight']

        paramstr = list(set([i[0] for i in pnheights]))
        try:
            SRIh5 = GeoData(readSRI_h5,(ISRloc,paramstr))
        except Exception:
            try:
                SRIh5 = GeoData.read_h5(ISRloc)
            except Exception:
                return
        dt1ts,dt2ts = self.params['timebounds']

        timelist = sp.where((SRIh5.times[:,1]>=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)
        uh=uh*1e3
        newcoordname = 'WGS84'

        if not (SRIh5.coordnames.lower() == newcoordname.lower()):
            changed_coords = SRIh5.__changecoords__(newcoordname)
            latmin,latmax = [changed_coords[:,0].min(),changed_coords[:,0].max()]
            lonmin,lonmax = [changed_coords[:,1].min(),changed_coords[:,1].max()]
            latvec = sp.linspace(latmin,latmax,self.params['ISRLatnum'])
            lonvec = sp.linspace(lonmin,lonmax,self.params['ISRLonnum'])

            LON,LAT = sp.meshgrid(lonvec,latvec)
            xycoords = sp.column_stack([LAT.flatten(),LON.flatten()])
                # 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,newcoordname,method='linear')
        self.GDISR = SRIh5
        print('Finished Reading in ISR Data')
        #%% Registration
    def RegisterData(self):
        """ This function will register data and return a dictionary that will be used
            keep track of the time associations between all of the different data sets.
            """
        tbounds = self.params['timebounds']
        tint=self.params['timewin']
        # make lists for plotting
        tectime = sp.arange(tbounds[0],tbounds[1],60.*tint)

        nptimes= len(tectime)
        timelists = [[tectime[i],tectime[i+1]] for i in range(nptimes-1)]
        # teclist is a Ntime length list
        teclist = [[]]*(nptimes-1)
        regdict = {'TEC':teclist,'AS':[None]*(nptimes-1),'ISR':[None]*(nptimes-1),'Time':timelists}

        if not self.GDGPS is None:
           for itasn in range(len(tectime)-1):
                itback=tectime[itasn]
                itfor = tectime[itasn+1 ]
                templist = [[]]*len(self.GDGPS)
                for k in range(len(self.GDGPS)):
                    Geoone=self.GDGPS[k]
                    timevec = Geoone.times[:,0]

                    templist[k] = sp.where(sp.logical_and(timevec>=itback, timevec<itfor))[0]
                teclist[itasn]  =templist

        if (not self.GDAS is None):
            GPS2AS=[sp.array([])]*(nptimes-1)
            GPS2ASlen = [0]*(nptimes-1)
            allskytime=self.GDAS.times[:,0]


            for itasn in range(len(tectime)-1):
                itback=tectime[itasn]
                itfor = tectime[itasn+1]
                itas = sp.where(sp.logical_and(allskytime>=itback, allskytime<itfor))[0]
                if len(itas)==0:
                    itas = sp.where(allskytime<=itback)[0]
                    if len(itas)==0:
                        continue
                    itas = sp.array([itas[-1]])
                GPS2AS[itasn] = itas
                GPS2ASlen[itasn]=len(itas)

            GPS2ASsingle = []
            teclist2 =[]
            timelist2 = []
            #repeat for all sky values
            for i1,ilen in enumerate(GPS2ASlen):
                GPS2ASsingle=GPS2ASsingle+GPS2AS[i1].tolist()
                teclist2 =teclist2+[ teclist[i1]]*ilen
                timelist2 =timelist2+[ timelists[i1]]*ilen
            regdict['TEC']=teclist2
            regdict['AS']=GPS2ASsingle
            regdict['Time']=timelist2
            regdict['ISR'] = [None]*len(GPS2ASsingle)
            if (not self.GDISR is None):
                self.GDAS=self.GDAS.timeslice(sp.unique(GPS2ASsingle))
                as2radar =self.GDAS.timeregister(self.GDISR)

                teclist3=[]
                timelist3=[]
                GPS2ASsingle2=[]
                AS2ISRsingle=[]
                for j1,jasval in enumerate(as2radar):
                    jlen=len(jasval)
                    AS2ISRsingle =AS2ISRsingle +jasval.tolist()
                    teclist3=teclist3+[teclist2[j1]]*jlen
                    timelist3=timelist3+[timelist2[j1]]*jlen
                    GPS2ASsingle2 = GPS2ASsingle2+[GPS2ASsingle[j1]]*jlen

                regdict['TEC']=teclist3
                regdict['AS']=GPS2ASsingle2
                regdict['Time']=timelist3
                regdict['ISR'] = AS2ISRsingle

        elif (not self.GDISR is None):
            GPS2ISR=[sp.array([])]*(nptimes-1)
            GPS2ISRlen = [0]*(nptimes-1)
            isrtime=self.GDISR.times


            for itasn in range(len(tectime)-1):
                itback=tectime[itasn]
                itfor = tectime[itasn+1]
                #need to fix this
                itas = sp.where(sp.logical_and(isrtime[:,1]>=itback, isrtime[:,0]<itfor))[0]
                if len(itas)==0:
                    itas = sp.where(isrtime<=itback)[0]
                    if len(itas)==0:
                        continue
                    itas = sp.array([itas[-1]])
                GPS2ISR[itasn] = itas
                GPS2ISRlen[itasn]=len(itas)

            GPS2ISRsingle = []
            teclist2 =[]
            timelist2 = []

            #repeat for all sky values
            for i1,ilen in enumerate(GPS2ISRlen):
                GPS2ISRsingle=GPS2ASsingle+GPS2ISR[i1].tolist()
                teclist2 =teclist2+[ teclist[i1]]*ilen
                timelist2 =timelist2+[ timelists[i1]]*ilen
            regdict['TEC']=teclist2
            regdict['ISR']=GPS2ISRsingle
            regdict['Time']=timelist2
            regdict['AS']=[None]*len(timelist2)

        self.Regdict=regdict
#%% Plotting
    def plotCircleData(self,plotdir,ax,fig):
        plotdir = Path(plotdir).expanduser()

        timelist = self.Regdict['Time']
        Nt = len(timelist)
        strlen = int(sp.ceil(sp.log10(Nt))+1)
        fmstr = '{0:0>'+str(strlen)+'}_'
        plotnum=0
        cbarax = []
        for itime in range(Nt):
            #plot the data
            hands,cbarax = self.plotCircle(ax,fig,itime,cbarax)

            ofn= plotdir /(fmstr.format(plotnum)+'ASwGPS.png')
            print('Ploting {} of {}  {}'.format(plotnum,Nt-1,ofn))

            plt.savefig(str(ofn))
            plotnum+=1
            for ihand in hands:
                if hasattr(ihand, "__len__"):
                    for ihand2 in ihand:
                        ihand2.remove()
                elif hasattr(ihand,'collections'):
                    for ihand2 in ihand.collections:
                        ihand2.remove()
                else:
                    ihand.remove()
        # write out ini file to record plot parameters
        ininame = Path(self.inifile).name
        writeini(self.params,plotdir/ininame)

    def plotCircle(self,ax,fig,timenum,cbarax): #CONSIDER DONIG THIS WITH POLAR PLOT/INTERPOLATION

        allhands=[[]]
        curwin=self.Regdict['Time'][timenum]
        optbnds = self.params['aslim']
        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

        #Plot AllSky Image
        if not self.GDAS is None:
            iop = self.Regdict['AS'][timenum]
            [r,az,el] = self.GDAS.dataloc.T
            az = az%360
            rel = 90-el
            x = rel*np.sin(az*np.pi/180)
            y = -rel*np.cos(az*np.pi/180)
            grid_x, grid_y = np.mgrid[-80:80:400j, -80:80:400j]
            asimg = griddata(np.array([x,y]).T,
                             self.GDAS.data['image'].T[iop],
                             (grid_x,grid_y),
                             method='linear')

            slice3 = ax.pcolormesh(grid_x,grid_y,asimg,cmap='summer',
                                   vmin=optbnds[0],vmax=optbnds[1],
                                   figure=fig)

            ax.axis([-85,85,-85,85])
            ax.axis('off')

            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')

            allhands.append(slice3)

        #Draw Polar Lines On Top
       # lines = []
        ang = np.arange(0,180,.5)/np.pi
        for i in np.arange(80,0,-20):
            r = (y[np.logical_and(abs(x)<.5,abs(el-i)<.5)][0])
            allhands.append(ax.plot(r*np.cos(ang),r*np.sin(ang),'k-',lw=.5,alpha=.5))
            allhands.append(ax.text(0,abs(r)-3,str(i),alpha=.5))

        angles = np.arange(0,180,30)
        textangles = {iang:(str(np.mod(270+iang,360)),str(np.mod(90+iang,360))) for iang in angles}
        maxy = np.max(y)
        for iang in angles:
            iangr = iang*np.pi/180
            xs = np.array([maxy*np.cos(iangr+np.pi),-maxy*np.cos(iangr+np.pi)])
            ys = np.array([maxy*np.sin(iangr+np.pi),-maxy*np.sin(iangr+np.pi)])
            allhands.append(ax.plot(xs,ys,'k-',alpha=.5,lw=.5))
            allhands.append(ax.text(1.05*xs[0]-2,1.05*ys[0]-2,textangles[iang][0],alpha=.5))
            allhands.append(ax.text(1.05*xs[1]-2,1.05*ys[1]-2,textangles[iang][1],alpha=.5))


        #Plot GPS Scatter
        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
                az = igps.data['az2sat'] % 360
                rel = 90-igps.data['el2sat']
                x = rel*np.sin(az*np.pi/180)
                y = -rel*np.cos(az*np.pi/180)
                sctter = ax.scatter(x[igpslist],y[igpslist],
                                    c=igps.data['TEC'][igpslist],
                                    cmap=defmap,vmin=gpsbounds[0],
                                    vmax=gpsbounds[1],figure=fig)
                satnames=[]
                for i in igpslist:
                    if igps.data['satnum'][i] in satnames: continue
                    allhands.append(ax.text(x[i]+1,y[i]+1,str(int(igps.data['satnum'][i]))))
                gpshands.append(sctter)

                if('lol' in igps.data):
                    for i in igpslist:
                        if(igps.data['lol'][i].any()):
                            Xdata = x[i]
                            Ydata = y[i]
                            gpshands.append(ax.plot(Xdata,Ydata,'kx',markersize=12)[0])

            if len(gpshands)>0:
                scatercb = plt.colorbar(sctter,cax=cbarax[cbcur])

                scatercb.set_label('TEC in TECu')
            cbcur+=1
            allhands[0]=gpshands

            titlelist.append( insertinfo('GPS $tmdy $thmsehms',posix=curwin[0],posixend=curwin[1]))


        ax.set_title('\n'.join(titlelist) )
        return allhands,cbarax


    def plotmap(self,fig,ax):
        """ This function will plot the map of Alaska. The data will be plotted
            over it and will use the basemap class to position everything.
            Input
                fig - The figure handle for the plots.
                ax - The axes handle that the map will be plotted over.
            Output
                m - This is the handle for the basemap object.
        """
        latlim2 = self.params['latbounds']
        lonlim2 = self.params['lonbounds']
        m = Basemap(projection='merc',lon_0=sp.mean(lonlim2),lat_0=sp.mean(latlim2),\
        lat_ts=sp.mean(latlim2),llcrnrlat=latlim2[0],urcrnrlat=latlim2[1],\
        llcrnrlon=lonlim2[0],urcrnrlon=lonlim2[1],\
        rsphere=6371200.,resolution='i',ax=ax)
        # draw coastlines, state and country boundaries, edge of map.
        #m.drawcoastlines()
    #    m.drawstates()
    #    m.drawcountries()
        m.readshapefile('st99_d00','states',drawbounds=True)

        merstep = sp.round_((lonlim2[1]-lonlim2[0])/5.)
        parstep = sp.round_((latlim2[1]-latlim2[0])/5.)
        meridians=sp.arange(lonlim2[0],lonlim2[1],merstep)
        parallels = sp.arange(latlim2[0],latlim2[1],parstep)
        m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
        m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
        plt.hold(True)
        return m

    def plotalldata(self,plotdir,m,ax,fig):
        """ This method will plot all of the images from the time period specified.
            The png files will be numbered and have the ISR parameter name in
            the title. The user can easily manipulate the files using comand line.
            Inputs
                plotdir - This is the directory that all of the plots will be saved
                    in.
                m - The map object that will be used to orient the data.
                fig - The figure handle for the plots.
                ax - The axes handle that the map will be plotted over.
        """
        plotdir = Path(plotdir).expanduser()
        timelist = self.Regdict['Time']
        Nt = len(timelist)
        strlen = int(sp.ceil(sp.log10(Nt))+1)
        fmstr = '{0:0>'+str(strlen)+'}_'
        plotnum=0
        cbarax = []
        if self.params['paramheight'] is None or self.GDISR is None:
            Ncase = 1
            paramstrs = ['']
        else:
            Ncase = len(self.params['paramheight'])
            paramstrs = [i[0]+str(int(i[1])) for i in self.params['paramheight']]
        Nplot = Ncase*Nt
        for itime in range(Nt):
            for icase in range(Ncase):
                hands,cbarax = self.plotsingle(m,ax,fig,itime,icase,cbarax)

                ofn = plotdir / (fmstr.format(plotnum)+paramstrs[icase]+'ASwGPS.png')
                print('Plotting {} of {} {}'.format(plotnum,Nplot,ofn))
                plt.savefig(str(ofn))

                if itime in self.params['TextList']:
                    hands = self.plotgpsnames(m,ax,fig,hands,timenum=itime)
                    plt.savefig( str(plotdir / ('wloctext' + fmstr.format(plotnum)+paramstrs[icase]+'ASwGPS.png')))

                for ihand in hands:
                    if hasattr(ihand, "__len__"):
                        for ihand2 in ihand:
                            ihand2.remove()
                    elif hasattr(ihand,'collections'):
                        for ihand2 in ihand.collections:
                            ihand2.remove()
                    else:
                        ihand.remove()
                plotnum+=1
        # write out ini file to record plot parameters
        ininame = Path(self.inifile).name
        writeini(self.params,plotdir/ininame)

    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


    def plotgpsnames(self,m,ax,fig,allhands,timenum=0):
        """ This will plot the names of the GPS recievers next to the pierce points.
            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.
                allhands - The list handles of the plotted data.
                timenum - The of GeoData objects derived from the ionofiles.
            Outputs
                allhands - The list handles of the plotted data.
            """
        if self.GDGPS is None:
            return allhands
        xoffset = 0.022*(m.xmax-m.xmin)
        yoffset = 0.022*(m.ymax-m.ymin)
        namehands = []
        for igpsnum, (igps,igpslist) in enumerate(zip(self.GDGPS,self.Regdict['TEC'][timenum])):
           # check if there's anything to plot
           if len(igpslist)==0:
               continue
           locs = igps.dataloc[igpslist]
           xwin,ywin = m(self.params['lonbounds'],self.params['latbounds'])
           x, y = m(locs[:,1], locs[:,0])
           keepboth =  (x>xwin[0])&(x<xwin[1])&(y>ywin[0])&(y<ywin[1])
           if keepboth.sum()==0:
               continue
           [xloc,yloc] = [x[keepboth][0],y[keepboth][0]]
           namehands.append(plt.text(xloc+xoffset,yloc+yoffset,self.GPSNames[igpsnum],fontsize=14,fontweight='bold',
                    color='r'))
        allhands.append(namehands)
        return allhands


    def writeiniclass(self,fname):
        """ The method for the class that calls the writeini function.
            Inputs
                fname - The name of the file it will be written out to.
        """
        writeini(self.params,fname)
예제 #10
0
    def ISRRead(self,ISRloc):
        """ This function will read in the ISR data from SRI files or structured
            h5 files for GeoData. It will assign the class variable GDISR to the
            resultant GeoData object.
            Input
                ISRloc - This can be either a file from SRI or an h5 file
                thats been pre interpolated. """
        if ISRloc is None:
            return

        ISRloc = Path(ISRloc).expanduser()

        if not ISRloc.is_file():
            print('ISR Data is not a file')
            return
        self.numGD+=1
        print('Reading in ISR Data')
        pnheights= self.params['paramheight']

        paramstr = list(set([i[0] for i in pnheights]))
        try:
            SRIh5 = GeoData(readSRI_h5,(ISRloc,paramstr))
        except Exception:
            try:
                SRIh5 = GeoData.read_h5(ISRloc)
            except Exception:
                return
        dt1ts,dt2ts = self.params['timebounds']

        timelist = sp.where((SRIh5.times[:,1]>=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)
        uh=uh*1e3
        newcoordname = 'WGS84'

        if not (SRIh5.coordnames.lower() == newcoordname.lower()):
            changed_coords = SRIh5.__changecoords__(newcoordname)
            latmin,latmax = [changed_coords[:,0].min(),changed_coords[:,0].max()]
            lonmin,lonmax = [changed_coords[:,1].min(),changed_coords[:,1].max()]
            latvec = sp.linspace(latmin,latmax,self.params['ISRLatnum'])
            lonvec = sp.linspace(lonmin,lonmax,self.params['ISRLonnum'])

            LON,LAT = sp.meshgrid(lonvec,latvec)
            xycoords = sp.column_stack([LAT.flatten(),LON.flatten()])
                # 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,newcoordname,method='linear')
        self.GDISR = SRIh5
        print('Finished Reading in ISR Data')
예제 #11
0
    def ASRead(self,ASloc):
        """ This function will read in the All sky data from FITS files or structured
            h5 files for GeoData.
            Input
                ASloc - This can be either a directory holding the FITS files or a
                h5 file thats been pre interpolated. It will assign the class variable GDAS to the
            resultant GeoData object."""

        if ASloc is None:
            return

        ASloc = Path(ASloc).expanduser()

        if not ASloc.is_dir() and not ASloc.is_file():
            print('All Sky Data cannot be read')
            return

        self.numGD+=1
        print('Reading in All sky data')
        wl = str(int(self.params['wl']))
        wlstr ='*_0'+wl+'_*.FITS'
        interpsavedfile = ASloc/('interp'+wl+'.h5')
        reinterp=self.params['reinterp']
        timelim=self.params['timebounds']

        if self.nointerp:
            flist558 = sorted(ASloc.glob(wlstr))
            self.GDAS =  GeoData(readAllskyFITS,(flist558,
                                                 ('PKR_DASC_20110112_AZ_10deg.FITS',
                                                  'PKR_DASC_20110112_EL_10deg.FITS'),
                                                 150.,timelim))
            return

        if reinterp or not ASloc.is_file():
           # pfalla = sp.array([65.136667,-147.447222,689.])

            flist558 = sorted(ASloc.glob(wlstr))
            if not flist558:
                return

            allsky_data = GeoData(readAllskyFITS,(flist558,('PKR_DASC_20110112_AZ_10deg.FITS','PKR_DASC_20110112_EL_10deg.FITS'),150.,timelim))
            if timelim is not None:
                allsky_data.timereduce(timelim)


            xcoords = allsky_data.__changecoords__('WGS84')
            latlim=[xcoords[:,0].min(),xcoords[:,0].max()]
            lonlim=[xcoords[:,1].min(),xcoords[:,1].max()]
            nlat = 256
            nlon = 256

            latvec = sp.linspace(latlim[0],latlim[1],nlat)
            lonvec = sp.linspace(lonlim[0],lonlim[1],nlon)
            [LATM,LONM] = sp.meshgrid(latvec,lonvec)

            newcoords = sp.column_stack((LATM.flatten(),LONM.flatten(),150.*sp.ones(LONM.size)))
            allsky_data.interpolate(newcoords,'WGS84',method='linear',twodinterp=True)
            allsky_data.write_h5(interpsavedfile)
        else:
            allsky_data = GeoData.read_h5(ASloc)
            if timelim is not None:
                allsky_data.timereduce(timelim)

        self.GDAS = allsky_data
        print('Finished Reading in Allsky Data')