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 a the format header. |
---|
18 |
|
---|
19 |
>>> main_data = MainData(_testSetUp('good','091117.mnd')) |
---|
20 |
>>> main_data.format_header[0] |
---|
21 |
'FORMAT-1\n' |
---|
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 blocks[0].split('\n') |
---|
40 |
if line.strip()] |
---|
41 |
self.file_header = [line.strip() |
---|
42 |
for line in blocks[1].split('\n') |
---|
43 |
if line.strip()] |
---|
44 |
self.profile_blocks = blocks[2:] |
---|
45 |
|
---|
46 |
def _testSetUp(mnd_dir,mnd_file): |
---|
47 |
current_dir = os.path.abspath(os.path.dirname(__file__)) |
---|
48 |
package_dir = os.path.split(current_dir)[0] |
---|
49 |
data_dir = os.path.join(package_dir,'tests','data') |
---|
50 |
good_dir = os.path.join(data_dir,mnd_dir) |
---|
51 |
mnd_file = os.path.join(good_dir,mnd_file) |
---|
52 |
mnd = open(mnd_file).read() |
---|
53 |
return mnd |
---|
54 |
|
---|
55 |
def _test(): |
---|
56 |
import doctest |
---|
57 |
doctest.testmod() |
---|
58 |
|
---|
59 |
if __name__ == "__main__": |
---|
60 |
_test() |
---|