Masked Array - 计算特定间隔内的值
我对屏蔽数组和卫星数据很陌生。我试图弄清楚如何计算 masked_array 中介于某个间隔(例如 40 到 80)之间的元素数量。这就是我所拥有的:
这是名为“grid”的 masked 数组的摘要。
masked_array(
data=[[[120, 120, 120, ..., 200, 200, 200],
[120, 120, 120, ..., 200, 200, 200],
[120, 120, 120, ..., 200, 200, 200],
...,
[120, 120, 120, ..., 200, 200, 200],
[120, 120, 120, ..., 200, 200, 200],
[120, 120, 120, ..., 200, 200, 200]]],
mask=False,
fill_value=999999,
dtype=uint8)
我想计算 masked_array 中 40 到 80 之间的元素的百分比。我尝试过。
masked = ma.masked_where((grid >= 40) & (grid <= 80), grid)
green_ratio = masked.count()/grid.count()
但这返回 1,这是不太可能的,因为我看到有大于 120 的值。
知道如何执行此操作吗?
I am quite new to masked arrays and satellite data. I am trying to figure out how to count the number of elements in a masked_array that are in between an interval e.g. say 40 to 80. This is what I have:
This is the summary of my masked array named 'grid'.
masked_array(
data=[[[120, 120, 120, ..., 200, 200, 200],
[120, 120, 120, ..., 200, 200, 200],
[120, 120, 120, ..., 200, 200, 200],
...,
[120, 120, 120, ..., 200, 200, 200],
[120, 120, 120, ..., 200, 200, 200],
[120, 120, 120, ..., 200, 200, 200]]],
mask=False,
fill_value=999999,
dtype=uint8)
I want to calculate the % of elements in the masked_array that are between 40 and 80. I tried.
masked = ma.masked_where((grid >= 40) & (grid <= 80), grid)
green_ratio = masked.count()/grid.count()
but this is returning 1 which is quite unlikely given that I see that there are values larger than 120.
Any idea on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
masked.count() 仍然为您提供未过滤的值总数,当然等于 grid.count() 。
由于 masked.mask 是一个布尔数组,因此您可以执行例如 masked.mask.sum()/grid.count() 来限制满足条件的值的比率你的情况。
masked.count()
still gives you the total unfiltered number of values which is of course equal togrid.count()
.Since
masked.mask
is a boolean array, you could do for examplemasked.mask.sum()/grid.count()
to limit the ratio to those values which meet your condition.