Пример #1
0
def main(input_str=None):
    args_commd = parse_command_line(input_str)
    if args_commd.path is None:
        curloc = Path(__file__).resolve()
        testpath = curloc.parent.parent/'Testdata'/'Barker'
    else:
        testpath = Path(args_commd.path)

    origparamsdir = testpath/'Origparams'
    testpath.mkdir(exist_ok=True,parents=True)
    print("Making a path for testdata at {}".format(testpath))

    origparamsdir.mkdir(exist_ok=True,parents=True)
    print("Making a path for testdata at {}".format(origparamsdir))
    makeconfigfilebarker(testpath)

    if args_commd.makeorigdata:
        Icont1 = MakeTestIonoclass(testv=True,testtemp=False,N_0=1e12,z_0=150.0,H_0=50.0)
        makeinputh5(Icont1,str(testpath))
        Icont1.saveh5(str(origparamsdir.joinpath('0 testiono.h5')))

    funcnamelist = args_commd.funclist

    failflag=runsim.main(funcnamelist,testpath,str(testpath.joinpath('barkertest.yml')),True)
    if not failflag:
        analysisdump(testpath,testpath.joinpath('barkertest.yml'))
Пример #2
0
def makehist(testpath, npulses):
    """
        This functions are will create histogram from data made in the testpath.
        Inputs
            testpath - The path that the data is located.
            npulses - The number of pulses in the sim.
    """
    sns.set_style("whitegrid")
    sns.set_context("notebook")
    params = ['Ne', 'Te', 'Ti', 'Vi']
    pvals = [1e11, 2.1e3, 1.1e3, 0.]
    histlims = [[4e10, 2e11], [1200., 3000.], [300., 1900.], [-250., 250.]]
    erlims = [[-2e11, 2e11], [-1000., 1000.], [-800., -800], [-250., 250.]]
    erperlims = [[-100., 100.]] * 4
    lims_list = [histlims, erlims, erperlims]
    errdict = makehistdata(params, testpath)[:4]
    ernames = ['Data', 'Error', 'Error Percent']
    sig1 = sp.sqrt(1. / npulses)

    # Two dimensiontal histograms
    pcombos = [i for i in itertools.combinations(params, 2)]
    c_rows = int(math.ceil(float(len(pcombos)) / 2.))
    (figmplf, axmat) = plt.subplots(c_rows,
                                    2,
                                    figsize=(12, c_rows * 6),
                                    facecolor='w')
    axvec = axmat.flatten()
    for icomn, icom in enumerate(pcombos):
        curax = axvec[icomn]
        str1, str2 = icom
        _, _, _ = make2dhist(testpath, PARAMDICT[str1], PARAMDICT[str2],
                             figmplf, curax)
    filetemplate = str(Path(testpath).joinpath('AnalysisPlots', 'TwoDDist'))
    plt.tight_layout()
    plt.subplots_adjust(top=0.95)
    figmplf.suptitle('Pulses: {0}'.format(npulses), fontsize=20)
    fname = filetemplate + '_{0:0>5}Pulses.png'.format(npulses)
    plt.savefig(fname)
    plt.close(figmplf)
    # One dimensiontal histograms
    for ierr, iername in enumerate(ernames):
        filetemplate = str(Path(testpath).joinpath('AnalysisPlots', iername))
        (figmplf, axmat) = plt.subplots(2, 2, figsize=(20, 15), facecolor='w')
        axvec = axmat.flatten()
        for ipn, iparam in enumerate(params):
            plt.sca(axvec[ipn])
            if sp.any(sp.isinf(errdict[ierr][iparam])):
                continue
            binlims = lims_list[ierr][ipn]
            bins = sp.linspace(binlims[0], binlims[1], 100)
            histhand = sns.distplot(errdict[ierr][iparam],
                                    bins=bins,
                                    kde=True,
                                    rug=False)

            axvec[ipn].set_title(iparam)
        figmplf.suptitle(iername + ' Pulses: {0}'.format(npulses), fontsize=20)
        fname = filetemplate + '_{0:0>5}Pulses.png'.format(npulses)
        plt.savefig(fname)
        plt.close(figmplf)
Пример #3
0
    def saveh5(self,filename):
        """
        This method will save the instance of the class to a structured h5 file.
        Input:
        filename - A string for the file name.
        """
        filename=Path(filename)
        if filename.is_file():
            filename.unlink()


        vardict = vars(self)

        with tables.open_file(str(filename), mode = "w", title = "IonoContainer out.") as f:

            try:
                # XXX only allow 1 level of dictionaries, do not allow for dictionary of dictionaries.
                # Make group for each dictionary
                for cvar in vardict.keys():
                    #group = f.create_group(posixpath.sep, cvar,cvar +'dictionary')
                    if type(vardict[cvar]) ==dict: # Check if dictionary
                        dictkeys = vardict[cvar].keys()
                        group2 = f.create_group('/',cvar,cvar+' dictionary')
                        for ikeys in dictkeys:
                            f.create_array(group2,ikeys,vardict[cvar][ikeys],'Static array')
                    else:
                        if not(vardict[cvar] is None):
                            f.create_array('/',cvar,vardict[cvar],'Static array')

            except Exception as inst:
                print(type(inst))
                print(inst.args)
                print(inst)
                raise NameError('Failed to write to h5 file.')
Пример #4
0
def makedata(testpath, tint):
    """ This will make the input data for the test case. The data will have cases
        where there will be enhancements in Ne, Ti and Te in one location. Each 
        case will have 3 integration periods. The first 3 integration periods will
        be the default set of parameters Ne=Ne=1e11 and Te=Ti=2000.
        Inputs
            testpath - Directory that will hold the data.
            tint - The integration time in seconds.
    """
    testpath = Path(testpath).expanduser()
    finalpath = testpath.joinpath('Origparams')
    if not finalpath.is_dir():
        finalpath.mkdir()
    data = sp.array([[1e11, 1100.], [1e11, 2100.]])
    z = (50. + sp.arange(50) * 10.)
    nz = len(z)
    params = sp.tile(data[sp.newaxis, sp.newaxis], (nz, 1, 1, 1))
    epnt = range(20, 22)
    p2 = sp.tile(params, (1, 4, 1, 1))
    #enhancement in Ne
    p2[epnt, 1, :, 0] = 5e11
    #enhancement in Ti
    p2[epnt, 2, 0, 1] = 2200.
    #enhancement in Te
    p2[epnt, 3, 1, 1] = 4200.
    coords = sp.column_stack((sp.ones(nz), sp.ones(nz), z))
    species = ['O+', 'e-']
    times = sp.array([[0, 1e3]])
    times2 = sp.column_stack((sp.arange(0, 4), sp.arange(1, 5))) * 3 * tint
    vel = sp.zeros((nz, 1, 3))
    vel2 = sp.zeros((nz, 4, 3))
    Icontstart = IonoContainer(coordlist=coords,
                               paramlist=params,
                               times=times,
                               sensor_loc=sp.zeros(3),
                               ver=0,
                               coordvecs=['x', 'y', 'z'],
                               paramnames=None,
                               species=species,
                               velocity=vel)
    Icont1 = IonoContainer(coordlist=coords,
                           paramlist=p2,
                           times=times2,
                           sensor_loc=sp.zeros(3),
                           ver=0,
                           coordvecs=['x', 'y', 'z'],
                           paramnames=None,
                           species=species,
                           velocity=vel2)

    finalfile = finalpath.joinpath('0 stats.h5')
    Icont1.saveh5(str(finalfile))
    Icontstart.saveh5(str(testpath.joinpath('startfile.h5')))
