欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)葵花8號(hào)衛(wèi)星數(shù)據(jù)自動(dòng)下載實(shí)例

 更新時(shí)間:2022年10月13日 11:52:31   作者:Comtech  
這篇文章主要為大家介紹了Python實(shí)現(xiàn)葵花8號(hào)衛(wèi)星數(shù)據(jù)自動(dòng)下載實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

一:數(shù)據(jù)源介紹

本篇文章介紹的是使用python實(shí)現(xiàn)對(duì)葵花8號(hào)衛(wèi)星數(shù)據(jù)進(jìn)行自動(dòng)下載。

葵花8號(hào)衛(wèi)星是日本的一顆靜止軌道氣象衛(wèi)星,覆蓋范圍為60S-60N, 80E-160W,除了提供十分鐘一幅的原始衛(wèi)星影像外,還提供了如氣溶膠光學(xué)厚度(AOT,也叫AOD)、葉綠素A、海表溫度、云層厚度以及火點(diǎn)等多種產(chǎn)品,這些數(shù)據(jù)都可以進(jìn)行下載。

二:FTP服務(wù)器描述

首先需要在葵花8官網(wǎng)申請(qǐng)帳號(hào)。

可以通過FTP(ftp.ptree.jaxa.jp)使用申請(qǐng)的帳號(hào)密碼訪問文件服務(wù)器,可以看到j(luò)ma文件夾、pub文件夾和兩個(gè)文本文件,其中,jma文件夾和pub文件夾中存放的都是葵花系列衛(wèi)星的影像產(chǎn)品,文本文件的內(nèi)容是每種影像產(chǎn)品的存放位置和數(shù)據(jù)介紹。

三: 程序描述

  • 本代碼下載Ftp服務(wù)器如下地址下的文件,如需使用可根據(jù)自己的需要進(jìn)行修改,也可以參考官方txt數(shù)據(jù)介紹文檔尋找自己需要的數(shù)據(jù)的存儲(chǔ)路徑。
  • 使用/031目錄是因?yàn)閿?shù)據(jù)最全。
  /pub/himawari/L3/ARP/031/
  • 本程序有兩個(gè)全局調(diào)試變量。
全局變量TrueFalse配置變量
debugLocalDownload下載到本地目錄下載到服務(wù)器指定目錄self._save_path
debugDownloadDaily下載當(dāng)前日期前1天的文件下載指定時(shí)間段的文件-

本程序有兩個(gè)版本在debugDownloadDaily=False時(shí)略有區(qū)別

  • HimawariDownloadBulitIn的時(shí)間變量寫在程序內(nèi)部,運(yùn)行前需手動(dòng)修改,適用于超算節(jié)點(diǎn)。
  • HimawariDownloadCmdLine的時(shí)間變量通過命令行輸入,適用于登陸節(jié)點(diǎn)。

四:注意事項(xiàng)

  • 代碼無法直接運(yùn)行 需要將以下行中的帳號(hào)和密碼替換成你申請(qǐng)的賬號(hào)密碼

五:代碼

# -*- codeing = utf-8 -*-
# 可以部署在日本的服務(wù)器上,下載速度很快
import ftplib
import json
import os
import time
import numpy as np
debugLocalDownload = True
debugDownloadDaily = False
globPersonalTime = [2022, 9, 7]
class NumpyEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, (np.int_, np.intc, np.intp, np.int8,
                            np.int16, np.int32, np.int64, np.uint8,
                            np.uint16, np.uint32, np.uint64)):
            return int(obj)
        elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)):
            return float(obj)
        elif isinstance(obj, (np.ndarray,)):
            return obj.tolist()
        return json.JSONEncoder.default(self, obj)
class himawari:
    ftp = ftplib.FTP()
    def __init__(self):
        self._url = '/pub/himawari/L3/ARP/031/'
        self._save_path = './Your_save_path'
        if debugLocalDownload:
            self._save_path = './Download/'
        self.ftp.connect('ftp.ptree.jaxa.jp', 21)
        self.ftp.login('YourFTPAccount', 'YourFTPPassWord')
        self._yearNum, self._monNum, self._dayNum = self.dayInit()
        self._nginx_path = ''
        print(self.ftp.welcome)  # 顯示登錄信息
    def run(self):
        self._nginx_path = ''
        try:
            if debugDownloadDaily:
                self._yearNum, self._monNum, self._dayNum = self.getYesterday(self._yearNum, self._monNum, self._dayNum)
            else:
                self._yearNum = globPersonalTime[0]
                self._monNum = globPersonalTime[1]
                self._dayNum = globPersonalTime[2]
            self._yearStr, self._monStr, self._dayStr = self.getDateStr(self._yearNum, self._monNum, self._dayNum)
            ftp_filePath = self._url + self._yearStr + self._monStr + "/" + self._dayStr + "/"
            # 從目標(biāo)路徑ftp_filePath將文件下載至本地路徑dst_filePath
            dst_filePath = self._nginx_path + self._save_path + self._yearStr + "/" + self._monStr + "/" + self._dayStr + "/" + "hour" + "/"
            self.deleteFile(dst_filePath)  # 先刪除未下載完成的臨時(shí)文件
            print("Local:" + dst_filePath)
            print("Remote:" + ftp_filePath)
            self.DownLoadFileTree(dst_filePath, ftp_filePath)
            if debugDownloadDaily:
                self.ftp.quit()
        except Exception as err:
            print(err)
    def getYesterday(self, yy, mm, dd):
        dt = (yy, mm, dd, 9, 0, 0, 0, 0, 0)
        dt = time.mktime(dt) - 86400
        yesterdayList = time.strftime("%Y-%m-%d", time.localtime(dt)).split('-')
        return int(yesterdayList[0]), int(yesterdayList[1]), int(yesterdayList[2])
    def dayInit(self, ):
        yesterdayList = time.strftime("%Y-%m-%d", time.localtime(time.time())).split('-')
        return int(yesterdayList[0]), int(yesterdayList[1]), int(yesterdayList[2])
    def getDateStr(self, yy, mm, dd):
        syy = str(yy)
        smm = str(mm)
        sdd = str(dd)
        if mm < 10:
            smm = '0' + smm
        if dd < 10:
            sdd = '0' + sdd
        return syy, smm, sdd
    # 刪除目錄下擴(kuò)展名為.temp的文件
    def deleteFile(self, fileDir):
        if os.path.isdir(fileDir):
            targetDir = fileDir
            for file in os.listdir(targetDir):
                targetFile = os.path.join(targetDir, file)
                if targetFile.endswith('.temp'):
                    os.remove(targetFile)
    # 下載單個(gè)文件,LocalFile表示本地存儲(chǔ)路徑和文件名,RemoteFile是FTP路徑和文件名
    def DownLoadFile(self, LocalFile, RemoteFile):
        bufSize = 102400
        file_handler = open(LocalFile, 'wb')
        print(file_handler)
        # 接收服務(wù)器上文件并寫入本地文件
        self.ftp.retrbinary('RETR ' + RemoteFile, file_handler.write, bufSize)
        self.ftp.set_debuglevel(0)
        file_handler.close()
        return True
    # 下載整個(gè)目錄下的文件,LocalDir表示本地存儲(chǔ)路徑, emoteDir表示FTP路徑
    def DownLoadFileTree(self, LocalDir, RemoteDir):
        # 如果本地不存在該路徑,則創(chuàng)建
        if not os.path.exists(LocalDir):
            os.makedirs(LocalDir)
            # 獲取FTP路徑下的全部文件名,以列表存儲(chǔ)
        self.ftp.cwd(RemoteDir)
        RemoteNames = self.ftp.nlst()
        RemoteNames.reverse()
        # print("RemoteNames:", RemoteNames)
        for file in RemoteNames:
            # 先下載為臨時(shí)文件Local,下載完成后再改名為nc4格式的文件
            # 這是為了防止上一次下載中斷后,最后一個(gè)下載的文件未下載完整,而再開始下載時(shí),程序會(huì)識(shí)別為已經(jīng)下載完成
            Local = os.path.join(LocalDir, file[0:-3] + ".temp")
            files = file[0:-3] + ".nc"
            LocalNew = os.path.join(LocalDir, files)
            '''
            下載小時(shí)文件,只下載UTC時(shí)間0時(shí)至24時(shí)(北京時(shí)間0時(shí)至24時(shí))的文件
            下載的文件必須是nc格式
            若已經(jīng)存在,則跳過下載
            '''
            # 小時(shí)數(shù)據(jù)命名格式示例:H08_20200819_0700_1HARP030_FLDK.02401_02401.nc
            if int(file[13:15]) >= 0 and int(file[13:15]) <= 24:
                if not os.path.exists(LocalNew):
                    #print("Downloading the file of %s" % file)
                    self.DownLoadFile(Local, file)
                    os.rename(Local, LocalNew)
                    print("The download of the file of %s has finished\n" % file)
                    #print("png of the file of %s has finished\n" % png_name)
                elif os.path.exists(LocalNew):
                    print("The file of %s has already existed!\n" % file)
        self.ftp.cwd("..")
        return
# 主程序
myftp = himawari()
if debugDownloadDaily:
    myftp.run()
else:
    yyStart, mmStart, ddStart = input("Start(yy mm dd):").split()
    yyStart, mmStart, ddStart = int(yyStart), int(mmStart), int(ddStart)
    yyEnd, mmEnd, ddEnd = input("End(yy mm dd):").split()
    yyEnd, mmEnd, ddEnd = int(yyEnd), int(mmEnd), int(ddEnd)
    dtStart = (yyStart, mmStart, ddStart, 9, 0, 0, 0, 0, 0)
    dtEnd = (yyEnd, mmEnd, ddEnd, 10, 0, 0, 0, 0, 0)
    timeIndex = time.mktime(dtStart)
    timeIndexEnd = time.mktime(dtEnd)
    while timeIndex < timeIndexEnd:
        indexDayList = time.strftime("%Y-%m-%d", time.localtime(timeIndex)).split('-')
        globPersonalTime[0] = int(indexDayList[0])
        globPersonalTime[1] = int(indexDayList[1])
        globPersonalTime[2] = int(indexDayList[2])
        print(globPersonalTime)
        myftp.run()
        timeIndex = int(timeIndex) + 3600 * 24

以上就是Python實(shí)現(xiàn)葵花8號(hào)衛(wèi)星數(shù)據(jù)自動(dòng)下載實(shí)例的詳細(xì)內(nèi)容,更多關(guān)于Python數(shù)據(jù)自動(dòng)下載的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 關(guān)于python安裝第三方庫的問題與解決方案

    關(guān)于python安裝第三方庫的問題與解決方案

    Python開發(fā)中經(jīng)常遇到第三方庫安裝困難的問題,速度慢可以使用國內(nèi)鏡像如清華鏡像加速,若遇到wheel錯(cuò)誤,可以手動(dòng)下載whl文件進(jìn)行安裝,對(duì)于找不到的包,可以嘗試在Python的官方包發(fā)布網(wǎng)站上進(jìn)行搜索和下載,本文提供了具體的解決方案和操作步驟
    2024-10-10
  • python中浮點(diǎn)數(shù)比較判斷!為什么不能用==(推薦)

    python中浮點(diǎn)數(shù)比較判斷!為什么不能用==(推薦)

    這篇文章主要介紹了python中浮點(diǎn)數(shù)比較判斷!為什么不能用==,本文給大家分享問題解決方法,需要的朋友可以參考下
    2023-09-09
  • python常用文件操作(讀寫追加等)

    python常用文件操作(讀寫追加等)

    在Python中,文件操作是一項(xiàng)常用的任務(wù),本節(jié)將介紹如何執(zhí)行基本的文件操作,如讀取、寫入和追加數(shù)據(jù),我們將通過實(shí)例代碼詳細(xì)講解每個(gè)知識(shí)點(diǎn)
    2023-06-06
  • Scrapy中詭異xpath的匹配內(nèi)容失效問題及解決

    Scrapy中詭異xpath的匹配內(nèi)容失效問題及解決

    這篇文章主要介紹了Scrapy中詭異xpath的匹配內(nèi)容失效問題及解決方案,具有很好的價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • python openpyxl提取Excel圖片實(shí)現(xiàn)原理技巧

    python openpyxl提取Excel圖片實(shí)現(xiàn)原理技巧

    在這篇文章中,將介紹如何使用openpyxl來提取Excel中的圖片,以及它的原理和技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • Python切片列表字符串如何實(shí)現(xiàn)切換

    Python切片列表字符串如何實(shí)現(xiàn)切換

    這篇文章主要介紹了Python切片列表字符串如何實(shí)現(xiàn)切換,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • 怎樣保存模型權(quán)重和checkpoint

    怎樣保存模型權(quán)重和checkpoint

    這篇文章主要介紹了如何保存模型權(quán)重和checkpoint,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • Pytorch中的masked_fill基本知識(shí)詳解

    Pytorch中的masked_fill基本知識(shí)詳解

    本文介紹了PyTorch中masked_fill函數(shù)的基本使用和原理,該函數(shù)接受一個(gè)輸入張量和一個(gè)布爾掩碼作為參數(shù),掩碼的形狀必須與輸入張量相同,True表示需要填充的位置,False表示保持原值
    2024-10-10
  • python針對(duì)excel的操作技巧

    python針對(duì)excel的操作技巧

    這篇文章主要介紹了python針對(duì)excel的操作方法,需要的朋友可以參考下
    2018-03-03
  • python實(shí)現(xiàn)文字版掃雷

    python實(shí)現(xiàn)文字版掃雷

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)文字版掃雷,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04

最新評(píng)論