Python處理GPM(IMERG/GSMaP)衛(wèi)星降水數據

概述(前言)

本文作為上一篇博客《MATLAB處理GPM(IMERG/GSMaP)衛(wèi)星降水數據》的后續(xù),作者選擇另一種語言python來實現處理降水領域高分辨率降水數據GPM-IMERG和GPM-GSMaP,兩種數據的詳細介紹、下載方式以及matlab讀取參見上一篇文章《MATLAB處理GPM(IMERG/GSMaP)衛(wèi)星降水數據》

image.png

正文

Python 處理GPM-IMERG數據

1. 數據下載(python ftplib)
參見文章《python 實現FTP文件批量下載》
2.數據讀取(python)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/28 17:28
# @Author  : zengsk in HoHai
# @File    : Calc_AVG_IMERG.py

'''
Calculating the average precipitation over a given region
'''

# Import packages
import os
import h5py
import numpy as np
import pandas as pd
import warnings

warnings.simplefilter("ignore")

# header
header = '''ncols         3600
nrows         1800
xllcorner     -180
yllcorner     -90
cellsize      0.1
NODATA_value  -999.0'''

# dataset directory
sPath = r'D:\降水數據\satellite_pre\IMERG\late\201508'
# mask region
mask = pd.read_table(r'.\assets\china_mask_gpm_01.txt', sep='\s+', header=None, skiprows=6).values

rain = np.empty([1800, 3600], dtype=float)
tag = np.empty(rain.shape, dtype=float)     # Record the effective precip times per grid

Files = os.listdir(sPath)
for file in Files:
   fpath = os.path.join(sPath, file)
   if os.path.splitext(fpath)[1] == '.RT-H5':
       print(os.path.basename(fpath))
       f = h5py.File(fpath)      # Open the H5 file, return the File class
       Uncal = f['/Grid/precipitationUncal'].value

       Uncal = np.transpose(Uncal)   # size: 1800 x 3600
       Uncal = np.flipud(Uncal)      # convert to  90N ~ 90S
       tag[Uncal>=0] = tag[Uncal>=0] + 1
       Uncal[Uncal<0] = 0
       Uncal /= 2
       rain += Uncal

# output
rainfall_avg = rain / tag * 2 * 24    # unit conversion
rainfall_avg[np.isnan(rainfall_avg)] = -999.00 # NODATA_value
rainfall_avg[mask<0] = -999.00

ofname = r'.\output\IMERG_AVG_201508mon.txt'
np.savetxt(ofname, rainfall_avg, fmt='%7.2f ', comments='', header=header)

print("\n***************** 數據處理完成!!! Nice Job!!! ****************")

Python 處理GPM-GSMaP數據

1. 數據下載(python ftplib)
參見文章《python 實現FTP文件批量下載》
2.數據讀取(python)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/4/13 18:34
# @Author  : zengsk in HoHai
# @File    : Calc_Avg_GSMaP.py

'''
Calculating the average precipitation over a given region
 GsMaP info:
    60N-->60S, 0-->360E;
    0.1*0.1degree;
    1 hourly or daily;
    4-byte-float;
'''

import os
import struct
import numpy as np
import pandas as pd
import warnings

warnings.simplefilter("ignore")

# header
header = '''ncols         3600
nrows         1200
xllcorner     0
yllcorner     -60
cellsize      0.1
NODATA_value  -999.0'''

# dataset directory
sPath = r'D:\data\GSMaP'
# mask region file
mask = pd.read_table(r'.\assets\china_mask_gpm_01.txt', sep='\s+', header=None, skiprows=6).values

rain = np.empty([1200, 3600], dtype=float)
tag = np.empty(rain.shape, dtype=float)     # Record the effective precip times per grid

Files = os.listdir(sPath)
for file in Files:
    filepath = os.path.join(sPath, file)
    if '.dat' == os.path.splitext(filepath)[1]:
        print(filepath)
        with open(filepath, 'rb') as fid:
            data = fid.read()
            data = struct.unpack('f'*3600*1200, data)
        data = np.array(data)
        data.resize(1200,3600)
        tag[data >= 0] = tag[data >= 0] + 1
        data[data < 0] = 0.0
        data *= 24           # unit conversion
        rain += data
# output
rainfall_avg = rain / tag
rainfall_avg[np.isnan(rainfall_avg)] = -999.00 # NODATA_value
rainfall_avg[mask<0] = -999.00

ofname = r'.\output\201607avg_gsmap.txt'
np.savetxt(ofname, rainfall_avg, fmt='%7.2f ', comments='', header=header)

print("\n+---------------- 數據處理完成!!! Nice Job!!! -----------------+\n")

最后來一張IMERG 2015年08月全球平均降水量分布圖(由上述代碼讀取)


IMERG 2015年08月全球平均降水量分布

歡迎留言討論!轉載請注明出處!!!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容