当前位置: 首页>>代码示例>>Python>>正文


Python pys.test函数代码示例

本文整理汇总了Python中pys.test函数的典型用法代码示例。如果您正苦于以下问题:Python test函数的具体用法?Python test怎么用?Python test使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了test函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: manual_genboundary

def manual_genboundary(bspec,**kw):
    kwp = sd(kw,**bspec);
    getkw = mk_getkw(kwp,outletdefaults,prefer_passed = True);
    btype = getkw("type");
    lims  = getkw('lim');
    di = dict();
    for dim,lim in zip(all_lims,lims):
        di[dim] = lim;
    if btype == 'outlet':
        model = getkw('model');
        di['label']= getkw('label');
        di['phase_velocity'] = getkw('phase_velocity');
        if model == 'none':
            ret = outlet_none_tmpl.format(**di);
        elif model == 'potential':
            di = sd(manbounds_defs,**di);
            if not test(di,'connection_rank'):
                di['connection_rank'] ='';
            else:
                di['connection_rank'] = 'connection_rank {}'.format(
                    getkw('connection_rank'));
            if not test(kwp,'voltage_measurement'):
                di['voltage_measurement'] = '';
            else:
                raise NotImplementedError("haven't got to this yet...");
            di['circuit'] = di['circuit'];
            ret = outlet_pot_tmpl.format(**di);
        elif model == 'laser':
            raise NotImplementedError("need to implement the laser...");
        else:
            raise ValueError("unknown outlet model {}".format(model));
    else:
        raise NotImplementedError("yeah...");
    return ret;
开发者ID:noobermin,项目名称:sharks,代码行数:34,代码来源:genlsp.py

示例2: mksim

def mksim(pbsbase,**d):
    print("making {}".format(pbsbase));
    myd = sd(lsp_d, **d);
    lsp=genlsp(**myd);
    #two color hack
    if test(myd, 'relative_phase'):
        relative_phases="phase {}".format(myd['relative_phase'])
    else:
        relative_phases=''
    lasers = '''
laser
wavelength 780e-7
spotsize   2.17e-4

laser
amplitude  0.36
wavelength 390e-7
{phase}
end
'''.format(phase=relative_phases);
    if test(myd, 'two_colors'):
        lsp = re.sub(r'type *19.*','type 85',lsp);
        lsp = re.sub(r' *; *\\lambda *spotsize','',lsp);
        lsp = re.sub('.*coefficients 7.80*e-03.*$', lasers,lsp,flags=re.MULTILINE);
    pbs=genpbs(pbsbase=pbsbase,domains=myd['domains']);
    pbs = re.sub("../scripts/autozipper","../../scripts/autozipper",pbs);
    pbs = re.sub("lsp-10-xy","lsp-10-xy-multilaser",pbs);
    output(lsp,pbs,pbsbase,
           dats=["sine700points.dat", myd['targetdat']],
           dir=pbsbase);
开发者ID:noobermin,项目名称:sharks,代码行数:30,代码来源:genall.py

示例3: genregions

def genregions(**kw):
    if test(kw,'region_split'):
        regs = genregions_uniform([kw['region_split']],**kw);
    elif test(kw, 'region_splits'):
        regs = genregions_uniform(kw['region_splits'],**kw);
    else:
        regs = genregions_uniform([],**kw);
    return mkregion_str(regs);
开发者ID:noobermin,项目名称:sharks,代码行数:8,代码来源:genlsp.py

示例4: gendens

