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

Changeset 270

Show
Ignore:
Timestamp:
12/03/09 21:23:48
Author:
cbc
Message:

Completed maindata.py.

Files:

Legend:

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

    r269 r270  
    2121    Parse a known good .mnd file: 
    2222    >>> main_data = MainData(good_mnd) 
    23      
    24     Parse the profile data: 
    2523    >>> len(main_data) 
    2624    48 
     25    >>> main_data.format 
     26    'FORMAT-1' 
     27    >>> main_data.first 
     28    datetime.datetime(2009, 11, 17, 0, 30) 
     29    >>> main_data.file_count 
     30    0 
     31    >>> main_data.comment_count 
     32    6 
     33    >>> main_data.variable_count 
     34    6 
     35    >>> main_data.elevation_count 
     36    39 
     37    >>> main_data.comments == {'device serial number':'A-F-0050', 
     38    ...                        'station code':'billymitchell', 
     39    ...                        'software version':'APRun 1.31', 
     40    ...                        'antenna azimuth angle [deg]':'0', 
     41    ...                        'height above ground [m]':'0', 
     42    ...                        'height above sea level [m]':'0'} 
     43    True 
     44    >>> main_data.variables == [{'label':'height','symbol':'z', 
     45    ...                              'units':'m','type':'Z1', 
     46    ...                              'mask':'0','gap':'99999',}, 
     47    ...                         {'label':'wind speed','symbol':'speed', 
     48    ...                              'units':'m/s','type':'G1', 
     49    ...                              'mask':'0','gap':'99.99',}, 
     50    ...                         {'label':'wind direction','symbol':'dir', 
     51    ...                              'units':'deg','type':'R1', 
     52    ...                              'mask':'0','gap':'999.9',}, 
     53    ...                         {'label':'wind W','symbol':'W', 
     54    ...                              'units':'m/s','type':'S', 
     55    ...                              'mask':'0','gap':'99.99',}, 
     56    ...                         {'label':'sigma W','symbol':'sigW', 
     57    ...                              'units':'m/s','type':'S', 
     58    ...                              'mask':'0','gap':'99.99',}, 
     59    ...                         {'label':'backscatter','symbol':'bck', 
     60    ...                              'units':'','type':'S', 
     61    ...                              'mask':'0','gap':'9.99E+37',},] 
     62    True 
     63    >>> main_data.error == {'label':'error code', 
     64    ...                 'bits':'- - - - - - - - groundclutter - - - - - - -', 
     65    ...                 'mask':'IIIIIIIIWIIIIIII',} 
     66    True 
    2767     
    2868    Parse the first profile: 
    2969    >>> len(main_data[0]) 
    3070    39 
    31     >>> main_data[0].start 
     71    >>> main_data(datetime(2009, 11, 17, 0, 30)).stop 
     72    datetime.datetime(2009, 11, 17, 0, 30) 
     73    >>> main_data(datetime(2009, 11, 17, 0, 0),True).start 
    3274    datetime.datetime(2009, 11, 17, 0, 0) 
    33     >>> main_data[0].stop 
    34     datetime.datetime(2009, 11, 17, 0, 30) 
    3575    >>> main_data[0].variables 
    3676    ['z', 'speed', 'dir', 'W', 'sigW', 'bck', 'error'] 
     
    5191    ...                       'error':'0'} 
    5292    True 
    53     >>> main_data(datetime(2009, 11, 17, 0, 30)).stop 
    54     datetime.datetime(2009, 11, 17, 0, 30) 
    55     >>> main_data(datetime(2009, 11, 17, 0, 0),True).start 
    56     datetime.datetime(2009, 11, 17, 0, 0) 
    5793     
    5894    Parse the last profile: 
    5995    >>> len(main_data[-1]) 
    6096    39 
    61     >>> main_data[-1].start 
    62     datetime.datetime(2009, 11, 17, 23, 30) 
    63     >>> main_data[-1].stop 
     97    >>> main_data(datetime(2009, 11, 18, 0, 0)).stop 
    6498    datetime.datetime(2009, 11, 18, 0, 0) 
     99    >>> main_data(datetime(2009, 11, 17, 23, 0),True).start 
     100    datetime.datetime(2009, 11, 17, 23, 0) 
    65101    >>> main_data[-1].variables 
    66102    ['z', 'speed', 'dir', 'W', 'sigW', 'bck', 'error'] 
     
    81117    ...                        'error':'0'} 
    82118    True 
    83     >>> main_data(datetime(2009, 11, 18, 0, 0)).stop 
    84     datetime.datetime(2009, 11, 18, 0, 0) 
    85     >>> main_data(datetime(2009, 11, 17, 23, 0),True).start 
    86     datetime.datetime(2009, 11, 17, 23, 0) 
    87119    """ 
    88120     
     
    105137         
    106138        Parse a known good .mnd file: 
    107          
    108139        >>> main_data = MainData(good_mnd) 
    109140        >>> main_data = MainData(good_mnd,good_name) 
     
    142173                              in blocks[0].split('\n') 
    143174                              if line.strip()] 
     175                               
     176        self.format = format_header_spec[0] 
     177         
     178        timestamp = format_header_spec[1] 
     179        date, first, file_count = timestamp.split() 
     180        date_year, date_month, date_day = date.split('-') 
     181        first_hour, first_minute, first_second = first.split(':') 
     182        self.first = datetime(int(date_year), 
     183                              int(date_month), 
     184                              int(date_day), 
     185                              int(first_hour), 
     186                              int(first_minute), # omit optional microseconds 
     187                              int(first_second)) # and tzinfo 
     188        self.file_count = int(file_count) 
     189         
     190        self.instrument_type = format_header_spec[2] 
     191         
     192        comment_count, variable_count, elevation_count = \ 
     193            format_header_spec[3].split() 
     194        self.comment_count = int(comment_count) 
     195        self.variable_count = int(variable_count) 
     196        self.elevation_count = int(elevation_count) 
    144197         
    145198        # The second block is the body of the format header. 
     
    148201                            for line 
    149202                            in blocks[1].split('\n') 
    150                             if line.strip()] 
     203                            if not line.strip().startswith('#')] 
     204        self.comments = dict([(name.strip(),value.strip()) 
     205                               for line 
     206                               in file_header_body[0:self.comment_count] 
     207                                   for name,value 
     208                                   in (line.split(':'),)]) 
     209        self.file_type = file_header_body[self.comment_count] 
     210        self.variables = [{'label':label.strip(), 
     211                           'symbol':symbol.strip(), 
     212                           'units':units.strip(), 
     213                           'type':vtype.strip(), 
     214                           'mask':mask.strip(), 
     215                           'gap':gap.strip(),} 
     216                          for line 
     217                          in file_header_body[self.comment_count + 1:-1] 
     218                              for label,symbol,units,vtype,mask,gap 
     219                              in (line.split('#'),)] 
     220        self.error = [{'label':label.strip(), 
     221                       'bits':bits.strip(), 
     222                       'mask':mask.strip(),} 
     223                      for label,bits,units,vtype,mask 
     224                      in (file_header_body[-1].split('#'),)][0] 
     225                        
    151226         
    152227        # All the remaing blocks are individual profiles 
     
    187262        >>> main_data(datetime(2009, 11, 16, 0, 30)) 
    188263        Traceback (most recent call last): 
    189             ... 
     264           ... 
    190265        ValueError: Timestamp datetime.datetime(2009, 11, 16, 0, 30) 
    191266        not found in 'MainData' object