ArgoCanada / medsrtqc

An experimental container for Argo Canada realtime quality control code
https://argocanada.github.io/medsrtqc/
MIT License
0 stars 1 forks source link

Mixed layer calculation error causing CHLA_QC=2 when it should be 1. #35

Closed cgrdn closed 1 year ago

cgrdn commented 1 year ago

very simple fix, but will require re-running RTQC on existing profiles, so documenting here

Mixed layer in the CHLA is calculated as the first time the difference in density is greater than 0.03 kg m-3, below 10m. However, because the profiles are reported bottom-to-surface, density is always decreasing. This is a problem because the logic to find the mixed layer is written as:

mixed_layer_start = (np.diff(density) > 0.03) & (pres.value[:-1] > 10)

np.diff is defined as:

The first difference is given by out[i] = a[i+1] - a[i] along the given axis, higher differences are calculated by using diff recursively.

So, since density is monotonically increasing with depth, np.diff(density) will always be negative. Therefore, a mixed layer is never found, and in that case CHLA_QC is set to 2.

This is fixed by taking absolute value of density difference, some logic will need to be re-arranged.

cgrdn commented 1 year ago

Fixed & tested on a recent file