예제 #1
0
def startvalfunc(Ne_init, loc, locsp, time, inputs, ambinfo=[0]):
    """ 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 array of starting values for the fitter parameters."""
    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 = makeionocombined(inputs)
    elif isinstance(inputs, list):
        ionoin = 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):
        #for iamb in ambinfo:
        newlocsp = locsp[ilocn]
        #newlocsp[0] += iamb
        (datast, vel) = ionoin.getclosestsphere(newlocsp, time)[:2]
        datast[:, -1, 0] = Ne_init[ilocn, :]
        # get the ion densities
        ionoden = datast[:, :-1, 0]
        # find the right normalization for the ion species
        ionodensum = sp.repeat(sp.sum(ionoden, axis=-1)[:, sp.newaxis],
                               ionoden.shape[-1],
                               axis=-1)
        # renormalized to the right level
        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))  #/float(len(ambinfo))
        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  #/float(len(ambinfo))
    return xarray
Created on Tue Apr 14 18:06:56 2015

@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: