zoukankan      html  css  js  c++  java
  • MeteoInfoLab脚本示例:计算不同区域平均值

    这里用美国做例子,有一个美国区域的格点温度场数据(usgrid.data),需要计算出每个州(state)的平均温度。当然需要有一个包含各州行政区域的shape文件了(相关文件可以在此帖中下载:http://bbs.06climate.com/forum.p ... d=11070&fromuid=106)。首先读取格点数据数组,然后读取states.shp文件生成us图层,对us图层所有的图元(shape,每个图元就是一个州)遍历,对于每个州,利用该州的图元maksout格点数据,然后求平均值、最大值和最小值,并打印出来(当然也可以输出到文件中,具体在网上找python输出文本文件的例子)。后面的绘图语句只是为了看看数据的分布情况。

    脚本程序:

    #Add a surfer grid data
    f = addfile_surfer('D:/Temp/ascii/usgrid.dat')
    tdata = f['var'][:,:]
    #Read US shape file
    us = shaperead('D:/Temp/map/states.shp')
    #Average temporature for each state
    i = 0
    for rpoly in us.getShapes():
        name = us.getCellValue('STATE_NAME', i)
        mdata = tdata.maskout(rpoly)
        tave = mdata.ave()
        tmin = mdata.min()
        tmax = mdata.max()
        print name + ', Ave: %.2f, Min: %.2f, Max: %.2f' %(tave, tmin, tmax)
        i += 1
        
    #Plot
    axesm()
    world = shaperead('D:/Temp/map/country1.shp')
    geoshow(world)
    geoshow(us, edgecolor=[0,0,255])
    layer = contourfm(tdata,20)
    title('Temporature distribution map')
    colorbar(layer)

  • 相关阅读:
    django-form表单
    django-登录页面添加验证码
    opensatck误删除service项目
    运维脚本
    大数据平台架构组件选择与运用场景
    HDP2.4安装(五):集群及组件安装
    Spark(三): 安装与配置
    Spark(二): 内存管理
    Spark(一): 基本架构及原理
    ElasticSearch基本使用
  • 原文地址:https://www.cnblogs.com/yaqiang/p/4641198.html
Copyright © 2011-2022 走看看