示例#1
0
def eps_sig_fij_sort(i=1, j=1, ipb=[1,2,3,4], opt=1, iph=1, difn=None):
    """
    Sorting the result from fij for ipb based on psi
    regardless of the detector it comes from.

    Arguments
    =========
    i   = 1
    j   = 1
    ipb = [1,2,3,4]
    opt = 1 (1: sort based on sin2psi,  2: sort based on psi)
    iph = 1

    # examples
    psi, sin2psi, eps, sigma = \
       eps_sig_fij_sort(i=1,j=1,ipb=[1,2,3], opt=1, iph=1)
    """
    # import the shell sort f2py-wrapped binary module
    fc(difn)
    from MP import ssort
    ssort = ssort.shellSort

    # from sort import shellsort as ssort

    phi   = []; beta  = []
    psi   = []; sigma = []
    eps   = []

    for k in xrange(len(ipb)):
        p, b, e1, e2, s = eps_sig_fij(i=i,j=j,ipb=ipb[k], iph=iph, difn=difn)
        phi.append(p); beta.append(beta)
        psi1 = b - 11.8; psi2 = b + 11.8
        psi.append(psi1); psi.append(psi2)
        sigma.append(s); sigma.append(s)
        eps.append(e1); eps.append(e2)

    # sort
    sin2psi = sin(np.array(psi)*pi/180.)**2
    if opt==1:
        sorted, ind = ssort(sin2psi, len(sin2psi))
    elif opt==2:
        sorted, ind = ssort(psi, len(psi))
    else: raise IOError, 'Wrong option'

    temp1 = []
    temp2 = []
    temp3 = []
    for k in xrange(len(sorted)):
        temp1.append(sigma[ind[k]-1])
        temp2.append(eps[ind[k]-1])
        temp3.append(psi[ind[k]-1])
    sigma = temp1
    eps = temp2
    psi = temp3

    return psi, sin2psi, eps, sigma
示例#2
0
def fij(i=1, j=1, iph=1, difn=None):
    """
    Arguments
    =========
    i   = 1
    j   = 1
    iph = 1

    Fij (step, phi, psi)
    psi (step, phi)
    """
    fc(difn)
    from MP import ssort

    ssort = ssort.shellSort
    # from ssort import shellSort as ssort
    istep = 1
    Psi = []
    F = []
    while True:
        print "istep:", istep
        try:
            psi, f = fijstep(i, j, istep, iph, difn=difn)
        except:
            break
        else:
            ## -- sorting block starts --
            # f(phi, psi)
            ft = f.T
            x = psi
            sortedpsi, ind = ssort(x)
            temp = []
            for k in xrange(len(sortedpsi)):
                temp.append(ft[ind[k] - 1])
            ft = np.array(temp)
            f = ft.T
            psi = sortedpsi
            ## -- sorting block ends --

            F.append(f)
            Psi.append(psi)

            istep = istep + 1

    # F(step, phi, psi)
    # Psi(step, phi)

    if len(F) == 0 or len(Psi) == 0:
        print "Something fishy happened: len(F)==0 or len(Psi)==0"
        print len(F), len(Psi)

    return np.array(F), np.array(Psi)
示例#3
0
def fij(i=1, j=1, iph=1, difn=None):
    """
    Arguments
    =========
    i   = 1
    j   = 1
    iph = 1

    Fij (step, phi, psi)
    psi (step, phi)
    """
    fc(difn)
    from MP import ssort
    ssort = ssort.shellSort
    #from ssort import shellSort as ssort
    istep = 1
    Psi = []
    F   = []
    while True:
        print 'istep:', istep
        try: psi, f = fijstep(i, j, istep, iph, difn=difn)
        except: break
        else:
            ## -- sorting block starts --
            #f(phi, psi)
            ft = f.T
            x = psi
            sortedpsi, ind = ssort(x)
            temp = []
            for k in xrange(len(sortedpsi)):
                temp.append(ft[ind[k]-1])
            ft = np.array(temp)
            f = ft.T
            psi = sortedpsi
            ## -- sorting block ends --

            F.append(f)
            Psi.append(psi)

            istep = istep + 1

    # F(step, phi, psi)
    # Psi(step, phi)

    if len(F)==0 or len(Psi)==0:
        print "Something fishy happened: len(F)==0 or len(Psi)==0"
        print len(F), len(Psi)

    return np.array(F), np.array(Psi)
