ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/ba_class.py
(Generate patch)
# Line 25 | Line 25
25    >>> print round(ba1.roi[0].value[299], 1)
26    160.6
27   """
28 < __version__ = "110518"
28 > __version__ = "111012"
29  
30  
31   ## Import libraries.
32   import numpy as np
33 + import cPickle as pickle
34   from datetime import date
35  
36  
# Line 79 | Line 80
80          for roi in self.roi: roi.plottable = False
81          for i in ilist: self.roi[i].plottable = True
82          return
83 +      
84 +    def save(self, filename="default.sba"):
85 +        """
86 +        Save (serialize) this ba object as a file.
87 +        Use the extension '.sba' and designate it file format 1.
88 +        Use cPickle protocol 2 (binary).
89 +        """
90 +        if (filename[-4:] != '.sba'): filename = filename + ".sba"
91 +        fp = open(filename, 'wb')
92 +        protocol = 2  ## Use cPickle protocol 2 (binary).
93 +        formatver = 1  ## My format version 1.
94 +        pickle.dump(formatver, fp, protocol)
95 +        pickle.dump(self.comments, fp, protocol)
96 +        pickle.dump(self.primarydatafiles, fp, protocol)
97 +        pickle.dump(self.dpoints, fp, protocol)
98 +        pickle.dump(self.rois, fp, protocol)
99 +        pickle.dump(self.roi, fp, protocol)
100          
101 <    """End of BiosensorArray class definition."""
102 <
101 >        fp.close()
102 >        return
103 >        """ End of save() method"""
104  
105 +    def load(self, filename="default.sba"):
106 +        """
107 +        Load data from sba file into this ba object.
108 +        """
109 +        fp = open(filename, 'rb')
110 +        formatver = pickle.load(fp)
111 +        if (formatver == 1):
112 +            self.comments = pickle.load(fp)
113 +            self.primarydatafiles = pickle.load(fp)
114 +            self.dpoints = pickle.load(fp)
115 +            self.rois = pickle.load(fp)
116 +            self.roi = pickle.load(fp)
117 +        else:
118 +            print "Error: file format version is not 1 but " + formatver
119 +        fp.close()
120 +        return
121 +        """ End of load() method"""
122 +        
123 +    """End of BiosensorArray class definition."""
124  
125  
126   class RegOfInterest(object):
# Line 229 | Line 267
267      
268      """End of RegOfInterest definition."""
269  
270 <
270 >        
271   def _test():
272      """
273      Automatic Code testing with doctest.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines