예제 #1
0
def main():
    """ Test function for the RadarData class."""
    t1 = time.time()
    curpath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    testpath = os.path.join(os.path.split(curpath)[0],'Testdata')
    Ionoin=IonoContainer.readh5(os.path.join(testpath,'lags.h5'))
    inifile = os.path.join(testpath,'PFISRExample.pickle')

    fitterone = Fitterionoconainer(Ionoin,inifile)
    (fitteddata,fittederror) = fitterone.fitdata(ISRSfitfunction,simpstart)
    (Nloc,Ntimes,nparams)=fitteddata.shape
    fittederronly = fittederror[:,:,range(nparams),range(nparams)]
    paramlist = sp.concatenate((fitteddata,fittederronly),axis=2)
    paramnames = []
    species = fitterone.simparams['species']
    for isp in species[:-1]:
        paramnames.append('Ni_'+isp)
        paramnames.append('Ti_'+isp)
    paramnames = paramnames+['Ne','Te','Vi']
    paramnamese = ['n'+ip for ip in paramnames]
    paranamsf = sp.array(paramnames+paramnamese)


    Ionoout=IonoContainer(Ionoin.Sphere_Coords,paramlist,Ionoin.Time_Vector,ver =1,
                          coordvecs = Ionoin.Coord_Vecs, paramnames=paranamsf,species=species)

    Ionoout.saveh5(os.path.join(testpath,'fittedtestdata.h5'))
    t2 = time.time()
    print(t2-t1)
예제 #2
0
def startvalfunc(Ne_init, loc, time, inputs):
    """ This is a method to determine the start values for the fitter.
    Inputs 
        Ne_init - A nloc x nt numpy array of the initial estimate of electron density. Basically
        the zeroth lag of the ACF.
        loc - A nloc x 3 numpy array of cartisian coordinates.
        time - A nt x 2 numpy array of times in seconds
        exinputs - A list of extra inputs allowed for by the fitter class. It only
            has one element and its the name of the ionocontainer file holding the 
            rest of the start parameters.
    Outputs
        xarray - This is a numpy arrya of starting values for the fitter parmaeters."""
    if isinstance(inputs, str):
        if os.path.splitext(inputs)[-1] == '.h5':
            Ionoin = IonoContainer.readh5(inputs)
        elif os.path.splitext(inputs)[-1] == '.mat':
            Ionoin = IonoContainer.readmat(inputs)
        elif os.path.splitext(inputs)[-1] == '':
            Ionoin = IonoContainer.makeionocombined(inputs)
    elif isinstance(inputs, list):
        Ionoin = IonoContainer.makeionocombined(inputs)
    else:
        Ionoin = inputs

    numel = sp.prod(Ionoin.Param_List.shape[-2:]) + 1

    xarray = sp.zeros((loc.shape[0], len(time), numel))
    for ilocn, iloc in enumerate(loc):
        (datast, vel) = Ionoin.getclosest(iloc, time)[:2]
        datast[:, -1, 0] = Ne_init[ilocn, :]
        ionoden = datast[:, :-1, 0]
        ionodensum = sp.repeat(sp.sum(ionoden, axis=-1)[:, sp.newaxis],
                               ionoden.shape[-1],
                               axis=-1)
        ionoden = sp.repeat(Ne_init[ilocn, :, sp.newaxis],
                            ionoden.shape[-1],
                            axis=-1) * ionoden / ionodensum
        datast[:, :-1, 0] = ionoden
        xarray[ilocn, :, :-1] = sp.reshape(datast, (len(time), numel - 1))
        locmag = sp.sqrt(sp.sum(iloc * iloc))
        ilocmat = sp.repeat(iloc[sp.newaxis, :], len(time), axis=0)
        xarray[ilocn, :, -1] = sp.sum(vel * ilocmat) / locmag
    return xarray
예제 #3
0
def main():
    """Testing function"""
    t1 = time.time()
    curpath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    testpath = os.path.join(os.path.split(curpath)[0],'Testdata')
    inifile = os.path.join(testpath,'PFISRExample.pickle')
    (sensdict,simparams) = readconfigfile(inifile)
    testh5 = os.path.join(testpath,'testiono.h5')
    ioncont = IonoContainer.readh5(testh5)
    outfile = os.path.join(testpath,'testionospec.h5')

    ioncont.makespectruminstanceopen(specfunctions.ISRSspecmake,sensdict,
                                     simparams['numpoints']).saveh5(outfile)
    radardata = RadarDataFile({0.0:outfile},inifile,testpath)

    ionoout = radardata.processdataiono()
    ionoout.saveh5(os.path.join(testpath,'lags.h5'))
    t2 = time.time()
    print(t2-t1)
