-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
depth_from_pressure
method required for the calculation of `v…
…ertical_offset` value (#1207) * added depth_from_pressure method * Function arguments can be scalars or sequences; and add more tests (#2) * Reverse order of equation terms to match UNESCO 1983 source * For depth_from_pressure, accept scalars, lists and arrays for all 3 arguments. Include consistency checks. * Add a greater variety of depth_from_pressure tests. * Update echopype/utils/misc.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Emilio Mayorga <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ab5a2bd
commit dcf98fc
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
import numpy as np | ||
from echopype.utils.misc import depth_from_pressure | ||
|
||
|
||
def test_depth_from_pressure(): | ||
# A single pressure value and defaults for the other arguments | ||
pressure = 100.0 | ||
depth = depth_from_pressure(pressure) | ||
assert np.isclose(depth, 99.2954) | ||
|
||
# Array of pressure and list of latitude values | ||
pressure = np.array([100.0, 101.0, 101.0]) | ||
latitude = [0.0, 30.0, 50.0] | ||
depth = depth_from_pressure(pressure, latitude) | ||
assert np.allclose(depth, [99.4265, 100.2881, 100.1096]) | ||
|
||
# Scalars specified for all 3 arguments | ||
pressure = 1000.0 | ||
latitude = 0.0 | ||
atm_pres_surf = 10.1325 # standard atm pressure at sea level | ||
depth = depth_from_pressure(pressure, latitude, atm_pres_surf) | ||
assert np.isclose(depth, 982.0882) | ||
|
||
# ValueError triggered by argument arrays having different lengths | ||
pressure = np.array([100.0, 101.0, 101.0]) | ||
latitude = [0.0, 30.0] | ||
with pytest.raises(ValueError) as excinfo: | ||
depth = depth_from_pressure(pressure, latitude) | ||
assert str(excinfo.value) == "Sequence shape or size does not match pressure" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters