\(\renewcommand\AA{\text{Å}}\)
21. GSAS-II Importer Modules
Almost all the types of data files that GSAS-II can accept are read using a layer of routines called importers. (The one exception is the reading of powder peak positions.) Importers usually require quite simple code, so they can be written quickly for new data formats. The interface to the importers is self-configuring, so all supplied importers are available once the importer is added to the code base. This allows GSAS-II to be quite flexible in adapting to use many data formats without need for extensive coding.
Imports are implemented by deriving a class from
GSASIIobj.ImportPhase, GSASIIobj.ImportStructFactor,
GSASIIobj.ImportPowderData ,
GSASIIobj.ImportSmallAngleData,
GSASIIobj.ImportReflectometryData,
GSASIIobj.ImportPDFData,
or GSASIIobj.ImportImage. These classes are in turn
derived from GSASIIobj.ImportBaseclass.
Module file names (G2phase_, G2pwd_ and G2sfact_, etc.) are used to
determine which type of data will be read and which menu an importer
routine should be placed into. (N.B. in retrospect this
naming was an unnecessary choice; importer types could have been determined
from the base class as is done for exporters.)
To implement the import of a phase, a single crystal or a powder dataset, etc., create a file named with the appropriate file name prefix:
‘img’ (images),
‘pdf’ (pair distribution function),
‘phase’ (cell/coordinates),
‘pwd’ (powder diffraction),
‘rfd’ (reflectivity),
‘sad’ (small-angle scattering) or
‘sfact’ (single crystal).
The importer file can be placed
either in the GSASII/imports directory (which requires
modification of the __init__.py and the meson.build files
or the importer file can be placed in
the ~/.GSASII/imports directory.
(Note that ~ here is translated to the
user’s home directory; for Windows this is usually taken from the
USERPROFILE setting or a combination of HOMEPATH and HOMEDRIVE,
so this directory will usually have form
C:\\Users\\YourUsername\\.GSASII\\imports.
The next time GSAS-II is started,
the file will be loaded with all the other GSAS-II files and
the new data format(s) will appear in the appropriate importer menu.
The importer file may contain a
single importer class or several.
Importers are documented below, separated by type. Importers tend to be fairly simple files, where many are in the range of 50-100 lines, and where more than half of those lines are directly copied from other importers without any changes. Details on this are given in the Writing a Importer Routine section, immediately below.
21.1. Writing an Importer Routine
When writing a importer routine, one should create a new class derived
from
GSASIIobj.ImportPhase, GSASIIobj.ImportStructFactor,
GSASIIobj.ImportPowderData ,
GSASIIobj.ImportSmallAngleData,
GSASIIobj.ImportReflectometryData,
GSASIIobj.ImportPDFData,
or GSASIIobj.ImportImage.
The name of the class is arbitrary, but if more than one class is
placed in file, each class must have a different name. The same name
can be repeated if it is in different files.
As described below,
to implement an importer class, you must implement
an __init__() and a Reader() method, and many will supply a
ContentsValidator() method, too. The purpose of each of these
routines is described below. The easiest way to craft a new importer
will be to use the other importers of the same data type as a model
for what values should be set inside each routine, with most of the
work needed to create a Reader() routine. The documentation
for the parent class may also have some useful information. See the appropriate class
for details on what values each type of Reader() should
set.
21.1.1. __init__()
The __init__ method will follow standard boilerplate largely independent
of the data type:
def __init__(self):
super(self.__class__,self).__init__( # fancy way to self-reference
extensionlist=('.ext1','ext2'),
strictExtension=True,
formatName = 'example image',
longFormatName = 'A longer description that this is an example image format'
)
The first line in the __init__ method calls the parent class
__init__ method with the following parameters:
extensionlist: a list of extensions that may be used for this type of file.
strictExtension: Should be True if only files with extensions inextensionlistare allowed; False if all file types should be offered in the file browser. Also if False, the importer class will be used on all files when “guess from format” is tried, though readers with matching extensions will be tried first. It is a very good idea to supply a ContentsValidator method whenstrictExtensionis False.
formatName: a string to be used in the menu. Should be short.
longFormatName: a longer string to be used to describe the format in help.
Note that if an importer detects a condition which prevents its use,
for example because a required Python package is not present, it can
set the value of self.UseReader to False. Another possible use for
this would be an importer that requires a network connection to a
remote site. Setting self.UseReader to False must be done in the
__init__ method and will prevent the
importer from being accessed or included in the appropriate GUI menu.
21.1.2. Reader()
The class must supply a Reader method that actually performs the
reading. All readers must have at a minimum these arguments:
def Reader(self, filename, filepointer, ParentFrame, **unused):
where the arguments have the following uses:
filename: a string with the name of the file being read
filepointer: a file object (created byopen()) that accesses the file and is points to the beginning of the file when Reader is called.
ParentFrame: a reference to the main GSAS-II (tree) windows, for the unusualReaderroutines that will create GUI windows to ask questions. For use with scripting, the Reader should do something reasonable such as assume a default ifParentFrameis None, which indicates that the GUI should not be accessed.
In addition, the following keyword parameters are defined that Reader
routines may optionally use:
buffer: a dict that can be used to retain information between repeated calls of the routine
blocknum: counts the number of times that a reader is called, to be used with files that contain more than one set of data (e.g. GSAS .gsa/.fxye files with multiple banks or image files with multiple images.)
usedRanIdList: a list of previously used random Id values that can be checked to determine that a value is unique.
Note that a Reader is used to read only a single phase, image,
dataset, etc. and will be called repeatedly when used to read files
that contain multiple datasets, etc. The buffer dict can be used
to hold information that will speed repeated calls.
As an example, the buffer dict is used in CIF reading to hold the parsed CIF file,
so that when reading multiple datasets or phases from a multi-block
CIF, the parsed information can be reused without having to reread and
reparse the file for subsequent calls. For multi-image files, the
indexing of where images are to be found is done once and saved. This
greatly speeds the time needed to process image file.
Some additional information specific to on what a Reader() method
should do for images and single-crystal datasets can be found in the
documentation for ImportImage (images) and
ImportStructFactor, respectively.
21.1.2.1. Reader return values
The Reader routine should return the value of True if the file has been
read successfully. Optionally, use self.warnings to indicate any
problems.
If the file cannot be read, the Reader routine should
return False or raise an GSASIIobj.ImportBaseclass.ImportException()
exception. (Why are both available? Sometimes an exception is the easiest way to
bail out of a called routine.) Place text in self.errors and/or use:
ImportException('Error message')
to give the user information on what went wrong during the reading. The following variables are used to indicate results from the reader:
self.warnings
Use self.warnings to indicate any information that should be displayed to the user if the file is read successfully, but perhaps not completely or additional settings will need to be made.
self.errors
Use self.errors to give the user information on where and why a read
error occurs in the file. Note that text supplied with the raise
statement will be appended to self.errors.
self.repeat
Set self.repeat to True (the default is False) if a Reader should be called again to after reading to indicate that more data may exist in the file to be read. This is used for reading multiple powder histograms or multiple images from a single file. Variable self.repeatcount is used to keep track of the block numbers.
21.1.2.2. Reader support routines
Note that module GSASIIctrlGUI supplies three GUI routines,
BlockSelector(),
MultipleBlockSelector(), and
MultipleChoicesDialog() that are useful for
selecting amongst one or more datasets (and perhaps phases) or data items for
Reader() routines that may encounter more than one set of information
in a file.
21.1.3. ContentsValidator()
Defining a ContentsValidator method is optional, but is usually a
good idea, particularly if the file extension is not a reliable
identifier for the file type. The intent of this routine is to take a
superficial look at the file to see if it has the expected
characteristics of the expected file type. For example, are there
numbers in the expected places?
This routine is passed a single argument:
filepointer: a file object [created by Python intrinsic
open()] that accesses the file and is points to the beginning of the file when ContentsValidator is called.
Note that CIFValidator()
found in GSASIIobj.ImportBaseclass is a ContentsValidator
for validating CIF files.
21.1.3.1. ContentsValidator return values
The ContentsValidator routine should return the value of True if
the file appears to match the type expected for the class.
If the file cannot be read by this class, the routine should return False. Preferably one will also place text in self.errors to give the user information on what went wrong during the reading.
21.1.4. ReInitialize()
Importer classes are substantiated only once and are used as needed.
This means that if something needs to be initialized before the
Reader() will be called to read a new file, the initialization step must be coded. The
ReInitialize() method is provided for this and it is always called
before the ContentsValidator method is called. Use care to call
the parent class ReInitialize() method, if this is overridden.
21.2. Phase Importer Routines
Phase importer routines are classes derived from
GSASIIobj.ImportPhase.
They must be found in files named G2phase*.py that are in the Python path
and the class must override the __init__ method and add a Reader method.
The distributed routines are:
21.2.1. Module G2phase (PDB, PDF, .EXP & JANA m40,m50)
A set of short routines to read in phases in a number of formats, as created by a number of external programs. The PDB (Protein Data Bank) format uses coordinates in Angstroms. Other software includes GSAS/EXPGUI .EXP, JANA .m40-.m50 and Powder Diffaction File entries from the ICDD.
There are several classes in G2phase.
The documentation for them follows.
- class GSASII.imports.G2phase.EXP_ReaderClass[source]
Routine to import Phase information from GSAS .EXP files
- Reader(filename, ParentFrame=None, usedRanIdList=[], **unused)[source]
Read a phase from a GSAS .EXP file using
ReadEXPPhase()
- class GSASII.imports.G2phase.JANA_ReaderClass[source]
Routine to import Phase information from a JANA2006 file
- ContentsValidator(filename)[source]
Taking a stab a validating a .m50 file (look for cell & at least one atom)
- Reader(filename, ParentFrame=None, **unused)[source]
Read a m50 file using
ReadJANAPhase()
- class GSASII.imports.G2phase.PDB_ReaderClass[source]
Routine to import Phase information from a PDB file
- ContentsValidator(filename)[source]
Taking a stab a validating a PDB file (look for cell & at least one atom)
- Reader(filename, ParentFrame=None, **unused)[source]
Read a PDB file using
ReadPDBPhase()
- class GSASII.imports.G2phase.PDF_ReaderClass[source]
Routine to import Phase information from ICDD Powder Diffraction File(r) Card, exported by their software.
- Reader(filename, ParentFrame=None, **unused)[source]
Read phase from a ICDD .str file using
ReadPDFPhase()
21.2.2. Module G2phase_GPX: Import phase from GSAS-II project
Copies a phase from another GSAS-II project file into the current project.
Class to read a phase from an existing GSAS-II project file
21.2.3. Module G2phase_CIF: Coordinates from CIF
Parses a CIF using PyCifRW from James Hester (https://github.com/jamesrhester/pycifrw) and pulls out the structural information.
If a CIF generated by ISODISTORT is encountered, extra information is added to the phase entry and constraints are generated.
- class GSASII.imports.G2phase_CIF.CIFPhaseReader[source]
Implements a phase importer from a possibly multi-block CIF file
- ContentsValidator(filename)[source]
This routine will attempt to determine if the file can be read with the current format. This will typically be overridden with a method that takes a quick scan of [some of] the file contents to do a “sanity” check if the file appears to match the selected format. the file must be opened here with the correct format (binary/text)
- ISODISTORT_proc(blk, atomlbllist, ranIdlookup, filename)[source]
Process ISODISTORT items to create constraints etc. Constraints are generated from information extracted from loops beginning with _iso_ and are placed into self.Constraints, which contains a list of constraints tree items and one dict. The dict contains help text for each generated ISODISTORT variable
At present only _iso_displacivemode…, _iso_occupancymode… and _iso_magneticmode… are processed. Not yet processed: _iso_rotationalmode… & _iso_strainmode…
21.2.4. Module G2phase_INS: Import phase from SHELX INS file
Copies a phase from SHELX ins file into the current project.
- class GSASII.imports.G2phase_INS.PhaseReaderClass[source]
Opens a .INS file and pulls out a selected phase
- Reader(filename, filepointer, ParentFrame=None, **unused)[source]
Read a ins file using
ReadINSPhase()
21.2.5. Module G2phase_rmc6f: Import phase from RMCProfile
Copies a phase from a file written by RMCProfile into the current GSAS-II project.
Class to read a phase from a RMCprofile output file
- class GSASII.imports.G2phase_rmc6f.PhaseReaderClass[source]
Opens a .rmc6f file and pulls out the phase
- Reader(filename, filepointer, ParentFrame=None, **unused)[source]
Read a rmc6f file using
Readrmc6fPhase()
21.2.6. Module G2phase_xyz: read coordinates from an xyz file
A short routine to read in a phase from an xyz Cartesian coordinate file
21.2.7. Module G2phase_RRUFF: read from RRUFF database
A short routine to read in a phase from the RRUFF database in the native format it uses.
Reads structure files downloaded from the RRUFF database either as ASCII text files or .rtf files that somehow are generated
- class GSASII.imports.G2phase_RRUFF.RRUFFReader[source]
A fairly quickly-written importer to pull out the phase info from a RRUFF database (https://rruff.info) text file.
21.3. Powder Data Importer Routines
Powder data importer routines are classes derived from
GSASIIobj.ImportPowderData.
They must be found in files named G2pwd*.py that are in the Python path
and the class must override the __init__ method and add a
Reader method.
The distributed powder data importers are:
21.3.1. Module G2pwd_GPX: GSAS-II projects
Routine to importer powder data from GSAS-II .gpx files
- class GSASII.imports.G2pwd_GPX.GSAS2_ReaderClass[source]
Routines to import powder data from a GSAS-II file This should work to pull data out from a out of date .GPX file as long as the details of the histogram data itself don’t change
21.3.2. Module G2pwd_fxye: GSAS data files
Routine to read in powder data in a variety of formats that were defined in the original GSAS/EXPGUI software suite.
- class GSASII.imports.G2pwd_fxye.GSAS_ReaderClass[source]
Routines to import powder data from a GSAS files
- ContentsValidator(filename)[source]
Validate by checking to see if the file has BANK lines & count them
- Reader(filename, ParentFrame=None, **kwarg)[source]
Read a GSAS (old formats) file of type FXY, FXYE, ESD or STD types. If multiple datasets are requested, use self.repeat and buffer caching.
EDS data is only in the STD format (10 values per line separated by spaces); the 1st line contains at col 60 the word “Two-Theta “ followed by the appropriate value. The BANK record contains the 3 values (4th not used) after ‘EDS’ for converting MCA channel number (c) to keV via E = A + Bc + Cc^2; these coefficients are generally predetermined by calibration of the MCA. They & 2-theta are transferred to the Instrument parameters data.
21.3.3. Module G2pwd_xye: Topas & Fit2D data
Routine to read in powder data from a number of related formats including ones used in Topas and Fit2D. Typical file extensions are .xye, .qye, .chi, and .qchi.
Importer for various two/three column formats with 2theta vs intensity or Q vs intensity with an optional 3rd column for s.u.(I)
21.3.4. Module G2pwd_CIF: CIF powder data
Routine to read in powder data from a CIF. Parses a CIF using PyCifRW from James Hester (https://github.com/jamesrhester/pycifrw).
Class to read a phase from a CIF
21.3.5. Module G2pwd_BrukerRAW: Bruker .raw
Routine to read in powder data from most Bruker versions 2, 3, or 4 .raw files.
21.3.6. Module G2pwd_BrukerBRML: Bruker .brml
Routine to read in powder data from a Bruker .brml file.
21.3.7. Module G2pwd_FP: FullProf .dat data
Routine to read in powder data from a FullProf .dat file
21.3.8. Module G2pwd_Panalytical: Panalytical .xrdml data
Routines to importer powder data from a Pananalytical (XML) .xrdm file.
- class GSASII.imports.G2pwd_Panalytical.Panalytical_ReaderClass[source]
Routines to import powder data from a Pananalytical.xrdm (xml) file.
- ContentsValidator(filename)[source]
This routine will attempt to determine if the file can be read with the current format. This will typically be overridden with a method that takes a quick scan of [some of] the file contents to do a “sanity” check if the file appears to match the selected format. the file must be opened here with the correct format (binary/text)
21.3.9. Module G2pwd_csv: Read Excel .csv data
Routine to read in powder data from Excel type comma separated variable column-oriented variable. The only allowed extensions for this are .csv, .xy, or .XY.
- class GSASII.imports.G2pwd_csv.csv_ReaderClass[source]
Routines to import powder data from a .xye file
- ContentsValidator(filename)[source]
This routine will attempt to determine if the file can be read with the current format. This will typically be overridden with a method that takes a quick scan of [some of] the file contents to do a “sanity” check if the file appears to match the selected format. the file must be opened here with the correct format (binary/text)
21.3.10. Module G2pwd_rigaku: powder data from a Rigaku .txt file
- class GSASII.imports.G2pwd_rigaku.Rigaku_rasReaderClass[source]
Routines to import powder data from a Rigaku .ras file with multiple scans. All scans will be imported as individual PWDR entries
- ContentsValidator(filename)[source]
This routine will attempt to determine if the file can be read with the current format. This will typically be overridden with a method that takes a quick scan of [some of] the file contents to do a “sanity” check if the file appears to match the selected format. the file must be opened here with the correct format (binary/text)
- class GSASII.imports.G2pwd_rigaku.Rigaku_txtReaderClass[source]
Routines to import powder data from a Rigaku .txt file with an angle and then 1 or 11(!) intensity values on the line. The example file is proceeded with 10 of blank lines, but I have assumed they could be any sort of text. This code should work with an angle and any number of intensity values/line as long as the number is the same on each line. The step size may not change. The number of comment lines can also change, but should not appear to be intensity values (numbers only).
- ContentsValidator(filename)[source]
This routine will attempt to determine if the file can be read with the current format. This will typically be overridden with a method that takes a quick scan of [some of] the file contents to do a “sanity” check if the file appears to match the selected format. the file must be opened here with the correct format (binary/text)
21.3.11. Module G2pwd_MIDAS: Read integration results from MIDAS
The MIDAS package can be used on to read and integrate images, particularly at APS Sector 1. This importer reads the Zarr container files created by MIDAS.
Import a collection of “lineouts” from MIDAS from a zarr zip file
- class GSASII.imports.G2pwd_MIDAS.MIDAS_Zarr_Reader[source]
Routine to read multiple powder patterns from a Zarr file created by MIDAS. Perhaps in the future, other software might also use this file type as well.
For Midas, the main file is <file>.zip, but optionally sample and instrument parameters can be placed in <file>.samprm and <file>.instprm. Any parameters placed in those files will override values set in the .zip file.
- ContentsValidator(filename)[source]
Test if valid by seeing if the zarr module recognizes the file. Then get file type (currently Midas only)
- Reader(filename, ParentFrame=None, **kwarg)[source]
Scan file for sections needed by defined file types (currently only Midas) and then use appropriate routine to read the file. Most of the time the results are placed in the buffer arg (if supplied) so the file is not read on most calls.
For MIDAS, masking can eliminate some or all points in an azimuthal region. This will only return “lineouts” (aka diffractograms) that have 20 or more points in them.
Note that if Reader.selections is used to select individual “lineouts”, the selections are numbered against all possible “lineouts” not the ones that have 20 or more points.
21.4. Single Crystal Data Importer Routines
Single crystal data importer routines are classes derived from
, GSASIIobj.ImportStructFactor.
They must be found in files named G2sfact*.py that are in the Python path
and the class must override the __init__ method and add a Reader method.
The distributed routines are:
21.4.1. Module G2sfact: simple HKL import
Read structure factors from a number of hkl file types. Routines are provided to read from files containing F or F2 values from a number of sources.
Classes to read single crystal reflection files in formats used by: Shelx, Jana, REMOS, TOPAS (SNS), HB-3A (HIFR)
- GSASII.imports.G2sfact.ColumnValidator(parent, filepointer, nCol=5)[source]
Validate a file to check that it contains columns of numbers
- class GSASII.imports.G2sfact.GSAS2_INT_ReaderClass[source]
Routines to import reflections from a GSAS-II gpx file
- class GSASII.imports.G2sfact.HKLF_ReaderClass[source]
Routines to import F, sig(F) reflections from a HKLF file
- class GSASII.imports.G2sfact.HKLMF_ReaderClass[source]
Routines to import F, reflections from a REMOS HKLMF file
- class GSASII.imports.G2sfact.M90_ReaderClass[source]
Routines to import F**2, sig(F**2) reflections from a JANA M90/M91 file
- class GSASII.imports.G2sfact.NT_HKLF2_ReaderClass[source]
Routines to import neutron TOF F**2, sig(F**2) reflections from a HKLF file
- class GSASII.imports.G2sfact.NT_JANA2K_ReaderClass[source]
Routines to import neutron TOF F**2, sig(F**2) reflections from a JANA2000 file
- class GSASII.imports.G2sfact.SHELX4ED_ReaderClass[source]
Routines to import F**2, sig(F**2), exp# & Z-pos reflections from a Shelx HKLF 4 microED file
- class GSASII.imports.G2sfact.SHELX4_ReaderClass[source]
Routines to import F**2, sig(F**2) reflections from a Shelx HKLF 4 file
- class GSASII.imports.G2sfact.SHELX5_ReaderClass[source]
Routines to import F**2, sig(F**2) twin/incommensurate reflections from a fixed format SHELX HKLF5 file
- class GSASII.imports.G2sfact.SHELX6_ReaderClass[source]
Routines to import F**2, sig(F**2) twin/incommensurate reflections from a fixed format SHELX HKLF6 file
21.4.2. Module G2sfact_CIF: CIF import
Read structure factors from a CIF reflection table CIF using PyCifRW from James Hester (https://github.com/jamesrhester/pycifrw).
Class to read single-crystal data from a CIF
21.5. Small Angle Scattering Data Importer Routines
Small angle scattering data importer routines are classes derived from
, GSASIIobj.ImportSmallAngleData.
They must be found in files named G2sad*.py that are in the Python path
and the class must override the __init__ method and add a Reader method.
The distributed routines are in:
21.5.1. Module G2sad_xye: read small angle data
Routines to read in small angle data from an .xye type file, with two-theta or Q steps. Expected extensions are .xsad, .xdat, .nsad, or .ndat.
- class GSASII.imports.G2sad_xye.txt_NeutronReaderClass[source]
Routines to import neutron q SAXD data from a .nsad or .ndat file
- class GSASII.imports.G2sad_xye.txt_XRayReaderClass[source]
Routines to import X-ray q SAXD data from a .xsad or .xdat file
21.6. Image Importer Routines
Image importer routines are classes derived from
GSASIIobj.ImportImage.
See Writing a Importer Routine for general
information on importers and the GSASIIobj.ImportImage for
information on what class variables a reader should set.
Image importers must be found in files named G2img*.py that are in the Python path
and the class must override the __init__ method and add a
Reader method.
The distributed routines are:
21.6.1. Module G2img_ADSC: .img image file
21.6.2. Module G2img_EDF: .edf image file
21.6.3. Module G2img_SumG2: Python pickled image
Routine to read an image from GSAS-II that has been pickled in Python. Images in this format are created by the “Sum image data” command. At least for now, only one image is permitted per file.
21.6.4. Module G2img_GE: summed GE image file
Read data from General Electric angiography x-ray detectors, primarily as used at APS 1-ID. This shows an example of an importer that will handle files with more than a single image.
- class GSASII.imports.G2img_GE.GE_ReaderClass[source]
Routine to read a GE image, typically from APS Sector 1.
The image files may be of form .geX (where X is ‘ ‘, 1, 2, 3, 4 or 5), which is a raw image from the detector. These files may contain more than one image and have a rudimentary header. Files with extension .sum or .cor are 4 byte integers/pixel, one image/file. Files with extension .avg are 2 byte integers/pixel, one image/file.
- Reader(filename, ParentFrame=None, **kwarg)[source]
Read using GE file reader,
GetGEsumData()
- class GSASII.imports.G2img_GE.GEsum_ReaderClass[source]
Routine to read multiple GE images & sum them, typically from APS Sector 1.
The image files may be of form .geX (where X is ‘ ‘, 1, 2, 3, 4 or 5), which is a raw image from the detector. These files may contain more than one image and have a rudimentary header. Files with extension .sum or .cor are 4 byte integers/pixel, one image/file. Files with extension .avg are 2 byte integers/pixel, one image/file.
- Reader(filename, ParentFrame=None, **kwarg)[source]
Read using GE file reader,
GetGEsumData()
21.6.5. Module G2img_MAR: MAR image files
21.6.6. Module G2img_Rigaku: .stl image file
21.6.7. Module G2img_1TIF: Tagged-image File images
Routine to read an image in Tagged-image file (TIF) format as well as a variety of slightly incorrect pseudo-TIF formats used at instruments around the world. This uses a custom reader that attempts to determine the instrument and detector parameters from various aspects of the file, not always successfully alas.
Note that the name G2img_1TIF is used so that this file will
sort to the top of the image formats and thus show up first in the menu.
(It is the most common, alas).
- GSASII.imports.G2img_1TIF.GetTifData(filename, imageOnly=False)[source]
Read an image in a pseudo-tif format, as produced by a wide variety of software, almost always incorrectly in some way.
- GSASII.imports.G2img_1TIF.TIFValidator(filename)[source]
Does the header match the required TIF header?
- class GSASII.imports.G2img_1TIF.TIF_ReaderClass[source]
Reads TIF files using a routine (
GetTifData()) that looks for files that can be identified from known instruments and will correct for slightly incorrect TIF usage.- Reader(filename, ParentFrame=None, **unused)[source]
Read the TIF file using
GetTifData()which attempts to recognize the detector type and set various parameters
21.6.8. Module G2img_PILTIF: Std Tagged-image File images
Routine to read an image in Tagged-image file (TIF) format using a standard image library function in Pillow or the now obsolete PIL package. This means that parameters such as the pixel size (which is in the TIFF header but is almost never correct) and distance to sample, etc. are not correct unless specified in a separate metadata file. See below for more information on metadata files.
Read TIF files using the PIL/Pillow module.
The metadata can be specified in a file with the same name and path as the TIFF file except that the the extension is .metadata.
The contents of that file are a series of lines of form:
keyword = value
Note that capitalization of keywords is ignored. Defined keywords are in table below. Any line without one of these keywords will be ignored.
keyword |
explanation |
|---|---|
wavelength |
Wavelength in \(\AA\) |
distance |
Distance to sample in mm |
polarization |
Percentage polarized in horizontal plane |
sampleChangerCoordinate |
Used for sample changers to track sample |
pixelSizeX |
Pixel size in X direction (microns) |
pixelSizeY |
Pixel size in Y direction (microns) |
CenterPixelX |
Location of beam center as a pixel number (in X) |
CenterPixelY |
Location of beam center as a pixel number (in X) |
- class GSASII.imports.G2img_PILTIF.TIF_LibraryReader[source]
Reads TIF files using a standard library routine. Metadata (such as pixel size) must be specified by user, either in GUI or via a metadata file. The library TIF reader can handle compression and other things that are not commonly used at beamlines.
21.6.9. Module G2img_png: png image file
Routine to read an image in .png (Portable Network Graphics) format. For now, the only known use of this is with converted Mars Rover (CheMin) tif files, so default parameters are for that.
21.6.10. Module G2img_CBF: .cbf cif image file
- class GSASII.imports.G2img_CBF.CBF_ReaderClass[source]
Routine to read a Read cif image data .cbf file. This is used by Pilatus.
- Reader(filename, ParentFrame=None, **unused)[source]
Read using Bob’s routine
GetCbfData()
21.6.11. Module G2img_HDF5: summed HDF5 image file
Reads images found in a HDF5 file. If the file contains multiple images, all are read.
A reader for HDF-5 files. This should be as generic as possible, but at present this is pretty much customized for XSD-MPE (APS) uses.
Note that for further development of this routine, as more types of HDF5 image files occur “in the wild,” it is often helpful to map out the contents of a HDF5 file. If debug mode is on and the full file name/path contains either ‘tmp’ or ‘scratch’ (case is ignored) then the two files are created with filename + _HDF5Map.txt and + _NeXusMap.txt that use HDF5 and NeXus routines to outline the file contents.
- class GSASII.imports.G2img_HDF5.HDF5_Reader[source]
Routine to read one or more HDF-5 images from a HDF5 file, typically from APS Sectors 1, 6 or 20.
Initial version from Barbara Frosik/SDM.
- ContentsValidator(filename)[source]
Test if valid by seeing if the HDF5 library recognizes the file.
- Reader(filename, ParentFrame=None, **kwarg)[source]
Read an image from a HDF5 file. Note that images are using
readDataset().When called the first time on a file, the file structure is scanned using
visit()to map out locations of image(s). On subsequent calls, if more than one image is in the file, the map of file structure (in buffer arg) is reused. Depending on the Config setting for HDF5selection, a window may be opened to allow selection of which images will be read.When an image is reread, the blocknum will be a list item with the location to be read, so the file scan can be skipped.
- visit(fp, log=None)[source]
Recursively visit every node in an HDF5 file & look at dimensions of contents. If the shape is length 2, 3, or 4 assume an image and index in self.buffer[‘imagemap’]. Optionally save an outline of the file contents on log, if defined.
- Parameters:
fp – an HDF5 file object from h5py.File()
log – an optional text file object [from open()]. If supplied, an outline of the file contents is placed here.
21.6.12. Module G2img_SFRM: Brucker .sfrm image file
- GSASII.imports.G2img_SFRM.GetGFRMData(self, filename)[source]
Read Bruker compressed binary detector data gfrm file
- GSASII.imports.G2img_SFRM.GetSFRMData(self, filename)[source]
Read cbf compressed binarydetector data sfrm file
- class GSASII.imports.G2img_SFRM.SFRM_ReaderClass[source]
Routine to read a Read Bruker Advance image data .sfrm/.grfm file.
- ContentsValidator(filename)[source]
GFRM files always begin with FORMAT, should also contain VERSION (also HDRBLKS, but not checked) No check for SRFM files
- Reader(filename, ParentFrame=None, **unused)[source]
Read using Bob’s routine
GetSFRMData()
21.6.13. Module G2img_pixirad_1ID_16bit: Pixirad detector
Reads images from the pixirad detector in use as APS Sector 1.
21.6.13.1. Module G2img_pixirad_1ID_16bit.py: 16-bit Pixirad TIF
Adaptation of G2img_1ID_32bit_TIFsum.py for use with the 1ID SAXS pixirad. Used at 1-ID with normalized 16bit Pixirad TIF for rapid access measurement
- GSASII.imports.G2img_pixirad_1ID_16bit.GetTifData(filename)[source]
Confirm that the file is in fact a 16bit tiff image with the correct parameters. Will nearly always throw an error unless used with the 1ID GSASII workflow, which assigns the proper tags and converts the Pixirad tiff images into the 16bit format with a different buffer in order to hold the larger amount of data in each pixel.
- class GSASII.imports.G2img_pixirad_1ID_16bit.TIF_ReaderClass[source]
Reads TIF files using a routine (
GetTifData()) that looks for files that can be identified from known instruments and will correct for slightly incorrect TIF usage. If that routine fails, it will be read with a standard TIF reader, which can handle compression and other things less commonly used at beamlines.- Reader(filename, ParentFrame=None, **unused)[source]
Read the TIF file using
GetTifData().
21.7. Pair Distribution Function (PDF) Importer Routines
PDF importer routines are classes derived from
GSASIIobj.ImportPDFData.
See Writing a Importer Routine for general information on importers.
The distributed routines are in:
21.7.1. Module G2pdf_gr: read PDF G(R) data
Routines to read in G(R) data from a pdfGet/GSAS-II .gr or gudrun .dat file (with \(\AA\) steps) or S(Q) data from a .fq file.
- class GSASII.imports.G2pdf_gr.txt_FSQReaderClass[source]
Routines to import S(Q) data from a .fq file
21.8. Reflectometry Importer Routines
Reflectometry importer routines are classes derived from
GSASIIobj.ImportReflectometryData.
See Writing a Importer Routine for general information on importers.
The distributed routines are:
21.8.1. Module G2rfd_xye: read reflectometry data
Routines to read in reflectometry data from an .xrfd, .xdat, .xtrfd, .xtdat, .nrfd or .ndat type file, with two-theta or Q steps.
- class GSASII.imports.G2rfd_xye.txt_NeutronReaderClass[source]
Routines to import neutron q REFD data from a .nrfd or .ndat file
21.8.2. Module G2rfd_Panalytical: read Panalytical reflectometry data
Routine to importer reflectivity data from a Panalytical .xrdm (xml) file.
- class GSASII.imports.G2rfd_Panalytical.Panalytical_ReaderClass[source]
Routines to import reflectivity data from a Panalytical.xrdm (xml) file.
- ContentsValidator(filename)[source]
This routine will attempt to determine if the file can be read with the current format. This will typically be overridden with a method that takes a quick scan of [some of] the file contents to do a “sanity” check if the file appears to match the selected format. the file must be opened here with the correct format (binary/text)
21.8.3. Module G2rdf_rigaku: reflectometry data from a Rigaku file
- class GSASII.imports.G2rfd_rigaku.Rigaku_rasReaderClass[source]
Routines to import reflectometry data from a Rigaku .ras file with multiple scans. All scans will be imported as individual PWDR entries
- ContentsValidator(filename)[source]
This routine will attempt to determine if the file can be read with the current format. This will typically be overridden with a method that takes a quick scan of [some of] the file contents to do a “sanity” check if the file appears to match the selected format. the file must be opened here with the correct format (binary/text)
- class GSASII.imports.G2rfd_rigaku.Rigaku_txtReaderClass[source]
Routines to import powder data from a Rigaku .txt file with an angle and then 1 or 11(!) intensity values on the line. The example file is proceeded with 10 of blank lines, but I have assumed they could be any sort of text. This code should work with an angle and any number of intensity values/line as long as the number is the same on each line. The step size may not change. The number of comment lines can also change, but should not appear to be intensity values (numbers only).
- ContentsValidator(filename)[source]
This routine will attempt to determine if the file can be read with the current format. This will typically be overridden with a method that takes a quick scan of [some of] the file contents to do a “sanity” check if the file appears to match the selected format. the file must be opened here with the correct format (binary/text)