Пример #5
0
def main(plist=None,
         functlist=['spectrums', 'radardata', 'fitting', 'analysis', 'stats'],
         datadir=None):
    """ This function will call other functions to create the input data, config
        file and run the radar data sim. The path for the simulation will be
        created in the Testdata directory in the SimISR module. The new
        folder will be called BasicTest. The simulation is a long pulse simulation
        will the desired number of pulses from the user.
        Inputs
            npulse - Number of pulses for the integration period, default==100.
            functlist - The list of functions for the SimISR to do.
    """
    if plist is None:
        plist = sp.array([50, 100, 200, 500, 1000, 2000, 5000])
    if isinstance(plist, list):
        plist = sp.array(plist)

    if datadir is None:
        curloc = Path(__file__).resolve().parent
        testpath = curloc.parent.joinpath('Testdata', 'StatsTest')
    else:
        datadir = Path(datadir)
        testpath = datadir

    testpath.mkdir(exist_ok=True, parents=True)

    functlist_default = ['spectrums', 'radardata', 'fitting']
    check_list = sp.array([i in functlist for i in functlist_default])
    check_run = sp.any(check_list)
    functlist_red = sp.array(functlist_default)[check_list].tolist()
    allfolds = []
    #    rsystools = []
    for ip in plist:
        foldname = 'Pulses_{:04d}'.format(ip)
        curfold = testpath.joinpath(foldname)
        allfolds.append(curfold)

        curfold.mkdir(exist_ok=True, parents=True)

        configfilesetup(curfold, ip)
        makedata(curfold)
        config = curfold / 'stats.ini'
        #        rtemp = RadarSys(sensdict,simparams['Rangegatesfinal'],ip)
        #        rsystools.append(rtemp.rms(sp.array([1e12]),sp.array([2.5e3]),sp.array([2.5e3])))
        if check_run:
            runsim(functlist_red, curfold, str(curfold.joinpath('stats.ini')),
                   True)
        if 'analysis' in functlist:
            analysisdump(curfold, config, params=['Ne', 'Te', 'Ti', 'Vi'])
        if 'stats' in functlist:
            makehist(curfold, ip)
Пример #6
0
def main():
    curloc = Path(__file__).resolve()
    testpath = curloc.parent.parent / 'Testdata' / 'Barker'
    origparamsdir = testpath / 'Origparams'
    pdb.set_trace()
    testpath.mkdir(exist_ok=True, parents=True)
    print("Making a path for testdata at {}".format(testpath))

    origparamsdir.mkdir(exist_ok=True, parents=True)
    print("Making a path for testdata at {}".format(origparamsdir))
    makeconfigfilebarker(testpath)

    Icont1 = MakeTestIonoclass(testv=True,
                               testtemp=False,
                               N_0=1e12,
                               z_0=150.0,
                               H_0=50.0)
    makeinputh5(Icont1, str(testpath))
    Icont1.saveh5(str(origparamsdir.joinpath('0 testiono.h5')))
    funcnamelist = ['spectrums', 'radardata', 'fitting']

    failflag = runsim.main(funcnamelist, testpath,
                           str(testpath.joinpath('barkertest.ini')), True)
    if not failflag:
        analysisdump(testpath, testpath.joinpath('barkertest.ini'))
Пример #7
0
def main(npulse=100,
         functlist=['spectrums', 'radardata', 'fitting', 'analysis']):
    """ This function will call other functions to create the input data, config
        file and run the radar data sim. The path for the simulation will be 
        created in the Testdata directory in the SimISR module. The new
        folder will be called BasicTest. The simulation is a long pulse simulation
        will the desired number of pulses from the user.
        Inputs
            npulse - Number of pulses for the integration period, default==100.
            functlist - The list of functions for the SimISR to do.
    """

    curloc = Path(__file__).resolve()
    testpath = curloc.parent.parent / 'Testdata' / 'BasicTest'
    if not testpath.is_dir():
        testpath.mkdir(parents=True)

    functlist_default = ['spectrums', 'radardata', 'fitting']
    check_list = sp.array([i in functlist for i in functlist_default])
    check_run = sp.any(check_list)
    functlist_red = sp.array(functlist_default)[check_list].tolist()

    configfilesetup(str(testpath), npulse)
    config = testpath.joinpath('stats.ini')
    (sensdict, simparams) = readconfigfile(str(config))
    makedata(testpath, simparams['Tint'])
    if check_run:
        runsim(functlist_red, str(testpath), config, True)
    if 'analysis' in functlist:
        analysisdump(str(testpath), config)
Пример #8
0
def main():
    """This function will run the test simulation buy first making a simple set of
    ionospheric parameters based off of a Chapman function. Then it will create configuration
    and start files followed by running the simulation."""
    curpath = Path(__file__).resolve().parent
    testpath = curpath.parent/'Testdata'/'Long_Pulse'
    origparamsdir = testpath/'Origparams'
    
    if not testpath.is_dir():
        testpath.mkdir(parents=True)
    print("Making a path for testdata at {}".format(str(testpath)))
    
    if not origparamsdir.is_dir():
        origparamsdir.mkdir(parents=True)
    print("Making a path for testdata at {}".format(origparamsdir))

    # clear everything out
    folderlist = ['Origparams','Spectrums','Radardata','ACF','Fitted']
    for ifl in folderlist:
        flist = (testpath/ifl).glob('*.h5')
        for ifile in flist:
            ifile.unlink()
    # Now make stuff again
    configsetup(testpath)

    Icont1 = MakeTestIonoclass(testv=True,testtemp=True)
    makeinputh5(MakeTestIonoclass(testv=True,testtemp=False),testpath)
    Icont1.saveh5(origparamsdir/'0 testiono.h5')
    funcnamelist=['spectrums','radardata','fitting']
    failflag = runsim.main(funcnamelist,testpath, testpath/'PFISRExample.ini',True)
    if not failflag:
        analysisdump(testpath,str(testpath/'PFISRExample.ini'))
Пример #9
0
def makeinputh5(Iono, basedir):
    basedir = Path(basedir).expanduser()

    Param_List = Iono.Param_List
    dataloc = Iono.Cart_Coords
    times = Iono.Time_Vector
    velocity = Iono.Velocity
    zlist, idx = sp.unique(dataloc[:, 2], return_inverse=True)
    siz = list(Param_List.shape[1:])
    vsiz = list(velocity.shape[1:])

    datalocsave = sp.column_stack(
        (sp.zeros_like(zlist), sp.zeros_like(zlist), zlist))
    outdata = sp.zeros([len(zlist)] + siz)
    outvel = sp.zeros([len(zlist)] + vsiz)

    for izn, iz in enumerate(zlist):
        arr = sp.argwhere(idx == izn)
        outdata[izn] = sp.mean(Param_List[arr], axis=0)
        outvel[izn] = sp.mean(velocity[arr], axis=0)

    Ionoout = IonoContainer(datalocsave,
                            outdata,
                            times,
                            Iono.Sensor_loc,
                            ver=0,
                            paramnames=Iono.Param_Names,
                            species=Iono.Species,
                            velocity=outvel)

    ofn = basedir / 'startdata.h5'
    print('writing {}'.format(ofn))
    Ionoout.saveh5(str(ofn))
