source: trunk/imports/G2pwd_Pnn.py @ 2285

Last change on this file since 2285 was 2285, checked in by vondreele, 7 years ago

add importer for Shelx .ins files
also one for old GSAS Pnn powder histogram files.

File size: 2.4 KB
Line 
1# -*- coding: utf-8 -*-
2########### SVN repository information ###################
3# $Date: 2014-12-27 11:14:59 -0600 (Sat, 27 Dec 2014) $
4# $Author: vondreele $
5# $Revision: 1620 $
6# $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/imports/G2pwd_xye.py $
7# $Id: G2pwd_xye.py 1620 2014-12-27 17:14:59Z vondreele $
8########### SVN repository information ###################
9'''
10*Module G2pwd_Pnn: GSAS .Pnn data*
11------------------------------------
12
13Routine to read in powder data from a GSAS .Pnn binary blocked file
14
15'''
16
17import sys
18import os.path as ospath
19import numpy as np
20import array as ar
21import GSASIIIO as G2IO
22import GSASIIpath
23GSASIIpath.SetVersionNumber("$Revision: 1620 $")
24class Pnn_ReaderClass(G2IO.ImportPowderData):
25    'Routines to import powder data from a .Pnn file'
26    def __init__(self):
27        super(self.__class__,self).__init__( # fancy way to self-reference
28            extensionlist=('.P*',),
29            strictExtension=False,
30            formatName = 'GSAS Pnn',
31            longFormatName = 'GSAS Pnn powder data file'
32            )
33
34    # Validate the contents -- make sure we only have valid lines
35    def ContentsValidator(self, filepointer):
36        'Look through the file for expected types of lines in a valid GSAS Pnn file'
37        gotCcomment = False
38        self.GSAS = False
39        return True # no errors encountered
40
41    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
42        'Read a GSAS Pnn file'
43        x = []
44        y = []
45        w = []
46        buf = filepointer.read()
47        print len(buf)
48        remain = len(buf)%512
49        if remain:
50            buf += (512-remain)*' '
51        print len(buf)
52        buf = np.array(ar.array('f',buf),dtype=np.float32)
53        print buf.shape
54        buf = np.reshape(buf,(-1,128))
55        print buf.shape
56        for block in buf:
57            block = np.reshape(block[:126],(14,9)).T
58            x += list(block[1]-block[7]/2.)
59            y += list(block[2]*block[4])
60            w += list(block[6])
61        N = len(x)
62        print N
63        self.powderdata = [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)]
64        self.powderentry[0] = filename
65        self.powderentry[2] = 1 # Pnn file only has one bank
66        self.idstring = ospath.basename(filename)
67        return True
68     
69           
70           
71
Note: See TracBrowser for help on using the repository browser.