OSOceanAcoustics / echopype

Enabling interoperability and scalability in ocean sonar data analysis
https://echopype.readthedocs.io/
Apache License 2.0
94 stars 73 forks source link

Parse AZFP pressure data when available #1181

Closed emiliom closed 4 months ago

emiliom commented 11 months ago

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 setting Platform.water_level to 0. See https://echopype.readthedocs.io/en/stable/data-proc-additional.html#vertical-coordinate-z-axis-variables

We'll need to obtain a sample data file that includes pressure data.

emiliom commented 10 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:

  1. Store 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:
    • "long_name": "Sea water pressure"
    • "standard_name": "sea_water_pressure_due_to_sea_water"
    • "units": "dbar"
  2. 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-gsw
emiliom commented 10 months ago

PR #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.

emiliom commented 10 months ago

For reference, here's the functionality used by the AZFP Matlab toolbox to calculate density (The links below are to a private repo):

emiliom commented 10 months ago

Hmm, 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.

emiliom commented 10 months ago

@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:.

ctuguinay commented 4 months ago

This should be closed by the merging of #1189 and #1207