howtos:toolcoding: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:

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

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.

howtos/toolcoding/boolean_masks.txt · Last modified: 2009/12/01 19:14 by marcus.williams