# developer.averaging

### From autoplot.org

Purpose: Describe aspects of combining data. Audience: Scientists and software developers.

## Contents |

# 1. Introduction

Things start getting tricky when you start to combine data. For example, if you wish to combine the measurements made over an hour, this might be typically done by averaging all the measurements together. But consider that software might be doing this with any data without human guidance, and the data might be a flag indicating data quality. In this case averaging 0=ok with 1=bad to get 0.5 doesn't make sense. For this reason, there are a bunch of problems where this needs consideration.

There are many applications that need to identify this:

- average measurements together
- interpolation between measurements

# 2. Enumerating Average Types

Let the term "average type" mean a method for combining two datums, with weights that measure the relevance of each point. Then:

- linear averaging (a1,w1,a2,w2) -> ( a1*w1 + a2*w1 ) / ( w1+w2 )
- geometric averaging (a1,w1,a2,w2) -> ( a1*w1 * a2*w1 ) / ( w1*w2 )
- nearest neighbor averaging (a1,w1,a2,w2) -> (w1>w2) ? a1 : a2
- if equal averaging (a1,w1,a2,w2) -> ( a1==a2 ) ? a1 : FILL
- no averaging (a1,w1,a2,w2) -> FILL
- max averaging (a1,w1,a2,w2) -> a1>a2 ? a1 : a2

## 2.1. CDAWeb ISTP AVG_TYPE

The CDF metadata "AVG_TYPE" identifies additional modes:

- log (alias for geometric) logarithm of the average of the anti-logarithms of the values.
- RMS -- square root of the average of the squares of the values.
- decibel -- 10 times the logarithm of the average of the anti-logarithms of the (values/10.).
- cosine -- cosine of the average of the arc-cosines of the values.
- angle_degrees -- "direction" average over 360 deg e.g., average of 5 and 355 is 0 instead of 180.
- angle_radians -- "direction" average over 2 pi
- angle_hour -- "direction" average over local times (hours), e.g., average of 2 and 22 is 0 instead of 12.

## 2.2. mod averaging

Suppose you want to find the average longitude, measured in degrees. Here you need to consider that 359 and 1 are just 2 degrees apart:

- mod360 averaging (a1,w1,a2,w2) -> ( a2-a1>180 ? ( (a2-360)*w1 + a1*w2 ) / ( w1 + w2 ) ) (etc)

CDAWeb identifies these as angle_hour, angle_radians, and angle_degrees.