Implement BUFRSounding.valid_by_timestamp()
This commit is contained in:
		
							parent
							
								
									17df1e1dba
								
							
						
					
					
						commit
						ff65688774
					
				
					 1 changed files with 21 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -155,3 +155,24 @@ class BUFRSounding(Sounding):
 | 
			
		|||
 | 
			
		||||
        return BUFRSounding.request_sounding(request,
 | 
			
		||||
                                             datatimes[-1].validPeriod)
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def valid_by_timestamp(station: str, timestamp: datetime.datetime) -> Self:
 | 
			
		||||
        epoch     = timestamp.timestamp()
 | 
			
		||||
        request   = BUFRSounding.create_request(station)
 | 
			
		||||
 | 
			
		||||
        datatimes = DataAccessLayer.getAvailableTimes(request)
 | 
			
		||||
        by_delta  = dict()
 | 
			
		||||
 | 
			
		||||
        for datatime in datatimes:
 | 
			
		||||
            ts    = datatime.getRefTime().time / 1000.0
 | 
			
		||||
            delta = epoch - ts
 | 
			
		||||
 | 
			
		||||
            by_delta[delta] = datatime
 | 
			
		||||
 | 
			
		||||
        for delta in sorted(by_delta.keys()):
 | 
			
		||||
            if delta < 0:
 | 
			
		||||
                continue
 | 
			
		||||
 | 
			
		||||
            return BUFRSounding.request_sounding(request,
 | 
			
		||||
                                                 by_delta[delta].validPeriod)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue