first commit
This commit is contained in:
commit
7092c56051
|
@ -0,0 +1,11 @@
|
|||
# desc
|
||||
|
||||
# install
|
||||
`pip install -r requirements.txt`
|
||||
|
||||
# dockerizing library
|
||||
build docker: `docker build .`
|
||||
|
||||
|
||||
docker build -t aetyp:0.0.1 .
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/python3
|
||||
#
|
||||
|
||||
import sys
|
||||
import cdsapi
|
||||
import argparse
|
||||
|
||||
def get_cdsapi(dataset, target, startdate, enddate, url=None, key=None):
|
||||
|
||||
print('############################################')
|
||||
print('Target: '+target)
|
||||
print('Start date: '+startdate)
|
||||
print('End date: '+enddate)
|
||||
print('############################################')
|
||||
|
||||
print('Downloading data... please wait...')
|
||||
|
||||
request = {
|
||||
"variable": [target],
|
||||
"date": [startdate+'/'+enddate],
|
||||
"time": [
|
||||
"00:00", "03:00",
|
||||
"06:00", "09:00",
|
||||
"12:00", "15:00",
|
||||
"18:00", "21:00"
|
||||
],
|
||||
"data_format": "netcdf_zip"
|
||||
}
|
||||
|
||||
print(request)
|
||||
|
||||
if url is not None and key is not None:
|
||||
client = cdsapi.Client(url=url, key=key)
|
||||
else:
|
||||
client = cdsapi.Client()
|
||||
client.retrieve(dataset, request).download()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
def parse_args():
|
||||
"""
|
||||
Parses command-line arguments for downloading data from CDSAPI.
|
||||
|
||||
Returns:
|
||||
argparse.Namespace: Parsed command-line arguments.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description="""Download data from CDSAPI.
|
||||
Arguments:
|
||||
target (str): Target variable to download.
|
||||
startdate (str): Start date in format YYYY-MM-DD.
|
||||
enddate (str): End date in format YYYY-MM-DD.
|
||||
dataset (str): Dataset to download.
|
||||
|
||||
Example usage:
|
||||
python get_cdsapi.py --target black_carbon_aerosol_optical_depth_550nm --startdate 2022-12-01 --enddate 2022-12-03 --dataset cams-global-reanalysis-eac4
|
||||
""")
|
||||
parser.add_argument('--target', type=str, help='Target variable')
|
||||
parser.add_argument('--startdate', type=str, help='Start date')
|
||||
parser.add_argument('--enddate', type=str, help='End date')
|
||||
parser.add_argument('--dataset', type=str, help='Dataset name')
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
parser.print_help(sys.stderr)
|
||||
sys.exit(1)
|
||||
return parser.parse_args()
|
||||
|
||||
args = parse_args()
|
||||
|
||||
get_cdsapi(args.dataset, args.target, args.startdate, args.enddate)
|
|
@ -0,0 +1 @@
|
|||
cdsapi
|
Loading…
Reference in New Issue