Boolean Masks

Boolean masks are often used to 'filter' the values of arrays, based on some logical criteria (e.g. negative or positive values). Using a mask is a two-step process:

  1. Creation of the mask using boolean operator(s) (e.g. greater than, less than or equal to)
  2. Application of the mask to some array to be filtered, simply by multiplication.

Example

Starting with this TOOL object newDwellings[dt,t]

the mask is created with this code

maskPositive[dt,t] = boolge (newDwellings[dt,t], 0)

and applied

newDwellingsPos[dt,t] = newDwellings[dt,t] * maskPositive[dt,t]

to produce

Note that the mask can be easily inverted by subtracting it from one

maskNegative[dt,t] = 1 - maskPositive[dt,t]



examplebooleanmask.t is the self-contained TOOL script for this example.