示例#4
0
def intepsphiout(istep=0, phi=0, iphi=0, iph=1, isort=False, iopt=0):
    """
    Arguments
    =========
    istep = 0 (starts from 0)
    phi   = -90 or iphi as index for iopt 4 and 5.
    iph   = 1 (phase starts from 1)
    isort = False
    iopt  =
            0: ('int_eps_ph%i.out') - at unloads,
            1: ('int_els_ph%i.out') - at loads
            2: ('igstrain_load_ph%i.out') - at
            3: ('igstrain_unload_ph%i.out') - at
            4: ('igstrain_unloads_avg.out') at unloads
            5: ('igstrain_loads_avg.out')   at loads
    """
    from MP import ssort

    sh = ssort.sh
    ind_swap = ssort.ind_swap
    ssort = ssort.shellSort

    # from ssort import shellSort as ssort
    # from ssort import sh
    # from ssort import ind_swap

    eps, sig, psi = [], [], []
    if iopt == 0:
        filename = "int_eps_ph%i.out" % iph
    elif iopt == 1:
        filename = "int_els_ph%i.out" % iph
    elif iopt == 2:
        filename = "igstrain_load_ph%i.out" % iph
    elif iopt == 3:
        filename = "igstrain_unload_ph%i.out" % iph
    elif iopt == 4:
        filename = "igstrain_unloads_avg.out"
    elif iopt == 5:
        filename = "igstrain_loads_avg.out"
    fc(filename)

    if iopt < 4:
        dl = open(filename, "r").readlines()
        npb = int(dl[1].split()[0])
        dat = dl[2:]
        dat = dat[(istep) * npb : (istep) * npb + npb]
        if len(dat) == 0:
            raise IOError, "empty dat is returned .."
        for i in xrange(len(dat)):
            temp = map(float, dat[i].split())
            step, p, beta, psi1, psi2, eps1, eps2, sig1, sig2, n1, n2, v1, v2 = temp[:13]

            ms11, ms22, ms33, ms23, ms13, ms12 = temp[13:19]
            me11, me22, me33, me23, me13, me12 = temp[19:25]

            if p == phi:
                eps.append(eps1)
                eps.append(eps2)
                sig.append(sig1)
                sig.append(sig2)
                psi.append(psi1)  # detector 1
                psi.append(psi2)  # detector 2
        if isort:
            temp1, temp2 = [], []
            sortedarray, ind = ssort(psi)  # , len(psi))
            for k in xrange(len(sortedarray)):
                temp1.append(eps[ind[k] - 1])
                temp2.append(sig[ind[k] - 1])

            eps = temp1
            sigma = temp2
            psi = sortedarray

        return np.array(psi), np.array(eps), np.array(sig), ms11, ms22, ms33, ms23, ms13, ms12

    if iopt == 4 or iopt == 5:
        from sff_converter import condition
        from pepshkl import reader3 as reader

        difl, nphi, phis, nbeta, neps, eps = condition()
        tdat, psi = reader(filename, isort)  # [ist,iphi,ipsi]
        sin2psi = np.sin(psi * np.pi / 180.0) ** 2
        npsi = len(psi)
        eps = tdat[istep, iphi]
        return psi, eps

    raise IOError, "Unexpected ioption give in intepsphiout"
