Ejemplo n.º 1
0
    def getclosest(self,coords,timelist=None):
        """This method will get the closest set of parameters in the coordinate space. It will return
        the parameters from all times.
        Input
        coords - A list of x,y and z coordinates.
        Output
        paramout - A NtxNp array from the closes output params
        sphereout - A Nc length array The sphereical coordinates of the closest point.
        cartout -  Cartisian coordinates of the closes point.
        """
        X_vec = self.Cart_Coords[:,0]
        Y_vec = self.Cart_Coords[:,1]
        Z_vec = self.Cart_Coords[:,2]

        xdiff = X_vec -coords[0]
        ydiff = Y_vec -coords[1]
        zdiff = Z_vec -coords[2]
        distall = xdiff**2+ydiff**2+zdiff**2
        minidx = np.argmin(distall)
        paramout = self.Param_List[minidx]
        velout = self.Velocity[minidx]
        datatime = self.Time_Vector
        if sp.ndim(self.Time_Vector)>1:
            datatime = datatime[:,0]
        if timelist is not None:
            timeindx = []
            for itime in timelist:
                timeindx.append(sp.argmin(sp.absolute(itime-datatime)))
            paramout=paramout[timeindx]
            velout=velout[timeindx]
        sphereout = self.Sphere_Coords[minidx]
        cartout = self.Cart_Coords[minidx]
        return (paramout,velout,sphereout,cartout,np.sqrt(distall[minidx]))
Ejemplo n.º 2
0
    def getclosest(self,coords,timelist=None):
        """
        This method will get the closest set of parameters in the coordinate space. It will return
        the parameters from all times.
        Input
        coords - A list of x,y and z coordinates.
        Output
        paramout - A NtxNp array from the closes output params
        sphereout - A Nc length array The sphereical coordinates of the closest point.
        cartout -  Cartisian coordinates of the closes point.
        distance - The spatial distance between the returned location and the
            desired location.
        minidx - The spatial index point.
        tvec - The times of the returned data.
        """
        X_vec = self.Cart_Coords[:,0]
        Y_vec = self.Cart_Coords[:,1]
        Z_vec = self.Cart_Coords[:,2]

        xdiff = X_vec -coords[0]
        ydiff = Y_vec -coords[1]
        zdiff = Z_vec -coords[2]
        distall = xdiff**2+ydiff**2+zdiff**2
        minidx = np.argmin(distall)
        paramout = self.Param_List[minidx]
        velout = self.Velocity[minidx]
        datatime = self.Time_Vector
        tvec = self.Time_Vector
        if sp.ndim(self.Time_Vector)>1:
            datatime = datatime[:,0]

        if isinstance(timelist,list):
            timelist=sp.array(timelist)
        if timelist is not None:
            timeindx = []
            for itime in timelist:
                if sp.isscalar(itime):
                    timeindx.append(sp.argmin(sp.absolute(itime-datatime)))
                else:
                    # look for overlap
                    log1 = (tvec[:,0]>=itime[0]) & (tvec[:,0]<itime[1])
                    log2 = (tvec[:,1]>itime[0]) & (tvec[:,1]<=itime[1])
                    log3 = (tvec[:,0]<=itime[0]) & (tvec[:,1]>itime[1])
                    log4 = (tvec[:,0]>itime[0]) & (tvec[:,1]<itime[1])
                    tempindx = sp.where(log1|log2|log3|log4)[0]

                    timeindx = timeindx +tempindx.tolist()
            paramout=paramout[timeindx]
            velout=velout[timeindx]
            tvec = tvec[timeindx]
        sphereout = self.Sphere_Coords[minidx]
        cartout = self.Cart_Coords[minidx]
        return (paramout,velout,sphereout,cartout,np.sqrt(distall[minidx]),minidx,tvec)
