Ignore:
Timestamp:
Oct 23, 2017 11:39:16 AM (6 years ago)
Author:
vondreele
Message:

make GSAS-II python 3.6 compliant & preserve python 2.7 use;changes:
do from future import division, print_function for all GSAS-II py sources
all menu items revised to be py 2.7/3.6 compliant
all wx.OPEN --> wx.FD_OPEN in file dialogs
all integer divides (typically for image pixel math) made explicit with ; ambiguous ones made floats as appropriate
all print "stuff" --> print (stuff)
all print >> pFile,'stuff' --> pFile.writeCIFtemplate('stuff')
all read file opens made explicit 'r' or 'rb'
all cPickle imports made for py2.7 or 3.6 as cPickle or _pickle; test for '2' platform.version_tuple[0] for py 2.7
define cPickleload to select load(fp) or load(fp,encoding='latin-1') for loading gpx files; provides cross compatibility between py 2.7/3.6 gpx files
make dict.keys() as explicit list(dict.keys()) as needed (NB: possible source of remaining py3.6 bugs)
make zip(a,b) as explicit list(zip(a,b)) as needed (NB: possible source of remaining py3.6 bugs)
select unichr/chr according test for '2' platform.version_tuple[0] for py 2.7 (G2pwdGUI * G2plot) for special characters
select wg.EVT_GRID_CELL_CHANGE (classic) or wg.EVT_GRID_CELL_CHANGED (phoenix) in grid Bind
maxint --> maxsize; used in random number stuff
raise Exception,"stuff" --> raise Exception("stuff")
wx 'classic' sizer.DeleteWindows?() or 'phoenix' sizer.Clear(True)
wx 'classic' SetToolTipString?(text) or 'phoenix' SetToolTip?(wx.ToolTip?(text)); define SetToolTipString?(self,text) to handle the choice in plots
status.SetFields? --> status.SetStatusText?
'classic' AddSimpleTool? or 'phoenix' self.AddTool? for plot toolbar; Bind different as well
define GetItemPydata? as it doesn't exist in wx 'phoenix'
allow python versions 2.7 & 3.6 to run GSAS-II
Bind override commented out - no logging capability (NB: remove all logging code?)
all import ContentsValidator? open filename & test if valid then close; filepointer removed from Reader
binary importers (mostly images) test for 'byte' type & convert as needed to satisfy py 3.6 str/byte rules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/imports/G2img_MAR.py

    r2817 r3136  
    1212'''
    1313
     14from __future__ import division, print_function
     15import platform
     16import sys
     17import struct as st
    1418import GSASIIobj as G2obj
    1519import GSASIIpath
     
    2731            )
    2832
    29     def ContentsValidator(self, filepointer):
     33    def ContentsValidator(self, filename):
    3034        '''no test at this time
    3135        '''
    3236        return True
    3337       
    34     def Reader(self,filename,filepointer, ParentFrame=None, **unused):
     38    def Reader(self,filename, ParentFrame=None, **unused):
    3539        self.Comments,self.Data,self.Npix,self.Image = GetMAR345Data(filename)
    3640        if self.Npix == 0 or not self.Comments:
     
    4448        import pack_f as pf
    4549    except:
    46         print '**** ERROR - Unable to load the GSAS MAR image decompression, pack_f'
     50        print ('**** ERROR - Unable to load the GSAS MAR image decompression, pack_f')
    4751        return None,None,None,None
    4852
    4953    if not imageOnly:
    50         print 'Read Mar345 file: ',filename
     54        print ('Read Mar345 file: '+filename)
    5155    File = open(filename,'rb')
    52     head = File.read(4095)
     56    head = File.read(4095).decode(encoding='latin-1')
    5357    lines = head[128:].split('\n')
    5458    head = []
     
    7983    data['size'] = [sizex,sizey]
    8084    File.seek(pos)
    81     line = File.read(8)
     85    line = File.read(8).decode(encoding='latin-1')
    8286    while 'CCP4' not in line:       #get past overflow list for now
    83         line = File.read(8)
     87        line = File.read(8).decode(encoding='latin-1')
    8488        pos += 8
    8589    pos += 37
    8690    File.seek(pos)
    87     raw = File.read()
     91    if '2' in platform.python_version_tuple()[0]:
     92        raw = File.read()
     93    else:
     94        raw = File.read()
     95        print (type(raw),sys.getsizeof(raw),raw[:10])
     96    image = np.zeros(shape=(sizex,sizey),dtype=np.int32)   
     97    image = np.flipud(pf.pack_f(len(raw),raw,sizex,sizey,image).T)  #transpose to get it right way around & flip
    8898    File.close()
    89     image = np.zeros(shape=(sizex,sizey),dtype=np.int32)
    90    
    91     image = np.flipud(pf.pack_f(len(raw),raw,sizex,sizey,image).T)  #transpose to get it right way around & flip
    9299    if imageOnly:
    93100        return image
Note: See TracChangeset for help on using the changeset viewer.