简体   繁体   English

将Healpy Mask应用于地图阵列

[英]applying healpy mask to array of maps

I have a series of maps with two different indices, i and j. 我有一系列带有两个不同索引i和j的地图。 Let this be indexed like map_series[i][j]. 让它像map_series [i] [j]一样被索引。

EDIT 1/21: A minimal working example would be something like map_series=np.array([np.array([np.arange(12) + 0.1*(i+1) + 0.01*(j+1) for j in range(3)]) for i in range(5)]) 编辑1/21:一个最小的工作示例将是map_series=np.array([np.array([np.arange(12) + 0.1*(i+1) + 0.01*(j+1) for j in range(3)]) for i in range(5)])

I'd like to apply the same mask to each; 我想对每个眼镜使用相同的面膜; if map_series is one-dimensional, these each work. 如果map_series是一维的,则这些都起作用。

I can imagine a few different ways of applying these maps: 我可以想象应用这些地图的几种不同方式:

(A) Applying the mask to the whole array: (A)将蒙版应用于整个数组:

map_series_ma = hp.ma(map_series)
map_series_ma.mask = predefined_mask

(B1) Applying the mask to each element of the array: (B1)将掩码应用于数组的每个元素:

map_series_ma = np.zeros_like(map_series)
for i in range(len(map_series)):
    for j in range(len(map_series[0])):
        temp = hp.ma(map_series[i][j])
        temp.mask = predefined_mask
        map_series_ma[i][j] = temp

(B2) Applying the mask to each element of the array: (B2)将掩码应用于数组的每个元素:

map_series_ma = np.zeros_like(map_series)
for i in range(len(map_series)):
    for j in range(len(map_series[0])):
        map_series_ma[i][j] = hp.ma(map_series[i][j])
        map_series_ma[i][j].mask = predefined_mask

(C) Pythonically enumerating the list: (C)用Python枚举列表:

map_series_ma = np.array([hp.ma(map_series[i][j]) for j in range(j_max) for i in range(i_max)])
map_series_ma.mask = predetermined_mask

All of these fail to give my desired output, however. 但是,所有这些都无法提供我想要的输出。

Upon trying (A) or (C) I get an error after the first step, telling me TypeError: bad number of pixels. 尝试(A)或(C)后,第一步后出现错误,告诉我TypeError:像素数错误。

Upon trying (B1) I don't get an error, but I also none of the elements of the maps_series_ma have masks; 尝试(B1)时,我没有收到错误,但是maps_series_ma的所有元素都没有遮罩; in fact, they do not even appear to be hp.ma objects. 实际上,它们甚至似乎都不是hp.ma对象。 Oddly enough, though: when I return temp it does have the appropriate mask. 奇怪的是:当我返回temp时,它确实具有适当的掩码。

Upon trying (B2) I get the error AttributeError: 'numpy.ndarray' object has no attribute 'mask' (which, after looking at my syntax, I totally understand!) 尝试(B2)时,出现错误AttributeError:'numpy.ndarray'对象没有属性'mask'(在看完我的语法后,我完全理解了!)

I'm a little confused how to go about this. 我对此有点困惑。 Both (A) and (B1) seem acceptable to me... (A)和(B1)对我来说似乎都可以接受...

Any help is much appreciated, Thanks, Sam 非常感谢您的帮助,谢谢,Sam

this works for me: 这对我有用:

import numpy as np
import healpy as hp

map_series=np.array([np.array([np.arange(12) + 0.1*(i+1) + 0.01*(j+1) for j in range(3)]) for i in range(5)])
map_series_ma = map(lambda x: hp.ma(x), map_series)
pm=[True, True,True,True,True,True,False,False,False,False,False,False]
for m in map_series_ma:
    for mm in m:
        mm.mask=pm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM