Beispiel #1
0
def importDB(fn=None):
    """Import a _post.py database and select it as the current."""

    if fn is None:
        fn = askFilename(pf.cfg['workdir'], 'postproc')
    if fn:
        chdir(fn)
        sizeM = round(os.stat(fn).st_size * 1.e-6, 0)
        if sizeM > 10.0 and ask(
                """
BEWARE!!!

The size of this file is very large: %.1fMB.
It is unlikely that I will be able to process this file.
I strongly recommend you to cancel the operation now.
""" % sizeM, ["Continue", "Cancel"]) != "Continue":
            return

        # import the results DB
        pf.GUI.setBusy(True)
        runScript(fn)
        pf.GUI.setBusy(False)

        ### check whether the import succeeded
        name = FeResult._name_
        db = pf.PF[name]
        if not isinstance(db, FeResult):
            warning(
                "!Something went wrong during the import of the database %s" %
                fn)
            return

        ### ok: select the DB
        selection.set([name])
        selectDB(db)
Beispiel #2
0
    def seconds(self, reset=False, rounded=False):
        """Return the timer readings in seconds.

        The default return value is a rounded integer number of seconds.
        With ``rounded == False``, a floating point value with granularity of
        1 microsecond is returned.

        If reset=True, the timer is reset at the time of reading.
        """
        e = self.read(reset)
        sec = e.days * 24 * 3600 + e.seconds + e.microseconds / 1000000.
        if rounded:
            sec = round(sec)
        return sec
Beispiel #3
0
def circle(a1=2., a2=0., a3=360., r=None, n=None, c=None, eltype='line2'):
    """A polygonal approximation of a circle or arc.

    All points generated by this function lie on a circle with unit radius at
    the origin in the x-y-plane.

    - `a1`: the angle enclosed between the start and end points of each line
      segment (dash angle).
    - `a2`: the angle enclosed between the start points of two subsequent line
      segments (module angle). If ``a2==0.0``, `a2` will be taken equal to `a1`.
    - `a3`: the total angle enclosed between the first point of the first
      segment and the end point of the last segment (arc angle).

    All angles are given in degrees and are measured in the direction from
    x- to y-axis. The first point of the first segment is always on the x-axis.

    The default values produce a full circle (approximately).
    If $a3 < 360$, the result is an arc.
    Large values of `a1` and `a2` result in polygons. Thus
    `circle(120.)` is an equilateral triangle and `circle(60.)`
    is regular hexagon.

    Remark that the default a2 == a1 produces a continuous line,
    while a2 > a1 results in a dashed line.

    Three optional arguments can be added to scale and position the circle
    in 3D space:

    - `r`: the radius of the circle
    - `n`: the normal on the plane of the circle
    - `c`: the center of the circle
    """
    if a2 == 0.0:
        a2 = a1
    ns = round(a3/a2)
    a1 *= pi/180.
    if eltype=='line2':
        F = Formex([[[1., 0., 0.], [cos(a1), sin(a1), 0.]]]).rosette(ns, a2, axis=2, point=[0., 0., 0.])
    elif eltype=='line3':
        F = Formex([[[1., 0., 0.], [cos(a1/2.), sin(a1/2.), 0.], [cos(a1), sin(a1), 0.]]], eltype=eltype).rosette(ns, a2, axis=2, point=[0., 0., 0.])
    if r is not None:
        F = F.scale(r)
    if n is not None:
        F = F.swapAxes(0, 2).rotate(rotMatrix(n))
    if c is not None:
        F = F.trl(c)
    return F
Beispiel #4
0
def seeding3zones(nseeds=[10, 10],zonesizes=[0.3, 0.3]):
    """it creates a 1D array of floats between 0.0 and 1.0 splitting this range in 3 zones: the first and the last have sizes determined in zonesizes and are populated with the numbers in nseeds. A trnasitional zone is calculated approximating a geometrical series (the next segment is as long as the previous*power)."""
    #nseeds = number of seeds in zone0 and zone1
    #sizesizes are the zone sizes in percentages
    #transition zone is seeded using an approximated geometrical series

    if sum(zonesizes)>1.:raise 'the sum of zone lengths has to be < 1.'
    seed0, seed1= [arange(nseeds[i]+1.)/float(nseeds[i])*zonesizes[i] for i in range(2) ]
    seed1=1.+seed1-seed1[-1]

    transzone=seed1[0]-seed0[-1]#transition zone
    near0=seed0[-1]-seed0[-2]
    near1=seed1[-1]-seed1[-2]
    #geometrical series: nextsegment = previoussegment**power
    ntransseeds= (  (log(near1/near0)) / log ( (transzone+near1)/(transzone+near0) )  ) -1.
    powertrans=(near1/near0)**(1./(ntransseeds+1.))
    napproxseeds=round(ntransseeds)
    xtrans= near0*array([(powertrans**i) for i in range(1, napproxseeds+1)])
    xtrans= cumsum(xtrans)
    xtrans=xtrans[:-1]*transzone/xtrans[-1]
    #if  len(xtrans)==0: warning('There is not enough space to fit a transition zone!')
    seedingarray=[seed0, xtrans+seed0[-1], seed1 ]
    return seedingarray#concatenate(seedingarray)
Beispiel #5
0
 def __init__(self, De, L, d, nx, be, ds=0.0, nb=4, connectors=True):
     """Create the Wire Stent."""
     D = De - 2 * d - ds
     r = 0.5 * D
     dz = 0.5 * (ds + d)
     p = pi * D * tand(be)
     nx = int(nx)
     ny = int(round(nx * L /
                    p))  # The actual length may differ a bit from L
     # a single bumped strut, oriented along the x-axis
     bump_z = lambda x: 1. - (x / nb)**2
     base = Formex('l:1').replic(nb, 1.0).bump1(2, [0., 0., dz], bump_z, 0)
     # scale back to size 1.
     base = base.scale([1. / nb, 1. / nb, 1.])
     # NE and SE directed struts
     NE = base.shear(1, 0, 1.)
     SE = base.reflect(2).shear(1, 0, -1.)
     NE.setProp(1)
     SE.setProp(3)
     # a unit cell of crossing struts
     cell1 = (NE + SE).rosette(2, 180)
     # add a connector between first points of NE and SE
     if connectors:
         cell1 += Formex([[NE[0][0], SE[0][0]]], 2)
     # create its mirror
     cell2 = cell1.reflect(2).translate([2., 2., 0.])
     base = cell1 + cell2
     # reposition to base to origin [0,0]
     base = base.translate(-base.bbox()[0])
     # Create the full pattern by replication
     dx, dy = base.bbox()[1][:2]
     F = base.replic2(nx, ny, dx, dy)
     # fold it into a cylinder
     self.F = F.translate([0., 0., r]).cylindrical(
         dir=[2, 0, 1], scale=[1., 360. / (nx * dx), p / nx / dy])
     self.ny = ny
Beispiel #6
0
def ric(f):
    return int(round(f))