# Technical Explanation – Depth Checks and Corrections

#### Theoretical description

What is it?

For aquatic animals, the pressure should be close to 0 when the animal surfaces (surfacings are usually obvious in the pressure plot as times when the pressure reaches the fairly flat line that joins the highest points). However, biologging data are not always ready-to-use when you read them off the tag. Some corrections may be needed. Pressure sensors tend to drift with temperature, so the pressure calibration needs the temperature data in order to correct this drift. The zero-pressure offset of the sensor is often a little off due to both errors in the pressure sensor and temperature sensitivity. There are two tools that you can try to fix the pressure data. `fix_pressure()` tries to correct temperature sensitivity and `fix_offset_pressure()` assuming that these are constant throughout the deployment.

How is it measured?

`fix_pressure()` finds minima in the dive/altitude profile that are consistent with surfacing/landing. It uses the depth/height at these points to fit a temperature regression.

`fix_offset_pressure()` finds minima in the dive/altitude profile that are consistent with surfacing/landing and smooths these to make a time-varying ‘0 pressure’ offset vector. This tool should be used if there are still pressure offsets after correcting for temperature using `fix_pressure()` function.

What is it good for?

`fix_pressure()` is good to correct the depth or altitude profile for offsets caused by mis-calibration and temperature.

`fix_offset_pressure()` is good to correct the depth or altitude profile for offsets caused by mis-calibration and sensor drift.

#### Technical description

Usage of tool

Here we describe the usage of `fix_offset_pressure()` wich will be use if there are still pressure offsets after correcting for temperature using `fix_pressure()`.

MATLAB
```[pf,poffs] = fix_offset_pressure(P,sampling_rate,intvl,tc)
```
R
```[pf,poffs] <- fix_offset_pressure(P,sampling_rate,intvl,tc)
```
###### Inputs:
• `p:` is a sensor list or vector of depth/altitude in meters.
• `sampling_rate:` the sampling rate of the sensor data in Hz (samples per second). This is only needed if p and t are not a sensor lists. The depth and temperature must both have the same sampling rate (use `decdc()` if needed to achieve this).
• `intvl`: is the search interval in seconds that is used to find surfacings or landings. This should be chosen to be a little more than the usual inter-surfacing/inter-landing interval. Default value is 1 hour.
• `tc`: is the smoothing time constant in seconds used to filter the surface depth offsets. `tc` should normally be several times larger than `intvl` unless the depth/altitude sensor has a fast drift. Default value is 12 hours.
###### Outputs:
• `pf:` is a sensor list, structure or vector of corrected depth/altitude measurements at the same sampling rate as the input data. If the input is a sensor list, the output will also be a sensor list.
• `poffs`: is a 2-column matrix containing a set of times (column 1) and estimated pressure offsets (column 2). Times are in seconds since the first sample in `p`. Pressure offsets are in meters.

#### Verification

You could simply verify that both `fix_pressure()`and `fix_offset_pressure()` works by simply plotting the the original depth, `p` and the fixed depth, `pf`, and check that the top of the dive profile, when the animal is at the surface, is flatter and close to zero.

MATLAB
```%%load ncfile
xx_file_path = xxx

plott(P)%plot P

[Pf,pc] = fix_pressure(Pc,Tc)% fix pressure

plott(P,Pf) % plot original depth P and the fixed depth Pf

[pf,poffs] = fix_offset_pressure(P,intvl,tc)% fix offset pressure

plott(P,pf) % plot original depth P and the fixed offset depth pf
```
R
```
```
MATLAB Output

Coming soon …

R Output

Coming soon …

#### Caveats

`fix_pressure()` makes a number of assumptions about the depth/altitude data and about the behavior of the animals:

• the depth data should have few incorrect outlier (negative) values that fall well beyond the surface. These can be reduced using the function `median_filter()` before calling `fix_pressure()`. For a full description on how `median_filter()` works, type help `median_filter` in Matlab and type ?median_filter in R.
• the animal is assumed to be near the surface at least 2% of the time. If the animal is less frequently at the surface, you may need to change the value of PRCTSURF near the start of the function.
• potential surfacings are detected by looking for zero-crossings in the vertical speed and this requires defining a threshold in vertical speed that must be crossed by each zero crossing. The value used is 0.05 m/s but this may be too high for animals that move very slowly near the surface. In which case, change MAXSPEED near the start of the function.

`fix_offset_pressure()` makes a number of assumptions about the depth/altitude data and about the behaviour of animals:

• the depth data should have few incorrect outlier (negative) values that fall well beyond the surface. These can be reduced using the function `median_filter()` before calling `fix_offset_pressure()`.
• the pressure offset in the sensor varies slowly and smoothly with respect to the inter-surfacing/inter-landing interval. This function will not be effective at correcting step changes in calibration.