From fa24c36c22f93d27424175db40595876b2a2b9c2 Mon Sep 17 00:00:00 2001 From: Chunxiao Li Date: Sun, 16 Jul 2023 23:03:30 +0800 Subject: [PATCH] Use wget to download data file instead --- .DS_Store | Bin 6148 -> 6148 bytes pyatmos/.DS_Store | Bin 8196 -> 8196 bytes pyatmos/utils/Const.py | 6 ++-- pyatmos/utils/data_download.py | 58 +++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 pyatmos/utils/data_download.py diff --git a/.DS_Store b/.DS_Store index 331a20d0c33d6af4dcf267ed37f21343de51d8ed..1e014ef7d8f95447c1c246cd3a5dde35da344e3a 100644 GIT binary patch delta 68 zcmZoMXffCj&cwKVas*SMns{}!rG<`yp{a4LjzYDik%5kaiLqI2EhmSlvc7dte0EN5 YUVi7~4@~lmU7H1%zq4#+ikkP7cm^0iZ)n%*}!JSQyso zC{&x91MM_1Hmj}WO2epGlV6F-O)e9Cif}(R W4+@Jv*vu~Rjb(D7fc!wY;4T16{$&~f 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