Пример #10
0
def makedatasets(maindir='~/DATA/Ion_Comp_Exp/',
                 nomult=sp.arange(1, 5, dtype=float),
                 baud_len=[7, 14, 21]):
    """
        This will make all of the data sets.
    """
    basepath = Path(maindir).expanduser()
    basepath.mkdir(exist_ok=True)
    iono_orig = pyglowinput()
    nion = len(iono_orig.Species) - 1
    npulses = 1000
    (sensdict, simparams) = getdefualtparams()
    tint = simparams['IPP'] * npulses
    ratio1 = tint / simparams['Tint']
    simparams['RangeLims'] = [80., 750.]
    simparams['Tint'] = ratio1 * simparams['Tint']
    simparams['Fitinter'] = ratio1 * simparams['Fitinter']
    simparams['TimeLim'] = 12 * tint
    ts = simparams['t_s']
    simparams['beamrate'] = 1
    simparams['outangles'] = [[0]]
    simparams['species'] = ['O+', 'NO+', 'O2+', 'H+', 'e-']
    origtime = iono_orig.Time_Vector[0, 0]

    for imult in nomult:
        curiono = iono_orig.copy()
        curiono.Param_List[:, :, 1, 0] *= imult
        ratio = curiono.Param_List[:, :, -1, 0] / curiono.Param_List[:, :, :-1,
                                                                     0].sum(-1)
        ratio_ar = sp.repeat(ratio[:, :, sp.newaxis], nion, axis=-1)
        curiono.Param_List[:, :, :-1, 0] *= ratio_ar
        figout = plotiono(curiono)[0]
        for ibaud in baud_len:
            newpath = basepath.joinpath('NOMult{0:02d}baud{1:02d}'.format(
                int(imult), int(ibaud)))
            newpath.joinpath('Origparams').mkdir(exist_ok=True, parents=True)
            figname = newpath.joinpath('InputParams.png')
            figout.savefig(str(figname))
            dataname = newpath.joinpath('Origparams',
                                        '{0:d}Params.h5'.format(origtime))
            curiono.saveh5(str(dataname))
            simparams['Pulselength'] = ibaud * ts
            sfile = str(newpath / 'startfile.h5')
            iono_orig.saveh5(sfile)
            simparams['startfile'] = sfile
            makeconfigfile(str(newpath / 'chem_test.yml'), [23465.],
                           'millstone', simparams)
Пример #11
0
def main(input_str=None):
    args_commd = parse_command_line(input_str)
    if args_commd.path is None:
        curloc = Path(__file__).resolve()
        testpath = curloc.parent.parent / 'Testdata' / 'Barker'
    else:
        testpath = Path(args_commd.path)

    origparamsdir = testpath / 'Origparams'
    testpath.mkdir(exist_ok=True, parents=True)
    print("Making a path for testdata at {}".format(testpath))

    origparamsdir.mkdir(exist_ok=True, parents=True)
    print("Making a path for testdata at {}".format(origparamsdir))
    makeconfigfilebarker(testpath)

    if args_commd.makeorigdata:
        Icont1 = MakeTestIonoclass(testv=True,
                                   testtemp=False,
                                   N_0=1e12,
                                   z_0=150.0,
                                   H_0=50.0)
        makeinputh5(Icont1, str(testpath))
        Icont1.saveh5(str(origparamsdir.joinpath('0 testiono.h5')))

    funcnamelist = args_commd.funclist

    failflag = runsim.main(funcnamelist, testpath,
                           str(testpath.joinpath('barkertest.yml')), True)
    if not failflag:
        analysisdump(testpath, testpath.joinpath('barkertest.yml'))
Пример #12
0
def applymat(basedir, configfile, optinputs):
    """
        This function apply the matrix version of the space time ambiugty function
        to the ACFs and save the outcome in h5 files within the directory ACFMat.
        Inputs:
        basedir: A string for the directory that will hold all of the data for the simulation.
        configfile: The configuration file for the simulation.
    """
    dirio = ('Spectrums', 'Mat', 'ACFMat')
    basedir = Path(basedir)
    inputdir = basedir.joinpath(dirio[0])
    outputdir2 = basedir.joinpath(dirio[2])

    dirlist = [str(i) for i in inputdir.glob('*.h5')]
    (listorder, timevector, _, _, _) = IonoContainer.gettimes(dirlist)
    ionolist = [dirlist[ikey] for ikey in listorder]
    rsto = RadarSpaceTimeOperator(ionolist, configfile, timevector, mattype='matrix')
    ionoout = rsto.mult_iono(ionolist)
    outfile = outputdir2.joinpath('00lags.h5')
    ionoout.saveh5(str(outfile))
Пример #13
0
def makedata(testpath,tint):
    """ This will make the input data for the test case. The data will have cases
        where there will be enhancements in Ne, Ti and Te in one location. Each
        case will have 3 integration periods. The first 3 integration periods will
        be the default set of parameters Ne=Ne=1e11 and Te=Ti=2000.
        Inputs
            testpath - Directory that will hold the data.
            tint - The integration time in seconds.
    """
    testpath = Path(testpath).expanduser()
    finalpath = testpath.joinpath('Origparams')
    if not finalpath.is_dir():
        finalpath.mkdir()
    data = sp.array([[1e11,1100.], [1e11,2100.]])
    z = (50.+sp.arange(50)*10.)
    nz = len(z)
    params = sp.tile(data[sp.newaxis, sp.newaxis],(nz, 1, 1, 1))
    epnt = range(20,22)
    p2 = sp.tile(params, (1, 4, 1, 1))
    #enhancement in Ne
    p2[epnt, 1, :, 0] = 5e11
    #enhancement in Ti
    p2[epnt,2,0,1] = 2200.
    #enhancement in Te
    p2[epnt,3,1,1] = 4200.
    coords = sp.column_stack((sp.zeros(nz), sp.zeros(nz), z))
    species=['O+', 'e-']
    times = sp.array([[0, 1e3]])
    times2 = sp.column_stack((sp.arange(0, 4), sp.arange(1, 5)))*3*tint
    vel = sp.zeros((nz, 1, 3))
    vel2 = sp.zeros((nz, 4, 3))
    Icontstart = IonoContainer(coordlist=coords, paramlist=params, times=times,
                               sensor_loc=sp.zeros(3), ver=0, coordvecs=['x', 'y', 'z'],
                               paramnames=None, species=species, velocity=vel)
    Icont1 = IonoContainer(coordlist=coords, paramlist=p2, times=times2,
                           sensor_loc=sp.zeros(3), ver=0, coordvecs=['x', 'y', 'z'],
                           paramnames=None, species=species, velocity=vel2)

    finalfile = finalpath.joinpath('0 stats.h5')
    Icont1.saveh5(str(finalfile))
    Icontstart.saveh5(str(testpath.joinpath('startfile.h5')))