Ejemplo n.º 3
0
def exact_moments( w, M1, M2, M3 ):
    """Tests the algorithm with exact means"""
    assert( ndim( w ) == 1 )

    # Input processing
    k = w.shape[0]
    M1, M2, M3 = M1, M2, M3 
    assert( mrank(M1) == k )
    assert( mrank(M2) == k )
    assert( mrank(M3) == k )

    # Get pairwise estimates
    P12 = M1.dot( diag( w ).dot( M2.T ) )
    P13 = M1.dot( diag( w ).dot( M3.T ) )
    #P123 = sum( [ w[i] * tensorify( M1.T[i], M2.T[i], M3.T[i] ) for i in xrange( k ) ] )
    P123 = lambda theta: M1.dot( diag( w ) ).dot( diag( M3.T.dot( theta ) ) ).dot( M2.T )

    return P12, P13, P123
Ejemplo n.º 4
0
def exact_moments( w, M1, M2, M3 ):
    """Tests the algorithm with exact means"""
    assert( ndim( w ) == 1 )

    # Input processing
    k = w.shape[0]
    M1, M2, M3 = M1, M2, M3 
    assert( mrank(M1) == k )
    assert( mrank(M2) == k )
    assert( mrank(M3) == k )

    # Get pairwise estimates
    P12 = M1.dot( diag( w ).dot( M2.T ) )
    P13 = M1.dot( diag( w ).dot( M3.T ) )
    P123 = lambda eta: \
        M1.dot( diag( M3.T.dot(eta) * w ) ).dot( M2.T ) 

    return P12, P13, P123
Ejemplo n.º 5
0
def fullrho(qu, squ):
    print("#Starting full density matrix simulation!")
    
    #Build state from pure states received from the MPS processes
    rho = sp.zeros((2**N, 2**N), dtype=sp.complex128)
    psis = [None] * N_samp
    for n in range(N_samp):
        pnum, psi = squ.get()
        psis[pnum] = psi
        rho += sp.outer(psi, psi.conj())
        squ.task_done()
        
    rho /= sp.trace(rho)

    Hfull = get_full_op(get_ham(N, lam))

    linds = get_linds(N, eps)
    linds = [(n, L.reshape(tuple([sp.prod(L.shape[:sp.ndim(L)/2])]*2))) for (n, L) in linds]
    linds_full = [sp.kron(sp.eye(2**(n-1)), sp.kron(L, sp.eye(2**(N - n + 1) / L.shape[0]))) for (n, L) in linds]
    for L in linds_full:
        assert L.shape == Hfull.shape

    Qfull = -1.j * Hfull - 0.5 * sp.sum([L.conj().T.dot(L) for L in linds_full], axis=0)

    szs = [None] + [sp.kron(sp.kron(sp.eye(2**(n - 1)), Sz), sp.eye(2**(N - n))) for n in range(1, N + 1)]
    
    for i in range(N_steps + 1):
        rho /= sp.trace(rho)
        esz = []
        for n in range(1, N + 1):
            esz.append(sp.trace(szs[n].dot(rho)).real)

        if i % res_every == 0:
            if qu is None:
                print(esz)
            else:
                qu.put([-1, i, esz])
                qu.put([-2, i, [sp.NaN] * N]) #this slot is reserved for a second "exact" result
        
        #Do Euler steps, approximately integrating the Lindblad master equation
        rho += dt * (Qfull.dot(rho) + rho.dot(Qfull.conj().T) +
                       sum([L.dot(rho).dot(L.conj().T) for L in linds_full]))
