def __init__(self,Ionocont,Ionosig,inifile):
        """ The init function for the fitter take the inputs for the fitter programs.

            Inputs:
            DataLags: A dictionary with keys 'Power' 'ACF','RG','Pulses' for
            the returned value from the RadarData class function processdata.
            NoiseLags: A dictionary with keys 'Power' 'ACF','RG','Pulses' for
            the returned value from the RadarData class function processdata.
            sensdict: The dictionary that holds the sensor info.
            simparams: The dictionary that hold the specific simulation params"""
        (self.sensdict,self.simparams) = readconfigfile(inifile)
        self.Iono = Ionocont
        self.sig = Ionosig
示例#2
0
    def __init__(self, Ionocont, Ionosig=None, inifile='default.ini'):
        """ The init function for the fitter take the inputs for the fitter programs.

            Inputs:
            DataLags: A dictionary with keys 'Power' 'ACF','RG','Pulses' for
            the returned value from the RadarData class function processdata.
            NoiseLags: A dictionary with keys 'Power' 'ACF','RG','Pulses' for
            the returned value from the RadarData class function processdata.
            sensdict: The dictionary that holds the sensor info.
            simparams: The dictionary that hold the specific simulation params"""
        (self.sensdict, self.simparams) = readconfigfile(inifile)
        self.Iono = Ionocont
        self.sig = Ionosig
示例#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,ionoin,configfile):
        r2d = 180.0/sp.pi
        d2r = sp.pi/180.0
        (sensdict,simparams) = readconfigfile(configfile)
        nt = ionoin.Time_Vector.shape[0]
        nloc = ionoin.Sphere_Coords.shape[0]

        #Input location
        self.Cart_Coords_in = ionoin.Cart_Coords
        self.Sphere_Coords_In = ionoin.Sphere_Coords,
        self.Time_In = ionoin.Time_Vector
        self.Cart_Coords_In_Rep = sp.tile(ionoin.Cart_Coords,(nt,1))
        self.Sphere_Coords_In_Rep = sp.tile(ionoin.Sphere_Coords,(nt,1))
        self.Time_In_Rep  = sp.repeat(ionoin.Time_Vector,nloc,axis=0)

        #output locations
        rng_vec2 = simparams['Rangegatesfinal']
        nrgout = len(rng_vec2)

        angles = simparams['angles']
        nang =len(angles)

        ang_data = sp.array([[iout[0],iout[1]] for iout in angles])
        rng_all = sp.tile(rng_vec2,(nang))
        ang_all = sp.repeat(ang_data,nrgout,axis=0)
        nlocout = nang*nrgout

        ntout = len(simparams['Timevec'])
        self.Sphere_Coords_Out = sp.column_stack((rng_all,ang_all))
        (R_vec,Az_vec,El_vec) = (self.Sphere_Coords_Out[:,0],self.Sphere_Coords_Out[:,1],self.Sphere_Coords_Out[:,2])
        xvecmult = sp.cos(Az_vec*d2r)*sp.cos(El_vec*d2r)
        yvecmult = sp.sin(Az_vec*d2r)*sp.cos(El_vec*d2r)
        zvecmult = sp.sin(El_vec*d2r)
        X_vec = R_vec*xvecmult
        Y_vec = R_vec*yvecmult
        Z_vec = R_vec*zvecmult

        self.Cart_Coords_Out = sp.column_stack((X_vec,Y_vec,Z_vec))
        self.Time_Out = simparams['Timevec']
        self.Time_Out_Rep =sp.repeat(simparams['Timevec'],nlocout,axis=0)
        self.Sphere_Coords_Out_Rep =sp.tile(self.Sphere_Coords_Out,(ntout,1))
        self.RSTMat = makematPA(ionoin.Sphere_Coords,ionoin.Time_Vector)