예제 #4
0
    def __init__(self,Ionodict,inifile, outdir,outfilelist=None):
       """This function will create an instance of the RadarData class.  It will
        take in the values and create the class and make raw IQ data.
        Inputs:
            sensdict - A dictionary of sensor parameters
            angles - A list of tuples which the first position is the az angle
                and the second position is the el angle.
            IPP - The interpulse period in seconds represented as a float.
            Tint - The integration time in seconds as a float.  This will be the
            integration time of all of the beams.
            time_lim - The length of time of the simulation the number of time points
                will be calculated.
            pulse - A numpy array that represents the pulse shape.
            rng_lims - A numpy array of length 2 that holds the min and max range
                that the radar will cover."""
       (sensdict,simparams) = readconfigfile(inifile)
       self.simparams = simparams
       N_angles = len(self.simparams['angles'])

       NNs = self.simparams['NNs']
       self.sensdict = sensdict
       Npall = sp.floor(self.simparams['TimeLim']/self.simparams['IPP'])
       Npall = sp.floor(Npall/N_angles)*N_angles
       Np = Npall/N_angles

       print "All spectrums created already"
       filetimes = Ionodict.keys()
       filetimes.sort()
       ftimes = sp.array(filetimes)
       simdtype = self.simparams['dtype']
       pulsetimes = sp.arange(Npall)*self.simparams['IPP']
       pulsefile = sp.array([sp.where(itimes-ftimes>=0)[0][-1] for itimes in pulsetimes])

       # differentiate between phased arrays and dish antennas
       if sensdict['Name'].lower() in ['risr','pfisr']:
           beams = sp.tile(sp.arange(N_angles),Npall/N_angles)
       else:
           # for dish arrays
            brate = simparams['beamrate']
            beams2 = sp.repeat(sp.arange(N_angles),brate)
            beam3 = sp.concatenate((beams2,beams2[:-1,::-1]))
            beams = sp.tile(beam3,Npall/len(beam3))

       pulsen = sp.repeat(sp.arange(Np),N_angles)
       pt_list = []
       pb_list = []
       pn_list = []
       fname_list = []
       self.datadir = outdir
       self.maindir = os.path.dirname(os.path.abspath(outdir))
       self.procdir =os.path.join(self.maindir,'ACF')
       self.procdir
       if outfilelist is None:
            print('\nData Now being created.')

            Noisepwr =  v_Boltz*sensdict['Tsys']*sensdict['BandWidth']
            self.outfilelist = []
            for ifn, ifilet in enumerate(filetimes):
                outdict = {}
                ifile = Ionodict[ifilet]
                print('\tData from {0:d} of {1:d} being processed Name: {2:s}.'.format(ifn,len(filetimes),os.path.split(ifile)[1]))
                curcontainer = IonoContainer.readh5(ifile)
                pnts = pulsefile==ifn
                pt =pulsetimes[pnts]
                pb = beams[pnts]
                pn = pulsen[pnts].astype(int)
                (rawdata,outdict['SpecsUsed'])= self.__makeTime__(pt,curcontainer.Time_Vector,
                    curcontainer.Sphere_Coords, curcontainer.Param_List,pb)
                Noise = sp.sqrt(Noisepwr/2)*(sp.random.randn(*rawdata.shape).astype(simdtype)+
                    1j*sp.random.randn(*rawdata.shape).astype(simdtype))
                outdict['AddedNoise'] =Noise
                outdict['RawData'] = rawdata+Noise
                outdict['RawDatanonoise'] = rawdata
                outdict['NoiseData'] = sp.sqrt(Noisepwr/2)*(sp.random.randn(len(pn),NNs).astype(simdtype)+
                    1j*sp.random.randn(len(pn),NNs).astype(simdtype))
                outdict['Pulses']=pn
                outdict['Beams']=pb
                outdict['Time'] = pt
                fname = '{0:d} RawData.h5'.format(ifn)
                newfn = os.path.join(self.datadir,fname)
                self.outfilelist.append(newfn)
                dict2h5(newfn,outdict)

                #Listing info
                pt_list.append(pt)
                pb_list.append(pb)
                pn_list.append(pn)
                fname_list.append(fname)
            infodict = {'Files':fname_list,'Time':pt_list,'Beams':pb_list,'Pulses':pn_list}
            dict2h5(os.path.join(outdir,'INFO.h5'),infodict)

       else:
           self.outfilelist=outfilelist
