Esempio n. 1
0
def Iblock(a, first):  # read Ascii block of Integers
    line1 = a[first]
    line2 = a[first + 1]
    val = ExtractInt(line2)
    numb = val[0]
    lines = numb / 10
    last = numb - 10 * lines
    if line1.startswith('I'):
        error = ''
    else:
        error = 'NOT an I block starting at line ' + str(first)
        logger.information('ERROR *** ' + error)
        sys.exit(error)
    ival = []
    for m in range(0, lines):
        mm = first + 2 + m
        val = ExtractInt(a[mm])
        for n in range(0, 10):
            ival.append(val[n])
    mm += 1
    val = ExtractInt(a[mm])
    for n in range(0, last):
        ival.append(val[n])
    mm += 1
    return mm, ival  # values as list
Esempio n. 2
0
def Fblock(a, first):  # read Ascii block of Floats
    line1 = a[first]
    line2 = a[first + 1]
    val = ExtractInt(line2)
    numb = val[0]
    lines = numb / 5
    last = numb - 5 * lines
    if line1.startswith('F'):
        error = ''
    else:
        error = 'NOT an F block starting at line ' + str(first)
        logger.information('ERROR *** ' + error)
        sys.exit(error)
    fval = []
    for m in range(0, lines):
        mm = first + 2 + m
        val = ExtractFloat(a[mm])
        for n in range(0, 5):
            fval.append(val[n])
    mm += 1
    val = ExtractFloat(a[mm])
    for n in range(0, last):
        fval.append(val[n])
    mm += 1
    return mm, fval  # values as list
Esempio n. 3
0
def ReadMap(path):
    asc = loadFile(path)

    lasc = len(asc)
    logger.information('Map file : ' + path + ' ; spectra = ' + str(lasc - 1))
    val = ExtractInt(asc[0])
    numb = val[0]
    if numb != (lasc - 1):
        error = 'Number of lines  not equal to number of spectra'
        logger.error(error)
        sys.exit(error)
    map = []
    for n in range(1, lasc):
        val = ExtractInt(asc[n])
        map.append(val[1])
    return map
Esempio n. 4
0
def ReadIbackGroup(a,first):                           #read Ascii block of spectrum values
    x = []
    y = []
    e = []
    next = first
    line1 = a[next]
    next += 1
    val = ExtractInt(a[next])
    n1 = val[0]
    ngrp = val[2]
    if line1.startswith('S'):
        error = ''
    else:
        error = 'NOT an S block starting at line ' +str(first)
        logger.notice('ERROR *** ' + error)
        sys.exit(error)
    next += 1
    next,Ival = Iblock(a,next)
    for m in range(0, len(Ival)):
        x.append(float(m))
        yy = float(Ival[m])
        y.append(yy)
        ee = math.sqrt(yy)
        e.append(ee)
    return next,x,y,e                                #values of x,y,e as lists
Esempio n. 5
0
def ReadMap(path,Verbose):
    workdir = config['defaultsave.directory']

    asc = loadFile(path)

    lasc = len(asc)
    if Verbose:
        logger.notice('Map file : ' + path +' ; spectra = ' +str(lasc-1))
    val = ExtractInt(asc[0])
    numb = val[0]
    if (numb != (lasc-1)):
        error = 'Number of lines  not equal to number of spectra'
        logger.notice('ERROR *** ' + error)
        sys.exit(error)
    map = []
    for n in range(1,lasc):
        val = ExtractInt(asc[n])
        map.append(val[1])
    return map
Esempio n. 6
0
def InxStart(instr, run, ana, refl, rejectZ, useM, mapPath, Plot, Save):
    StartTime('Inx')
    workdir = config['defaultsave.directory']

    path, fname = getFilePath(run, '.inx', instr)

    logger.information('Reading file : ' + path)

    asc = loadFile(path)
    lasc = len(asc)

    val = ExtractInt(asc[0])
    lgrp = int(val[0])
    ngrp = int(val[2])
    title = asc[1]
    ltot = ngrp * lgrp
    logger.information('Number of spectra : ' + str(ngrp))
    if ltot == lasc:
        error = ''
    else:
        error = 'file ' + filext + ' should be ' + str(ltot) + ' lines'
        logger.information('ERROR *** ' + error)
        sys.exit(error)
    _Qaxis = ''
    xDat = []
    yDat = []
    eDat = []
    ns = 0
    Q = []
    tot = []
    for m in range(0, ngrp):
        Qq, nd, xd, yd, ed = ReadInxGroup(asc, m, lgrp)
        tot.append(sum(yd))
        logger.information('Spectrum ' + str(m + 1) + ' at Q= ' + str(Qq) +
                           ' ; Total counts = ' + str(tot))
        if ns != 0:
            _Qaxis += ','
        _Qaxis += str(Qq)
        Q.append(Qq)
        for n in range(0, nd):
            xDat.append(xd[n])
            yDat.append(yd[n])
            eDat.append(ed[n])
        xDat.append(2 * xd[nd - 1] - xd[nd - 2])
        ns += 1
    ascWS = fname + '_' + ana + refl + '_inx'
    outWS = fname + '_' + ana + refl + '_red'
    CreateWorkspace(OutputWorkspace=ascWS,
                    DataX=xDat,
                    DataY=yDat,
                    DataE=eDat,
                    Nspec=ns,
                    UnitX='DeltaE')
    InstrParas(ascWS, instr, ana, refl)
    efixed = RunParas(ascWS, instr, 0, title)
    pi4 = 4.0 * math.pi
    wave = 1.8 * math.sqrt(25.2429 / efixed)
    theta = []
    for n in range(0, ngrp):
        qw = wave * Q[n] / pi4
        ang = 2.0 * math.degrees(math.asin(qw))
        theta.append(ang)
    ChangeAngles(ascWS, instr, theta)
    if useM:
        map = ReadMap(mapPath)
        UseMap(ascWS, map)
    if rejectZ:
        RejectZero(ascWS, tot)
    if not useM and not rejectZ:
        CloneWorkspace(InputWorkspace=ascWS, OutputWorkspace=outWS)
    if Save:
        opath = os.path.join(workdir, outWS + '.nxs')
        SaveNexusProcessed(InputWorkspace=outWS, Filename=opath)
        logger.information('Output file : ' + opath)
    if Plot:
        plotForce(outWS, Plot)
    EndTime('Inx')
