osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to create a boolean mask for the data arrays with uint16, int8 type?


Hi,

How can I create a boolean mask for the data arrays with integer type? I want to create a 'useSample' boolean array for masking or discarding the unwanted data from the array.

[nr,nc] = np.shape(ftype)  # 
useSamples = np.full((nr,nc), True, dtype=bool)

I want to transform the following MATLAB code lines to create the masked array:

useSamples(ftype == 3 & subtype ~=2) = false
useSamples(cad > -70) = false
useSamples(extnQC < 0) = false

Finally, I want to extract X variable samples to exclude/ screen out what I don't want (MATLAB expression)

X_screened = X(useSamples)  

Can someone help me how I can transform the above MATLAB lines into Python code?

I have the following data arrays with types uint16 and int8. The 8 columns correspond to 8 layers. Number of layers observed is given by 'nlay' variable as shown below.

ftype = array([[1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [3, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [3, 1, 1, 1, 1, 1, 1, 1],
       [3, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [3, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [3, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1]], dtype=uint16)

subtype = array([[0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [5, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [2, 0, 0, 0, 0, 0, 0, 0],
       [2, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [2, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [2, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint16)

cad = array([[-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [ -84, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [ -63, -127, -127, -127, -127, -127, -127, -127],
       [ -72, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [ -38, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [ -70, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127],
       [-127, -127, -127, -127, -127, -127, -127, -127]], dtype=int8)


extnQC = array([[32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [   18, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [   18, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [    0, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [    0, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [   18, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
       [32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768]],
      dtype=uint16)

nlay = array([[0],
       [0],
       [0],
       [0],
       [0],
       [1],
       [0],
       [0],
       [1],
       [1],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [1],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [0],
       [1],
       [0],
       [0],
       [0],
       [0],
       [0]], dtype=int8)