The Calculator block allows you to apply your own arithmetic to combinations of bands from various datasets. In its simplest form, this is just combining different image bands using mathematical expressions such as add, subtract, and divide (often referred to as Band Math). But the calculator block also allows you to use more advanced functionality that makes it an extremely versatile and powerful tool.

Make sure you have read about the **Calculator** block before reading this article.

The calculator block is case-sensitive, so where possible, please use the same upper or lower case as this guide.

# Advanced Functions Within Calculator Block

**TABLE OF CONTENTS**

- Adding Comments
- Trig Functions
- Logarithmic and Exponential Functions
- Conditional Statements (including IF, THEN, ELSE)
- Advanced Masking and Variable Transparency
- ConnectedPixelCount
- Other Functions

## Adding Comments

Before getting into the functions, you might find it helpful to note that you can use "//" before text in the calculator block to add text as comments (to keep track of what you are doing or to make it easier for other users to follow your calculations). For example:

## Trig Functions

- All basic trigonometric functions are available on the calculator keyboard:
**sin, cos, tan, asin, acos, atan**. **cosh, sinh, tanh**are available by typing them into the calculator block manually.- All trig functions use RADIANS as default (not degrees). To convert X degrees into Y radians use Y=3.14*(X/180)

## Logarithmic and Exponential Functions

- There are two log functions on the keyboard
**log**is the natural logarithm (to base e).**log10**is the logarithm to base 10.

- To set an exponent, you can click on the y
^{x}on the keyboard, or use **. - You can also type
**exp()**to calculate e to the power of the value in brackets.

## Conditional Statements (including IF, THEN, ELSE)

- Logical operators can be used from the keyboard or typed in. Note that:
- == is "equal to", and
- != is "not equal to".

### Single Logical Argument

- When a logical operator is used on its own, the result is an image where the pixel is assigned a value of 1 where the argument is TRUE, and 0 where FALSE. (Note: this is different from a mask which assigns transparency value based on the argument).
- Example 1: A common task would be to define a threshold to DATA so that it is 1 if it crosses the threshold value, and 0 otherwise. The expression DATA > 20 would define a new data layer that is 1 where DATA is greater than 20 and 0 otherwise.
- Example 2: You can include logical expressions such as OR and AND. The expression DATA >= 2 AND DATA <=5 will return 1 for all pixels between 2 and 5, and zero everywhere else.

### IF, THEN, ELSE

- You can do a conditional operation using the combination of ? and : symbols.
- The logic is (LOGICAL EXPRESSION)? (IF TRUE set this value) : (ELSE set this value).
- For example, if you want DATA to have a minimum value of zero (so that any negative numbers are set to zero), you could type:
- (DATA <= 0) ? 0 : DATA. That is, if the DATA value is less than or equal to zero, set the pixel to zero. Otherwise, set it to the original DATA value.

## Advanced Masking and Variable Transparency

- You can use the
**mask**(IMAGE1, IMAGE2) function to define a mask that has variable transparency.- IMAGE1 is the data layer you want to mask.
- IMAGE2 is a data layer with values from 0 to 1. This defines the opacity of the mask such that 0=fully transparent (so you won't see any data) and 1=fully opaque (so you can see the data). A value of 0.5 would be semi-transparent.

- Note that the Mask Out Part of Image block only defines a transparency layer of 0 or 1, whereas
**mask**gives you the ability to define different levels of transparency. - If you have a data layer that has some transparent bits, then you can also unmask using the function:
**unmask**(IMAGE1, 0)- Where IMAGE1 is the data layer you want to unmask (if it has transparent areas)
- The value 0 in this example is the pixel value that is filling the previously masked pixels. This mask value can be defined by you.

## ConnectedPixelCount

- This function applies to small collections of pixels. It assigns a pixel value for all the connected pixels equal to the number of pixels that are connected in the object.
- This means that if you have masked data so that it only leaves small collections of pixels that define some kind of object, then
**connectedPixelCount**is a function that can help with the object analysis. - An example would be looking at ships in radar data. In this case, you can use
**mask**(described above) to mask out all pixels except for the brightest pixels that represent the ships. Lets call this IMAGE1. **connectedPixelCount**(IMAGE1) will then assign pixel values to connected pixels. If it is a single pixel, then the pixel will be assigned a value of 1. If there are 10 pixels that are all connected, the value in each pixel is 10. This gives a value that can determine the size of the object.- Be careful with using this function for map output -- the map results are based on the pixels within the pyramid layer being displayed, not the original pixels. Any tabulation of the data will be at the native resolution.

## Other Functions

All of the following functions are also available to use on the Calculator Block.

These functions take two or more arguments.

*We always track the feedback you give us so that **we can improve how we help you. *

*Please let us know if you found this one helpful.*

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Feedback sent

We appreciate your effort and will try to fix the article