示例#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 = 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
示例#6
0
    def __init__(self, ionoin, configfile, timein=None, mattype='matrix'):
        """ This will create the RadarSpaceTimeOperator object.
            Inputs
                ionoin - The input ionocontainer. This can be either an string that is a ionocontainer file,
                    a list of ionocontainer objects or a list a strings to ionocontainer files
                config  - The ini file that used to set up the simulation.
                timein - A Ntx2 numpy array of times.
                RSTOPinv - The inverse operator object.
                invmat - The inverse matrix to the original operator.
        """
        mattype = mattype.lower()
        accepttypes = ['matrix', 'sim', 'real']
        if not mattype in accepttypes:
            raise ValueError('Matrix type can only be {0}'.format(
                ', '.join(accepttypes)))
        d2r = sp.pi / 180.0
        (sensdict, simparams) = readconfigfile(configfile)
        # determine if the input ionocontainer is a string, a list of strings or a list of ionocontainers.
        ionoin = makeionocombined(ionoin)
        #Input location
        self.Cart_Coords_In = ionoin.Cart_Coords
        self.Sphere_Coords_In = ionoin.Sphere_Coords

        # Set the input times
        if timein is None:
            self.Time_In = ionoin.Time_Vector
        else:
            self.Time_In = timein

        #Create an array of output location based off of the inputs
        rng_vec2 = simparams['Rangegatesfinal']
        nrgout = len(rng_vec2)

        angles = simparams['angles']
        nang = len(angles)

        ang_data = sp.array([[iout[0], iout[1]] for iout in angles])
        rng_all = sp.repeat(rng_vec2, (nang), axis=0)
        ang_all = sp.tile(ang_data, (nrgout, 1))
        self.Sphere_Coords_Out = sp.column_stack((rng_all, ang_all))
        (R_vec, Az_vec,
         El_vec) = (self.Sphere_Coords_Out[:, 0], self.Sphere_Coords_Out[:, 1],
                    self.Sphere_Coords_Out[:, 2])
        xvecmult = sp.sin(Az_vec * d2r) * sp.cos(El_vec * d2r)
        yvecmult = sp.cos(Az_vec * d2r) * sp.cos(El_vec * d2r)
        zvecmult = sp.sin(El_vec * d2r)
        X_vec = R_vec * xvecmult
        Y_vec = R_vec * yvecmult
        Z_vec = R_vec * zvecmult

        self.Cart_Coords_Out = sp.column_stack((X_vec, Y_vec, Z_vec))
        self.Time_Out = sp.column_stack(
            (simparams['Timevec'],
             simparams['Timevec'] + simparams['Tint'])) + self.Time_In[0, 0]
        self.simparams = simparams
        self.sensdict = sensdict
        self.lagmat = self.simparams['amb_dict']['WttMatrix']
        self.mattype = mattype
        # create the matrix
        (self.RSTMat, self.overlaps,
         self.blocklocs) = makematPA(ionoin.Sphere_Coords, ionoin.Cart_Coords,
                                     ionoin.Time_Vector, configfile,
                                     ionoin.Velocity, mattype)
