Changeset 4901


Ignore:
Timestamp:
May 3, 2021 10:46:42 PM (3 years ago)
Author:
toby
Message:

add TOF corrections on read in scripts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIscriptable.py

    r4880 r4901  
    12721272import GSASIIfiles as G2fil
    12731273import GSASIIimage as G2img
     1274import GSASIIlattice as G2lat
    12741275
    12751276# Delay imports to not slow down small scripts that don't need them
     
    15481549    """
    15491550
    1550     import GSASIIlattice as G2lat
    15511551    if len(cell) != 6:
    15521552        raise G2ScriptException("GenerateReflections: Invalid unit cell:" + str(cell))
     
    17101710        Iparm1, Iparm2 = load_iprms(instprm, reader, bank=bank)
    17111711        G2fil.G2Print('Instrument parameters read:',reader.instmsg)
     1712
     1713    if 'T' in Iparm1['Type'][0]:
     1714        if not reader.clockWd and reader.GSAS:
     1715            reader.powderdata[0] *= 100.        #put back the CW centideg correction
     1716        cw = np.diff(reader.powderdata[0])
     1717        reader.powderdata[0] = reader.powderdata[0][:-1]+cw/2.
     1718        if reader.GSAS:     #NB: old GSAS wanted intensities*CW even if normalized!
     1719            npts = min(len(reader.powderdata[0]),len(reader.powderdata[1]),len(cw))
     1720            reader.powderdata[1] = reader.powderdata[1][:npts]/cw[:npts]
     1721            reader.powderdata[2] = reader.powderdata[2][:npts]*cw[:npts]**2  #1/var=w at this point
     1722        else:       #NB: from topas/fullprof type files
     1723            reader.powderdata[1] = reader.powderdata[1][:-1]
     1724            reader.powderdata[2] = reader.powderdata[2][:-1]
     1725        if 'Itype' in Iparm2:
     1726            Ibeg = np.searchsorted(reader.powderdata[0],Iparm2['Tminmax'][0])
     1727            Ifin = np.searchsorted(reader.powderdata[0],Iparm2['Tminmax'][1])
     1728            reader.powderdata[0] = reader.powderdata[0][Ibeg:Ifin]
     1729            YI,WYI = G2pwd.calcIncident(Iparm2,reader.powderdata[0])
     1730            reader.powderdata[1] = reader.powderdata[1][Ibeg:Ifin]/YI
     1731            var = 1./reader.powderdata[2][Ibeg:Ifin]
     1732            var += WYI*reader.powderdata[1]**2
     1733            var /= YI**2
     1734            reader.powderdata[2] = 1./var
     1735        reader.powderdata[1] = np.where(np.isinf(reader.powderdata[1]),0.,reader.powderdata[1])
     1736        reader.powderdata[3] = np.zeros_like(reader.powderdata[0])
     1737        reader.powderdata[4] = np.zeros_like(reader.powderdata[0])
     1738        reader.powderdata[5] = np.zeros_like(reader.powderdata[0])
     1739
    17121740    Ymin = np.min(reader.powderdata[1])
    17131741    Ymax = np.max(reader.powderdata[1])
     
    17181746                  'refOffset': -0.1*Ymax, 'refDelt': 0.1*Ymax,
    17191747                  'Yminmax': [Ymin, Ymax]}
     1748    # apply user-supplied corrections to powder data
     1749    if 'CorrectionCode' in Iparm1:
     1750        print('Applying corrections from instprm file')
     1751        corr = Iparm1['CorrectionCode'][0]
     1752        try:
     1753            exec(corr)
     1754            print('done')
     1755        except Exception as err:
     1756            print(u'error: {}'.format(err))
     1757            print('with commands -------------------')
     1758            print(corr)
     1759            print('---------------------------------')
     1760        finally:
     1761            del Iparm1['CorrectionCode']
    17201762    reader.Sample['ranId'] = valuesdict['ranId']
    1721     if 'T' in Iparm1['Type'][0]:
    1722         if not reader.clockWd and reader.GSAS:
    1723             reader.powderdata[0] *= 100.        #put back the CW centideg correction
    17241763
    17251764    # Ending keys:
     
    17361775    Tmin = np.min(reader.powderdata[0])
    17371776    Tmax = np.max(reader.powderdata[0])
     1777    Tmin1 = Tmin
     1778    if 'NT' in Iparm1['Type'][0] and G2lat.Pos2dsp(Iparm1,Tmin) < 0.4:               
     1779        Tmin1 = G2lat.Dsp2pos(Iparm1,0.4)
    17381780
    17391781    default_background = [['chebyschev-1', False, 3, 1.0, 0.0, 0.0],
     
    17421784
    17431785    output_dict = {u'Reflection Lists': {},
    1744                    u'Limits': reader.pwdparms.get('Limits', [(Tmin, Tmax), [Tmin, Tmax]]),
     1786                   u'Limits': reader.pwdparms.get('Limits', [(Tmin, Tmax), [Tmin1, Tmax]]),
    17451787                   u'data': [valuesdict, reader.powderdata, HistName],
    17461788                   u'Index Peak List': [[], []],
     
    44574499        See :ref:`PeakRefine` for an example.
    44584500        '''
    4459         import GSASIIlattice as G2lat
    44604501        import GSASIImath as G2mth
    44614502        if (not dspace) + (not Q) + (not ttheta) != 2:
     
    45874628        :returns: name of file that was written
    45884629        '''
    4589         import GSASIIlattice as G2lat
    45904630        import math
    45914631        nptand = lambda x: np.tan(x*math.pi/180.)
     
    49534993        """
    49544994        # translated from GSASIIstrIO.ExportBaseclass.GetCell
    4955         import GSASIIlattice as G2lat
    49564995        import GSASIImapvars as G2mv
    49574996        try:
     
    57795818                sv[1] = insChar
    57805819            return ':'.join(sv)
    5781         import GSASIIlattice as G2lat
    57825820        import GSASIIstrIO as G2stIO
    57835821       
Note: See TracChangeset for help on using the changeset viewer.