Python为多个目录和文件动画制作NetCDF数组,用于雷达降雨

时间:2013-09-24 01:20:32

标签: python animation directory subdirectory netcdf

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

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

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

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

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

1 个答案:

答案 0 :(得分:0)

在经过相当多的搜索之后,我很顺利......但是无法弄清楚如何动画......并且还要创建所有阵列的Sum(累积)?

   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()