示例#7
0
def makematPA(Sphere_Coords,
              Cart_Coords,
              timein,
              configfile,
              vel=None,
              mattype='matrix'):
    """Make a Ntimeout*Nbeam*Nrng x Ntime*Nloc sparse matrix for the space time operator. 
       The output space will have range repeated first, then beams then time. 
       The coordinates will be [t0,b0,r0],[t0,b0,r1],[t0,b0,r2],...
       [t0,b1,r0],[t0,b1,r1], ... [t1,b0,r0],[t1,b0,r1],...[t1,b1,r0]...
       Inputs
           Sphere_Coords - A Nlocx3 array of the spherical coordinates of the input data.
           timein - A Ntbegx2 numpy array with the start and stop times of the input data.
           configfile - The ini file used for the simulation configuration.
           vel - A NlocxNtx3 numpy array of velocity.
       Outputs
           outmat - A list of matricies or a single matrix that is the forward between physical space
               to the discrete samples space of the radar.
           blocks - A tuple that holds the number of block matricies in overall forward operator.
           blocksize - A tuple that holds the shape of the outmatrix size.
           blockloc - An Ntout x Ntbeg array that holds the corresponding spatial forward model.
    """
    #
    (sensdict, simparams) = readconfigfile(configfile)
    timeout = simparams['Timevec']
    Tint = simparams['Tint']
    timeout = sp.column_stack((timeout, timeout + Tint)) + timein[0, 0]

    rng_bin = sensdict['t_s'] * v_C_0 * 1e-3 / 2.

    angles = simparams['angles']
    Nbeams = len(angles)

    rng_vec2 = simparams['Rangegatesfinal']
    nrgout = len(rng_vec2)
    pulse = simparams['Pulse']
    p_samps = pulse.shape[0]
    rng_len = p_samps * rng_bin
    Nlocbeg = Cart_Coords.shape[0]
    Nlocout = Nbeams * nrgout
    Ntbeg = len(timein)
    Ntout = len(timeout)
    if vel is None:
        vel = sp.zeros((Nlocbeg, Ntbeg, 3))

    # determine the overlaps
    # change

    blockloc_in = [[i * Nlocbeg, (i + 1) * Nlocbeg] for i in range(Ntout)]
    blockloc_out = [[i * Nlocout, (i + 1) * Nlocout] for i in range(Ntout)]
    blockloc = [blockloc_in, blockloc_out]
    # set up blocks
    blocksize = (Ntout * Nbeams * nrgout, Nlocbeg * Ntout)
    # make the matrix
    outmat = sp.sparse.lil_matrix(blocksize, dtype=sp.float64)
    overlaps = {}
    if mattype.lower() == 'real':
        cor_ratio = .5
    else:
        cor_ratio = 1.
    for iton, ito in enumerate(timeout):
        overlaps[iton] = []
        firstone = True
        for ix, x in enumerate(timein):
            if (x[0] + 1 < ito[1] or ix == (Ntbeg - 1)) and x[1] - 1 > ito[0]:

                # find the end of the data
                if ix == Ntbeg - 1:
                    enp = ito[1]
                else:
                    enp = sp.minimum(ito[1], x[1])
                stp = sp.maximum(x[0], ito[0])

                curvel = vel[:, 0] * 1e-3
                # XXX This is just a quick fix
                curvel[:, -1] = 0
                if firstone:
                    firstone = False
                    t_0 = stp.copy()
                    curdiff = sp.zeros_like(vel[:, ix])
                    curdiff2 = curdiff + float(enp - stp) * curvel
                else:
                    T_1 = float(x[0] - t_0)
                    t_0 = stp.copy()
                    curdiff = curdiff2
                    curdiff2 = curdiff + float(enp - stp) * curvel
                #find amount of time for overlap
                ratio = float(enp - stp) / Tint
                # set up new coordinate system
                # The thee types of coordinates are as follows
                # The matrix type assumes that the matrix will be applied to the data.
                # The sim type
                if mattype.lower() == 'matrix':
                    newcoorsds1 = cart2sphere(Cart_Coords)
                    newcoorsds2 = cart2sphere(Cart_Coords)
                elif mattype.lower == 'real':
                    newcoorsds1 = cart2sphere(Cart_Coords + curdiff)
                    newcoorsds2 = cart2sphere(Cart_Coords + curdiff2)
                else:
                    newcoorsds1 = cart2sphere(Cart_Coords + curdiff)
                    newcoorsds2 = cart2sphere(Cart_Coords + curdiff)
                overlaps[iton].append([ix, ratio, newcoorsds1, newcoorsds2])
    # make the matrix
    for iton, ito in enumerate(timeout):
        cur_over = overlaps[iton]
        #        if mattype=='matrix':
        #            cur_over=[cur_over[0]]
        #            cur_over[0][1]=1.
        beamnorm = sp.ones(Nbeams * nrgout)
        for it_in, it_info in enumerate(cur_over):
            print('\t Making Input time {0:d} of {1:d}'.format(
                it_in, len(cur_over)))
            cur_it, cur_ratio, Sp1, Sp2 = it_info
            #            if mattype.lower()=='sim':
            #                cur_ratio=1.
            rho1 = Sp1[:, 0]
            Az1 = Sp1[:, 1]
            El1 = Sp1[:, 2]
            rho2 = Sp2[:, 0]
            Az2 = Sp2[:, 1]
            El2 = Sp2[:, 2]

            # get the weights
            weights1 = {
                ibn: sensdict['ArrayFunc'](Az1, El1, ib[0], ib[1],
                                           sensdict['Angleoffset'])
                for ibn, ib in enumerate(angles)
            }
            weights2 = {
                ibn: sensdict['ArrayFunc'](Az2, El2, ib[0], ib[1],
                                           sensdict['Angleoffset'])
                for ibn, ib in enumerate(angles)
            }

            for ibn in range(Nbeams):

                print('\t\t Making Beam {0:d} of {1:d}'.format(ibn, Nbeams))
                weight1 = weights1[ibn]
                weight2 = weights2[ibn]
                for isamp in range(nrgout):
                    # make the row
                    irow = ibn + isamp * Nbeams + Nbeams * nrgout * iton
                    range_g = rng_vec2[isamp]
                    rnglims = [range_g - rng_len / 2., range_g + rng_len / 2.]

                    # assume centered lag product.
                    rangelog = ((rho1 >= rnglims[0]) & (rho1 < rnglims[1]))
                    # This is a nearest neighbors interpolation for the spectrums in the range domain
                    if sp.sum(rangelog) == 0:
                        minrng = sp.argmin(sp.absolute(range_g - rho1))
                        rangelog[minrng] = True
                    #create the weights and weight location based on the beams pattern.
                    weight_cur = weight1[rangelog]
                    # fix averaging problems
                    if it_in == 0:
                        beamnorm[ibn + isamp * Nbeams] = weight_cur.sum()
                    weight_cur = weight_cur / beamnorm[ibn + isamp * Nbeams]
                    icols = sp.where(rangelog)[0] + Nlocbeg * iton
                    #                    icols = sp.where(rangelog)[0] + Nlocbeg*cur_it

                    weights_final = weight_cur * range_g**2 / rho1[rangelog]**2
                    outmat[
                        irow,
                        icols] = weights_final * cur_ratio * cor_ratio + outmat[
                            irow, icols]

                    if mattype.lower() == 'real':
                        # assume centered lag product.
                        rangelog = ((rho2 >= rnglims[0]) & (rho2 < rnglims[1]))
                        # This is a nearest neighbors interpolation for the spectrums in the range domain
                        if sp.sum(rangelog) == 0:
                            minrng = sp.argmin(sp.absolute(range_g - rho2))
                            rangelog[minrng] = True
                        #create the weights and weight location based on the beams pattern.
                        weight_cur = weight2[rangelog]
                        weight_cur = weight_cur // beamnorm[ibn +
                                                            isamp * Nbeams]
                        #                    icols = sp.where(rangelog)[0]+ Nlocbeg*cur_it
                        icols = sp.where(rangelog)[0] + Nlocbeg * iton
                        weights_final = weight_cur * range_g**2 / rho2[
                            rangelog]**2
                        outmat[
                            irow,
                            icols] = weights_final * cur_ratio * cor_ratio + outmat[
                                irow, icols]

    return (outmat, overlaps, blockloc)
