爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 17700|回复: 21

MeteoInfo脚本示例:计算每个区域的平均温度

[复制链接]

新浪微博达人勋

发表于 2012-11-15 14:04:53 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 MeteoInfo 于 2012-11-15 14:08 编辑

最近一个美国人问怎样批量输出GrADS的maskout数据,比如输出每个县的maskout文件,用'Output Map Data'对话框手动来做是很让人抓狂的,因此帮他写了一个脚本来自动处理,为简单起见,行政区域到state一级,也就是把每个state的maskout格点数据输出到一个GrADS格点数据文件中。他想用这些maskout数据来计算每个区域的温度平均等。

需要用到MeteoInfo的最新文件(见置顶帖子)。

其实用MeteoInfo脚本就很容易实现计算每个区域的平均等,因此也顺便写了一个脚本来演示如何实现。用到的美国state一级行政区域shape文件: STATES.SHP (217.13 KB, 下载次数: 62)
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-11-15 17:58:42 | 显示全部楼层
第一个报道学习了,王老师辛苦了!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-11-15 19:18:44 | 显示全部楼层
本帖最后由 ♂雨已~○ 于 2012-11-15 19:19 编辑

王老师,我用你新更新的文件再执行以前你给的MeteoinfoDemo的时候,下面这几句代码不行了,不知道王老师在最新版的文件中把这个  GridDataPara类弄到哪儿呢?还是给去掉了?用了新更新的文件这个插值功能就不行了!
  1.    private void TSMI_StationShaded_Click(object sender, EventArgs e)
  2.         {
  3.             this.Cursor = Cursors.WaitCursor;

  4.             //Read data info
  5.             MeteoDataInfo aDataInfo = new MeteoDataInfo();
  6.             string aFile = Application.StartupPath + "\\Sample\\rain_2008072220.csv";
  7.             aDataInfo.OpenLonLatData(aFile);

  8.             //Get station data
  9.             StationData stationData = aDataInfo.GetStationData("Precipitation6h");

  10.             //Interpolate
  11.             GridDataPara aGDP = new GridDataPara();
  12.             aGDP.dataExtent.minX = 60;
  13.             aGDP.dataExtent.maxX = 140;
  14.             aGDP.dataExtent.minY = -20;
  15.             aGDP.dataExtent.maxY = 60;
  16.             aGDP.xNum = 80;
  17.             aGDP.yNum = 80;
  18.             GridInterpolation gridInterp = new GridInterpolation();
  19.             gridInterp.GridDataParaV = aGDP;

  20.             gridInterp.GridInterMethodV = GridInterMethod.IDW_Radius;
  21.             gridInterp.Radius = 2;
  22.             gridInterp.MinPointNum = 1;

  23.             double[] X = new double[1];
  24.             double[] Y = new double[1];
  25.             ContourDraw.CreateGridXY(gridInterp.GridDataParaV, ref X, ref Y);
  26.             double[,] S = stationData.Data;
  27.             S = ContourDraw.FilterDiscreteData_Radius(S, gridInterp.Radius,
  28.                 gridInterp.GridDataParaV.dataExtent, stationData.UNDEF);
  29.             GridData gridData = ContourDraw.InterpolateDiscreteData_Radius(S,
  30.                 X, Y, gridInterp.MinPointNum, gridInterp.Radius, stationData.UNDEF);

  31.             //Create legend scheme
  32.             bool hasNoData = true;
  33.             LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(gridData, LegendType.GraduatedColor,
  34.                 ShapeTypes.Polygon, ref hasNoData);
  35.             ((PolygonBreak)aLS.breakList[0]).DrawFill = false;

  36.             //Create layer
  37.             VectorLayer aLayer = new VectorLayer(ShapeTypes.Polygon);
  38.             aLayer = DrawMeteoData.CreateShadedLayer(gridData, aLS, "Rain", "Rain");
  39.             aLayer.IsMaskout = true;

  40.             //Add layer
  41.             layersLegend1.ActiveMapFrame.AddLayer(aLayer);
  42.             layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 0);
  43.             layersLegend1.Refresh();

  44.             //Change title of the layout
  45.             LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
  46.             aTitle.SetLabelText("MeteoInfo Class Library Demo - Station Shaded Layer");

  47.             //Add or change the legend in layout
  48.             LayoutLegend aLegend;
  49.             if (mapLayout1.GetLegends().Count > 0)
  50.                 aLegend = mapLayout1.GetLegends()[0];
  51.             else
  52.                 aLegend = mapLayout1.AddLegend(650, 100);
  53.             aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
  54.             aLegend.LegendLayer = aLayer;
  55.             if (tabControl1.SelectedIndex == 1)
  56.                 mapLayout1.PaintGraphics();

  57.             this.Cursor = Cursors.Default;