Пример #14
0
def makeconfigfilebarker(testpath):
    testpath = Path(testpath).expanduser()

    beamlist = [
        64094, 64091, 64088, 64085, 64082, 64238, 64286, 64070, 64061, 64058,
        64055, 64052, 64049, 64046, 64043, 64067, 64040, 64037, 64034
    ]
    radarname = 'pfisr'

    Tint = 4.0 * 60.0
    time_lim = 3.0 * Tint
    pulse = GenBarker(7)
    rng_lims = [75.0, 250.0]
    IPP = .0087
    NNs = 28
    NNp = 100
    t_s = 2e-5
    Pulselength = len(pulse) * t_s
    simparams = {
        'IPP': IPP,
        'TimeLim': time_lim,
        'RangeLims': rng_lims,
        'Pulse': pulse,
        'Pulsetype': 'barker',
        'Pulselength': Pulselength,
        't_s': t_s,
        'Tint': Tint,
        'Fitinter': Tint,
        'NNs': NNs,
        'NNp': NNp,
        'dtype': sp.complex128,
        'ambupsamp': 30,
        'species': ['O+', 'e-'],
        'numpoints': 128,
        'FitType': 'acf',
        'startfile': str(testpath.joinpath('startdata.h5'))
    }

    fn = testpath / 'barkertest.yml'

    makeconfigfile(fn, beamlist, radarname, simparams)
Пример #15
0
def makedatasets(maindir='~/DATA/Ion_Comp_Exp/', nomult=sp.arange(1, 5, dtype=float), baud_len=[7, 14, 21]):
    """
        This will make all of the data sets.
    """
    basepath = Path(maindir).expanduser()
    basepath.mkdir(exist_ok=True)
    iono_orig = pyglowinput()
    nion = len(iono_orig.Species)-1
    npulses = 1000
    (sensdict, simparams) = getdefualtparams()
    tint = simparams['IPP']*npulses
    ratio1 = tint/simparams['Tint']
    simparams['RangeLims'] = [80., 750.]
    simparams['Tint'] = ratio1 * simparams['Tint']
    simparams['Fitinter'] = ratio1 * simparams['Fitinter']
    simparams['TimeLim'] = 12*tint
    ts = simparams['t_s']
    simparams['beamrate'] = 1
    simparams['outangles'] = [[0]]
    simparams['species'] = ['O+', 'NO+', 'O2+', 'H+', 'e-']
    origtime = iono_orig.Time_Vector[0,0]

    for imult in nomult:
        curiono = iono_orig.copy()
        curiono.Param_List[:, :, 1, 0] *= imult
        ratio = curiono.Param_List[:, :, -1, 0]/curiono.Param_List[:, :, :-1, 0].sum(-1)
        ratio_ar = sp.repeat(ratio[:, :, sp.newaxis], nion, axis=-1)
        curiono.Param_List[:, :, :-1, 0] *= ratio_ar
        figout = plotiono(curiono)[0]
        for ibaud in baud_len:
            newpath = basepath.joinpath('NOMult{0:02d}baud{1:02d}'.format(int(imult), int(ibaud)))
            newpath.joinpath('Origparams').mkdir(exist_ok=True, parents=True)
            figname = newpath.joinpath('InputParams.png')
            figout.savefig(str(figname))
            dataname = newpath.joinpath('Origparams', '{0:d}Params.h5'.format(origtime))
            curiono.saveh5(str(dataname))
            simparams['Pulselength'] = ibaud*ts
            sfile = str(newpath/'startfile.h5')
            iono_orig.saveh5(sfile)
            simparams['startfile'] = sfile
            makeconfigfile(str(newpath/'chem_test.yml'), [23465.], 'millstone', simparams)
Пример #16
0
def configfilesetup(testpath,npulses):
    """ This will create the configureation file given the number of pulses for 
        the test. This will make it so that there will be 12 integration periods 
        for a given number of pulses.
        Input
            testpath - The location of the data.
            npulses - The number of pulses. 
    """
    
    curloc = Path(__file__).resolve().parent
    defcon = curloc.joinpath('statsbase.ini')
    
    (sensdict,simparams) = readconfigfile(defcon)
    tint = simparams['IPP']*npulses
    ratio1 = tint/simparams['Tint']
    simparams['Tint']=ratio1 * simparams['Tint']
    simparams['Fitinter'] = ratio1 * simparams['Fitinter']
    simparams['TimeLim'] = ratio1 * simparams['TimeLim']
    
    simparams['startfile']='startfile.h5'
    makeconfigfile(testpath.joinpath('stats.ini'),simparams['Beamlist'],sensdict['Name'],simparams)
Пример #17
0
def configfilesetup(testpath,npulses):
    """ This will create the configureation file given the number of pulses for
        the test. This will make it so that there will be 12 integration periods
        for a given number of pulses.
        Input
            testpath - The location of the data.
            npulses - The number of pulses.
    """

    curloc = Path(__file__).resolve().parent
    defcon = curloc.joinpath('statsbase.ini')

    (sensdict, simparams) = readconfigfile(defcon)
    tint = simparams['IPP']*npulses
    ratio1 = tint/simparams['Tint']
    simparams['Tint'] = ratio1 * simparams['Tint']
    simparams['Fitinter'] = ratio1 * simparams['Fitinter']
    simparams['TimeLim'] = ratio1 * simparams['TimeLim']

    simparams['startfile'] = 'startfile.h5'
    makeconfigfile(testpath.joinpath('stats.ini'),simparams['Beamlist'],sensdict['Name'],simparams)
Пример #18
0
def makeconfigfilebarker(testpath):
    testpath = Path(testpath).expanduser()

    beamlist = [64094,64091,64088,64085,64082,64238,64286,64070,64061,64058,64055,64052,
                64049,64046,64043,64067,64040,64037,64034]
    radarname = 'pfisr'

    Tint = 4.0*60.0
    time_lim = 3.0*Tint
    pulse = GenBarker(7)
    rng_lims = [75.0,250.0]
    IPP = .0087
    NNs = 28
    NNp = 100
    t_s=2e-5
    Pulselength=len(pulse)*t_s
    simparams =   {'IPP':IPP,
                   'TimeLim':time_lim,
                   'RangeLims':rng_lims,
                   'Pulse':pulse,
                   'Pulsetype':'barker',
                   'Pulselength':Pulselength,
                   't_s':t_s,
                   'Tint':Tint,
                   'Fitinter':Tint,
                   'NNs': NNs,
                   'NNp':NNp,
                   'dtype':sp.complex128,
                   'ambupsamp':30,
                   'species':['O+','e-'],
                   'numpoints':128,
                   'FitType':'acf',
                   'startfile':str(testpath.joinpath('startdata.h5'))}

    fn = testpath/'barkertest.yml'

    makeconfigfile(fn,beamlist,radarname,simparams)
