【记录】数据处理过程

1.从KNMI官网上下载数据(需要开加速器挂梯子)

2.下载的数据为5分钟一组,有时会少项,所以需要检查

3.下载后的数据格式为.h5文件,用matlab处理图片:

Files = dir(fullfile('G:\deeeep\dataset\data\data2020\2020.12'));
%LengthFiles = length(Files);
for i=01:31
    for j=00:23
        for k=00:11
            filename=['G:\deeeep\dataset\data\data2020\2020.12\RAD_NL25_PCP_NA_202012', num2str(i,'%02d') ,num2str(j,'%02d'),num2str(5*k,'%02d'),'.h5'];
            info=h5info(filename);
            data = h5read(['G:\deeeep\dataset\data\data2020\2020.12\RAD_NL25_PCP_NA_202012',num2str(i,'%02d') ,num2str(j,'%02d'),num2str(5*k,'%02d'),'.h5'],'/image1/image_data');
            map=[255 255	255
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
255	232	222
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
204	204	204
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
153	153	153
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
77	77	77
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	128	128
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
255	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
0	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
128	0	0
240	240	240
];
            MAP=map/255;
            I2 = imcrop(data,[239 206 287 287]);
            save(['G:\done\2020.12\RAD_NL25_PCP_NA_202012',num2str(i,'%02d') ,num2str(j,'%02d'),num2str(5*k,'%02d'),'.mat']','I2','-mat')
        end
    end
   
    
    


end


最终可以得到I2,也就是24*24的图片每一个像素对应的降雨量,类比于电量数据集中的家庭(576个格子)。

4.将.mat文件转为.txt文件,得到最终数据。

"""
@author: Yao

得到txt格式的数据
"""

import os
import scipy.io as scio
import csv
import numpy as np

y = np.zeros(shape=(1, 24, 24))

#stack

for i in range(1,32):
    for j in range(0,24):
        for k in range(0,12):
            path = r"G:\data\done\2020.12\RAD_NL25_PCP_NA_202012"+str(i).rjust(2,'0')+str(j).rjust(2,'0')+str(5*k).rjust(2,'0')+".mat"
            data = scio.loadmat(path)

            X1 = data['I2']
            # X1 = X1[np.newaxis, :]
            # y = np.vstack((y,X1))
            y=X1.reshape(1,576)

            # 写入txt文档
            # path=r"G:\data\txt\RAD_NL25_PCP_NA_202001"+str(i).rjust(2,'0')+str(j).rjust(2,'0')+str(5*k).rjust(2,'0')+'.txt'
            path = r"G:\data\txt\data.txt"
            file3 = open(path, 'a+',encoding='UTF-8')
            # 写的内容:
            file3.write('"2020-12-'+str(i).rjust(2,'0')+' '+str(j).rjust(2,'0')+':'+str(5*k).rjust(2,'0')+':00";')
            file3.write(str(y)+'\n')














5.得到的txt文件如下:

【记录】数据处理过程_第1张图片

 

你可能感兴趣的:(python,matlab)