# Common Horizon Tasks (Horizon Maths)

The following are simple Horizon Maths formulas for common interpretation scenarios.

Note: For help with math functions and conditional statements, click on the Help icon or see Math functions in Horizon/Volume Maths.

## Combine/merge horizons

The most natural-seeming way to combine horizons would be to "add" them together, as in a + b + c, but this does not work for two reasons:

• First, in places where they overlap, that would give you the arithmetic sum of the points at that location — which is probably not what is intended.
• Second, missing locations are generally represented by the value NaN (not-a-number). NaN plus any other value equals NaN, so this would have the effect of only producing output at locations where all inputs are defined. This is also probably not what is intended.

To simplify this, you can use the following formulas to combine horizons in Insight:

• merge(a, b, c,...) - combines any number of horizons, in order of precedence. i.e., where horizons overlap, the value of the first one in the list will be used
• min(a, b, c,...) - combines any number of horizons, using the smallest available value (i.e. shallowest, if the values are in time or depth)
• max(a, b, c,...) - combines any number of horizons, using the largest available value  (i.e. deepest, if the values are in time or depth)
• sum(a, b, c,...) - arithmetic sum of any number of horizons, ignoring those that aren't defined at a location
• avg(a, b, c,...) - arithmetic mean of any number of horizons, ignoring those that aren't defined at a location
• random(min,max) - generate a random number between min and max inclusive.

Note: The Merge operation only works on one survey. If you merge horizons that are picked on different surveys, the result will be a multi-survey horizon, with multiple picks in the areas that overlap. To resolve the multiple picks, perform a Regrid operation to produce a single-survey (or X/Y) horizon.

### Combine horizons with conditional statements

When you combine horizons, missing locations are generally represented by NaN (Not-A-Number). You must use the special functions isNaN() or isMissing() to test for a missing value, or isDefined() or isValid() to test for a valid value.

For example:

if (isDefined(a), a, b)

or

if (isMissing(a), b, a)

Both formulas are equivalent to 'merge(a,b)', i.e. the result at a location will be the value of horizon 'a' if it exists, otherwise the value of horizon 'b'.

a+b

This formula will create a new horizon that is the sum of horizons 'a' and 'b' where (and only where) they overlap. If either 'a' or 'b' (or both) is NaN, the result will be NaN. It is not the same as 'sum(a, b)' as that will produce a result wherever either horizon is defined.

if (isDefined(a), if (isDefined(b), if (a < b, a, b), a), b)

This formula is equivalent to 'min(a,b)', i.e. the result at a location will be the minimum values of horizons "a" or "b", even if one of the two is missing.

## Delete horizon points with conditional statements

With Horizon Maths, you can also delete or crop points in your horizons based on conditional statements. This function is commonly used to remove outliers prior to using the Interpolation/extrapolation operation.

For example, to delete all points where a < 500, use:

if (a < 500, NaN, a)

### Creating a subcrop horizon

When two horizons intersect, you may wish to remove horizon values above the unconformity.

To delete horizon points where one horizon is shallower than the other, use:

if ((a < b) , NaN, a)

The formula basically translates as: where 'a' is shallower than 'b', make it NaN. This would have the effect of turning a valid 'a' into NaN if and only if both 'a' and 'b' are non-NaN at that location.

To keep a valid 'b' anywhere that 'a' doesn't exist, then the following formula should do the trick:

if (a < b, NaN, if (isnan(a), b, a))

•    If 'a' and 'b' are both valid, and 'a' is shallower, then Insight will set the value to NaN.
•    Otherwise, if 'a' is invalid, use the value from 'b' (which may or may not also be invalid).
•    Otherwise, use the value from 'a'.