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"))
Exemplo n.º 2
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)
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]
    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"))
Exemplo n.º 4
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')