Changeset 2087

Dec 8, 2015 6:02:57 PM (7 years ago)

change error handling if h5py not installed; add new condition variable to importers (self.UseReader?); changes to docs to reflect this and consolidate description of package requirements

5 edited


  • trunk/

    r2084 r2087  
    285285                        else:
    286286                            reader = clss[1]() # create an import instance
    287                             readerlist.append(reader)
     287                            if reader.UseReader:
     288                                readerlist.append(reader)
    288289            except AttributeError:
    289290                print 'Import_'+errprefix+': Attribute Error '+str(filename)
  • trunk/

    r2083 r2087  
    13311331        '''
    13321332        pass
     1334    UseReader = True  # in __init__ set value of self.UseReader to False to skip use of current importer
    13341335    def __init__(self,
    13351336                 formatName,
  • trunk/docs/source/imports.rst

    r2068 r2087  
    6060    method when ``strictExtension`` is False.
    6161  * ``formatName``: a string to be used in the menu. Should be short.
    62   * ``longFormatName``: a longer string to be used to describe the format in help.
     62  * ``longFormatName``: a longer string to be used to describe the
     63    format in help.
     65Note that if an importer detects a condition which prevents its use,
     66for example because a required Python package is not present, it can
     67set the value of ``self.UseReader`` to False. Another possible use for
     68this would be an importer that requires a network connection to a
     69remote site. Setting ``self.UseReader`` to False must be done in the
     70``__init__`` method and will prevent the
     71importer from being used or included in the expected menu.
  • trunk/docs/source/index.rst

    r2027 r2087  
    3232* NumPy (,
    3333* SciPy (,
    34 * matplotlib ( 
    35 * PIL or Pillow ( and
     34* matplotlib (  and
    3635* PyOpenGL (
    38 These packages are not distributed as part of the Python standard
     37Two packages are used by some parts of the code, but are not required:
     38* PIL ( or Pillow ( This is used to save
     39  and read certain types of images.
     40* h5py is the HDF5 support package. This is (not surprisingly) required
     41  to import images from HDF5 files. If this library is not present,
     42  the HDF5 importer(s) will not appear in the import menu and a
     43  warning message appears on GSAS-II startup.
     45Note that the packages listed above are not distributed as part of the Python standard
    3946library and must be obtained separately (or in a bundled Python
    40 package such as the Enthought Python Distribution/Canopy or
    41's anaconda).  The PyOpenGL package will be installed into
     47package such as the Enthought Inc.'s Canopy or's anaconda; we also use the older Enthought Python
     50One exception is the PyOpenGL package. This will be installed into
    4251Python by GSAS-II if not found, so it does not need to be included in
    4352the Python bundle, but the setuptools package
  • trunk/imports/

    r2081 r2087  
    1818import numpy as np
    19 import h5py
    2019import GSASIIIO as G2IO
    2120import GSASIIpath
    2221GSASIIpath.SetVersionNumber("$Revision: $")
    24 class Hdf5_Reader(G2IO.ImportImage):
     23class HDF5_Reader(G2IO.ImportImage):
    2524    '''Routine to read a HD5 image, typically from APS Sector 6.
    2625    B. Frosik/SDM. Initial version.
    3130    def __init__(self):
    32         print 'start'
     31        # check if HDF5 library is present, if not importer cannot be used
     32        try:
     33            import h5py
     34        except:
     35            self.UseReader = False
     36            print 'HDF5 Reader skipped because h5py library not installed'
    3337        super(self.__class__,self).__init__( # fancy way to self-reference
    3438                                             extensionlist=('.hdf5','.hd5','.h5','.hdf'),
    4044    def ContentsValidator(self, filepointer):
    41         '''no test at this time
    42         '''
     45        '''test by using the HDF5 open
     46        '''
     47        import h5py
    4348        try:
    4449            # the following does not work, filepointer is not a filename
    5257        '''Read using HDF5 file reader, :func:`ReadData`
    5358        '''
     59        import h5py
    5460        imagenum = kwarg.get('blocknum')
    5561        if imagenum is None: imagenum = 1
    7480    def visit(self, f):         
     81        import h5py
    7582        def func(name, dset):
    7683            datakeyword = 'data'
Note: See TracChangeset for help on using the changeset viewer.