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 | |
---|
13 | Routine to read in powder data from a GSAS .Pnn binary blocked file |
---|
14 | |
---|
15 | ''' |
---|
16 | |
---|
17 | import sys |
---|
18 | import os.path |
---|
19 | import numpy as np |
---|
20 | import array as ar |
---|
21 | import GSASIIIO as G2IO |
---|
22 | import GSASIIpath |
---|
23 | GSASIIpath.SetVersionNumber("$Revision: 1620 $") |
---|
24 | class 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=('.P01','.P02','.P03','.P04','.P05','.P06', |
---|
29 | '.P07','.P08','.P09','.P*',), |
---|
30 | strictExtension=False, |
---|
31 | formatName = 'GSAS .Pnn', |
---|
32 | longFormatName = 'GSAS .Pnn powder data file' |
---|
33 | ) |
---|
34 | |
---|
35 | # Validate the contents -- make sure we only have valid lines |
---|
36 | def ContentsValidator(self, filepointer): |
---|
37 | 'Look through the file for expected types of lines in a valid GSAS Pnn file' |
---|
38 | gotCcomment = False |
---|
39 | self.GSAS = False |
---|
40 | # file extension must be .Pxx or .pxx |
---|
41 | ext = os.path.splitext(filepointer.name)[1] |
---|
42 | if ext[1].upper() != 'P' or len(ext) != 4: |
---|
43 | return False |
---|
44 | if ext[2].isdigit() and ext[3].isdigit(): |
---|
45 | return True # no errors encountered |
---|
46 | return False |
---|
47 | |
---|
48 | |
---|
49 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
50 | 'Read a GSAS Pnn file' |
---|
51 | x = [] |
---|
52 | y = [] |
---|
53 | w = [] |
---|
54 | buf = filepointer.read() |
---|
55 | print len(buf) |
---|
56 | remain = len(buf)%512 |
---|
57 | if remain: |
---|
58 | buf += (512-remain)*' ' |
---|
59 | print len(buf) |
---|
60 | buf = np.array(ar.array('f',buf),dtype=np.float32) |
---|
61 | print buf.shape |
---|
62 | buf = np.reshape(buf,(-1,128)) |
---|
63 | print buf.shape |
---|
64 | for block in buf: |
---|
65 | block = np.reshape(block[:126],(14,9)).T |
---|
66 | x += list(block[1]-block[7]/2.) |
---|
67 | y += list(block[2]*block[4]) |
---|
68 | w += list(block[6]) |
---|
69 | N = len(x) |
---|
70 | print N |
---|
71 | self.powderdata = [np.array(x),np.array(y),np.array(w),np.zeros(N),np.zeros(N),np.zeros(N)] |
---|
72 | self.powderentry[0] = filename |
---|
73 | self.powderentry[2] = 1 # Pnn file only has one bank |
---|
74 | self.idstring = os.path.basename(filename) |
---|
75 | return True |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | |
---|