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

Changeset 66

Show
Ignore:
Timestamp:
08/17/07 17:19:43
Author:
cbc
Message:

Daily check-in of code. Started _normalize.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sodar/trunk/sodar/data.py

    r65 r66  
    5959 
    6060import re 
    61  
     61import numpy as n 
    6262 
    6363class Data(list): 
     
    7575                     [sample.strip() for sample in data.split('$')] 
    7676                     if sample.strip()]) 
     77        self._normalize() 
    7778 
    7879    def __getitem__(self, index): 
     
    107108        raise IndexError('Data index out of range') 
    108109 
     110    def _normalize(self): 
     111        """Clean up data for analysis.""" 
     112        self._copy() 
     113        # self._convert() 
     114        # compute time interval 
     115        # correct for missing times 
     116        # compute minium altitude 
     117        # compute maximum overall altitude 
     118        # compute number of altitudes 
     119        # compute altitude interval 
     120        # correct for missing altitudes 
     121        # mark maximum altitude with good values for each sample 
     122        # mark minimum altitude with invalid values for each sample 
     123        # convert direction to radians 
     124        # compute u,v,c components 
     125        # compute colorspecs 
     126        # compute plotting parameters 
     127     
     128    def _copy(self): 
     129        """Create a deep copy of all the samples in this Data instance.""" 
     130        self.samples = [(dict(sample.header), list(sample.body)) 
     131                        for sample in self] 
     132        for sample in self.samples: 
     133            for altitude in sample[1]: 
     134                altitude = dict(altitude) 
     135     
     136    def _convert(self): 
     137        """Convert to numbers and correct for invalid values.""" 
     138        INVALID = "-9999" 
     139        # convert to numbers and correct for invalid values 
     140        for sample in self.samples: 
     141            for altitude in sample[1]: 
     142                for key in altitude.keys(): 
     143                    try: 
     144                        if altitude[key] == INVALID: 
     145                            raise ValueError 
     146                        altitude[key] = float(altitude[key]) 
     147                    except (ValueError, TypeError, KeyError): 
     148                        altitude[key] = n.NaN 
     149 
    109150 
    110151class Sample(object):