复制代码

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-11-15 19:30:51 | 显示全部楼层
王老师,我尝试着用你这种方法来先将数据maskout后作图,但是出现了只有左边图例,没有图形,这是为什么?下面是我的代码,请王老师帮忙看看~~~~
截图.png
  1.            //Create a legend scheme
  2.            MeteoDataInfo aDataInfo = new MeteoDataInfo();

  3.            //Open GrADS data file
  4.            string aFile = Application.StartupPath + "\\Sample\\model.ctl";
  5.            aDataInfo.OpenGrADSData(aFile);

  6.            //Get GridData
  7.            GridData press = aDataInfo.GetGridData("PS");

  8.           aFile = Application.StartupPath + "\\Map\\四川重庆.shp";
  9.           MapLayer maskLayer = MapDataManage.OpenLayer(aFile);
  10.           layersLegend1.ActiveMapFrame.AddLayer(maskLayer);
  11.           layersLegend1.Refresh();
  12.               

  13.            //Create a legend scheme
  14.             
  15.            GridData maskpress = press.Maskout(mapView1,"四川重庆.shp");

  16.            bool hasUndefData = false;
  17.            LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(maskpress,
  18.                        LegendType.GraduatedColor, ShapeTypes.Polygon, ref hasUndefData);

  19.            //Create a contour layer
  20.            VectorLayer aLayer = DrawMeteoData.CreateShadedLayer(maskpress, aLS, "Shaded_PS", "PS");
  21.            
  22.            //Add layer
  23.            layersLegend1.ActiveMapFrame.AddLayer(aLayer);
  24.            layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 0);
  25.            layersLegend1.Refresh();

  26.            //Change title of the layout
  27.            LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
  28.            aTitle.SetLabelText("MeteoInfo Class Library Demo - Shaded Layer");

  29.            //Add or change the legend in layout
  30.            LayoutLegend aLegend;
  31.            if (mapLayout1.GetLegends().Count > 0)
  32.                aLegend = mapLayout1.GetLegends()[0];
  33.            else
  34.                aLegend = mapLayout1.AddLegend(650, 100);
  35.            aLegend.LegendStyle = LegendStyleEnum.Bar_Vertical;
  36.            aLegend.LegendLayer = aLayer;
  37.            if (tabControl1.SelectedIndex == 1)
  38.                mapLayout1.PaintGraphics();
复制代码


密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2012-11-15 20:46:01 | 显示全部楼层

改了一些类的名称,你在http://www.meteothinker.com/上下载最新的Demo程序看看相关代码就知道了。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2012-11-15 20:49:17 | 显示全部楼层
♂雨已~○ 发表于 2012-11-15 19:30
王老师,我尝试着用你这种方法来先将数据maskout后作图,但是出现了只有左边图例,没有图形,这是为什么?下 ...

model.ctl数据分辨率很粗,在重庆市区域也就一个点,当然做不出等值线图来了。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-11-15 21:16:19 | 显示全部楼层
MeteoInfo 发表于 2012-11-15 20:49
model.ctl数据分辨率很粗,在重庆市区域也就一个点,当然做不出等值线图来了。

奥,明白了,谢谢王老师,我用站点资料就行了~~~
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-11-18 18:02:11 | 显示全部楼层
学习了,谢谢王老师!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2012-12-13 20:40:24 | 显示全部楼层
MeteoInfo 发表于 2012-11-15 20:46
改了一些类的名称,你在http://www.meteothinker.com/上下载最新的Demo程序看看相关代码就知道了。

王老师,要是初学meteinfo的脚本应该从什么地方开始?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2012-12-13 21:20:28 | 显示全部楼层
卉卉 发表于 2012-12-13 20:40
王老师,要是初学meteinfo的脚本应该从什么地方开始?

学习IronPython, MeteoInfo类库,论坛里的脚本帖子
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表