NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/sodar/branches/scintec-branch/sodar/scintec/maindata.py

Revision 251 (checked in by cbc, 14 years ago)

Refactoring tests.

Line 
1 """
2 Module to handle Scintec sodar .mnd files.
3 """
4
5 __author__ = 'Chris Calloway'
6 __email__ = 'cbc@chriscalloway.org'
7 __copyright__ = 'Copyright 2009 UNC-CH Department of Marine Science'
8 __license__ = 'GPL2'
9
10 import os
11
12 class MainData(object):
13     """
14     Class to parse Scintec sodar .mnd files.
15     
16     Parse the format header:
17     
18     >>> main_data = MainData(_testSetUp('good','091117.mnd'))
19     >>> main_data.format_header[0]
20     'FORMAT-1'
21     """
22    
23     def __init__(self, mnd):
24         """
25         Parse main daily Scintec sodar .mnd file.
26         
27         MainData(mnd) -> <MainData object>
28         
29         Where mnd is a str object containing the complete contents read from a
30         Scintec .mnd daily sodar file including all line endings.
31         """
32        
33         super(MainData, self).__init__()
34         self.blocks = [block.strip()
35                       for block in mnd.split('\n\n')
36                       if block.strip()]
37         self.format_header = [line.strip()
38                               for line in self.blocks[0].split('\n')
39                               if line.strip()]
40         self.file_header = [line.strip()
41                             for line in self.blocks[1].split('\n')
42                             if line.strip()]
43         self.profile_blocks = self.blocks[2:]
44                            
45 def _testSetUp(mnd_dir,mnd_file):
46     module_dir = os.path.abspath(os.path.dirname(__file__))
47     package_dir = os.path.split(module_dir)[0]
48     mnd_file = os.path.join(package_dir,'tests','data',mnd_dir,mnd_file)
49     mnd = open(mnd_file).read()
50     return mnd
51
52 def _test():
53     import doctest
54     doctest.testmod()
55
56 if __name__ == "__main__":
57     _test()
Note: See TracBrowser for help on using the browser.