mda2idd_report

Source code documentation

mda2idd_report Module

Generate ASCII text files from MDA files for APS station 2-ID-D

Objectives

  • Replaces yviewer, asciiRpt.py and mdaRpt.py
  • Creates a GUI similar to that of asciiRpt.py (aka yviewer)

Different than the output from mdaAscii, this module converts 1-D and 2-D scans stored in MDA files [1] into the text file format produced by yca scanSee_report (a Yorick-based support).

[1]MDA format specification: http://www.aps.anl.gov/bcda/synApps/sscan/saveData_fileFormat.txt

Main Methods

  • report(): converts MDA file to 1 or more ASCII text files, based on the rank
  • report_list(): process a list of MDA files
  • summaryMda(): text summary of a single MDA file (name, rank, datetime, …)

Internal (but interesting) Methods

Dependencies

operating system

None. This software was developed on a Windows 7 system and tested on various Linux distributions (Ubuntu, mint, and RHEL Linux) and on MacOSX. It was also tested on solaris but the performance was too poor on that specific system to advocate its continued use.

>>> git clone https://github.com/BCDA-APS/mda2idd_report.git

Source Code Documentation

summaryMda(mdaFileName) text summary of a single MDA file (name, rank, datetime, …)
report(mdaFileName[, allowException]) converts MDA file to 1 or more ASCII text files, based on the rank
report_1d(data) report 1-D MDA scan data in this format:
report_2d(data) report 2-D MDA scan data in this format, one file for each detector:
columnsToText(columns) convert a list of column lists into rows of text
writeOutput(path, filename, output) write the output text buffer to the file
getAsciiFileName(data[, detNum]) return the proper text file name, based on the file name stored in the MDA data structure
getAsciiPath(mdaFileName) given the path to the MDA file, return the related ASCII file path
report_list(mdaFileList) process a list of MDA files

exception mda2idd_report.RankException[source]

Bases: exceptions.Exception

this report can only handle ranks 1 and 2

exception mda2idd_report.ReadMdaException[source]

Bases: exceptions.Exception

MDA files are all version 1.3 (+/- 0.01)

mda2idd_report.columnsToText(columns)[source]

convert a list of column lists into rows of text

column widths will be chosen from the maximum character width of each column

Parameters:columns ([[str]]) – list of column lists (all same length)
Returns str:text block, with line separators

Example:

>>> columns = [ ['1A', '2A'], ['1B is long', '2B'], ['1C', '2C'] ]
>>> print columnsToText( columns )
1A  1B is long  1C
2A  2B          2C
mda2idd_report.developer_test()[source]

only for use in code development and testing

mda2idd_report.getAsciiFileName(data, detNum=None)[source]

return the proper text file name, based on the file name stored in the MDA data structure

Parameters:
  • data (obj) – MDA data structure returned by mda.readMDA()
  • detNum (int) – (2-D only)
mda2idd_report.getAsciiPath(mdaFileName)[source]

given the path to the MDA file, return the related ASCII file path

Create the path to the ASCII directory if it does not exist. If we cannot create the ASCII dir path, return the MDA file path instead.

The default expectation is that the files are stored in this type of directory structure:

some/path/to/data/
  ./MDA/
     scan_0001.mda
  ./ASCII/
     scan_0001.1d.txt
mda2idd_report.main()[source]

handles command-line input

mda2idd_report.report(mdaFileName, allowException=False)[source]

converts MDA file to 1 or more ASCII text files, based on the rank

Parameters:mdaFileName (str) – includes absolute or relative path to MDA file
Returns dict:{mdaFileName: [asciiFileName]}
mda2idd_report.report_1d(data)[source]

report 1-D MDA scan data in this format:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
; 
; ========================================================
; Filename: /home/2-iddf/data12c3/Alix_NWU/mda/2iddf_0001.mda
; 1D Scanno # =        1
; title= (Scan # 1)
; xtitle= PI_sample1_X(micron)
; ytitle= 
; timeStamp= OCT 30, 2012 12:03:41
; comment= 
; 
; 
; DIS:             P1                 D1                 D2                 ...
; Name:            2iddf:m38.VAL      S:SRcurrentAI      2idd:scaler1_cts1. ...
; Desc:            PI_sample1_X       SR Current                            ...
; Unit:            micron             mA                                    ...
  1               1197.47            122.374            169.800             ...
  2               1198.97            122.347            169.400             ...
  3               1200.47            122.318            171.000             ...
  4               1201.97            122.289            173.600             ...
  5               1203.47            122.777            169.000             ...
mda2idd_report.report_2d(data)[source]

report 2-D MDA scan data in this format, one file for each detector:

1
2
3
4
5
6
7
8
9
; FILE:  /home/2-iddf/data12c3/Alix_NWU/mda/2iddf_0012.mda
; Title:  Image#16 (2iddf:mca1.R9) - D01
; Scan # =       12 ,  Detector # =       16 ,   col=       51 ,   row=       51
;            Yvalue:        -1712.03        -1711.53        -1711.03        -1710.53        ...
;             Yindex               1               2               3               4        ...
; Xindex,    Xvalue,        Image(I,J) Array                                                ...
  1          1289.55         0.00000         0.00000         0.00000         0.00000        ...
  2          1290.05         0.00000         0.00000         0.00000         0.00000        ...
  3          1290.55         0.00000         0.00000         0.00000         0.00000        ...
mda2idd_report.report_list(mdaFileList)[source]

process a list of MDA files

mda2idd_report.summaryMda(mdaFileName)[source]

text summary of a single MDA file (name, rank, datetime, …)

Developed for the GUI to give the user a preview of the file before saving its data as ASCII to a text file.

mda2idd_report.writeOutput(path, filename, output)[source]

write the output text buffer to the file

Parameters:
  • path (str) – absolute or relative path to directory where file should be written
  • filename (str) – name of file to be written, existing file will be overwritten without warning
  • output (str) – text buffer to write to file