New products from the Meteoinfo family: Calculating the mean of different regions

Source: Internet
Author: User

Here, for example in the United States, there is a grid temperature field data (Usgrid.data) for the United States region, which needs to calculate the average temperature for each state. Of course, there is a shape file containing the administrative regions of each state (the relevant documents can be downloaded in this post: HTTP://BBS.06CLIMATE.COM/FORUM.P ... d=11070&fromuid=106). First, the lattice data array is read, and then the states.shp file is read to generate the US layer, traversing all the elements of the US layer (shape, each entity is a state), and for each state, using the state's elements to maksout the grid point data, and then averaging, maximum, and minimum values, and print out (of course, you can also output to a file, specifically on the web to find Python output text file example). The subsequent drawing statements are just to see how the data is distributed.

Script Program:

#ADD a surfer grid dataf = Addfile_surfer ('D:/temp/ascii/usgrid.dat') Tdata= f['var'][:,:]#Read US shape fileUS = Shaperead ('d:/temp/map/states.shp')#Average temporature for each statei =0 forRpolyinchus.getshapes (): Name= Us.getcellvalue ('State_name', i) Mdata=tdata.maskout (rpoly) Tave=mdata.ave () tmin=mdata.min () Tmax=Mdata.max ()PrintName +', Ave:%.2f, Min:%.2f, Max:%.2f'%(Tave, tmin, Tmax) I+ = 1#Plotaxesm () 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)

New products from the Meteoinfo family: Calculating the mean of different regions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.