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

Changeset 259

Show
Ignore:
Timestamp:
11/25/09 15:07:07
Author:
cbc
Message:

Create maindata.Profile class.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sodar/branches/scintec-branch/sodar/scintec/maindata.py

    r258 r259  
    1212class MainData(list): 
    1313    """ 
    14     Class to parse Scintec sodar .mnd files. 
     14    Class to contain data from Scintec sodar .mnd files. 
    1515     
    16     Parse the a known good .mnd file: 
     16    Parse a known good .mnd file: 
    1717    >>> main_data = MainData(good_mnd) 
    1818     
     
    3535    Parse the first profile: 
    3636    >>> 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 
    3843    >>> 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' 
    4045    >>> main_data[0][-1] 
    4146    '200  99.99  999.9  -0.07  99.99  9.99E+37       0' 
     
    4348    Parse the last profile: 
    4449    >>> 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 
    4656    >>> 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' 
    4858    >>> main_data[-1][-1] 
    4959    '200  15.05   71.8  -0.19   0.53  9.99E+37       0' 
     
    100110                                  for self._line in self._blocks[1].split('\n') 
    101111                                  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()]) 
    105115                     for self._block in self._blocks[2:]]) 
     116        del self._blocks, self._block, self._line 
     117 
     118class 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:]) 
    106164 
    107165def _test(): 
     
    112170    """ 
    113171     
    114     import os 
    115172    import doctest 
    116173    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() 
    119175    doctest.testmod(extraglobs=dict(good_mnd=mnd, 
    120176                                    good_name=mnd_file, 
    121                                     good_path=mnd_path)) 
     177                                    good_path=mnd_path, 
     178                                    good_profile=profile), 
     179                    optionflags=doctest.NORMALIZE_WHITESPACE) 
    122180 
    123181if __name__ == "__main__": 
  • sodar/branches/scintec-branch/sodar/tests/suite.py

    r257 r259  
    3232    data_path = os.path.join(module_dir,'data',data_dir,data_file) 
    3333    data = open(data_path).read() 
    34     return (data_path, data
     34    return (data_path, data,
    3535 
    3636def setUpGoodMndData(): 
     
    4141    mnd_dir = os.path.join('scintec','good',) 
    4242    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,) 
    4448 
    4549def setUpGoodMnd(test): 
     
    4852    """ 
    4953     
    50     mnd_path,mnd = setUpGoodMndData() 
    51     mnd_path,mnd_file = os.path.split(mnd_path)  
     54    mnd_path,mnd_file,mnd,profile = setUpGoodMndData() 
    5255    test.globs.update(good_mnd=mnd, 
    5356                      good_name=mnd_file, 
    54                       good_path=mnd_path) 
     57                      good_path=mnd_path, 
     58                      good_profile=profile) 
    5559 
    5660def test_suite(): 
     
    6165    suite = [] 
    6266    suite.append(doctest.DocTestSuite(module='sodar.scintec.maindata', 
    63                                       setUp=setUpGoodMnd)) 
     67                                      setUp=setUpGoodMnd, 
     68                                      optionflags= 
     69                                          doctest.NORMALIZE_WHITESPACE)) 
    6470    return unittest.TestSuite(suite)