0

下一部分气象局谜题:我有一个目录结构

> `-- 2012/
>     |           |-- 02/
>     |           |   |-- 27/
>     |           |   |-- 28/
>     |           |   `-- 29/ 
>     |           `-- 03/
>     |               |-- 01/
>     |               |-- 02/ 
>     |               |-- 03/
>     |               |-- 04/ 
>     |               `-- 05/

包含 10 分钟时间片中雷达降雨的 netcdf 文件,用于 8 天风暴事件。我希望能够为事件的 RADAR 循环设置动画,并生成总累积降雨量的最终图。

我不知道如何开始?我需要读取目录和文件,并创建一个我想象的数组?这些文件都在这里压缩:https ://dl.dropboxusercontent.com/u/15223371/2012.zip

非常感谢有关如何启动代码的任何指示?

4

1 回答 1

0

好吧,经过相当多的搜索后,我的路还不错....但是无法弄清楚如何动画....并且尚未创建所有数组的总和(累加)?

   import os
import sys
import glob
import numpy as np
from scipy.io import netcdf
import pylab as pl
from easygui import *
import fnmatch
import matplotlib.pyplot as plt



print 'START...'
cur_dir= os.getcwd()
top_dir = os.path.dirname(cur_dir)
print cur_dir
print top_dir
print 'Present Directory Open...'
title = "Select Directory to Read Multiple rainfall .nc files"
msg = "This is a test of the diropenbox.\n\nPick the directory that you wish to open."
d = diropenbox(msg, title)
fromdir = d
rootPath = fromdir
pattern = '*.nc'

for root, dirs, files in os.walk(rootPath):
    for filename in fnmatch.filter(files, pattern):
        #print( os.path.join(root, filename))
        print filename
        # Now read NetCDF file and Plot the Radar Rainfall Array
        """
        data = NetCDFFile(filename, netcdf_mode_r)
        print 'VARIABLES:'
        print data.variables        
        """

        data = netcdf.NetCDFFile(os.path.join(root, filename), 'r')
        #print 'VARIABLES:'
        #print data.variables
        try:
            precip = data.variables['precipitation'].data
            x = data.variables['x_loc'].data
            y = data.variables['y_loc'].data
        except:
            precip = data.variables['precip'].data
            x = data.variables['x_loc'].data
            y = data.variables['y_loc'].data
        #raw_input('hold..')
        #print x
        plt.title('RADAR RAINFALL'+filename, size=20)
        plt.imshow(precip, origin='lower', interpolation='bicubic',extent=(x.min(), x.max(), y.min(), y.max()))
        plt.colorbar()
        plt.show()
于 2013-09-24T05:05:02.580 回答