Changeset 259
- Timestamp:
- 11/25/09 15:07:07
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sodar/branches/scintec-branch/sodar/scintec/maindata.py
r258 r259 12 12 class MainData(list): 13 13 """ 14 Class to parseScintec sodar .mnd files.14 Class to contain data from Scintec sodar .mnd files. 15 15 16 Parse thea known good .mnd file:16 Parse a known good .mnd file: 17 17 >>> main_data = MainData(good_mnd) 18 18 … … 35 35 Parse the first profile: 36 36 >>> len(main_data[0]) 37 41 37 39 38 >>> main_data[0].timestamp 39 '2009-11-17 00:30:00 00:30:00' 40 >>> main_data[0].variables == ['z', 'speed', 'dir', 'W', 41 ... 'sigW', 'bck', 'error'] 42 True 38 43 >>> main_data[0][0] 39 ' 2009-11-17 00:30:00 00:30:00'44 '10 99.99 999.9 -0.05 0.40 5.46E+03 0' 40 45 >>> main_data[0][-1] 41 46 '200 99.99 999.9 -0.07 99.99 9.99E+37 0' … … 43 48 Parse the last profile: 44 49 >>> len(main_data[-1]) 45 41 50 39 51 >>> main_data[-1].timestamp 52 '2009-11-18 00:00:00 00:30:00' 53 >>> main_data[-1].variables == ['z', 'speed', 'dir', 'W', 54 ... 'sigW', 'bck', 'error'] 55 True 46 56 >>> main_data[-1][0] 47 ' 2009-11-18 00:00:00 00:30:00'57 '10 99.99 999.9 -0.32 99.99 9.99E+37 0' 48 58 >>> main_data[-1][-1] 49 59 '200 15.05 71.8 -0.19 0.53 9.99E+37 0' … … 100 110 for self._line in self._blocks[1].split('\n') 101 111 if self._line.strip()] 102 self.extend([ [self._line.strip()103 for self._line in self._block.split('\n')104 if self._line.strip()]112 self.extend([Profile([self._line.strip() 113 for self._line in self._block.split('\n') 114 if self._line.strip()]) 105 115 for self._block in self._blocks[2:]]) 116 del self._blocks, self._block, self._line 117 118 class Profile(list): 119 """ 120 Class to data for single profile from Scintec sodar .mnd files. 121 122 Parse a known good profile block: 123 >>> profile = Profile(good_profile) 124 >>> profile.timestamp 125 '2009-11-17 00:30:00 00:30:00' 126 >>> profile.variables == ['z', 'speed', 'dir', 'W', 127 ... 'sigW', 'bck', 'error'] 128 True 129 >>> profile[0] 130 '10 99.99 999.9 -0.05 0.40 5.46E+03 0' 131 >>> profile[-1] 132 '200 99.99 999.9 -0.07 99.99 9.99E+37 0' 133 """ 134 135 def __init__(self, profile_block): 136 """ 137 Parse a profile block from a main daily Scintec sodar .mnd file. 138 139 Profile(profile_data) -> <Profile object> 140 141 Where: 142 143 profile_block is a list of str objects containing all the lines 144 from a single profile in a Scintec .mnd daily sodar file. 145 146 Parse a known good profile block: 147 >>> profile = Profile(good_profile) 148 >>> profile.timestamp 149 '2009-11-17 00:30:00 00:30:00' 150 >>> profile.variables == ['z', 'speed', 'dir', 'W', 151 ... 'sigW', 'bck', 'error'] 152 True 153 >>> profile[0] 154 '10 99.99 999.9 -0.05 0.40 5.46E+03 0' 155 >>> profile[-1] 156 '200 99.99 999.9 -0.07 99.99 9.99E+37 0' 157 """ 158 159 super(Profile, self).__init__() 160 161 self.timestamp = profile_block[0] 162 self.variables = profile_block[1].split()[1:] 163 self.extend(profile_block[2:]) 106 164 107 165 def _test(): … … 112 170 """ 113 171 114 import os115 172 import doctest 116 173 from sodar.tests import suite 117 mnd_path,mnd = suite.setUpGoodMndData() 118 mnd_path,mnd_file = os.path.split(mnd_path) 174 mnd_path,mnd_file,mnd,profile = suite.setUpGoodMndData() 119 175 doctest.testmod(extraglobs=dict(good_mnd=mnd, 120 176 good_name=mnd_file, 121 good_path=mnd_path)) 177 good_path=mnd_path, 178 good_profile=profile), 179 optionflags=doctest.NORMALIZE_WHITESPACE) 122 180 123 181 if __name__ == "__main__": sodar/branches/scintec-branch/sodar/tests/suite.py
r257 r259 32 32 data_path = os.path.join(module_dir,'data',data_dir,data_file) 33 33 data = open(data_path).read() 34 return (data_path, data )34 return (data_path, data,) 35 35 36 36 def setUpGoodMndData(): … … 41 41 mnd_dir = os.path.join('scintec','good',) 42 42 mnd_file = '091117.mnd' 43 return setUpData(mnd_dir,mnd_file) 43 mnd_path,mnd = setUpData(mnd_dir,mnd_file) 44 mnd_path,mnd_file = os.path.split(mnd_path) 45 profile = mnd.split('\n\n')[2].split('\n') 46 profile = [line.strip() for line in profile if line] 47 return (mnd_path,mnd_file,mnd,profile,) 44 48 45 49 def setUpGoodMnd(test): … … 48 52 """ 49 53 50 mnd_path,mnd = setUpGoodMndData() 51 mnd_path,mnd_file = os.path.split(mnd_path) 54 mnd_path,mnd_file,mnd,profile = setUpGoodMndData() 52 55 test.globs.update(good_mnd=mnd, 53 56 good_name=mnd_file, 54 good_path=mnd_path) 57 good_path=mnd_path, 58 good_profile=profile) 55 59 56 60 def test_suite(): … … 61 65 suite = [] 62 66 suite.append(doctest.DocTestSuite(module='sodar.scintec.maindata', 63 setUp=setUpGoodMnd)) 67 setUp=setUpGoodMnd, 68 optionflags= 69 doctest.NORMALIZE_WHITESPACE)) 64 70 return unittest.TestSuite(suite)