Ejemplo n.º 6
0
def plotacfs(
    coords,
    times,
    configfile,
    maindir,
    cartcoordsys=True,
    indisp=True,
    acfdisp=True,
    fitdisp=True,
    filetemplate="acf",
    suptitle="ACF Comparison",
    invacf="",
):
    """ This will create a set of images that compare the input ISR acf to the
        output ISR acfs from the simulator.
        Inputs
        coords - An Nx3 numpy array that holds the coordinates of the desired points.
            times - A numpy list of times in seconds.
            configfile - The name of the configuration file used.
            cartcoordsys - (default True)A bool, if true then the coordinates are given in cartisian if
            false then it is assumed that the coords are given in sphereical coordinates.
            specsfilename - (default None) The name of the file holding the input spectrum.
            acfname - (default None) The name of the file holding the estimated ACFs.
            filetemplate (default 'spec') This is the beginning string used to save the images.
    """
    #    indisp = specsfilename is not None
    #    acfdisp = acfname is not None
    maindir = Path(maindir).expanduser()
    sns.set_style("whitegrid")
    sns.set_context("notebook")
    acfname = maindir.joinpath("ACF", "00lags.h5")
    ffit = maindir.joinpath("Fitted", "fitteddata.h5")

    specsfiledir = maindir.joinpath("Spectrums")
    (sensdict, simparams) = readconfigfile(configfile)
    simdtype = simparams["dtype"]
    npts = simparams["numpoints"] * 3.0
    amb_dict = simparams["amb_dict"]
    if sp.ndim(coords) == 1:
        coords = coords[sp.newaxis, :]
    Nt = len(times)
    Nloc = coords.shape[0]
    sns.set_style("whitegrid")
    sns.set_context("notebook")
    pulse = simparams["Pulse"]
    ts = sensdict["t_s"]
    tau1 = sp.arange(pulse.shape[-1]) * ts

    if indisp:
        dirlist = [i.name for i in specsfiledir.glob("*.h5")]
        timelist = sp.array([float(i.split()[0]) for i in dirlist])
        for itn, itime in enumerate(times):
            filear = sp.argwhere(timelist >= itime)
            if len(filear) == 0:
                filenum = len(timelist) - 1
            else:
                filenum = filear[0][0]
            specsfilename = specsfiledir.joinpath(dirlist[filenum])
            Ionoin = IonoContainer.readh5(str(specsfilename))
            if itn == 0:
                specin = sp.zeros((Nloc, Nt, Ionoin.Param_List.shape[-1])).astype(Ionoin.Param_List.dtype)
            omeg = Ionoin.Param_Names
            npts = Ionoin.Param_List.shape[-1]

            for icn, ic in enumerate(coords):
                if cartcoordsys:
                    tempin = Ionoin.getclosest(ic, times)[0]
                else:
                    tempin = Ionoin.getclosestsphere(ic, times)[0]
                #                if sp.ndim(tempin)==1:
                #                    tempin = tempin[sp.newaxis,:]
                specin[icn, itn] = tempin[0, :] / npts
    if acfdisp:
        Ionoacf = IonoContainer.readh5(str(acfname))
        ACFin = sp.zeros((Nloc, Nt, Ionoacf.Param_List.shape[-1])).astype(Ionoacf.Param_List.dtype)

        omeg = sp.arange(-sp.ceil((npts + 1) / 2), sp.floor((npts + 1) / 2)) / ts / npts
        for icn, ic in enumerate(coords):
            if cartcoordsys:
                tempin = Ionoacf.getclosest(ic, times)[0]
            else:
                tempin = Ionoacf.getclosestsphere(ic, times)[0]
            if sp.ndim(tempin) == 1:
                tempin = tempin[sp.newaxis, :]
            ACFin[icn] = tempin

            # Determine the inverse ACF stuff
    if len(invacf) == 0:
        invacfbool = False
    else:
        invacfbool = True
        invfile = maindir.joinpath("ACFInv", "00lags" + invacf + ".h5")
        Ionoacfinv = IonoContainer.readh5(str(invfile))
        ACFinv = sp.zeros((Nloc, Nt, Ionoacfinv.Param_List.shape[-1])).astype(Ionoacfinv.Param_List.dtype)

        for icn, ic in enumerate(coords):
            if cartcoordsys:
                tempin = Ionoacfinv.getclosest(ic, times)[0]
            else:
                tempin = Ionoacfinv.getclosestsphere(ic, times)[0]
            if sp.ndim(tempin) == 1:
                tempin = tempin[sp.newaxis, :]
            ACFinv[icn] = tempin

    if fitdisp:
        Ionofit = IonoContainer.readh5(str(ffit))
        (omegfit, outspecsfit) = ISRspecmakeout(
            Ionofit.Param_List, sensdict["fc"], sensdict["fs"], simparams["species"], npts
        )
        Ionofit.Param_List = outspecsfit
        Ionofit.Param_Names = omegfit
        specfit = sp.zeros((Nloc, Nt, npts))
        for icn, ic in enumerate(coords):
            if cartcoordsys:
                tempin = Ionofit.getclosest(ic, times)[0]
            else:
                tempin = Ionofit.getclosestsphere(ic, times)[0]
            if sp.ndim(tempin) == 1:
                tempin = tempin[sp.newaxis, :]
            specfit[icn] = tempin / npts / npts

    nfig = int(sp.ceil(Nt * Nloc / 3.0))
    imcount = 0
    for i_fig in range(nfig):
        lines = [None] * 4
        labels = [None] * 4
        lines_im = [None] * 4
        labels_im = [None] * 4
        (figmplf, axmat) = plt.subplots(3, 2, figsize=(16, 12), facecolor="w")
        for ax in axmat:
            if imcount >= Nt * Nloc:
                break
            iloc = int(sp.floor(imcount / Nt))
            itime = int(imcount - (iloc * Nt))

            maxvec = []
            minvec = []

            if indisp:
                # apply ambiguity funciton to spectrum
                curin = specin[iloc, itime]
                (tau, acf) = spect2acf(omeg, curin)
                acf1 = scfft.ifftshift(acf)[: len(pulse)] * len(curin)
                rcs = acf1[0].real
                guess_acf = sp.dot(amb_dict["WttMatrix"], acf)
                guess_acf = guess_acf * rcs / guess_acf[0].real

                # fit to spectrums
                maxvec.append(guess_acf.real.max())
                maxvec.append(guess_acf.imag.max())
                minvec.append(acf1.real.min())
                minvec.append(acf1.imag.min())
                lines[0] = ax[0].plot(tau1 * 1e6, guess_acf.real, label="Input", linewidth=5)[0]
                labels[0] = "Input ACF With Ambiguity Applied"
                lines_im[0] = ax[1].plot(tau1 * 1e6, guess_acf.imag, label="Input", linewidth=5)[0]
                labels_im[0] = "Input ACF With Ambiguity Applied"

            if fitdisp:
                curinfit = specfit[iloc, itime]
                (taufit, acffit) = spect2acf(omegfit, curinfit)
                rcsfit = curinfit.sum()
                guess_acffit = sp.dot(amb_dict["WttMatrix"], acffit)
                guess_acffit = guess_acffit * rcsfit / guess_acffit[0].real

                lines[1] = ax[0].plot(tau1 * 1e6, guess_acffit.real, label="Input", linewidth=5)[0]
                labels[1] = "Fitted ACF"
                lines_im[1] = ax[1].plot(tau1 * 1e6, guess_acffit.imag, label="Input", linewidth=5)[0]
                labels_im[1] = "Fitted ACF"
            if acfdisp:
                lines[2] = ax[0].plot(tau1 * 1e6, ACFin[iloc, itime].real, label="Output", linewidth=5)[0]
                labels[2] = "Estimated ACF"
                lines_im[2] = ax[1].plot(tau1 * 1e6, ACFin[iloc, itime].imag, label="Output", linewidth=5)[0]
                labels_im[2] = "Estimated ACF"

                maxvec.append(ACFin[iloc, itime].real.max())
                maxvec.append(ACFin[iloc, itime].imag.max())
                minvec.append(ACFin[iloc, itime].real.min())
                minvec.append(ACFin[iloc, itime].imag.min())
            if invacfbool:

                lines[3] = ax[0].plot(tau1 * 1e6, ACFinv[iloc, itime].real, label="Output", linewidth=5)[0]
                labels[3] = "Reconstructed ACF"
                lines_im[3] = ax[1].plot(tau1 * 1e6, ACFinv[iloc, itime].imag, label="Output", linewidth=5)[0]
                labels_im[3] = "Reconstructed ACF"
            ax[0].set_xlabel(r"$\tau$ in $\mu$s")
            ax[0].set_ylabel("Amp")
            ax[0].set_title("Real Part")  # Location {0}, Time {1}'.format(coords[iloc],times[itime]))
            ax[0].set_ylim(min(minvec), max(maxvec) * 1)
            ax[0].set_xlim([tau1.min() * 1e6, tau1.max() * 1e6])

            ax[1].set_xlabel(r"$\tau$ in $\mu$s")
            ax[1].set_ylabel("Amp")
            ax[1].set_title("Imag Part")  # Location {0}, Time {1}'.format(coords[iloc],times[itime]))
            ax[1].set_ylim(min(minvec), max(maxvec) * 1)
            ax[1].set_xlim([tau1.min() * 1e6, tau1.max() * 1e6])
            imcount = imcount + 1
        figmplf.suptitle(suptitle, fontsize=20)
        if None in labels:
            labels.remove(None)
            lines.remove(None)
        plt.figlegend(lines, labels, loc="lower center", ncol=5, labelspacing=0.0)
        fname = filetemplate + "_{0:0>3}.png".format(i_fig)
        plt.savefig(fname, dpi=300)
        plt.close(figmplf)