예제 #5
0
    def __init__(self,Ionodict,inifile, outdir,outfilelist=None):
       """This function will create an instance of the RadarData class.  It will
        take in the values and create the class and make raw IQ data.
        Inputs:
            sensdict - A dictionary of sensor parameters
            angles - A list of tuples which the first position is the az angle
                and the second position is the el angle.
            IPP - The interpulse period in seconds represented as a float.
            Tint - The integration time in seconds as a float.  This will be the
            integration time of all of the beams.
            time_lim - The length of time of the simulation the number of time points
                will be calculated.
            pulse - A numpy array that represents the pulse shape.
            rng_lims - A numpy array of length 2 that holds the min and max range
                that the radar will cover."""
       (sensdict,simparams) = readconfigfile(inifile)
       self.simparams = simparams
       N_angles = len(self.simparams['angles'])

       NNs = int(self.simparams['NNs'])
       self.sensdict = sensdict
       Npall = sp.floor(self.simparams['TimeLim']/self.simparams['IPP'])
       Npall = sp.floor(Npall/N_angles)*N_angles
       Np = Npall/N_angles

       print "All spectrums created already"
       filetimes = Ionodict.keys()
       filetimes.sort()
       ftimes = sp.array(filetimes)
       simdtype = self.simparams['dtype']
       pulsetimes = sp.arange(Npall)*self.simparams['IPP'] +ftimes.min()
       pulsefile = sp.array([sp.where(itimes-ftimes>=0)[0][-1] for itimes in pulsetimes])
       # differentiate between phased arrays and dish antennas
       if sensdict['Name'].lower() in ['risr','pfisr','risr-n']:
            beams = sp.tile(sp.arange(N_angles),Npall/N_angles)
       else:
            # for dish arrays
            brate = simparams['beamrate']
            beams2 = sp.repeat(sp.arange(N_angles),brate)
            beam3 = sp.concatenate((beams2,beams2[::-1]))
            ntile = sp.ceil(Npall/len(beam3))
            leftover = Npall-ntile*len(beam3)
            if ntile>0:
                beams = sp.tile(beam3,ntile)
                beams=sp.concatenate((beams,beam3[:leftover]))
            else:
                beams=beam3[:leftover]

       pulsen = sp.repeat(sp.arange(Np),N_angles)
       pt_list = []
       pb_list = []
       pn_list = []
       fname_list = []
       self.datadir = outdir
       self.maindir = os.path.dirname(os.path.abspath(outdir))
       self.procdir =os.path.join(self.maindir,'ACF')
       if outfilelist is None:
            print('\nData Now being created.')

            Noisepwr =  v_Boltz*sensdict['Tsys']*sensdict['BandWidth']
            self.outfilelist = []
            for ifn, ifilet in enumerate(filetimes):
                
                outdict = {}
                ifile = Ionodict[ifilet]
                print('\tData from {0:d} of {1:d} being processed Name: {2:s}.'.format(ifn,len(filetimes),
                      os.path.split(ifile)[1]))
                curcontainer = IonoContainer.readh5(ifile)
                if ifn==0:
                    self.timeoffset=curcontainer.Time_Vector[0,0]
                pnts = pulsefile==ifn
                pt =pulsetimes[pnts]
                pb = beams[pnts]
                pn = pulsen[pnts].astype(int)
                rawdata= self.__makeTime__(pt,curcontainer.Time_Vector,
                    curcontainer.Sphere_Coords, curcontainer.Param_List,pb)
                Noise = sp.sqrt(Noisepwr/2)*(sp.random.randn(*rawdata.shape).astype(simdtype)+
                    1j*sp.random.randn(*rawdata.shape).astype(simdtype))
                outdict['AddedNoise'] =Noise
                outdict['RawData'] = rawdata+Noise
                outdict['RawDatanonoise'] = rawdata
                outdict['NoiseData'] = sp.sqrt(Noisepwr/2)*(sp.random.randn(len(pn),NNs).astype(simdtype)+
                                                            1j*sp.random.randn(len(pn),NNs).astype(simdtype))
                outdict['Pulses']=pn
                outdict['Beams']=pb
                outdict['Time'] = pt
                fname = '{0:d} RawData.h5'.format(ifn)
                newfn = os.path.join(self.datadir,fname)
                self.outfilelist.append(newfn)
                dict2h5(newfn,outdict)

                #Listing info
                pt_list.append(pt)
                pb_list.append(pb)
                pn_list.append(pn)
                fname_list.append(fname)
            infodict = {'Files':fname_list,'Time':pt_list,'Beams':pb_list,'Pulses':pn_list}
            dict2h5(os.path.join(outdir,'INFO.h5'),infodict)

       else:
           infodict= h52dict(os.path.join(outdir,'INFO.h5'))
           alltime=sp.hstack(infodict['Time'])
           self.timeoffset=alltime.min()
           self.outfilelist=outfilelist