Skip to content

Commit b5b67f4

Browse files
committed
scripting: access pixel-mask & image
1 parent 4e4d63a commit b5b67f4

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

GSASII/GSASIIscriptable.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6772,6 +6772,15 @@ def initMasks(self):
67726772
Imax = np.max(ImageZ)
67736773
self.data['Masks']['Thresholds'] = [(0,Imax),[Imin,Imax]]
67746774

6775+
def getImage(self):
6776+
'''Returns the image, even if not already cached
6777+
'''
6778+
LoadG2fil()
6779+
if self.image is not None:
6780+
return self.image
6781+
else:
6782+
return _getCorrImage(Readers['Image'],self.proj,self)
6783+
67756784
def getMasks(self):
67766785
'''load masks from an IMG tree entry
67776786
'''

docs/source/GSASIIobj.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ as provides misc. support routines for accessing them.
77
*GSASIIobj Classes and routines*
88
------------------------------------
99

10-
.. automodule:: GSASIIobj
10+
.. automodule:: GSASII.GSASIIobj
1111
:members:
1212
:private-members:
1313
:special-members:

docs/source/GSASIIscriptable.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ method Use
443443
:meth:`~GSASIIscriptable.G2Image.setControls` Updates the Image Controls dict for the current image with specified key/value pairs.
444444
:meth:`~GSASIIscriptable.G2Image.getMasks` Returns the Masks dict for the current image.
445445
:meth:`~GSASIIscriptable.G2Image.setMasks` Updates the Masks dict for the current image with specified key/value pairs.
446+
:meth:`~GSASIIscriptable.G2Image.getImage` Returns the image array for the current image.
446447
:meth:`~GSASIIscriptable.G2Image.IntThetaAzMap` Computes the set of 2theta-azimuth mapping matrices to integrate the current image.
447448
:meth:`~GSASIIscriptable.G2Image.IntMaskMap` Computes the masking map for the current image for integration.
448449
:meth:`~GSASIIscriptable.G2Image.MaskThetaMap` Computes the 2theta mapping matrix to determine a pixel mask.
@@ -1605,6 +1606,39 @@ six-fold speedup has been seen with 16 cores.
16051606
if nodes > 0: pool.close()
16061607
print(f'Total elapsed time={time.time()-scriptstart:.3f} sec')
16071608
1609+
1610+
.. _PixelMask_Example:
1611+
1612+
Access the Image Pixel-Mask
1613+
------------------------------
1614+
1615+
In this example, a pixel mask has already been computed and has been
1616+
saved with the image in a .gpx file. This example then reads the .gpx file,
1617+
locates an image and then pulls the spot mask (an array of True and
1618+
False values for every pixel) from the data structure. As an extra
1619+
check (and demo) the image is reread and the dimensions of the image
1620+
are confirmed to match those of the image. Note that the
1621+
:meth:`~GSASIIscriptable.G2Image.GeneratePixelMask` routine could also
1622+
have been used to compute the mask.
1623+
1624+
This also provides an example showing how a result that is not made
1625+
directly available from the GSASIIscriptable API can still be accessed
1626+
from the GSAS-II data structures, but this requires some care to
1627+
determine where values are stored.
1628+
1629+
.. code-block:: python
1630+
1631+
import os
1632+
import G2script as G2sc
1633+
datadir = os.path.expanduser("~/Scratch/MPE_H5")
1634+
PathWrap = lambda fil: os.path.join(datadir,fil)
1635+
gpx = G2sc.G2Project(PathWrap('pixelMask.gpx'))
1636+
img0 = gpx.image(0) # access 1st image
1637+
spotMask = img0.data['Masks']['SpotMask'].get('spotMask')
1638+
if spotMask is not None:
1639+
assert spotMask.shape == img0.getImage().shape # diagnostic to confirm sizes match
1640+
1641+
16081642
.. _HistExport:
16091643

16101644
Histogram Export

0 commit comments

Comments
 (0)