Ejemplo n.º 7
0
def plotspecs(
    coords,
    times,
    configfile,
    maindir,
    cartcoordsys=True,
    indisp=True,
    acfdisp=True,
    fitdisp=True,
    filetemplate="spec",
    suptitle="Spectrum Comparison",
):
    """ This will create a set of images that compare the input ISR spectrum to the
        output ISR spectrum from the simulator.
        Inputs
        coords - An Nx3 numpy array that holds the coordinates of the desired points.
        times - A numpy list of times in seconds.
        configfile - The name of the configuration file used.
        cartcoordsys - (default True)A bool, if true then the coordinates are given in cartisian if
        false then it is assumed that the coords are given in sphereical coordinates.
        specsfilename - (default None) The name of the file holding the input spectrum.
        acfname - (default None) The name of the file holding the estimated ACFs.
        filetemplate (default 'spec') This is the beginning string used to save the images.
    """

    sns.set_style("whitegrid")
    sns.set_context("notebook")
    maindir = Path(maindir).expanduser()
    acfname = maindir.joinpath("ACF", "00lags.h5")
    ffit = maindir.joinpath("Fitted", "fitteddata.h5")
    specsfiledir = maindir.joinpath("Spectrums")
    (sensdict, simparams) = readconfigfile(configfile)
    simdtype = simparams["dtype"]
    npts = simparams["numpoints"] * 3.0
    amb_dict = simparams["amb_dict"]
    if sp.ndim(coords) == 1:
        coords = coords[sp.newaxis, :]
    Nt = len(times)
    Nloc = coords.shape[0]
    sns.set_style("whitegrid")
    sns.set_context("notebook")

    if indisp:
        dirlist = [i.name for i in specsfiledir.glob("*.h5")]
        timelist = sp.array([float(i.split()[0]) for i in dirlist])
        for itn, itime in enumerate(times):
            filear = sp.argwhere(timelist >= itime)
            if len(filear) == 0:
                filenum = len(timelist) - 1
            else:
                filenum = filear[0][0]
            specsfilename = specsfiledir.joinpath(dirlist[filenum])
            Ionoin = IonoContainer.readh5(str(specsfilename))
            if itn == 0:
                specin = sp.zeros((Nloc, Nt, Ionoin.Param_List.shape[-1])).astype(Ionoin.Param_List.dtype)
            omeg = Ionoin.Param_Names
            npts = Ionoin.Param_List.shape[-1]

            for icn, ic in enumerate(coords):
                if cartcoordsys:
                    tempin = Ionoin.getclosest(ic, times)[0]
                else:
                    tempin = Ionoin.getclosestsphere(ic, times)[0]

                specin[icn, itn] = tempin[0, :] / npts / npts
    fs = sensdict["fs"]

    if acfdisp:
        Ionoacf = IonoContainer.readh5(str(acfname))
        ACFin = sp.zeros((Nloc, Nt, Ionoacf.Param_List.shape[-1])).astype(Ionoacf.Param_List.dtype)
        ts = sensdict["t_s"]
        omeg = sp.arange(-sp.ceil((npts - 1.0) / 2.0), sp.floor((npts - 1.0) / 2.0) + 1) / ts / npts
        for icn, ic in enumerate(coords):
            if cartcoordsys:
                tempin = Ionoacf.getclosest(ic, times)[0]
            else:
                tempin = Ionoacf.getclosestsphere(ic, times)[0]
            if sp.ndim(tempin) == 1:
                tempin = tempin[sp.newaxis, :]
            ACFin[icn] = tempin
        specout = scfft.fftshift(scfft.fft(ACFin, n=npts, axis=-1), axes=-1)

    if fitdisp:
        Ionofit = IonoContainer.readh5(str(ffit))
        (omegfit, outspecsfit) = ISRspecmakeout(
            Ionofit.Param_List, sensdict["fc"], sensdict["fs"], simparams["species"], npts
        )
        Ionofit.Param_List = outspecsfit
        Ionofit.Param_Names = omegfit
        specfit = sp.zeros((Nloc, Nt, npts))
        for icn, ic in enumerate(coords):
            if cartcoordsys:
                tempin = Ionofit.getclosest(ic, times)[0]
            else:
                tempin = Ionofit.getclosestsphere(ic, times)[0]
            if sp.ndim(tempin) == 1:
                tempin = tempin[sp.newaxis, :]
            specfit[icn] = tempin / npts / npts

    nfig = int(sp.ceil(Nt * Nloc / 6.0))
    imcount = 0

    for i_fig in range(nfig):
        lines = [None] * 3
        labels = [None] * 3
        (figmplf, axmat) = plt.subplots(2, 3, figsize=(16, 12), facecolor="w")
        axvec = axmat.flatten()
        for iax, ax in enumerate(axvec):
            if imcount >= Nt * Nloc:
                break
            iloc = int(sp.floor(imcount / Nt))
            itime = int(imcount - (iloc * Nt))

            maxvec = []
            if fitdisp:
                curfitspec = specfit[iloc, itime]
                rcsfit = curfitspec.sum()
                (taufit, acffit) = spect2acf(omegfit, curfitspec)
                guess_acffit = sp.dot(amb_dict["WttMatrix"], acffit)
                guess_acffit = guess_acffit * rcsfit / guess_acffit[0].real
                spec_intermfit = scfft.fftshift(scfft.fft(guess_acffit, n=npts))
                lines[1] = ax.plot(omeg * 1e-3, spec_intermfit.real, label="Fitted Spectrum", linewidth=5)[0]
                labels[1] = "Fitted Spectrum"
            if indisp:
                # apply ambiguity function to spectrum
                curin = specin[iloc, itime]
                rcs = curin.real.sum()
                (tau, acf) = spect2acf(omeg, curin)
                guess_acf = sp.dot(amb_dict["WttMatrix"], acf)

                guess_acf = guess_acf * rcs / guess_acf[0].real

                # fit to spectrums
                spec_interm = scfft.fftshift(scfft.fft(guess_acf, n=npts))
                maxvec.append(spec_interm.real.max())
                lines[0] = ax.plot(omeg * 1e-3, spec_interm.real, label="Input", linewidth=5)[0]
                labels[0] = "Input Spectrum With Ambiguity Applied"

            if acfdisp:
                lines[2] = ax.plot(omeg * 1e-3, specout[iloc, itime].real, label="Output", linewidth=5)[0]
                labels[2] = "Estimated Spectrum"
                maxvec.append(specout[iloc, itime].real.max())
            ax.set_xlabel("f in kHz")
            ax.set_ylabel("Amp")
            ax.set_title("Location {0}, Time {1}".format(coords[iloc], times[itime]))
            ax.set_ylim(0.0, max(maxvec) * 1)
            ax.set_xlim([-fs * 5e-4, fs * 5e-4])
            imcount = imcount + 1
        figmplf.suptitle(suptitle, fontsize=20)
        if None in labels:
            labels.remove(None)
            lines.remove(None)
        plt.figlegend(lines, labels, loc="lower center", ncol=5, labelspacing=0.0)
        fname = filetemplate + "_{0:0>3}.png".format(i_fig)

        plt.savefig(fname)
        plt.close(figmplf)