def gendens(**kw):
    getkw = mk_getkw(kw, densdefaults);
    speciesl =  getkw('speciesl');
    outputfmt = "n_{}";
    if test(kw,'target_density'):
        Q = kw['target_density'];
        fracs = getkw('fracs');
        if test(kw, 'target_density_plainconst'):
            ret = {
                outputfmt.format(species) : plainconst_tmpl.format(data=Q*f)
                for species,f in zip(speciesl,fracs) };
            kw.update(ret);
            return kw;
        if type(Q) == tuple:
        #the reason for tuple and not a general iterable
        #is when we pass a single scale, for example, which
        #we scale by fracs
            pass;
        else:
            if hasattr(Q[0], '__call__'):
                Q = [  lambda x: frac*iQf(x)
                       for frac,iQf in zip(fracs,Q) ];
            else:
                Q = [ frac*iQ
                      for frac,iQ in zip(fracs,Q) ];
        if hasattr(Q[0],'__call__'):
            #invariant: txmin,txmax are in cm.
            x = np.linspace(kw['txmin'][0],kw['txmax'][1],20);
            Q[:] = [iQ(x) for iQ in Q];
        ret = {
            outputfmt.format(species) : densitypairs_tmpl.format(data = iQ)
            for species,iQ in zip(speciesl,Q) };
        kw.update(ret)
        return kw;
    else:
        kw['dens_dat'] = getkw('dens_dat');
        kw['dens_imul'] = getkw('dens_imul');
        kw['dens_type'] = getkw('dens_type');
        kw['fracs']     = getkw('fracs');
        def copy_kw(l):
            if type(kw[l]) != tuple:
                kw[l] = (kw[l],)*len(speciesl)
        copy_kw('dens_dat');
        copy_kw('dens_imul');
        copy_kw('dens_type');
        for i,species in enumerate(speciesl):
            kw['n_'+species] = densityfile_tmpl.format(
                targetdat = kw['dens_dat'][i],
                type = kw['dens_type'][i],
                imul = kw['dens_imul'][i],
                dmul = kw['fracs'][i]);
        return kw;
    pass;
开发者ID:noobermin,项目名称:sharks,代码行数:53,代码来源:genlsp.py

示例5: getkw

 def getkw(l,scale=None):
     if test(kw, l):
         if scale:
             return [scale*i for i in kw[l]];
         return kw[l];
     else:
         return defaults[l];
开发者ID:noobermin,项目名称:sharks,代码行数:7,代码来源:genlsp.py

示例6: gengrids

def gengrids(**kw):
    getkw = mk_getkw(kw,grid_defs,prefer_passed = True);
    outgrids = ['','',''];
    simple_gridtmpl = '''
{dim}min             {min:e}
{dim}max             {max:e}
{dim}-cells          {cells}''';
    vargrid_tmpl = '''
{dim}min             {min:e}
{dim}max             {max:e}
{dim}-cells          {cells}
{dim}-intervals
 d{dim}-start {dxstart:e}
{intervals}
end'''
    vargrid_intv_tmpl = " length {length:e} for {N}";
    grids = []
    for dim in 'xyz':
        if getkw('{}cells'.format(dim)) == 0:
            grids.append("");
            continue;
        vgridlabel = '{}vargrid'.format(dim);
        if test(kw,vgridlabel):
            intv = '\n'.join([
                vargrid_intv_tmpl.format(length=l, N=N)
                for l,N in getkw(vgridlabel)]);
            if test(kw, 'd{}start'.format(dim)):
                ddimstart = getkw('d{}start'.format(dim));
            else:
                l = getkw(vgridlabel)[0][0];
                N = getkw(vgridlabel)[0][1];
                ddimstart = l/N;
            grid = vargrid_tmpl.format(
                dim=dim,
                min=getkw('{}min'.format(dim)),
                max=getkw('{}max'.format(dim)),
                cells=getkw('{}cells'.format(dim)),
                dxstart=ddimstart,
                intervals=intv)
        else:                    
            grid= simple_gridtmpl.format(
                dim=dim,
                min=getkw('{}min'.format(dim)),
                max=getkw('{}max'.format(dim)),
                cells=getkw('{}cells'.format(dim)));
        grids.append(grid);
    return grids;
开发者ID:noobermin,项目名称:sharks,代码行数:47,代码来源:genlsp.py

示例7: gentemp

