Changeset 3190


Ignore:
Timestamp:
Dec 12, 2017 12:31:12 AM (5 years ago)
Author:
toby
Message:

Search through comments for values of sample parameters & and labels for FreePrmX

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r3189 r3190  
    694694    name = name.replace('IMG ',data['type']+' ')
    695695    Comments = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id, 'Comments'))
     696    Controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls'))
    696697    if 'PWDR' in name:
    697698        names = ['Type','Lam','Zero','Polariz.','U','V','W','X','Y','Z','SH/L','Azimuth']
     
    744745                except:
    745746                    polariz = 0.99
     747            for key in ('Temperature','Pressure','Time','FreePrm1','FreePrm2','FreePrm3','Omega',
     748                'Chi','Phi'):
     749                if key.lower() in item.lower():
     750                    try:
     751                        Sample[key] = float(item.split('=')[1])
     752                    except:
     753                        pass
     754            if 'label_prm' in item.lower():
     755                for num in ('1','2','3'):
     756                    if 'label_prm'+num in item.lower():
     757                        Controls['FreePrm'+num] = item.split('=')[1].strip()
    746758        if 'PWDR' in Aname:
    747759            parms = ['PXC',data['wavelength'],0.0,polariz,1.0,-0.10,0.4,0.30,1.0,0.0,0.0001,Azms[i]]
     
    21672179        pixelSize:lambda x: [74.8, 74.8]|0
    21682180        ISOlikeDate: lambda dow,m,d,t,y:"{}-{}-{}T{} ({})".format(y,m,d,t,dow)|0,1,2,3,4
     2181        Temperature: float|53
     2182        FreePrm2: int | 34 | Free Parm2 Label
    21692183        # define other variables
    21702184        0:day
     
    21802194       to determine values that are used for image interpretation (see table,
    21812195       below). Any others are copied to the Comments subsection of the Image
    2182        tree item.
     2196       tree item. 
    21832197     * Column labels are defined with a column number (integer) followed by
    21842198       a colon (:) and a label to be assigned to that column. All labeled
     
    21922206    The parameter name is followed by a colon. After the colon, specify
    21932207    Python code that defines or specifies a function that will be called to
    2194     generate a value for that parameter. After that code, supply a vertical
    2195     bar (|) and then a list of one more more columns that will be supplied
    2196     as arguments to that function. The examples above are discussed below:
     2208    generate a value for that parameter.
     2209
     2210    Note that several keywords, if defined in the Comments, will be found and
     2211    placed in the appropriate section of the powder histogram(s)'s Sample
     2212    Parameters after an integration: 'Temperature','Pressure','Time',
     2213    'FreePrm1','FreePrm2','FreePrm3','Omega','Chi', and 'Phi'.
     2214
     2215    After the Python code, supply a vertical bar (|) and then a list of one
     2216    more more columns that will be supplied as arguments to that function.
     2217
     2218    Note that the labels for the three FreePrm items can be changed by
     2219    including that label as a third item with an additional vertical bar. Labels
     2220    will be ignored for any other named parameters.
     2221   
     2222    The examples above are discussed here:
    21972223
    21982224    ``filename:lambda x,y: "{}_{:0>6}".format(x,y)|33,34``
     
    22192245        value is not used in the expression.
    22202246
    2221      ``ISOlikeDate: lambda dow,m,d,t,y:"{}-{}-{}T{} ({})".format(y,m,d,t,dow)|0,1,2,3,4``
     2247    ``ISOlikeDate: lambda dow,m,d,t,y:"{}-{}-{}T{} ({})".format(y,m,d,t,dow)|0,1,2,3,4``
    22222248        This example defines a parameter that takes items in the first five columns
    22232249        and formats them in a different way. This parameter is not one of the pre-defined
    22242250        parameter names below. Some external code could be used to change the month string
    2225         (argument ``m``) to a integer from 1 to 12.
     2251        (argument ``m``) to a integer from 1 to 12.
     2252       
     2253    ``FreePrm2: int | 34 | Free Parm2 Label``
     2254        In this example, the contents of column 34 will be converted to an integer and
     2255        placed as the second free-named parameter in the Sample Parameters after an
     2256        integration. The label for this parameter will be changed to "Free Parm2 Label".
    22262257           
    22272258    **Pre-defined parameter names**
     
    22652296        keyExp = {}
    22662297        keyCols = {}
     2298        labels = {}
    22672299        for line in fp: # read label definitions
    22682300            items = line.strip().split(':')
     
    22822314                    print(msg)
    22832315                keyCols[key] = [int(i) for i in items[1].strip().split(',')]
     2316                if key.lower().startswith('freeprm') and len(items) > 2:
     2317                    labels[key] = items[2]
    22842318                continue
    22852319            if len(items) == 2: # simple column definition
     
    22952329            name = keyExp['filename'](*[items[j] for j in keyCols['filename']])
    22962330            if name == imageName: # got our match, parse the line and finish
    2297                 metadata = {lbldict[i]:items[i] for i in lbldict}
     2331                metadata = {lbldict[j]:items[j] for j in lbldict}
    22982332                metadata.update(
    22992333                    {key:keyExp[key](*[items[j] for j in keyCols[key]]) for key in keyExp})
    23002334                metadata['par file'] = parFil
    23012335                metadata['lbls file'] = lblFil
    2302                 print("Metadata read from {}".format(parFil))
     2336                for lbl in labels:
     2337                    metadata['label_'+lbl[4:].lower()] = labels[lbl]
     2338                print("Metadata read from {} line {}".format(parFil,i+1))
    23032339                return metadata
    23042340        else:
  • trunk/docs/source/index.rst

    r3187 r3190  
    2222  GSASIIscriptable.rst
    2323  GSASIIscripts.rst
     24  imports.rst
    2425  exports.rst
    25   imports.rst
    2626
    2727*Required packages*
Note: See TracChangeset for help on using the changeset viewer.