Ejemplo n.º 8
0
def plotacfs(coords,times,configfile,maindir,cartcoordsys = True, indisp=True,acfdisp= True,
             fitdisp=True, filetemplate='acf',suptitle = 'ACF Comparison'):

    """ This will create a set of images that compare the input ISR acf to the
    output ISR acfs from the simulator.
    Inputs
    coords - An Nx3 numpy array that holds the coordinates of the desired points.
    times - A numpy list of times in seconds.
    configfile - The name of the configuration file used.
    cartcoordsys - (default True)A bool, if true then the coordinates are given in cartisian if
    false then it is assumed that the coords are given in sphereical coordinates.
    specsfilename - (default None) The name of the file holding the input spectrum.
    acfname - (default None) The name of the file holding the estimated ACFs.
    filetemplate (default 'spec') This is the beginning string used to save the images."""
#    indisp = specsfilename is not None
#    acfdisp = acfname is not None

    acfname = os.path.join(maindir,'ACF','00lags.h5')
    ffit = os.path.join(maindir,'Fitted','fitteddata.h5')

    specsfiledir = os.path.join(maindir,'Spectrums')
    (sensdict,simparams) = readconfigfile(configfile)
    simdtype = simparams['dtype']
    npts = simparams['numpoints']*3.0
    amb_dict = simparams['amb_dict']
    if sp.ndim(coords)==1:
        coords = coords[sp.newaxis,:]
    Nt = len(times)
    Nloc = coords.shape[0]
    sns.set_style("whitegrid")
    sns.set_context("notebook")
    pulse = simparams['Pulse']
    ts = sensdict['t_s']
    tau1 = sp.arange(pulse.shape[-1])*ts
    if indisp:
        dirlist = os.listdir(specsfiledir)
        timelist = sp.array([int(i.split()[0]) for i in dirlist])
        for itn,itime in enumerate(times):
            filear = sp.argwhere(timelist>=itime)
            if len(filear)==0:
                filenum = len(timelist)-1
            else:
                filenum = filear[0][0]
            specsfilename = os.path.join(specsfiledir,dirlist[filenum])
            Ionoin = IonoContainer.readh5(specsfilename)
            if itn==0:
                specin = sp.zeros((Nloc,Nt,Ionoin.Param_List.shape[-1])).astype(Ionoin.Param_List.dtype)
            omeg = Ionoin.Param_Names
            npts = Ionoin.Param_List.shape[-1]

            for icn, ic in enumerate(coords):
                if cartcoordsys:
                    tempin = Ionoin.getclosest(ic,times)[0]
                else:
                    tempin = Ionoin.getclosestsphere(ic,times)[0]
