Changeset 3828


Ignore:
Timestamp:
Feb 22, 2019 9:35:29 AM (3 years ago)
Author:
toby
Message:

fix cif export w/unused histogram; switch 3.x imports to pickle w/warn if _pickle not available; doc fixes; scriptable enhancements

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r3825 r3828  
    3838    import cPickle
    3939else:
    40     import _pickle as cPickle
     40    import pickle as cPickle
    4141import sys
    4242import re
  • trunk/GSASIIdataGUI.py

    r3826 r3828  
    3030    import cPickle
    3131else:
    32     import _pickle as cPickle
     32    try:
     33        import _pickle as cPickle
     34    except:
     35        print('Warning: failed to import the optimized Py3 pickle (_pickle)')
     36        import pickle as cPickle
    3337import numpy as np
    3438import numpy.ma as ma
  • trunk/GSASIIscriptable.py

    r3822 r3828  
    563563    strtypes = (str,unicode)
    564564else:
    565     import _pickle as cPickle
     565    import pickle as cPickle
    566566    strtypes = (str,bytes)
    567567import imp
     
    32103210                   'SampleAbs', 'center', 'ellipses', 'linescan',
    32113211                    'pixelSize', 'range', 'ring', 'rings', 'size', ],
    3212         'dict': ['varylist'],
     3212        'dict': ['varyList'],
    32133213        }
    32143214    '''Defines the items known to exist in the Image Controls tree section
     
    32713271        if arg in self.data['Image Controls']:
    32723272            return self.data['Image Controls'][arg]
     3273        print(self.findControl(''))
    32733274        raise Exception('arg {} not defined in G2Image.getControl'.format(arg))
    32743275
     
    33733374        print('file {} read into {}'.format(filename,self.name))
    33743375       
     3376    def getVary(self,*args):
     3377        '''Return the refinement flag(s) for Image Controls parameter(s)
     3378        in the current image.
     3379        If the parameter is not found, an exception is raised.
     3380
     3381        :param str arg: the name of a refinement parameter in the
     3382          varyList for the image. The name should be one of
     3383          'dep', 'det-X', 'det-Y', 'dist', 'phi', 'tilt', or 'wave'
     3384        :param str arg1: the name of a parameter (dict entry) as before,
     3385          optional
     3386
     3387
     3388        :returns: a list of bool value(s)
     3389        '''
     3390        res = []
     3391        for arg in args:
     3392            if arg in self.data['Image Controls']['varyList']:
     3393                res.append(self.data['Image Controls']['varyList'][arg])
     3394            else:
     3395                raise Exception('arg {} not defined in G2Image.getVary'.format(arg))
     3396        return res
     3397   
     3398    def setVary(self,arg,value):
     3399        '''Set a refinement flag for Image Controls parameter in the
     3400        current image.
     3401        If the parameter is not found an exception is raised.
     3402
     3403        :param str arg: the name of a refinement parameter in the
     3404          varyList for the image. The name should be one of
     3405          'dep', 'det-X', 'det-Y', 'dist', 'phi', 'tilt', or 'wave'
     3406        :param str arg: the name of a parameter (dict entry) in the
     3407          image. The parameter must be found in :data:`ControlList`
     3408          or an exception is raised.
     3409        :param value: the value to set the parameter. The value is
     3410          cast as the appropriate type from :data:`ControlList`.
     3411        '''
     3412        if arg in self.data['Image Controls']['varyList']:
     3413            self.data['Image Controls']['varyList'][arg] = bool(value)
     3414        else:
     3415            raise Exception('arg {} not defined in G2Image.setVary'.format(arg))
     3416
    33753417    def Recalibrate(self):
    33763418        '''Invokes a recalibration fit (same as Image Controls/Calibration/Recalibrate
     
    33793421        This may produce a better result if run more than once.
    33803422        '''
     3423        LoadG2fil()
    33813424        ImageZ = GetCorrImage(Readers['Image'],self.proj,self)
    33823425        G2img.ImageRecalibrate(None,ImageZ,self.data['Image Controls'],self.data['Masks'])
  • trunk/docs/source/imports.rst

    r3823 r3828  
    44Imports are implemented by deriving a class from
    55:class:`GSASIIobj.ImportPhase`, :class:`GSASIIobj.ImportStructFactor`,
    6 :class:`GSASIIobj.ImportPowderData`
    7 or :class:`GSASIIIO.ImportPowderData` (which are in turn
     6:class:`GSASIIobj.ImportPowderData` ,
     7:class:`GSASIIobj.ImportSmallAngleData`, 
     8:class:`GSASIIobj.ImportReflectometryData`, 
     9:class:`GSASIIobj.ImportPDFData`, 
     10or :class:`GSASIIobj.ImportImage` (which are in turn
    811derived from :class:`GSASIIobj.ImportBaseclass`)
    912to implement import of
     
    1114Module file names (`G2phase_`, `G2pwd_` and `G2sfact_`, etc.) are used to
    1215determine which menu an import routine should be placed into. (N.B. this
    13 was an unnecessary choice; this could be done from the class used.)
    14 
    15 This list may not include all currently defined formats, since modules
    16 may be loaded from anywhere in the path.
     16naming was an unnecessary choice; importer types could be determined
     17from the base class.)
     18
     19Most importers are listed below by type (provided this documentation is
     20up to date), but note that since modules
     21may be loaded from anywhere in the path, your installation could have
     22locally-defined importers as well.
    1723
    1824.. _import_routines:
     
    2228
    2329When writing a import routine, one should create a new class derived
    24 from :class:`GSASIIIO.ImportPhase`, :class:`GSASIIIO.ImportStructFactor`
    25 or :class:`GSASIIIO.ImportPowderData`. As described below,
     30from
     31:class:`GSASIIobj.ImportPhase`, :class:`GSASIIobj.ImportStructFactor`,
     32:class:`GSASIIobj.ImportPowderData` ,
     33:class:`GSASIIobj.ImportSmallAngleData`, 
     34:class:`GSASIIobj.ImportReflectometryData`, 
     35:class:`GSASIIobj.ImportPDFData`, 
     36or :class:`GSASIIobj.ImportImage`. As described below,
    2637all these classes will implement
    2738an ``__init__()`` and a ``Reader()`` method, and most will supply a
    2839``ContentsValidator()`` method, too.
    29 See the :class:`~GSASIIIO.ImportPhase`,
    30 :class:`~GSASIIIO.ImportStructFactor`,
    31 :class:`~GSASIIIO.ImportPowderData`
    32 or :class:`~GSASIIIO.ImportImage` class documentation
     40See the appropriate class documentation
    3341for details on what values each type of ``Reader()`` should set.
    3442
     
    112120
    113121If the file cannot be read,  the ``Reader`` routine should
    114 return False or raise an :class:`GSASIIIO.ImportBaseclass.ImportException`
     122return False or raise an :class:`GSASIIobj.ImportBaseclass.ImportException`
    115123exception. (Why either? Sometimes an exception is the easiest way to
    116124bail out of a called routine.) Place text in `self.errors` and/or use::
     
    173181  called.
    174182
    175 Note that :meth:`GSASIIIO.ImportBaseclass.CIFValidator` is a ContentsValidator
     183Note that :meth:`GSASIIobj.ImportBaseclass.CIFValidator` is a ContentsValidator
    176184for validating CIF files.
    177185
     
    300308-----------------------------------------------------
    301309Image import routines are classes derived from
    302 :class:`GSASIIIO.ImportImage`.
     310:class:`GSASIIobj.ImportImage`.
    303311See :ref:`Writing a Import Routine<import_routines>` for general
    304312information on importers and the :class:`GSASIIobj.ImportImage` for
     
    340348    :members:
    341349
     350.. automodule:: G2img_SFRM
     351    :members:
     352       
    342353PDF Import Routines
    343354-----------------------------------------------------
  • trunk/exports/G2export_CIF.py

    r3800 r3828  
    635635            for histogram in sorted(phasedict['Histograms']):
    636636                if histogram.startswith("HKLF"): continue # powder only
     637                if not self.Phases[phasenam]['Histograms'][histogram]['Use']: continue
    637638                Histogram = self.Histograms.get(histogram)
    638639                if not Histogram: continue
  • trunk/imports/G2img_GE.py

    r3473 r3828  
    127127        import cPickle
    128128    else:
    129         import _pickle as cPickle
     129        import pickle as cPickle
    130130    import time
    131131    more = False
  • trunk/imports/G2phase_GPX.py

    r3310 r3828  
    2121    import cPickle
    2222else:
    23     import _pickle as cPickle
     23    import pickle as cPickle
    2424import random as ran
    2525import GSASIIobj as G2obj
  • trunk/imports/G2pwd_GPX.py

    r3136 r3828  
    1818    import cPickle
    1919else:
    20     import _pickle as cPickle
     20    import pickle as cPickle
    2121import numpy as np
    2222import GSASIIobj as G2obj
  • trunk/testDeriv.py

    r3826 r3828  
    2828    import StringIO
    2929else:
    30     import _pickle as cPickle
     30    import pickle as cPickle
    3131    import io as StringIO
    3232import cProfile,pstats
Note: See TracChangeset for help on using the changeset viewer.