示例#8
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
示例#9
0
def makematPA(Sphere_Coords,timein,configfile):
    """Make a Ntimeout*Nbeam*Nrng x Ntime*Nloc matrix. The output space will have range repeated first,
    then beams then time. The coordinates will be [t0,b0,r0],[t0,b0,r1],[t0,b0,r2],...
    [t0,b1,r0],[t0,b1,r1], ... [t1,b0,r0],[t1,b0,r1],...[t1,b1,r0]..."""
    #
    (sensdict,simparams) = readconfigfile(configfile)
    timeout = simparams['Timevec']
    Tint = simparams['Tint']
    timeout = sp.column_stack((timeout,timeout+Tint))
    fullmat = True
    rng_vec = simparams['Rangegates']
    rng_bin=sensdict['t_s']*v_C_0/1000.0
    sumrule = simparams['SUMRULE']
    #
    minrgbin = -sumrule[0].min()
    maxrgbin = len(rng_vec)-sumrule[1].max()
    minrg = minrgbin*rng_bin
    maxrg = maxrgbin*rng_bin
    angles = simparams['angles']
    Nbeams = len(angles)
    rho = Sphere_Coords[:,0]
    Az = Sphere_Coords[:,1]
    El = Sphere_Coords[:,2]

    rng_vec2 = simparams['Rangegatesfinal']
    nrgout = len(rng_vec2)

    Nlocbeg = len(rho)
    Ntbeg = len(timein)
    Ntout = len(timeout)
    if fullmat:
        outmat = sp.matrix(sp.zeros((Ntout*Nbeams*nrgout,Nlocbeg*Ntbeg)))
    else:
        outmat = sp.sparse((Ntout*Nbeams*nrgout,Nlocbeg*Ntbeg),dype =sp.float64)

    weights = {ibn:sensdict['ArrayFunc'](Az,El,ib[0],ib[1],sensdict['Angleoffset']) for ibn, ib in enumerate(angles)}

    for iton,ito in enumerate(timeout):
        overlaps = sp.array([getOverlap(ito,x) for x in timein])
        weights_time = overlaps/overlaps.sum()
        itpnts = sp.where(weights_time>0)[0]

        # usually the matrix size is nbeamsxnrange
        for ibn in range(Nbeams):
            print('\t\t Making Beam {0:d} of {1:d}'.format(ibn,Nbeams))
            weight = weights[ibn]
            for isamp in range(nrgout):
                # make the row
                irow = isamp+ibn*nrgout+iton*nrgout*Nbeams

                range_g = rng_vec2[isamp]
                rnglims = [range_g-minrg,range_g+maxrg]
                rangelog = sp.argwhere((rho>=rnglims[0])&(rho<rnglims[1]))

                # This is a nearest neighbors interpolation for the spectrums in the range domain
                if sp.sum(rangelog)==0:
                    minrng = sp.argmin(sp.absolute(range_g-rho))
                    rangelog[minrng] = True
                #create the weights and weight location based on the beams pattern.
                weight_cur =weight[rangelog[:,0]]
                weight_cur = weight_cur/weight_cur.sum()
                weight_loc = sp.where(rangelog[:,0])[0]

                w_loc_rep = sp.tile(weight_loc,len(itpnts))
                t_loc_rep = sp.repeat(itpnts,len(weight_loc))
                icols = t_loc_rep*Nlocbeg+w_loc_rep

                weights_final = weights_time[t_loc_rep]*weight_cur[w_loc_rep]*range_g**2/rho[w_loc_rep]**2
                outmat[irow,icols] = weights_final


    return(outmat)