def gentemp(**kw):
    getkw = mk_getkw(kw, tempdefaults);
    speciesl = getkw('speciesl');
    otherfuncs = '';
    funcnum = getkw('funcnum');
    if test(kw,'target_temps'):
        Q = kw['target_temps'];
        def process_temp(iq):
            if not iq: return None;
            if hasattr(iq, '__call__'):
                xres = getkw('dat_xres')
                x = np.linspace(kw['txmin'][0],kw['txmax'][1],xres);
                iq = iq(x);
                raise ValueError("Not implemented yet!");
            elif type(iq) is dict:
                _getkw = mk_getkw(iq, species_tempdefault);
                ret = densityfile_tmpl.format(
                    targetdat = _getkw('dat'),
                    type = _getkw('type'),
                    imul = _getkw('imul'),
                    dmul = _getkw('frac'));
            return ret;                
        ss = [ process_temp(iq) for iq in Q ];
    else:
        Q = [dict()]*len(speciesl);
        ss= [None]  *len(speciesl);
    for iq,species,s,e in zip(Q,speciesl,ss,getkw('thermal_energy')):
        cur = 'thermal_energy {}\n'.format(e);
        if s:
            otherfuncs += "function{}\n".format(funcnum);
            otherfuncs += s;
            # if 'energy_flags' in iq:
            #     energyflags = iq['energy_flags'];
            # else:
            #     energyflags = getkw('energy_flags');
            cur += 'spatial_function {}\n'.format(funcnum);
            # cur += 'energy_flags {}\n'.format(
            #     joinspace([
            #         1 if i else 0
            #         for i in getkw("dens_flags")]));
            funcnum += 1;
        kw['{}_thermalopts'.format(species)] = cur;
    if otherfuncs != '':
        if not test(kw, 'other_funcs'):
            kw['other_funcs'] = ''
        kw['other_funcs'] += otherfuncs;
    return kw;
开发者ID:noobermin,项目名称:sharks,代码行数:47,代码来源:genlsp_obj.py

示例8: format_region

 def format_region(region):
     if not test(region,"cells"):
         region['cells'] = ""
     else:
         region['cells'] = "cells = {}".format(region['cells'])
     if split_cells is not None and split_cells/region['domains'] < 4:
         print("warning: {} limits less than 4 cells thick".format(
             region['split'][0]));
     return region_tmpl.format(**region);
开发者ID:noobermin,项目名称:sharks,代码行数:9,代码来源:genlsp.py

示例9: setspeciesv

 def setspeciesv(fmt,defaultl,join=False,scale=False):
     l = fmt.format(species);
     if test(kw,l):
         v = kw[l];
         if scale: v=mt(v,getkw('ux'));
         if join:  v=joinspace(v);
     else:
         v = fmtd[defaultl];
     fmtd[l] = v;
开发者ID:noobermin,项目名称:sharks,代码行数:9,代码来源:genlsp.py

示例10: genlsp

def genlsp(**kw):
    def getkw(l,scale=None):
        if test(kw, l):
            if scale:
                return [scale*i for i in kw[l]];
            return kw[l];
        else:
            return defaults[l];
    E0 = np.sqrt(2*getkw('I')*1e4/(c*e0))*1e-5
    xmin,xmax, ymin,ymax = getkw('lim',scale=1e-4)
    fp = joinspace(getkw("fp"));
    components = joinspace(getkw("components"));
    phases = joinspace(getkw("phases"));
    l = getkw('l')*100.0
    if test(kw,'resd'):
        xres,yres = getkw("resd");
        xcells = (xmax-xmin)/(l/xres);
        ycells = (ymax-ymin)/(l/yres);
    else:
        xcells, ycells = getkw("res");
    w0 = getkw('w')*100.0;
    T  = getkw('T')*1e9;
    targ_xmin,targ_xmax, targ_ymin,targ_ymax =getkw('tlim',scale=1e-4);
    domains=getkw('domains');
    # we have that na~l/(pi*w), and the f-number~1/2na, thus
    # f-number ~ pi*w/2l
    fnum=np.pi*w0/2/l;
    totalt=getkw('totaltime')*1e9
    timestep=getkw('timestep')*1e9;
    couraunt = min(
        ((xmax-xmin)/xcells/c)*1e9,
        ((ymax-ymin)/ycells/c)*1e9)
    if timestep > couraunt:
        import sys
        sys.stderr.write("warning: timestep exceeds couraunt limit\n");
    targetdat = getkw('targetdat');
    dumpinterval=getkw('dumpinterval')*1e9;
    description=getkw('description');
    with open("hotwater2d_tmpl.lsp") as f:
        s=f.read();
    s=s.format(
        xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,
        xcells=xcells,ycells=ycells,
        l=l,w0=w0,E0=E0,
        fnum=fnum,
        targ_xmin=targ_xmin, targ_xmax=targ_xmax,
        targ_ymin=targ_ymin, targ_ymax=targ_ymax,
        fp=fp,pulse=T,components=components,phases=phases,
        intensity=getkw('I'),
        domains=domains,totalt=totalt,
        timestep=timestep,
        targetdat=targetdat,
        dumpinterval=dumpinterval,
        description=description
    );
    return s;
