Closed emiliom closed 4 months ago
After parsing the pressure data, the data array needs to be written into the EchoData object.
I think there are two steps here:
pressure
in the Environment
group, via the set_env
class method. Populate its variable attributes. Base this on what's done for temperature, but modifying attribute values to correspond to pressure. Here are the attribute values to use:
pressure
and a standard seawater equation ("equations of state") to calculate depth (meters). Then set Platform.vertical_offset
to this depth array, multiplied by -1 (see here). LoadAZFP.m
has this conversion in the computeDepth
function. It doesn't look like we have a seawater density function in echopype, but we can incorporate one. The "ideal" package would be https://github.com/TEOS-10/GSW-Python, but unfortunately it depends on a C library. Note that GSW-Python
already includes a function to go from pressure to depth (see gsw.conversions.z_from_p), but it requires at least one parameter that may not be available: latitude. @leewujung should we use simplifications for density (we'll have to use a default salinity anyways) and omit a latitude adjustment? We could try to extract pure-Python code from the now-deprecated package https://github.com/TEOS-10/python-gswPR #1189 addressed item 1 above: parsing and storing pressure data, plus tests.
For item 2, we'll need to decide what conversion formula / algorithm / library to use to convert from pressure to depth.
For reference, here's the functionality used by the AZFP Matlab toolbox to calculate density (The links below are to a private repo):
LoadAZFP.m
, computeDepth function:
g = 9.815;
dens = sw_dens(Parameters.Salinity,T,Pressure);
Depth = Pressure*10000 / (dens * g);
sw_dens
is found in the same toolbox, in sw_dens.m. It's based on the "Density of Sea Water using UNESCO 1983 (EOS 80) polynomial." It calls two other functions, sw_dens0.m and sw_seck.mHmm, the python-gsw
function z_from_p doesn't require a density calculation, or salinity. It does require latitude, naturally, but since AZFP data will lack latitude, we could input a mid-range value, say, 45 degrees.
@praneethratna Ok, I now have a recommendation for implementing the conversion from pressure to depth. Let's use the UNESCO 1983 formulation (pages 25-27). This site lists the equations nicely and includes a calculator. We'll make the standard seawater assumption used in that site: salinity of 35 PSU and temperature of 0 C. That makes the $ΔD$ term in UNESCO 1983 equation 25 become zero. That equation is then identical as eq. 3 in the other site.
Let's implement this as a new function depth_from_pressure
in utils/misc.py
. The arguments will be:
In the function, atm_pres_surf
will be subtracted from the pressure array.
The function returns a depth numpy array.
PS. I'm including here other references I consulted. No need to look at them. I just want to be able to find them after I close those tabs in my browser :wink:.
This should be closed by the merging of #1189 and #1207
AZFP deployments can contain a pressure sensor. However, the echopype AZFP parser currently does not look for and read pressure data, as it does for temperature. Add this.
When read, it should be used to populate
Platform.vertical_offset
while also settingPlatform.water_level
to 0. See https://echopype.readthedocs.io/en/stable/data-proc-additional.html#vertical-coordinate-z-axis-variablesWe'll need to obtain a sample data file that includes pressure data.