ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/converter.py
(Generate patch)
# Line 1 | Line 1
1   """
2   Converter: Perform the datafile reading, pre-processing and writing.
3   Yuhang Wan, Christopher Lausted
4 < Last modified on 100405 (yymmdd)
4 > Last modified on 100407 (yymmdd)
5  
6   Typical Pipeline:
7   >import converter as cv
# Line 13 | Line 13
13   >dat = cv.data_output_clamp(dat, "/dir", 0,1,2,3)
14   >dat = cv.data_output_biosensor(dat, "/dir", 0)
15   """
16 < __version__ = "100405"
16 > __version__ = "100407"
17  
18 + ## Import libraries.
19   import numpy as np
20   import pylab as plt
21   import sys
# Line 22 | Line 23
23   import time
24   import os
25   import copy
26 <
26 < ## import matplotlib.pyplot as plt
27 < ## import matplotlib.mlab as mlb
28 < ## import packageClamp_100210 as Pack
26 > #import matplotlib.pyplot as plt
27   import SPRdataclass as spr
28  
29 + ## Global constants and variables.
30 + FMT_UNKNOWN = 0
31 + FMT_SPRIT = 1        ## Old Plexera SPRit format.
32 + FMT_ICMTXT = 2       ## Plexera Instrument Control Module text.
33 + FMT_CLAMP34 = 3      ## Morton & Myszka CLAMP Version 3.4+
34 + FMT_DAMXLS = 4       ## Plexera Data Analysis Module Excel export.
35 +
36  
37   def check_format_input(fname):
38 <    """Examine the format of a input .txt data file."""
39 <    # open a file, if file doesn't exit, then exit
38 >    """Examine the format of an input .txt data file."""
39 >    ## Modified 100407 CGL.
40 >    
41 >    ## Open text file. Exit if file not found.
42      try:
43          fp = open(fname, "r")
44      except IOError:
45 <        print 'Cannot open file %s for reading' % fname
45 >        print "Error: Unable to open file %s for reading." % fname
46          sys.exit(0)
40    # examine the first line of the input file
41    # for SPRit output:"Elapsed Time (Seconds)  Average Intensity (Pixel Intensity)"
42    # for Plexera ICM output:
43    head_input1="Elapsed Time (Seconds)\tAverage Intensity (Pixel Intensity)"
47      
48 <    Format_input = 0
49 <    # check file format  
50 <    Tmpstr = fp.readline()
51 <    if (head_input1 in Tmpstr):
52 <        Format_input=1      
53 <    elif Tmpstr[-1]=='\n' and Tmpstr[-2]=='\r' and Tmpstr.split(' ')[0].split('/')[2].startswith('20'):
54 <        Format_input=2
55 <    elif Tmpstr.startswith('Vers'):
56 <        Format_input=3
57 <        
48 >    ## Examine first line of text file to guess format.
49 >    fmt = FMT_UNKNOWN  
50 >    sprit_line1="Elapsed Time (Seconds)\tAverage Intensity (Pixel Intensity)"
51 >    clamp_line1="Vers 3.4"
52 >    line1 = fp.readline()
53 >    if (sprit_line1 in line1):
54 >        fmt = FMT_SPRIT      
55 >    elif (line1[2]=="/" and line1[5]=="/"):
56 >        ## This format has date mm/dd/yyy in first column.
57 >        fmt=FMT_ICMTXT
58 >    elif (clamp_line1 in line1):
59 >        fmt = FMT_CLAMP34
60 >    
61      fp.close()
62 <    return Format_input, Tmpstr
62 >    return fmt, line1
63  
64  
65   def sprit_format(fname):

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines