117 lines
4.7 KiB
Python
117 lines
4.7 KiB
Python
import os
|
||
import Download_AOD as Daod
|
||
import datetime as dt
|
||
|
||
today = dt.date(2022, 8, 1)
|
||
print(today)
|
||
_yearNum = today.year
|
||
_monNum = today.month
|
||
_dayNum = today.day
|
||
_yearStr = ""
|
||
_monStr = ""
|
||
_dayStr = ""
|
||
_hourStr = [f"0{x}"if x < 10 else str(x) for x in range(23)]
|
||
|
||
if __name__ == "__main__":
|
||
# 传入IP地址
|
||
# 传入的YesdayNum在下载日数据时(昨天的)会需要
|
||
ftp = Daod.myFTP(host='ftp.ptree.jaxa.jp', YesdayNum=_dayNum - 1)
|
||
|
||
# 传入用户名和密码,可以自行注册并修改
|
||
ftp.Login('jh_zhao_asagi.waseda.jp', 'SP+wari8')
|
||
|
||
# 从目标路径ftp_filePath将文件下载至本地路径dst_filePath
|
||
dst_filePath = './data'
|
||
dst_filePath = dst_filePath + "/" + dt.datetime.strftime(today, '%Y-%m-%d')
|
||
if not os.path.exists(dst_filePath):
|
||
os.makedirs(dst_filePath)
|
||
|
||
'''
|
||
下载小时数据和日数据时,前置路径都是:/pub/himawari/L3/ARP/031(20-22年)
|
||
下载每10分钟数据时,前置路径是:/pub/himawari/L2/ARP/030(20-22年)
|
||
下载日数据时,示例路径:/pub/himawari/L3/ARP/031/202008/daily/
|
||
下载小时数据时,示例路径:/pub/himawari/L3/ARP/031/202008/19/
|
||
下载10分钟数据时,示例路径:/pub/himawari/L2/ARP/030/202210/10/
|
||
'''
|
||
print("请选择要下载的数据:")
|
||
_choice = int(input("1.AOD小时数据(当天所有) 2.AOD日均数据(昨天) 3.PAR分钟数据(当天所有)\n"))
|
||
|
||
# Download_Path用于存储下载的原始数据
|
||
Download_Path = ""
|
||
# Analysis_Path用于存储处理后的数据(即转为TIFF后的数据)的文件夹
|
||
Analysis_Path = ""
|
||
|
||
# 如果选择为AOD小时数据
|
||
if _choice == 1:
|
||
_yearStr, _monStr, _dayStr = Daod.getDateStr(_yearNum, _monNum, _dayNum)
|
||
ftp_filePath = "/pub/himawari/L3/ARP/031" + "/" + _yearStr + _monStr + "/" + _dayStr + "/"
|
||
|
||
Download_Path = dst_filePath + "/AOD_Hourly_Download"
|
||
if not os.path.exists(Download_Path):
|
||
os.makedirs(Download_Path)
|
||
Daod.deleteFile(Download_Path) # 删除存储路径中的临时文件(也就是上次未下载完整的文件)
|
||
|
||
Analysis_Path = dst_filePath + "/AOD_Hourly_Analysis"
|
||
if not os.path.exists(Analysis_Path):
|
||
os.makedirs(Analysis_Path)
|
||
|
||
ftp.DownLoadFileTree(Download_Path, ftp_filePath, _choice)
|
||
|
||
# 如果选择为AOD日数据(昨天的)
|
||
elif _choice == 2:
|
||
_yearNum, _monNum, _dayNum = Daod.getYesterday(_yearNum, _monNum, _dayNum)
|
||
_yearStr, _monStr, _dayStr = Daod.getDateStr(_yearNum, _monNum, _dayNum)
|
||
ftp_filePath = "/pub/himawari/L3/ARP/030" + "/" + _yearStr + _monStr + "/" + "daily" + "/"
|
||
|
||
Download_Path = dst_filePath + "/AOD_Daily_Download"
|
||
if not os.path.exists(Download_Path):
|
||
os.makedirs(Download_Path)
|
||
Daod.deleteFile(Download_Path) # 删除存储路径中的临时文件(也就是上次未下载完整的文件)
|
||
|
||
Analysis_Path = dst_filePath + "/AOD_Daily_Analysis"
|
||
if not os.path.exists(Analysis_Path):
|
||
os.makedirs(Analysis_Path)
|
||
|
||
ftp.DownLoadFileTree(Download_Path, ftp_filePath, _choice)
|
||
|
||
elif _choice == 3:
|
||
while today <= dt.date.today():
|
||
_yearNum = today.year
|
||
_monNum = today.month
|
||
_dayNum = today.day
|
||
_yearStr = ""
|
||
_monStr = ""
|
||
_dayStr = ""
|
||
_hourStr = [f"0{x}" if x < 10 else str(x) for x in range(23)]
|
||
_yearStr, _monStr, _dayStr = Daod.getDateStr(_yearNum, _monNum, _dayNum)
|
||
ftp_filePath = "/pub/himawari/L2/PAR/020" + "/" + _yearStr + _monStr + "/" + _dayStr + "/"
|
||
Download_Path = dst_filePath + "/PAR_Minutes_Download"
|
||
if not os.path.exists(Download_Path):
|
||
os.makedirs(Download_Path)
|
||
Daod.deleteFile(Download_Path) # 删除存储路径中的临时文件(也就是上次未下载完整的文件)
|
||
for hour in _hourStr:
|
||
print(f"{ftp_filePath}{hour}/")
|
||
ftp.DownLoadFileTree(Download_Path, f"{ftp_filePath}{hour}/", _choice)
|
||
# Analysis_Path = dst_filePath + "/PAR_Minutes_Analysis"
|
||
# if not os.path.exists(Analysis_Path):
|
||
# os.makedirs(Analysis_Path)
|
||
today = today + dt.timedelta(days=1)
|
||
else:
|
||
print("选择错误!")
|
||
|
||
# 下载结束
|
||
ftp.close()
|
||
print("下载完成!")
|
||
|
||
# 下面开始数据处理
|
||
# 读取所有nc数据
|
||
# data_list = glob.glob(Download_Path + "\\*.nc")
|
||
|
||
# # for循环完成解析
|
||
# for i in range(len(data_list)):
|
||
# data = data_list[i]
|
||
# trans.NC_to_tiffs(data, Analysis_Path)
|
||
# print(data + "-----转tif成功")
|
||
|
||
print("----转换结束----")
|