发布于2022-11-28 07:38 阅读(1031) 评论(0) 点赞(11) 收藏(1)
Given latitude and longitude arrays, I'm tryin to genereate a land_mask, an array of the same size that tells whether a coordinate is land or not.
lon=np.random.uniform(0,150,size=[1000,1000])
lat=np.random.uniform(-90,90,size=[1000,1000])
from global_land_mask import globe
land_mask=globe.is_land(lat,lon)
This is a very efficient method to create land mask if all values are defined. But if some values in lat or lon are masked or are nan values, it throws an error.
I've tried to use for loops to avoid that error but it's taking almost 15-20 minutes to run. I've to run it on an array with 3000×3000 elements, some of which are masked.
What would be a better way for generating land mask for arrays with masked/nan values?
所以它似乎globe.is_land(y,x)
不需要屏蔽数组。一个公平的解决方案是使用域外的坐标(如果可能)。所以:
lon[lon==327.67] = 170
lat[lat==327.67] = -90
from global_land_mask import globe
land_mask=globe.is_land(lat,lon)
masked = np.where((lat==-90)|(lon==170), False, land_mask)
或者,您可以在传入值之前屏蔽这些值:
lat_mask = np.where(lat==326.67, np.nan, lat)
lon_mask = np.where(lon==326.67, np.nan, lon)
master_mask = np.where((lat_mask==np.nan)|(lon_mask==np.nan), False, True)
lat[master_mask]==True
lon[master_mask]==True
from global_land_mask import globe
land_mask=globe.is_land(lat,lon)
第二种解决方案将更改(展平)您的纬度/经度数组,但不需要您找到域外的区域
作者:黑洞官方问答小能手
链接:https://www.pythonheidong.com/blog/article/1861563/4d25586d635c14e165a6/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!