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

Changeset 262

Show
Ignore:
Timestamp:
11/27/09 09:05:33
Author:
cbc
Message:

Create maindata.Observation class.

Files:

Legend:

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

    r261 r262  
    1212class MainData(list): 
    1313    """ 
    14     Contain data from Scintec sodar .mnd files
     14    Contain data from a Scintec sodar .mnd file
    1515     
    1616    Parse a known good .mnd file: 
     
    4141    ...                            'sigW', 'bck', 'error'] 
    4242    True 
    43     >>> main_data[0][0] 
    44     '10  99.99  999.9  -0.05   0.40  5.46E+03       0' 
    45     >>> main_data[0][-1] 
    46     '200  99.99  999.9  -0.07  99.99  9.99E+37       0' 
     43    >>> main_data[0][0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', 
     44    ...                     'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', 
     45    ...                     'error':'0'} 
     46    True 
     47    >>> main_data[0][-1] == {'z':'200', 'speed':'99.99', 'dir':'999.9', 
     48    ...                      'W':'-0.07', 'sigW':'99.99', 'bck':'9.99E+37', 
     49    ...                      'error':'0'} 
     50    True 
    4751     
    4852    Parse the last profile: 
     
    5458    ...                             'sigW', 'bck', 'error'] 
    5559    True 
    56     >>> main_data[-1][0] 
    57     '10  99.99  999.9  -0.32  99.99  9.99E+37       0' 
    58     >>> main_data[-1][-1] 
    59     '200  15.05   71.8  -0.19   0.53  9.99E+37       0' 
     60    >>> main_data[-1][0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', 
     61    ...                     'W':'-0.32', 'sigW':'99.99', 'bck':'9.99E+37', 
     62    ...                     'error':'0'} 
     63    True 
     64    >>> main_data[-1][-1] == {'z':'200', 'speed':'15.05', 'dir':'71.8', 
     65    ...                      'W':'-0.19', 'sigW':'0.53', 'bck':'9.99E+37', 
     66    ...                      'error':'0'} 
     67    True 
    6068    """ 
    6169     
     
    7179            Scintec .mnd daily sodar file including all line endings, 
    7280             
    73             file_name is an optional string object representing a file name for 
     81            file_name is an optional str object representing a file name for 
    7482            a file which contains the referenced .mnd daily sodar file, 
    7583             
    76             file_path is an optional string object representing the path to 
     84            file_path is an optional str object representing the path to 
    7785            file_name. 
    7886         
     
    118126class Profile(list): 
    119127    """ 
    120     Contain data for single profile from Scintec sodar .mnd files
     128    Contain data for single profile from a Scintec sodar .mnd file
    121129     
    122130    Parse a known good profile block: 
     
    127135    ...                       'sigW', 'bck', 'error'] 
    128136    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' 
     137    >>> profile[0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', 
     138    ...                'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', 
     139    ...                'error':'0'} 
     140    True 
     141    >>> profile[-1] == {'z':'200', 'speed':'99.99', 'dir':'999.9', 
     142    ...                 'W':'-0.07', 'sigW':'99.99', 'bck':'9.99E+37', 
     143    ...                 'error':'0'} 
     144    True 
    133145    """ 
    134146     
     
    151163        ...                       'sigW', 'bck', 'error'] 
    152164        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' 
     165        >>> profile[0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', 
     166        ...                'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', 
     167        ...                'error':'0'} 
     168        True 
     169        >>> profile[-1] == {'z':'200', 'speed':'99.99', 'dir':'999.9', 
     170        ...                 'W':'-0.07', 'sigW':'99.99', 'bck':'9.99E+37', 
     171        ...                 'error':'0'} 
     172        True 
    157173        """ 
    158174         
     
    161177        self.timestamp = profile_block[0] 
    162178        self.variables = profile_block[1].split()[1:] 
    163         self.extend(profile_block[2:]) 
     179        self.extend([Observation(observation.split(),self.variables) 
     180                     for observation in profile_block[2:]]) 
     181 
     182class Observation(dict): 
     183    """ 
     184    Contain data for single observation from a Scintec sodar .mnd files. 
     185     
     186    Parse a known good observation: 
     187    >>> observation = Observation(good_observation,good_variables) 
     188    >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', 
     189    ...                 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', 
     190    ...                 'error':'0'} 
     191    True 
     192    """ 
     193     
     194    def __init__(self,data,variables): 
     195        """ 
     196        Parse an observation from a main daily Scintec sodar .mnd file. 
     197         
     198        Observation(data,variables) -> <Observation object> 
     199         
     200        Where: 
     201          
     202            data is a list of str object representing variable values, 
     203             
     204            variables is a list of str objects representing variable labels. 
     205         
     206        Parse a known good observation: 
     207        >>> observation = Observation(good_observation,good_variables) 
     208        >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', 
     209        ...                 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', 
     210        ...                 'error':'0'} 
     211        True 
     212        """ 
     213 
     214        super(Observation, self).__init__() 
     215         
     216        self.update(dict(zip(variables,data))) 
    164217 
    165218def _test(): 
     
    172225    import doctest 
    173226    from sodar.tests import suite 
    174     mnd_path,mnd_file,mnd,profile = suite.setUpGoodMndData() 
     227    mnd_path,mnd_file,mnd,profile,variables,observation = \ 
     228        suite.setUpGoodMndData() 
    175229    doctest.testmod(extraglobs=dict(good_mnd=mnd, 
    176230                                    good_name=mnd_file, 
    177231                                    good_path=mnd_path, 
    178                                     good_profile=profile), 
     232                                    good_profile=profile, 
     233                                    good_variables=variables, 
     234                                    good_observation=observation), 
    179235                    optionflags=doctest.NORMALIZE_WHITESPACE) 
    180236 
  • sodar/branches/scintec-branch/sodar/tests/suite.py

    r259 r262  
    4545    profile = mnd.split('\n\n')[2].split('\n') 
    4646    profile = [line.strip() for line in profile if line] 
    47     return (mnd_path,mnd_file,mnd,profile,) 
     47    variables = profile[1].split()[1:] 
     48    observation = profile[2].split() 
     49    return (mnd_path,mnd_file,mnd,profile,variables,observation,) 
    4850 
    4951def setUpGoodMnd(test): 
     
    5254    """ 
    5355     
    54     mnd_path,mnd_file,mnd,profile = setUpGoodMndData() 
     56    mnd_path,mnd_file,mnd,profile,variables,observation = setUpGoodMndData() 
    5557    test.globs.update(good_mnd=mnd, 
    5658                      good_name=mnd_file, 
    5759                      good_path=mnd_path, 
    58                       good_profile=profile) 
     60                      good_profile=profile, 
     61                      good_variables=variables, 
     62                      good_observation=observation) 
    5963 
    6064def test_suite():