Google earth engine(GEE)——平均气温计算并且显示直方图

举报
此星光明 发表于 2022/04/16 03:02:24 2022/04/16
【摘要】 美国三个州的平均气温计算并且显示直方图  完整的图形是这样的  这是我改了代码之后显示了一年十二个月的一个数据,坐标标签直接改成数字了   这里面有一个数据集OREGONSTATE/PRISM/Norm81m 用数据的时候可以引用这个文章 Daly, C., Halbleib, M., Sm...

美国三个州的平均气温计算并且显示直方图

 完整的图形是这样的

 这是我改了代码之后显示了一年十二个月的一个数据,坐标标签直接改成数字了

 

这里面有一个数据集OREGONSTATE/PRISM/Norm81m

用数据的时候可以引用这个文章

Daly, C., Halbleib, M., Smith, J.I., Gibson, W.P., Doggett, M.K., Taylor, G.H., Curtis, J., and Pasteris, P.A. 2008. Physiographically-sensitive mapping of temperature and precipitation across the conterminous United States. International Journal of Climatology, 28: 2031-2064

[Daly, C., J.I. Smith, and K.V. Olson. 2015. Mapping atmospheric moisture climatologies across the conterminous United States. PloS ONE 10(10):e0141140. doi:10.1371/journal.pone.0141140.

ee.Filter.notNull(properties)

如果所有命名属性不为空,则返回一个过滤器。

Returns a filter that passes if all the named properties are not null.

Arguments:

properties (List)过滤的值是一个列表,

Returns: Filter

这次主要用到的函数

ui.Chart.feature.byProperty(features, xPropertiesseriesProperty)

Generates a Chart from a set of features. Plots property values of one or more features.

- X-axis = Property name, labeled by xProperties (default: all properties).

- Y-axis = Property value (must be numeric).

- Series = Features, labeled by seriesProperty (default: 'system:index').矢量属性值

All properties except seriesProperty are included on the x-axis by default.

默认情况下,除 seriesProperty 之外的所有属性都包含在 x 轴上。

Returns a chart.

Arguments:

features (Feature|FeatureCollection|List<Feature>):

The features to include in the chart.

xProperties (List<String>|Object|String, optional):

One of (1) a property to be plotted on the x-axis; (2) a list of properties to be plotted on the x-axis; or (3) a (property, label) dictionary specifying labels for properties to be used as values on the x-axis. If omitted, all properties will be plotted on the x-axis, labeled with their names.

seriesProperty (String, optional):

The name of the property used to label each feature in the legend. Defaults to 'system:index'.

Returns: ui.Chart

通过这个案例就是给出的三个州气温,明尼苏达州,德克萨斯州和佛罗里达州,1月,四月,7月和10月,如果想多个月份,只管在months加入元素即可


  
  1. //导入研究区
  2. var states = ee.FeatureCollection('TIGER/2018/States');
  3. // 导入温度法线并将月份特征转换为波段。
  4. var normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m')
  5. .select(['tmean'])
  6. .toBands();
  7. // 计算每个月每个州的平均值
  8. states = normClim.reduceRegions({
  9. collection: states,
  10. reducer: ee.Reducer.mean(),
  11. scale: 5e4})
  12. .filter(ee.Filter.notNull(['01_tmean']));
  13. // 计算每个州1月和7月的温度均值然后给与这个州添加温度差值属性
  14. states = states.map(function(state) {
  15. var julyTemp = ee.Number(state.get('06_tmean'));
  16. var janTemp = ee.Number(state.get('01_tmean'));
  17. return state.set('seasonal_delta', julyTemp.subtract(janTemp));
  18. });
  19. // 选择极端的州的天气,通过再次通过merge选取
  20. var extremeStates =
  21. states.limit(1, '01_tmean') // Coldest.
  22. .merge(states.limit(1, '07_tmean', false)) // Hottest.
  23. .merge(states.limit(1, 'seasonal_delta')); // Least variation.
  24. // 分别定义属性值在图表中,对应的月份和对应的温度所匹配
  25. // Define properties to chart.
  26. var months = {
  27. '01_tmean': 1,
  28. '02_tmean': 2,
  29. '03_tmean': 3,
  30. '04_tmean': 4,
  31. '05_tmean': 5,
  32. '06_tmean': 6,
  33. '07_tmean': 7,
  34. '08_tmean': 8,
  35. '09_tmean': 9,
  36. '10_tmean': 10,
  37. '11_tmean': 11,
  38. '12_tmean': 12
  39. };
  40. // Prepare the chart.
  41. var extremeTempsChart =
  42. ui.Chart.feature.byProperty(extremeStates, months, 'NAME')
  43. .setChartType('LineChart')
  44. .setOptions({
  45. title: 'Average Temperatures in U.S. States',
  46. hAxis: {
  47. title: 'Month',
  48. ticks: [{v: months['01_tmean'], f: 'January'},
  49. {v: months['02_tmean'], f: '2'},
  50. {v: months['03_tmean'], f: '3'},
  51. {v: months['04_tmean'], f: 'April'},
  52. {v: months['05_tmean'], f: '5'},
  53. {v: months['06_tmean'], f: '6'},
  54. {v: months['07_tmean'], f: 'July'},
  55. {v: months['08_tmean'], f: '8'},
  56. {v: months['09_tmean'], f: '9'},
  57. {v: months['10_tmean'], f: 'October'},
  58. {v: months['11_tmean'], f: '11'},
  59. {v: months['12_tmean'], f: '12'},]
  60. },
  61. vAxis: {
  62. title: 'Temperature (Celsius)'
  63. },
  64. lineWidth: 1,
  65. pointSize: 3
  66. });
  67. print(extremeTempsChart);

文章来源: blog.csdn.net,作者:此星光明2021年博客之星云计算Top3,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/qq_31988139/article/details/118976744

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。