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

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

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

Propagate svn:ignore properties to subpackages.

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