Пример #19
0
def configfilesetup(testpath, npulses, radar='PFISR'):
    """ This will create the configureation file given the number of pulses for
        the test. This will make it so that there will be 12 integration periods
        for a given number of pulses.
        Input
            testpath - The location of the data.
            npulses - The number of pulses.
    """
    testpath = Path(testpath).expanduser()
    curloc = Path(__file__).resolve().parent
    if radar.lower() == 'pfisr':
        defcon = curloc / 'statsbase.ini'
    elif radar.lower() == 'millstonez':
        defcon = curloc / 'statsbasemhz.yml'
    (sensdict, simparams) = readconfigfile(defcon)
    tint = simparams['IPP'] * npulses
    ratio1 = tint / simparams['Tint']
    simparams['Tint'] = ratio1 * simparams['Tint']
    simparams['Fitinter'] = ratio1 * simparams['Fitinter']
    simparams['TimeLim'] = 2 * tint
    simparams['fitmode'] = 1
    simparams['startfile'] = 'startfile.h5'
    makeconfigfile(str(testpath / 'stats.yml'), simparams['Beamlist'],
                   sensdict['Name'], simparams)
Пример #20
0
def main(funcnamelist):
    """This function will run the test simulation buy first making a simple set of
    ionospheric parameters based off of a Chapman function. Then it will create configuration
    and start files followed by running the simulation."""
    curpath = Path(__file__).resolve().parent
    testpath = curpath / 'Testdata' / 'DishMode'
    origparamsdir = testpath / 'Origparams'

    testpath.mkdir(exist_ok=True, parents=True)

    origparamsdir.mkdir(exist_ok=True, parents=True)

    if 'configupdate' in funcnamelist:
        configsetup(testpath)
        funcnamelist.remove('configupdate')
    # clear everything out
    folddict = {
        'origdata': ['Origparams'],
        'spectrums': ['Spectrums'],
        'radardata': ['ACF', 'Radardata'],
        'fitting': ['Fitted']
    }
    folderlist = []
    for i in funcnamelist:
        folderlist = folderlist + folddict[i]
#    folderlist = ['Origparams','Spectrums','Radardata','ACF','Fitted']
    for ifl in folderlist:
        flist = (testpath / ifl).glob('*.h5')
        for ifile in flist:
            ifile.unlink()
    # Now make stuff again

    if 'origdata' in funcnamelist:

        Icont1 = MakeTestIonoclass(testv=True, testtemp=True)
        makeinputh5(MakeTestIonoclass(testv=True, testtemp=False), testpath)
        Icont1.saveh5(origparamsdir / '0 testiono.h5')
        funcnamelist.remove('origdata')


#    funcnamelist=['spectrums','radardata','fitting']
    failflag = runsim.main(funcnamelist, testpath,
                           testpath / 'DishExample.ini', True)
    if not failflag:
        analysisdump(testpath, testpath / 'DishExample.ini')
Пример #21
0
def configsetup(testpath):
    """This function will make a pickle file used to configure the simulation.
    Inputs
    testpath - A string for the path that this file will be saved."""
    testpath=Path(testpath)
    beamlist = [64094,64091,64088,64085,64082,64238,64286,64070,64061,64058,64055,64052,
                64049,64046,64043,64067,64040,64037,64034] # list of beams in
    radarname = 'pfisr'# name of radar for parameters can either be pfisr or risr

    Tint=60.0 # integration time in seconds
    time_lim = 4.0*Tint # simulation length in seconds
    fitter_int = 60.0 # time interval between fitted params
#    pulse = sp.ones(14)# pulse
    rng_lims = [150,500]# limits of the range gates
    IPP = .0087 #interpulse period in seconds
    NNs = 28 # number of noise samples per pulse
    NNp = 100 # number of noise pulses
    simparams =   {'IPP':IPP, #interpulse period
                   'TimeLim':time_lim, # length of simulation
                   'RangeLims':rng_lims, # range swath limit
#                   'Pulse':pulse, # pulse shape
                   'Pulselength':280e-6,
                   'FitType' :'acf',
                   't_s': 20e-6,
                   'Pulsetype':'long', # type of pulse can be long or barker,
                   'Tint':Tint, #Integration time for each fitting
                   'Fitinter':fitter_int, # time interval between fitted params
                   'NNs': NNs,# number of noise samples per pulse
                   'NNp':NNp, # number of noise pulses
                   'dtype':sp.complex128, #type of numbers used for simulation
                   'ambupsamp':1, # up sampling factor for ambiguity function
                   'species':['O+','e-'], # type of ion species used in simulation
                   'numpoints':128, # number of points for each spectrum
                   'startfile': str(testpath/'startdata.h5')} # file used for starting points
#                   'SUMRULE': sp.array([[-2,-3,-3,-4,-4,-5,-5,-6,-6,-7,-7,-8,-8,-9]
#                       ,[1,1,2,2,3,3,4,4,5,5,6,6,7,7]])}

    fname = testpath/'PFISRExample'

    makeconfigfile(str(fname.with_suffix('.ini')),beamlist,radarname,simparams)
Пример #22
0
def makespectrums(basedir, configfile, printlines=True):
    """ This will make all of the spectra for a set of data and save it in a
    folder in basedir called Spectrums. It is assumed that the data in the Origparams
    is time tagged in the title with a string seperated by a white space and the
    rest of the file name. For example ~/DATA/Basedir/0 origdata.h5.
    Inputs:
        basedir: A string for the directory that will hold all of the data for the simulation.
        configfile: The configuration file for the simulation.
         """
    basedir = Path(basedir).expanduser()
    dirio = ('Origparams', 'Spectrums')
    inputdir = basedir/dirio[0]
    outputdir = basedir/dirio[1]
    # determine the list of h5 files in Origparams directory
    dirlist = sorted(inputdir.glob('*.h5'))
    # Make the lists of numbers and file names for the dictionary
    (listorder, _, _, timebeg, _) = IonoContainer.gettimes(dirlist)
    slist = [dirlist[ikey] for ikey in listorder]
    (sensdict, simparams) = readconfigfile(configfile)
    # Delete data
    outfiles = outputdir.glob('*.h5')
    for ifile in outfiles:
        ifile.unlink()

    for inum, curfile in zip(timebeg, slist):

        outfile = outputdir / (str(inum)+' spectrum.h5')
        update_progress(float(inum)/float(len(slist)),
                        'Processing file {} starting at {}'.format(curfile.name, datetime.now()))
        curiono = IonoContainer.readh5(str(curfile))

        curiono.makespectruminstanceopen(specfuncs.ISRSspecmake, sensdict,
                                         int(simparams['numpoints']), float(inum),
                                         float(len(slist)), printlines).saveh5(str(outfile))
        update_progress(float(inum+1)/float(len(slist)),
                        'Finished file {} starting at {}'.format(curfile.name, datetime.now()))
Пример #23
0
        Icont1.saveh5(origparamsdir / '0 testiono.h5')
        funcnamelist.remove('origdata')