示例#5
0
def eps_sig_fij_sort(i=1, j=1, ipb=[1, 2, 3, 4], opt=1, iph=1, difn=None):
    """
    Sorting the result from fij for ipb based on psi
    regardless of the detector it comes from.

    Arguments
    =========
    i   = 1
    j   = 1
    ipb = [1,2,3,4]
    opt = 1 (1: sort based on sin2psi,  2: sort based on psi)
    iph = 1

    # examples
    psi, sin2psi, eps, sigma = \
       eps_sig_fij_sort(i=1,j=1,ipb=[1,2,3], opt=1, iph=1)
    """
    # import the shell sort f2py-wrapped binary module
    fc(difn)
    from MP import ssort

    ssort = ssort.shellSort

    # from sort import shellsort as ssort

    phi = []
    beta = []
    psi = []
    sigma = []
    eps = []

    for k in xrange(len(ipb)):
        p, b, e1, e2, s = eps_sig_fij(i=i, j=j, ipb=ipb[k], iph=iph, difn=difn)
        phi.append(p)
        beta.append(beta)
        psi1 = b - 11.8
        psi2 = b + 11.8
        psi.append(psi1)
        psi.append(psi2)
        sigma.append(s)
        sigma.append(s)
        eps.append(e1)
        eps.append(e2)

    # sort
    sin2psi = sin(np.array(psi) * pi / 180.0) ** 2
    if opt == 1:
        sorted, ind = ssort(sin2psi, len(sin2psi))
    elif opt == 2:
        sorted, ind = ssort(psi, len(psi))
    else:
        raise IOError, "Wrong option"

    temp1 = []
    temp2 = []
    temp3 = []
    for k in xrange(len(sorted)):
        temp1.append(sigma[ind[k] - 1])
        temp2.append(eps[ind[k] - 1])
        temp3.append(psi[ind[k] - 1])
    sigma = temp1
    eps = temp2
    psi = temp3

    return psi, sin2psi, eps, sigma
示例#6
0
def intepsphiout(istep=0, phi=0, iphi=0, iph=1, isort=False, iopt=0):
    """
    Arguments
    =========
    istep = 0 (starts from 0)
    phi   = -90 or iphi as index for iopt 4 and 5.
    iph   = 1 (phase starts from 1)
    isort = False
    iopt  =
            0: ('int_eps_ph%i.out') - at unloads,
            1: ('int_els_ph%i.out') - at loads
            2: ('igstrain_load_ph%i.out') - at
            3: ('igstrain_unload_ph%i.out') - at
            4: ('igstrain_unloads_avg.out') at unloads
            5: ('igstrain_loads_avg.out')   at loads
    """
    from MP import ssort
    sh=ssort.sh
    ind_swap=ssort.ind_swap
    ssort=ssort.shellSort

    #from ssort import shellSort as ssort
    #from ssort import sh
    #from ssort import ind_swap

    eps, sig, psi = [], [], []
    if iopt==0:   filename='int_eps_ph%i.out'%iph
    elif iopt==1: filename='int_els_ph%i.out'%iph
    elif iopt==2: filename='igstrain_load_ph%i.out'%iph
    elif iopt==3: filename='igstrain_unload_ph%i.out'%iph
    elif iopt==4: filename='igstrain_unloads_avg.out'
    elif iopt==5: filename='igstrain_loads_avg.out'
    fc(filename)

    if iopt<4:
        dl = open(filename, 'r').readlines()
        npb = int(dl[1].split()[0])
        dat = dl[2:]
        dat = dat[(istep)*npb: (istep)*npb + npb]
        if len(dat)==0: raise IOError, 'empty dat is returned ..'
        for i in xrange(len(dat)):
            temp = map(float, dat[i].split())
            step, p, beta, psi1, psi2, eps1, eps2,\
                sig1, sig2, n1, n2, v1, v2 = temp[:13]

            ms11, ms22, ms33, ms23, ms13, ms12 = temp[13:19]
            me11, me22, me33, me23, me13, me12 = temp[19:25]

            if p==phi:
                eps.append(eps1); eps.append(eps2)
                sig.append(sig1); sig.append(sig2)
                psi.append(psi1) # detector 1
                psi.append(psi2) # detector 2
        if isort:
            temp1, temp2 = [], []
            sortedarray, ind = ssort(psi)#, len(psi))
            for k in xrange(len(sortedarray)):
                temp1.append(eps[ind[k]-1])
                temp2.append(sig[ind[k]-1])

            eps = temp1
            sigma = temp2
            psi = sortedarray

        return np.array(psi), np.array(eps), np.array(sig),\
            ms11, ms22, ms33, ms23, ms13, ms12

    if iopt==4 or iopt==5:
        from sff_converter import condition
        from pepshkl import reader3 as reader
        difl, nphi, phis, nbeta, neps, eps = condition()
        tdat, psi = reader(filename,isort) #[ist,iphi,ipsi]
        sin2psi = np.sin(psi*np.pi/180.)**2
        npsi = len(psi)
        eps = tdat[istep, iphi]
        return psi, eps

    raise IOError, 'Unexpected ioption give in intepsphiout'