开发者ID:noobermin,项目名称:sharks,代码行数:56,代码来源:genlsp.py

示例11: mkscale_sim

def mkscale_sim(**d):
    datf = "water-{}.dat".format(d["dat"])
    d = sd(scale_sim, **d)
    d["targetdat"] = datf
    d["description"] = "scale length sim with {}".format(d["dat"])
    if not test(d, "name"):
        name = "longl_l={}_{}".format(d["dat"], d["I"])
    else:
        name = d["name"]
    mksim(name, **d)
开发者ID:noobermin,项目名称:sharks,代码行数:10,代码来源:genall.py

示例12: genregions

def genregions(**kw):
    def getkw(l,scale=None):
        if test(kw, l):
            ret = kw[l]
        else:
            ret = region_defaults[l];
        if scale:
            return [scale*i for i in ret];
        return ret;
    regsplit_dir, subdivs = getkw('region_split');
    
    nonsplits = [x for x in ['x','y','z']
                 if x != regsplit_dir ];
    limkw = [x+lims
             for x in ['x','y','z']
             for lims in ['min','max']];
    lims = {k:lim for k,lim in zip(limkw,getkw('lim',scale=1e-4))};
    
    total_doms = getkw('domains');
    doms =  [total_doms//subdivs for i in range(subdivs)];
    doms[-1] += total_doms % subdivs;
    lmn,lmx = regsplit_dir+'min', regsplit_dir+'max';
    mn,mx = lims[lmn],lims[lmx]
    edges = [mn+i*(mx-mn)/subdivs
             for i in range(subdivs)] + [mx];
    split_cells = getkw(getkw("region_dom_split")+"cells");
    
    mins = edges[:-1];
    maxs = edges[1:];
    if test(kw,"xcells") and test(kw,"ycells") and test(kw,"zcells"):
        zcells_per_region = [kw['zcells']//subdivs 
                             for i in range(subdivs)]
        zcells_per_region[-1] += kw['zcells'] % subdivs;
        
        cellses = [ kw['xcells']*kw['ycells']*zc
                    for i,zc in enumerate(zcells_per_region)];
    else:
        cellses = [None for i in range(subdivs)];
    reg = sd(lims,split=getkw("region_dom_split").upper()+"SPLIT")
    regions = [ sd(reg,**{lmn:mn,lmx:mx,'i':i+1,'domains':di,'cells':cells})
                for i,(mn,mx,di,cells) in enumerate(zip(mins,maxs,doms,cellses)) ];
    return mkregion_str(regions, split_cells=split_cells);
开发者ID:noobermin,项目名称:sharks,代码行数:42,代码来源:genlsp_obj.py

示例13: genregions_uniform

def genregions_uniform(subdivs,**kw):
    '''
    genregions in a uniform fashion

    subdivs is a list of tuples, each of which specify a range to divide
    along an axis. There are two options, the first is
       (d, split)
    in which d is a string representing the dimension, and split is
    the number of subdivions along that axis.
    The section option is
       (d, split, dmin, dmax) or (d, split, (dmin, dmax))
    where dmin is the minimum along the d axis and dmax is the max.

    The subdivisions are cartesian multiplied (or cartesian product).
    '''
    getkw = mk_getkw(kw, unireg_defaults);
    lims = mt(getkw('lim'),getkw('ux'));
    dims = 'xyz';
    out={}
    for subdiv in subdivs:
        if len(subdiv) == 3:
            subdiv = subdiv[:2] + subdiv[2];
        elif len(subdiv) == 2:
            i=dims.index(subdiv[0])
            subdiv = subdiv + tuple(lims[i*2:i*2+2])
        ax, split, mn, mx = subdiv;
        if ax not in out:
            out[ax]=[];
        out[ax].extend(list(
            np.linspace(mn,mx,split+1)));
    for i,dim in enumerate(dims):
        if dim not in out:
            out[dim] =lims[i*2:i*2+2];
    regs = [ dict(xmin=xmin,xmax=xmax,
                  ymin=ymin,ymax=ymax,
                  zmin=zmin,zmax=zmax,)
             for xmin,xmax in zip(out['x'],out['x'][1:])
             for ymin,ymax in zip(out['y'],out['y'][1:])
             for zmin,zmax in zip(out['z'],out['z'][1:]) ];
    for i,reg in enumerate(regs):
        reg['i'] = i+1;
    if test(kw,"domains_per_region"):
        for reg in regs:
            reg['domains'] = getkw("domains_per_region");
    else:
        ndom = getkw("domains")//len(regs);
        ex   = getkw("domains") %len(regs);
        for reg in regs:
            reg['domains'] = ndom;
        regs[-1]['domains'] += ex;
    for reg in regs:
        reg['split'] = "{}SPLIT".format(
            getkw("region_dom_split").upper());
    return regs;
开发者ID:noobermin,项目名称:sharks,代码行数:54,代码来源:genlsp.py

示例14: genconductor_boundaries

def genconductor_boundaries(**kw):
    getkw=mk_getkw(kw, condb_defaults);
    conductorss='';
    for I,conductor in enumerate(getkw('conductors')):
        cd = sd(condb_objdef, **conductor);
        if test(cd,'from') and test(cd,'to'):
            cd['xmin'],cd['ymin'],cd['zmin'] = cd['from']
            cd['xmax'],cd['ymax'],cd['zmax'] = cd['to']
            pass;
        else:
            outlet = cd['outlet'];
            if outlet not in all_lims:
                raise ValueError('Unknown outlet "{}"'.format(outlet));
            coords = outlet_coords(outlet,kw);
            cd['width']*=1e-4;
            cd['start']*=1e-4;
            sign = lambda outlet: 1.0 if outlet[-2:] == 'ax' else -1.0
            coords[outlet] += sign(outlet)*(cd['width'] + cd['start']);
            coords[otherside(outlet)] += sign(outlet)*cd['start'];
        conductorss += condb_tmpl.format(
            i=I+1,
            **sd(cd,**coords));
    return conductorss;
开发者ID:noobermin,项目名称:sharks,代码行数:23,代码来源:genlsp_obj.py

示例15: highlight

def highlight(ret, val,
              q=None, color='white', alpha=0.15, erase=False):
    '''
    Highlight a pc. Essentially a wrapper of plt.contour
    
    Arguments:
      ret   -- dict returned from pc.
      val   -- value to highlight
      q     -- quantity to highlight. If None, highlight ret's quantity
    
    Keyword Arguments:
      color -- color of highlight
      alpha -- alpha of highlight
      erase -- erases the highlights. Defaults to false (opposite of matplotlib!)
    
    Returns:
      ret but with stuff that plt.contour adds.
    '''
    ax = ret['axes'];
    x,y=ret['x'],ret['y'];
    if q is None:
        q = ret['q'];
    if test(ret,'flip') or test(ret,'rotate'):
        x,y=y,x;
    #elif q is not ret['q'] and test(ret,'flip'):
    if not test(ret, 'cbar'):
        ret['cbar'] = plt.colorbar(ret['pc']);
    cbar = ret['cbar'];
    if not test(ret, 'cts'):
        ret['cts'] = [];
    ct = ax.contour(x,y,q, [val],
                    colors=[color], alpha = alpha);
    ret['cts'].append(ct);
    if q is ret['q']:
        cbar.add_lines(ct,erase=erase);
    return ret;
开发者ID:noobermin,项目名称:lspplot,代码行数:36,代码来源:pc.py


注:本文中的pys.test函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。