Refactor RAOBObs.parse_ttaa() to return Sounding object
This commit is contained in:
		
							parent
							
								
									8787a37773
								
							
						
					
					
						commit
						d83e52acb7
					
				
					 1 changed files with 13 additions and 11 deletions
				
			
		| 
						 | 
					@ -13,13 +13,9 @@ CHUNK_STRIP_CHARS = "\x01\x03\x0a\x20"
 | 
				
			||||||
class RAOBReaderException(Exception):
 | 
					class RAOBReaderException(Exception):
 | 
				
			||||||
    ...
 | 
					    ...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class RAOBSounding():
 | 
					 | 
				
			||||||
    def __init__(self):
 | 
					 | 
				
			||||||
        self.timestamp: datetime.datetime    = None
 | 
					 | 
				
			||||||
        self.station:   int                  = None
 | 
					 | 
				
			||||||
        self.samples:   list[SoundingSample] = list()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class RAOBObs():
 | 
					class RAOBObs():
 | 
				
			||||||
 | 
					    DATA_SOURCE = 'UCAR'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, kind: str):
 | 
					    def __init__(self, kind: str):
 | 
				
			||||||
        self.kind:   str       = kind
 | 
					        self.kind:   str       = kind
 | 
				
			||||||
        self.tokens: list[str] = list()
 | 
					        self.tokens: list[str] = list()
 | 
				
			||||||
| 
						 | 
					@ -214,7 +210,7 @@ class RAOBObs():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return sample
 | 
					        return sample
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def parse_ttaa(self) -> RAOBSounding:
 | 
					    def parse_ttaa(self) -> Sounding:
 | 
				
			||||||
        #
 | 
					        #
 | 
				
			||||||
        # Return None if there is no height data up to 100mb.
 | 
					        # Return None if there is no height data up to 100mb.
 | 
				
			||||||
        #
 | 
					        #
 | 
				
			||||||
| 
						 | 
					@ -232,10 +228,16 @@ class RAOBObs():
 | 
				
			||||||
        if sample is None:
 | 
					        if sample is None:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        sounding = RAOBSounding()
 | 
					        timestamp = self.parse_timestamp(self.tokens[0])
 | 
				
			||||||
        sounding.timestamp = self.parse_timestamp(self.tokens[0])
 | 
					
 | 
				
			||||||
        sounding.station   = int(self.tokens[1])
 | 
					        sounding = Sounding()
 | 
				
			||||||
        sounding.samples.append(sample)
 | 
					        sounding.samples = [sample]
 | 
				
			||||||
 | 
					        sounding.station = self.tokens[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sounding.data_source_pressure = self.DATA_SOURCE
 | 
				
			||||||
 | 
					        sounding.data_source_other    = self.DATA_SOURCE
 | 
				
			||||||
 | 
					        sounding.timestamp_observed   = timestamp
 | 
				
			||||||
 | 
					        sounding.timestamp_released   = timestamp - datetime.timedelta(minutes=45)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for i in range(5, len(self.tokens), 3):
 | 
					        for i in range(5, len(self.tokens), 3):
 | 
				
			||||||
            if len(self.tokens) < i+3 or self.tokens[i][-1] == '=':
 | 
					            if len(self.tokens) < i+3 or self.tokens[i][-1] == '=':
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue