Python在氣象中的應(yīng)用

-4- 更新一些處理數(shù)據(jù)中可能會用到的Function

def Copy_attribute(self, data, data_copy):
        '''
        Function:This script is used to refresh data properties.
                    Copy the properties of the data_copy to the data_new and the data data to the data_new.
        Author:xiaohuoya
        Date:2020-05-20
        '''
        data_new = data_copy.copy()
        data_new.values = data
        return data_new

    def Read_region(self, data, region_shp):
        '''
        Function:This script is used for irregular region data reading, such as reading data for the Yangtze River Delta region.
        Author:xiaohuoya
        Date:2020-05-20
        '''
        import geopandas
        import salem

        region_shp = geopandas.read_file(region_shp)
        data_region = data.salem.roi(shape=region_shp)
        return data_region

    def Data_to_Excel(self,data, file_name,header):
        '''
        Function:This script is used to write data to Excel.
        Author:xiaohuoya
        Date:2020-05-21
        Eg: -1- data: the data
            -2- file_name: the file name
            -3- sheet_name: the sheet name
            -4- header: the header('a','b','c')
        '''
        import pandas as pd
        import openpyxl

        data = pd.DataFrame(data)
        writer = pd.ExcelWriter(file_name)
        data.to_excel(writer, self.sheet_name, float_format='%.4f',header=header)
        writer.save()
        writer.close()

1.Copy_attribute函數(shù)用于復(fù)制一個數(shù)據(jù)的屬性到另一個數(shù)據(jù),例如data(time,lat,lon),data_copy(time,lat1,lon1),data_new(time,lat1,lon1)其中的數(shù)據(jù)為data
2.Read_region函數(shù)引用salem、geopandas可以用來處理特定地形的數(shù)據(jù),導(dǎo)入對應(yīng)的地形shp文件即可
3.Data_to_Excel函數(shù)可以將數(shù)據(jù)輸出成excel

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請通過簡信或評論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容