Use wget to download data file instead
This commit is contained in:
		
							parent
							
								
									52b10c3f75
								
							
						
					
					
						commit
						fa24c36c22
					
				
							
								
								
									
										
											BIN
										
									
								
								pyatmos/.DS_Store
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								pyatmos/.DS_Store
									
									
									
									
										vendored
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -15,12 +15,10 @@ fourpi = 4*np.pi | |||||||
| degrad = pi / 180 | degrad = pi / 180 | ||||||
| al10 = np.log(10) | al10 = np.log(10) | ||||||
| 
 | 
 | ||||||
| # AVOGAD is Avogadro's number in mks units (molecules/kmol) | avogad = 6.02257e26 # The Avogadro's number in mks units (molecules/kmol) | ||||||
| avogad = 6.02257e26 |  | ||||||
| pivo2 = 1.5707963 | pivo2 = 1.5707963 | ||||||
| pivo4 = 1.5707963   | pivo4 = 1.5707963   | ||||||
| 
 | 
 | ||||||
| # RSTAR is the universal gas-constant in mks units (joules/K/kmol) | rstar = 8314.32 # The universal gas-constant in mks units (joules/K/kmol) | ||||||
| rstar = 8314.32 |  | ||||||
| 
 | 
 | ||||||
| x = np.arange(0.5,48)/24 | x = np.arange(0.5,48)/24 | ||||||
							
								
								
									
										58
									
								
								pyatmos/utils/data_download.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								pyatmos/utils/data_download.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,58 @@ | |||||||
|  | from datetime import datetime,timedelta | ||||||
|  | from os import path,makedirs,remove | ||||||
|  | from pathlib import Path | ||||||
|  | 
 | ||||||
|  | from .try_download import wget_download  | ||||||
|  | 
 | ||||||
|  | def download_iers(out_days=7,dir_to=None): | ||||||
|  |     """ | ||||||
|  |     Download or update the Earth Orientation Parameters(EOP) file and Leap Second file from IERS | ||||||
|  | 
 | ||||||
|  |     Usage:  | ||||||
|  |         >>> dir_to,dir_eop_file,dir_leapsecond_file = download_iers() | ||||||
|  |     Inputs:  | ||||||
|  |         out_days -> [int, optional, default = 7] Updating cycle of the IERS files | ||||||
|  |         dir_to   -> [str, optional, default = None] Directory for storing EOP file | ||||||
|  |     Outputs:  | ||||||
|  |         dir_to -> [str] Directory of the IERS files | ||||||
|  |         dir_eop_file -> [str] Path of the EOP file | ||||||
|  |         dir_leapsecond_file -> [str] Path of the Leap Second file | ||||||
|  |     """ | ||||||
|  |     if dir_to is None: | ||||||
|  |         home = str(Path.home()) | ||||||
|  |         dir_to = home + '/src/iers/' | ||||||
|  |      | ||||||
|  |     eop_file = 'finals2000A.all' | ||||||
|  |     leapsecond_file = 'Leap_Second.dat' | ||||||
|  |     dir_eop_file = dir_to + eop_file | ||||||
|  |     dir_leapsecond_file = dir_to + leapsecond_file | ||||||
|  | 
 | ||||||
|  |     url_eop = 'https://datacenter.iers.org/products/eop/rapid/standard/finals2000A.all' | ||||||
|  |     url_leapsecond = 'https://hpiers.obspm.fr/iers/bul/bulc/Leap_Second.dat' | ||||||
|  | 
 | ||||||
|  |     if not path.exists(dir_to): makedirs(dir_to) | ||||||
|  |     if not path.exists(dir_eop_file): | ||||||
|  |         desc = "Downloading the latest EOP file '{:s}' from IERS".format(eop_file) | ||||||
|  |         wget_out = wget_download(url_eop,dir_eop_file,desc) | ||||||
|  |     else: | ||||||
|  |         modified_time = datetime.fromtimestamp(path.getmtime(dir_eop_file)) | ||||||
|  |         if datetime.now() > modified_time + timedelta(days=out_days): | ||||||
|  |             remove(dir_eop_file) | ||||||
|  |             desc = "Updating the EOP file '{:s}' from IERS".format(eop_file) | ||||||
|  |             wget_out = wget_download(url_eop,dir_eop_file,desc) | ||||||
|  |         else: | ||||||
|  |             print("The EOP file '{:s}' in {:s} is already the latest.".format(eop_file,dir_to))  | ||||||
|  | 
 | ||||||
|  |     if not path.exists(dir_leapsecond_file): | ||||||
|  |         desc = "Downloading the latest Leap Second file '{:s}' from IERS".format(leapsecond_file) | ||||||
|  |         wget_out = wget_download(url_leapsecond,dir_leapsecond_file,desc) | ||||||
|  |     else: | ||||||
|  |         modified_time = datetime.fromtimestamp(path.getmtime(dir_leapsecond_file)) | ||||||
|  |         if datetime.now() > modified_time + timedelta(days=out_days): | ||||||
|  |             remove(dir_leapsecond_file) | ||||||
|  |             desc = "Updating the Leap Second file '{:s}' from IERS".format(leapsecond_file) | ||||||
|  |             wget_out = wget_download(url_leapsecond,dir_leapsecond_file,desc) | ||||||
|  |         else: | ||||||
|  |             print("The Leap Second file '{:s}' in {:s} is already the latest.".format(leapsecond_file,dir_to))         | ||||||
|  | 
 | ||||||
|  |     return dir_to,dir_eop_file,dir_leapsecond_file     | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user