diff --git a/.DS_Store b/.DS_Store index 331a20d..1e014ef 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/pyatmos/.DS_Store b/pyatmos/.DS_Store index d752f51..dfca1f5 100644 Binary files a/pyatmos/.DS_Store and b/pyatmos/.DS_Store differ diff --git a/pyatmos/utils/Const.py b/pyatmos/utils/Const.py index 135efca..847df08 100644 --- a/pyatmos/utils/Const.py +++ b/pyatmos/utils/Const.py @@ -15,12 +15,10 @@ fourpi = 4*np.pi degrad = pi / 180 al10 = np.log(10) -# AVOGAD is Avogadro's number in mks units (molecules/kmol) -avogad = 6.02257e26 +avogad = 6.02257e26 # The Avogadro's number in mks units (molecules/kmol) pivo2 = 1.5707963 pivo4 = 1.5707963 -# RSTAR is the universal gas-constant in mks units (joules/K/kmol) -rstar = 8314.32 +rstar = 8314.32 # The universal gas-constant in mks units (joules/K/kmol) x = np.arange(0.5,48)/24 \ No newline at end of file diff --git a/pyatmos/utils/data_download.py b/pyatmos/utils/data_download.py new file mode 100644 index 0000000..08c84c6 --- /dev/null +++ b/pyatmos/utils/data_download.py @@ -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 \ No newline at end of file