Esempio n. 7
0
def IbackStart(instr, run, ana, refl, rejectZ, useM, mapPath, Plot,
               Save):  # Ascii start routine
    StartTime('Iback')
    workdir = config['defaultsave.directory']

    path, fname = getFilePath(run, '.asc', instr)

    logger.information('Reading file : ' + path)

    asc = loadFile(path)

    # raw head
    text = asc[1]
    run = text[:8]
    first = 5
    next, _Ival = Iblock(asc, first)
    next += 2
    title = asc[next]  # title line
    next += 1
    text = asc[next]  # user line
    next += 6  # 5 lines of text
    # back head1
    next, Fval = Fblock(asc, next)
    if instr == 'IN10':
        freq = Fval[89]
    if instr == 'IN16':
        freq = Fval[2]
        amp = Fval[3]
        wave = Fval[69]
        npt = int(Fval[6])
        nsp = int(Fval[7])
    # back head2
    next, Fval = Fblock(asc, next)
    theta = []
    for m in range(0, nsp):
        theta.append(Fval[m])
    # raw spectra
    val = ExtractInt(asc[next + 3])
    npt = val[0]
    lgrp = 5 + npt / 10
    val = ExtractInt(asc[next + 1])
    if instr == 'IN10':
        nsp = int(val[2])
    logger.information('Number of spectra : ' + str(nsp))
    # read monitor
    nmon = next + nsp * lgrp
    _nm, _xm, ym, em = ReadIbackGroup(asc, nmon)
    # monitor calcs
    imin = 0
    ymax = 0
    for m in range(0, 20):
        if ym[m] > ymax:
            imin = m
            ymax = ym[m]
    npt = len(ym)
    imax = npt
    ymax = 0
    for m in range(npt - 1, npt - 20, -1):
        if ym[m] > ymax:
            imax = m
            ymax = ym[m]
    new = imax - imin
    imid = new / 2 + 1
    if instr == 'IN10':
        DRV = 18.706  # fast drive
        vmax = freq * DRV
    if instr == 'IN16':
        vmax = 1.2992581918414711e-4 * freq * amp * 2.0 / wave  # max energy
    dele = 2.0 * vmax / new
    xMon = []
    yOut = []
    eOut = []
    for m in range(0, new + 1):
        xe = (m - imid) * dele
        mm = m + imin
        xMon.append(xe)
        yOut.append(ym[mm] / 100.0)
        eOut.append(em[mm] / 10.0)
    xMon.append(2 * xMon[new - 1] - xMon[new - 2])
    monWS = '__Mon'
    CreateWorkspace(OutputWorkspace=monWS,
                    DataX=xMon,
                    DataY=yOut,
                    DataE=eOut,
                    Nspec=1,
                    UnitX='DeltaE')
    #
    _Qaxis = ''
    xDat = []
    yDat = []
    eDat = []
    tot = []
    for n in range(0, nsp):
        next, _xd, yd, ed = ReadIbackGroup(asc, next)
        tot.append(sum(yd))
        logger.information('Spectrum ' + str(n + 1) + ' at angle ' +
                           str(theta[n]) + ' ; Total counts = ' + str(sum(yd)))
        for m in range(0, new + 1):
            mm = m + imin
            xDat.append(xMon[m])
            yDat.append(yd[mm])
            eDat.append(ed[mm])
        if n != 0:
            _Qaxis += ','
        xDat.append(2 * xDat[new - 1] - xDat[new - 2])
        _Qaxis += str(theta[n])
    ascWS = fname + '_' + ana + refl + '_asc'
    outWS = fname + '_' + ana + refl + '_red'
    CreateWorkspace(OutputWorkspace=ascWS,
                    DataX=xDat,
                    DataY=yDat,
                    DataE=eDat,
                    Nspec=nsp,
                    UnitX='DeltaE')
    Divide(LHSWorkspace=ascWS,
           RHSWorkspace=monWS,
           OutputWorkspace=ascWS,
           AllowDifferentNumberSpectra=True)
    DeleteWorkspace(monWS)  # delete monitor WS
    InstrParas(ascWS, instr, ana, refl)
    RunParas(ascWS, instr, run, title)
    ChangeAngles(ascWS, instr, theta)
    if useM:
        map = ReadMap(mapPath)
        UseMap(ascWS, map)
    if rejectZ:
        RejectZero(ascWS, tot)
    if not useM and not rejectZ:
        CloneWorkspace(InputWorkspace=ascWS, OutputWorkspace=outWS)
    if Save:
        opath = os.path.join(workdir, outWS + '.nxs')
        SaveNexusProcessed(InputWorkspace=outWS, Filename=opath)
        logger.information('Output file : ' + opath)
    if Plot:
        plotForce(outWS, Plot)
    EndTime('Iback')