#    funcnamelist=['spectrums','radardata','fitting']
    failflag = runsim.main(funcnamelist, testpath,
                           testpath / 'DishExample.ini', True)
    if not failflag:
        analysisdump(testpath, testpath / 'DishExample.ini')

if __name__ == '__main__':
    from argparse import ArgumentParser
    p = ArgumentParser(
        description=
        'Planeproc.py -f <function: configupdate, origdata, spectrums, radardata, fitting or all>'
    )
    p.add_argument('-f', '--funcnamelist', nargs='+')
    p.add_argument('-r', '--re', action='store_true')
    p = p.parse_args()

    curpath = Path(__file__).resolve().parent

    remakealldata = p.re

    if p.funcnamelist is None or 'all' in p.funcnamelist:
        funcnamelist = [
            'configupdate', 'origdata', 'spectrums', 'radardata', 'fitting'
        ]

    main(funcnamelist)
Пример #24
0
fittersimple.py
This module will implement a simple fitter for ISR spectra.
@author: John Swoboda
"""

import scipy as sp
import scipy.optimize
from SimISR import Path
from SimISR.IonoContainer import IonoContainer, makeionocombined
from SimISR.utilFunctions import readconfigfile, update_progress,spect2acf
import SimISR.specfunctions as specfuncs

PVALS = [1e11, 2.1e3, 1.1e3, 0.]
SVALS = [1.1e3, 1e11, 2.1e3, 0.]
SIMVALUES = sp.array([[PVALS[0],PVALS[2]],[PVALS[0],PVALS[1]]])
curloc = Path(__file__).resolve().parent
defcon = curloc/'statsbase.ini'

def runfitter(paramdict, SNR, n_pulses, n_runs, Niratio, x_0=SVALS):
    """
        paramdict
    """

    data = SIMVALUES
    z = sp.linspace(50., 1e3, 50)
    nz = len(z)
    params = sp.tile(data[sp.newaxis, sp.newaxis, :, :], (nz, 1, 1, 1))
    coords = sp.column_stack((sp.ones(nz), sp.ones(nz), z))
    species = ['O+', 'e-']
    times = sp.array([[0, 1e9]])
    vel = sp.zeros((nz, 1, 3))
Пример #25
0
def makehistdata(params, maindir):
    """ This will make the histogram data for the statistics.
        Inputs
            params -  A list of parameters that will have statistics created
            maindir - The directory that the simulation data is held.
        Outputs
            datadict - A dictionary with the data values in numpy arrays. The keys are param names.
            errordict - A dictionary with the data values in numpy arrays. The keys are param names.
            errdictrel -  A dictionary with the error values in numpy arrays, normalized by the correct value. The keys are param names.
    """
    maindir = Path(maindir)
    ffit = maindir.joinpath('Fitted', 'fitteddata.h5')
    inputfiledir = maindir.joinpath('Origparams')

    paramslower = [ip.lower() for ip in params]
    eparamslower = ['n' + ip.lower() for ip in params]

    # set up data dictionary

    errordict = {ip: [] for ip in params}
    errordictrel = {ip: [] for ip in params}
    #Read in fitted data

    Ionofit = IonoContainer.readh5(str(ffit))
    times = Ionofit.Time_Vector

    dataloc = Ionofit.Sphere_Coords
    rng = dataloc[:, 0]
    rng_log = sp.logical_and(rng > 200., rng < 400)
    dataloc_out = dataloc[rng_log]
    pnames = Ionofit.Param_Names
    pnameslower = sp.array([ip.lower() for ip in pnames.flatten()])
    p2fit = [
        sp.argwhere(ip == pnameslower)[0][0] if ip in pnameslower else None
        for ip in paramslower
    ]

    datadict = {
        ip: Ionofit.Param_List[rng_log, :, p2fit[ipn]].flatten()
        for ipn, ip in enumerate(params)
    }

    ep2fit = [
        sp.argwhere(ip == pnameslower)[0][0] if ip in pnameslower else None
        for ip in eparamslower
    ]

    edatadict = {
        ip: Ionofit.Param_List[rng_log, :, ep2fit[ipn]].flatten()
        for ipn, ip in enumerate(params)
    }
    # Determine which input files are to be used.

    dirlist = [str(i) for i in inputfiledir.glob('*.h5')]
    _, outime, filelisting, _, _ = IonoContainer.gettimes(dirlist)
    time2files = []
    for itn, itime in enumerate(times):
        log1 = (outime[:, 0] >= itime[0]) & (outime[:, 0] < itime[1])
        log2 = (outime[:, 1] > itime[0]) & (outime[:, 1] <= itime[1])
        log3 = (outime[:, 0] <= itime[0]) & (outime[:, 1] > itime[1])
        tempindx = sp.where(log1 | log2 | log3)[0]
        time2files.append(filelisting[tempindx])

    curfilenum = -1
    for iparam, pname in enumerate(params):
        curparm = paramslower[iparam]
        # Use Ne from input to compare the ne derived from the power.
        if curparm == 'nepow':
            curparm = 'ne'
        datalist = []
        for itn, itime in enumerate(times):
            for filenum in time2files[itn]:
                filenum = int(filenum)
                if curfilenum != filenum:
                    curfilenum = filenum
                    datafilename = dirlist[filenum]
                    Ionoin = IonoContainer.readh5(datafilename)
                    if ('ti' in paramslower) or ('vi' in paramslower):
                        Ionoin = maketi(Ionoin)
                    pnames = Ionoin.Param_Names
                    pnameslowerin = sp.array(
                        [ip.lower() for ip in pnames.flatten()])
                prmloc = sp.argwhere(curparm == pnameslowerin)
                if prmloc.size != 0:
                    curprm = prmloc[0][0]
                # build up parameter vector bs the range values by finding the closest point in space in the input
                curdata = sp.zeros(len(dataloc_out))

                for irngn, curcoord in enumerate(dataloc_out):

                    tempin = Ionoin.getclosestsphere(curcoord, [itime])[0]
                    Ntloc = tempin.shape[0]
                    tempin = sp.reshape(tempin, (Ntloc, len(pnameslowerin)))
                    curdata[irngn] = tempin[0, curprm]
                datalist.append(curdata)
        errordict[pname] = datadict[pname] - sp.hstack(datalist)
        errordictrel[pname] = 100. * errordict[pname] / sp.absolute(
            sp.hstack(datalist))
    return datadict, errordict, errordictrel, edatadict
Пример #26
0
def main():

    curpath = Path(__file__).resolve().parents[1]
    print(curpath)
    testpath = curpath / 'Testdata' / 'MatrixTest'
    origparamsdir = testpath / 'Origparams'

    testpath.mkdir(exist_ok=True, parents=True)

    origparamsdir.mkdir(exist_ok=True, parents=True)

    # clear everything out
    folderlist = ['Origparams', 'Spectrums', 'Radardata', 'ACF', 'Fitted']
    for ifl in folderlist:
        flist = (testpath / ifl).glob('*.h5')
        for ifile in flist:
            ifile.unlink()
    # Make Config file
    configname = testpath / 'config.ini'

    if not configname.is_file():
        srcfile = curpath / 'SimISR' / 'default.ini'
        shutil.copy(str(srcfile), str(configname))

    # make the coordinates
    xvec = sp.zeros((1))
    yvec = sp.zeros((1))
    zvec = sp.arange(50.0, 900.0, 2.0)
    # Mesh grid is set up in this way to allow for use in MATLAB with a simple reshape command
    xx, zz, yy = sp.meshgrid(xvec, zvec, yvec)
    coords = sp.zeros((xx.size, 3))
    coords[:, 0] = xx.flatten()
    coords[:, 1] = yy.flatten()
    coords[:, 2] = zz.flatten()
    Z_0 = 250.
    H_0 = 30.
    N_0 = 6.5e11
    Icont1 = MakeTestIonoclass(testv=True,
                               testtemp=True,
                               N_0=N_0,
                               z_0=Z_0,
                               H_0=H_0,
                               coords=coords)
    Icont1.saveh5(origparamsdir / '0 testiono.h5')
    Icont1.saveh5(testpath / 'startdata.h5')
    funcnamelist = ['spectrums', 'applymat', 'fittingmat']
    runsim.main(funcnamelist, testpath, configname, True)

    plotdir = testpath / 'AnalysisPlots'

    plotdir.mkdir(exist_ok=True, parents=True)

    f_templ = str(plotdir / 'params')

    plotbeamparametersv2([0.],
                         str(configname),
                         str(testpath),
                         fitdir='FittedMat',
                         params=['Ne', 'Ti', 'Te'],
                         filetemplate=f_templ,
                         suptitle='With Mat',
                         werrors=False,
                         nelog=False)
Пример #27
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 = int(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 = int(sp.ceil(Npall / len(beam3)))
            leftover = int(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 = outdir.parent
        self.procdir = self.maindir / 'ACF'
        Nf = len(filetimes)
        progstr = 'Data from {:d} of {:d} being processed Name: {:s}.'
        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]
                ifilename = Path(ifile).name
                update_progress(
                    float(ifn) / Nf, progstr.format(ifn, Nf, ifilename))
                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)
                d_shape = rawdata.shape
                n_tempr = sp.random.randn(*d_shape).astype(simdtype)
                n_tempi = 1j * sp.random.randn(*d_shape).astype(simdtype)
                noise = sp.sqrt(Noisepwr / 2) * (n_tempr + n_tempi)
                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 = self.datadir / fname
                self.outfilelist.append(str(newfn))
                dict2h5(str(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(str(outdir.joinpath('INFO.h5')), infodict)

        else:
            infodict = h52dict(str(outdir.joinpath('INFO.h5')))
            alltime = sp.hstack(infodict['Time'])
            self.timeoffset = alltime.min()
            self.outfilelist = outfilelist
Пример #28
0
def makehistdata(params,maindir):
    """ This will make the histogram data for the statistics.
        Inputs
            params -  A list of parameters that will have statistics created
            maindir - The directory that the simulation data is held.
        Outputs
            datadict - A dictionary with the data values in numpy arrays. The keys are param names.
            errordict - A dictionary with the data values in numpy arrays. The keys are param names.
            errdictrel -  A dictionary with the error values in numpy arrays, normalized by the correct value. The keys are param names.
    """
    maindir=Path(maindir)
    ffit = maindir.joinpath('Fitted','fitteddata.h5')
    inputfiledir = maindir.joinpath('Origparams')

    paramslower = [ip.lower() for ip in params]
    eparamslower = ['n'+ip.lower() for ip in params]
    
    # set up data dictionary
    
    errordict = {ip:[] for ip in params}
    errordictrel = {ip:[] for ip in params}
    #Read in fitted data
    
    Ionofit = IonoContainer.readh5(ffit)
    times=Ionofit.Time_Vector
    
    dataloc = Ionofit.Sphere_Coords
    pnames = Ionofit.Param_Names
    pnameslower = sp.array([ip.lower() for ip in pnames.flatten()])
    p2fit = [sp.argwhere(ip==pnameslower)[0][0] if ip in pnameslower else None for ip in paramslower]
    
    datadict = {ip:Ionofit.Param_List[:,:,p2fit[ipn]].flatten() for ipn, ip in enumerate(params)}
    
    ep2fit = [sp.argwhere(ip==pnameslower)[0][0] if ip in pnameslower else None for ip in eparamslower]
    
    edatadict = {ip:Ionofit.Param_List[:,:,ep2fit[ipn]].flatten() for ipn, ip in enumerate(params)}
    # Determine which input files are to be used.
    
    dirlist = [str(i) for i in inputfiledir.glob('*.h5')]
    sortlist,outime,filelisting,timebeg,timelist_s = IonoContainer.gettimes(dirlist)
    time2files = []
    for itn,itime in enumerate(times):
        log1 = (outime[:,0]>=itime[0]) & (outime[:,0]<itime[1])
        log2 = (outime[:,1]>itime[0]) & (outime[:,1]<=itime[1])
        log3 = (outime[:,0]<=itime[0]) & (outime[:,1]>itime[1])
        tempindx = sp.where(log1|log2|log3)[0]
        time2files.append(filelisting[tempindx])
    
    
    curfilenum=-1
    for iparam,pname in enumerate(params):            
        curparm = paramslower[iparam]
        # Use Ne from input to compare the ne derived from the power.
        if curparm == 'nepow':
            curparm = 'ne'
        datalist = []
        for itn,itime in enumerate(times):
            for iplot,filenum in enumerate(time2files[itn]):
                filenum = int(filenum)
                if curfilenum!=filenum:
                    curfilenum=filenum
                    datafilename = dirlist[filenum]
                    Ionoin = IonoContainer.readh5(datafilename)
                    if ('ti' in paramslower) or ('vi' in paramslower):
                        Ionoin = maketi(Ionoin)
                    pnames = Ionoin.Param_Names
                    pnameslowerin = sp.array([ip.lower() for ip in pnames.flatten()])
                prmloc = sp.argwhere(curparm==pnameslowerin)
                if prmloc.size !=0:
                    curprm = prmloc[0][0]
                # build up parameter vector bs the range values by finding the closest point in space in the input
                curdata = sp.zeros(len(dataloc))
                
                for irngn, curcoord in enumerate(dataloc):
                    
                    tempin = Ionoin.getclosestsphere(curcoord,[itime])[0]
                    Ntloc = tempin.shape[0]
                    tempin = sp.reshape(tempin,(Ntloc,len(pnameslowerin)))
                    curdata[irngn] = tempin[0,curprm]
                datalist.append(curdata)
        errordict[pname] = datadict[pname]-sp.hstack(datalist)
        errordictrel[pname] = 100.*errordict[pname]/sp.absolute(sp.hstack(datalist))
    return datadict,errordict,errordictrel,edatadict
Пример #29
0
                the full simulation. The user can also start with a directory
                from a later stage of the simulation instead though.

            -c The configuration used for the simulation. Can be an ini file or
                a pickle file.

            Optional arguments

            -r If a y follows this then the raw radar data will be remade. If
                this is not used the radar data will only be made if it does
                not exist in the file first.

             Example:
             python runsim.py -f radardata -f fitting -i ~/DATA/ExampleLongPulse -c ~/DATA/Example -r y'''

    args_commd = parse_command_line()
    if args_commd.path is None:
        print("Please provide an input source with the -p option!")
        sys.exit(1)
    basedir =  str(Path(args_commd.path).expanduser())
    configfile = str(Path(args_commd.config).expanduser())
    funcname = args_commd.funclist
    remakealldata = args_commd.remake

    if funcname.lower() == 'all':
        funcnamelist = ['spectrums', 'radardata', 'fitting']
    else:
        funcnamelist = funcname.split()

    failflag = main(funcnamelist, basedir, configfile, remakealldata)
Пример #30
0
    axmat[0].set_xlim([maxden*1e-5, maxden])
    axmat[0].set_xlabel(r'Densities in m$^{-3}$')
    axmat[0].set_ylabel('Alt in km')
    axmat[0].legend()

    axmat[1].set_title('Temperture')
    axmat[1].set_xlim([100., 2500.])
    axmat[1].set_xlabel(r'Temp in $^{\circ}$ K')
    axmat[1].set_ylabel('Alt in km')
    axmat[1].legend()
    plt.tight_layout()
    return figmplf,axmat


if __name__ == '__main__':
    exppath = Path('~/DATA/Ion_Comp_Exp').expanduser()
    drpath = Path('~/Dropbox (MIT)/').expanduser()
    funclist = ['spectrums', 'radardata','fitting']
    list1 = [i for i in exppath.glob('NO*')]
    configlist = [i.joinpath('chem_test.yml') for i in exppath.glob('NO*')]

    for idata,icon in zip(list1,configlist):
        runsimisr(funclist,str(idata),str(icon),True)

    for idata,icon in zip(list1,configlist):
        analysisdump(str(idata),str(icon),params = ['Ne','Nepow','Te','Ti'])

    for ipath in list1:
        idir=ipath.joinpath('AnalysisPlots')
        idest = drpath.joinpath(*ipath.parts[-2:])
        shutil.copytree(str(idir),str(idest))
Пример #31
0
def main(funcnamelist,basedir,configfile,remakealldata,fitlist=None,invtype='',printlines=True):
    """ Main function for this module. The function will set up the directory
    structure, create or update a diary file and run the simulation depending
    on the user input.
    Inputs
        funcnamelist: A list of strings that coorespond to specific functions.
                The stirng and function they correspond to, that will be shown.

                 spectrums: makespectrums, This will create the ISR spectrums

                 radardata :makeradardata, This will make the radar data and
                     form the ACF estimates. If the raw radar data exists then
                     the user must use the -r option on the command line and set
                     it to y.

                 fitting :fitdata, This will apply the fitter to the data in
                 the ACF folder of the base directory.

                 fittingmat :fitdata,This will apply the fitter to the data in
                 the ACFMat folder of the base directory.

                 fittinginv :fitdata,This will apply the fitter to the data in
                 the ACFInv folder of the base directory.

                 applymat :applymat, This wil create and apply a matrix
                 formulation of thespace-time ambiguity function to ISR spectrums.
        basedir: The base directory that will contain all of the data. This directory
                must contain a directory called Origparams with h5 files to run
                the full simulation. The user can also start with a directory
                from a later stage of the simulation instead though.

        configfile: The configuration used for the simulation. Can be an ini file or
                a pickle file.

        remakealldata: A bool to determine if the raw radar data will be remade. If
                this is False the radar data will only be made if it does
                not exist in the file first.
        fitlist:  A list of time entries that will be fit.

        invtype

    """

    inputsep = '***************************************************************\n'

    funcdict = {'spectrums':makespectrums, 'radardata':makeradardata, 'fitting':fitdata,'fittingmat':fitdata,
                'fittinginv':fitdata,'applymat':applymat,'fittingmatinv':fitdata}
    #inout = {'spectrums':('Origparams','Spectrums'),'radardata':('Spectrums','Radardata'),'fitting':('ACF','Fitted')}
    #pdb.set_trace()

    # check for the directories
    dirnames = ['Origparams','Spectrums','Radardata','ACF','Fitted','ACFOrig','ACFMat','ACFInv','FittedMat','FittedInv','ACFMatInv','FittedMatInv']
    basedir=Path(basedir).expanduser()
    for idir in dirnames:
        curdir = basedir/idir
        curdir.mkdir(exist_ok=True,parents=True)

    if len(funcnamelist)==3:
        funcname='all'
    else:
        funcname=''.join(funcnamelist)

    dfilename = 'diary'+funcname+'.txt'
    dfullfilestr = basedir/dfilename

    with open(str(dfullfilestr),'a') as f:
        failure=False
        for curfuncn in funcnamelist:
            curfunc = funcdict[curfuncn]
            f.write(inputsep)
            f.write(curfunc.__name__+'\n')
            f.write(time.asctime()+'\n')
            if curfunc.__name__=='fitdata':
                ex_inputs=[curfuncn,fitlist,invtype,printlines]
            elif curfunc.__name__=='makeradardata':
                ex_inputs = remakealldata
            else:
                ex_inputs=printlines
            try:
                stime = datetime.now()
                curfunc(basedir,configfile,ex_inputs)
                ftime = datetime.now()
                ptime = ftime-stime
                f.write('Success!\n')
                f.write('Duration: {}\n'.format(ptime))
                f.write('Base directory: {}\n'.format(basedir))

            except Exception as e:
                f.write('Failed!\n')
                ftime = datetime.now()
                ptime = ftime-stime
                f.write('Duration: {}\n'.format(ptime))
                f.write('Base directory: {}\n'.format(basedir))
                traceback.print_exc(file=sys.stdout)
                traceback.print_exc(file=f)
                failure = True
                break

        f.write(inputsep)


    return failure
Пример #32
0
    axmat[0].set_xlim([maxden * 1e-5, maxden])
    axmat[0].set_xlabel(r'Densities in m$^{-3}$')
    axmat[0].set_ylabel('Alt in km')
    axmat[0].legend()

    axmat[1].set_title('Temperture')
    axmat[1].set_xlim([100., 2500.])
    axmat[1].set_xlabel(r'Temp in $^{\circ}$ K')
    axmat[1].set_ylabel('Alt in km')
    axmat[1].legend()
    plt.tight_layout()
    return figmplf, axmat


if __name__ == '__main__':
    exppath = Path('~/DATA/Ion_Comp_Exp').expanduser()
    drpath = Path('~/Dropbox (MIT)/').expanduser()
    funclist = ['spectrums', 'radardata', 'fitting']
    list1 = [i for i in exppath.glob('NO*')]
    configlist = [i.joinpath('chem_test.yml') for i in exppath.glob('NO*')]

    for idata, icon in zip(list1, configlist):
        runsimisr(funclist, str(idata), str(icon), True)

    for idata, icon in zip(list1, configlist):
        analysisdump(str(idata), str(icon), params=['Ne', 'Nepow', 'Te', 'Ti'])

    for ipath in list1:
        idir = ipath.joinpath('AnalysisPlots')
        idest = drpath.joinpath(*ipath.parts[-2:])
        shutil.copytree(str(idir), str(idest))