#                if sp.ndim(tempin)==1:
#                    tempin = tempin[sp.newaxis,:]
                specin[icn,itn] = tempin[0,:]/npts
    if acfdisp:
        Ionoacf = IonoContainer.readh5(acfname)
        ACFin = sp.zeros((Nloc,Nt,Ionoacf.Param_List.shape[-1])).astype(Ionoacf.Param_List.dtype)

        omeg = sp.arange(-sp.ceil((npts+1)/2),sp.floor((npts+1)/2))/ts/npts
        for icn, ic in enumerate(coords):
            if cartcoordsys:
                tempin = Ionoacf.getclosest(ic,times)[0]
            else:
                tempin = Ionoacf.getclosestsphere(ic,times)[0]
            if sp.ndim(tempin)==1:
                tempin = tempin[sp.newaxis,:]
            ACFin[icn] = tempin


    if fitdisp:
        Ionofit = IonoContainer.readh5(ffit)
        (omegfit,outspecsfit) =ISRspecmakeout(Ionofit.Param_List,sensdict['fc'],sensdict['fs'],simparams['species'],npts)
        Ionofit.Param_List= outspecsfit
        Ionofit.Param_Names = omegfit
        specfit = sp.zeros((Nloc,Nt,npts))
        for icn, ic in enumerate(coords):
            if cartcoordsys:
                tempin = Ionofit.getclosest(ic,times)[0]
            else:
                tempin = Ionofit.getclosestsphere(ic,times)[0]
            if sp.ndim(tempin)==1:
                tempin = tempin[sp.newaxis,:]
            specfit[icn] = tempin/npts/npts

    nfig = int(sp.ceil(Nt*Nloc/6.0))
    imcount = 0

    for i_fig in range(nfig):
        lines = [None]*6
        labels = [None]*6
        (figmplf, axmat) = plt.subplots(2, 3,figsize=(24, 18), facecolor='w')
        axvec = axmat.flatten()
        for iax,ax in enumerate(axvec):
            if imcount>=Nt*Nloc:
                break
            iloc = int(sp.floor(imcount/Nt))
            itime = int(imcount-(iloc*Nt))

            maxvec = []
            minvec = []

            if indisp:
                # apply ambiguity funciton to spectrum
                curin = specin[iloc,itime]
                (tau,acf) = spect2acf(omeg,curin)
                acf1 = scfft.ifftshift(acf)[:len(pulse)]
                rcs=acf1[0].real
                guess_acf = sp.dot(amb_dict['WttMatrix'],acf)
                guess_acf = guess_acf*rcs/guess_acf[0].real

                # fit to spectrums
                maxvec.append(guess_acf.real.max())
                maxvec.append(guess_acf.imag.max())
                minvec.append(acf1.real.min())
                minvec.append(acf1.imag.min())
                lines[0]= ax.plot(tau1*1e6,guess_acf.real,label='Input',linewidth=5)[0]
                labels[0] = 'Input ACF With Ambiguity Applied Real'
                lines[1]= ax.plot(tau1*1e6,guess_acf.imag,label='Input',linewidth=5)[0]
                labels[1] = 'Input ACF With Ambiguity Applied Imag'

            if fitdisp:
                curinfit = specfit[iloc,itime]
                (taufit,acffit) = spect2acf(omegfit,curinfit)
                rcsfit=acffit[0].real
                guess_acffit = sp.dot(amb_dict['WttMatrix'],acffit)
                guess_acffit = guess_acffit*rcsfit/guess_acffit[0].real

                lines[2]= ax.plot(tau1*1e6,guess_acffit.real,label='Input',linewidth=5)[0]
                labels[2] = 'Fitted ACF real'
                lines[3]= ax.plot(tau1*1e6,guess_acffit.imag,label='Input',linewidth=5)[0]
                labels[3] = 'Fitted ACF Imag'
            if acfdisp:
                lines[4]=ax.plot(tau1*1e6,ACFin[iloc,itime].real,label='Output',linewidth=5)[0]
                labels[4] = 'Estimated ACF Real'
                lines[5]=ax.plot(tau1*1e6,ACFin[iloc,itime].imag,label='Output',linewidth=5)[0]
                labels[5] = 'Estimated ACF Imag'

                maxvec.append(ACFin[iloc,itime].real.max())
                maxvec.append(ACFin[iloc,itime].imag.max())
                minvec.append(ACFin[iloc,itime].real.min())
                minvec.append(ACFin[iloc,itime].imag.min())
            ax.set_xlabel('t in us')
            ax.set_ylabel('Amp')
            ax.set_title('Location {0}, Time {1}'.format(coords[iloc],times[itime]))
            ax.set_ylim(min(minvec),max(maxvec)*1)
            ax.set_xlim([tau1.min()*1e6,tau1.max()*1e6])
            imcount=imcount+1
        figmplf.suptitle(suptitle, fontsize=20)
        if None in labels:
            labels.remove(None)
            lines.remove(None)
        plt.figlegend( lines, labels, loc = 'lower center', ncol=5, labelspacing=0. )
        fname= filetemplate+'_{0:0>3}.png'.format(i_fig)
        plt.savefig(fname)
        plt.close(figmplf)