[GSAS-II] exception when loading gpx file in GSASIIscriptable project

Mark Wolfman mwolf22 at uic.edu
Sun Jul 1 23:23:19 CDT 2018


Hi, all.

I'm trying to use the GSAS-II scripting API described here[1] with
python 3.6 (thanks so much for updating that, btw). I have a gpx file
uploaded to the box folder[2] that contains one phase and one powder
data-set. After doing a Pawley refinement on it through the GSAS-II
GUI, I tried to use it to initialize a G2Project object using this
file and am presented with the exception listed below. Since this
takes place inside the ``G2PwdrData`` class, I assume
``self.data['data']`` should have 1 entry for each phase. Indeed, the
value of ``self.data`` is ``{'data': {'Corundum': {}}, 'Corundum':
None}``, but it looks like the code uses list-indexing, while the
entry being indexed is a dictionary.

It seems that later on, it actually does become a list. I tried using
the dictionary keys directly and instead I get a new exception when,
later on, the value of ``self.data['data']`` is actually a list.

.. code:: python

    @id.setter
    def id(self, val):
        key = tuple(self.data['data'].keys())[0]
        self.data['data'][key]['hId'] = val

    AttributeError: 'list' object has no attribute 'keys'

If I replace that property with a try-except block as in the snippet
below (GSASIIscriptable.py ln. 2075), then it loads without
exceptions. I don't know if this messes up things down the road,
though. Any thoughts?

.. code:: python

    @id.setter
    def id(self, val):
        try:
            self.data['data'][0]['hid'] = val
        except keyerror:
            pass

I noticed that I don't have pyspg installed. Trying ``pip install
pyspg`` yields an error in its setup.py file when trying to open the
VERSION file, so I never managed to fix that problem.

Thanks,
Mark

======================================================================
failed to run pyspg in /home/mwolf/build/pygsas/bin
error: no module named 'pyspg'
======================================================================
gsas-ii binary directory: /home/mwolf/build/pygsas/bindist
6 values read from config file /home/mwolf/build/pygsas/config.py
python module versions loaded:
  python:     3.6.6
  wx:         4.0.1
  matplotlib: 2.2.2
  numpy:      1.13.3
  scipy:      1.1.0
  opengl:     3.1.1a1
  PIL.Image:  5.1.0
  Platform:   linux64bitx86_64
This is GSAS-II revision 3459

Installed GSAS-II version: 3459
GSAS-II version on server: 3459
wrote file /home/mwolf/build/pyGSAS/config.py

In [9]: from GSASIIscriptable import G2Project

In [10]: prj = G2Project(fname)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-10-f6ebf08dde45> in <module>()
----> 1 prj = G2Project(fname)

~/build/pyGSAS/GSASIIscriptable.py in __init__(self, gpxfile, author, filename, newgpx)
   1263             # TODO set author
   1264             self.data, self.names = LoadDictFromProjFile(gpxfile)
-> 1265             self.update_ids()
   1266         else:
   1267             raise ValueError("Not sure what to do with gpxfile")

~/build/pyGSAS/GSASIIscriptable.py in update_ids(self)
   1648         #   GSASIIdataGUI.py:4107
   1649         for i, h in enumerate(self.histograms()):
-> 1650             h.id = i
   1651         for i, p in enumerate(self.phases()):
   1652             p.id = i

~/build/pyGSAS/GSASIIscriptable.py in id(self, val)
   2075     @id.setter
   2076     def id(self, val):
-> 2077         self.data['data'][0]['hId'] = val
   2078 
   2079     def fit_fixed_points(self):

KeyError: 0


[1] http://gsas-ii.readthedocs.io/en/latest/GSASIIscriptable.html

[2] https://uofi.app.box.com/folder/50843806744
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://mailman.aps.anl.gov/pipermail/gsas-ii/attachments/20180701/7e124ca4/attachment.sig>


More information about the GSAS-II mailing list