Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
public_projects
kadlu
Commits
c5b7246b
Commit
c5b7246b
authored
4 years ago
by
Oliver Kirsebom
Browse files
Options
Download
Email Patches
Plain Diff
renamed geophony.create_transm_loss_calc to geophony.create_transm_loss_calculator
parent
a1fe6f25
geophony_output
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kadlu/sound/geophony.py
+5
-4
kadlu/sound/geophony.py
kadlu/tests/sound/test_geophony.py
+14
-14
kadlu/tests/sound/test_geophony.py
with
19 additions
and
18 deletions
+19
-18
kadlu/sound/geophony.py
View file @
c5b7246b
...
...
@@ -82,7 +82,7 @@ def source_level(freq, x, y, area, ocean, sl_func, neg_inf_on_land=True):
return
sl
def
create_transm_loss_calc
(
freq
,
propagation_range
,
lat
=
None
,
lon
=
None
,
data_range
=
None
,
def
create_transm_loss_calc
ulator
(
freq
,
propagation_range
,
lat
=
None
,
lon
=
None
,
data_range
=
None
,
seafloor
=
{
'sound_speed'
:
1700
,
'density'
:
1.5
,
'attenuation'
:
0.5
},
return_ocean
=
False
,
**
kwargs
):
""" Initialize transmission loss calculator.
...
...
@@ -145,11 +145,11 @@ def create_transm_loss_calc(freq, propagation_range, lat=None, lon=None, data_ra
if
return_ocean
:
return
transm_loss
,
ocean
else
:
return
transm_loss
def
geophony
(
freq
,
depth
,
sl_func
=
kewley_sl_func
,
def
calc_spl
(
freq
,
depth
,
sl_func
=
kewley_sl_func
,
seafloor
=
{
'sound_speed'
:
1700
,
'density'
:
1.5
,
'attenuation'
:
0.5
},
below_seafloor
=
False
,
progress_bar
=
True
,
neg_inf_on_land
=
True
,
**
kwargs
):
""" Calculate ocean ambient noise
levels
.
""" Calculate ocean ambient noise
sound pressure level (SPL) in a 3D spatial grid
.
Noise levels can be calculated either a set of lat-lon coordinates,
or on a regular grid within a geographic bounding box.
...
...
@@ -255,7 +255,7 @@ def geophony(freq, depth, sl_func=kewley_sl_func,
# initialize transmission loss calculator
kwargs
[
'lat'
]
=
lat
kwargs
[
'lon'
]
=
lon
transm_loss
,
ocean
=
create_transm_loss_calc
(
freq
=
freq
,
seafloor
=
seafloor
,
transm_loss
,
ocean
=
create_transm_loss_calc
ulator
(
freq
=
freq
,
seafloor
=
seafloor
,
return_ocean
=
True
,
**
kwargs
)
# interpolate bathymetry
...
...
@@ -416,3 +416,4 @@ def _source_level_polar_grid(freq, radial_axis, azimuthal_axis, ocean, sl_func,
sl
=
sl
[
np
.
newaxis
,
:,
:]
return
sl
This diff is collapsed.
Click to expand it.
kadlu/tests/sound/test_geophony.py
View file @
c5b7246b
...
...
@@ -14,7 +14,7 @@
import
pytest
import
os
import
numpy
as
np
from
kadlu.sound.geophony
import
geophony
,
create_transm_loss_calc
,
kewley_sl_func
,
source_level
from
kadlu.sound.geophony
import
calc_spl
,
create_transm_loss_calc
ulator
,
kewley_sl_func
,
source_level
from
kadlu.geospatial.ocean
import
Ocean
from
kadlu.utils
import
R1_IUGG
,
deg2rad
...
...
@@ -40,11 +40,11 @@ def test_source_level():
assert
sl
[
0
]
==
42.5
assert
sl
[
1
]
==
sl
[
0
]
+
10
*
np
.
log10
(
2
)
def
test_
geophony
_flat_seafloor
():
""" Check that we can execute the
geophony
method for a
def
test_
calc_spl
_flat_seafloor
():
""" Check that we can execute the
calc_spl
method for a
flat seafloor and uniform sound speed profile"""
kwargs
=
{
'load_bathymetry'
:
10000
,
'load_wind_uv'
:
1.0
,
'ssp'
:
1480
,
'angular_bin'
:
90
,
'dr'
:
1000
,
'dz'
:
1000
}
geo
=
geophony
(
freq
=
100
,
south
=
44
,
north
=
46
,
west
=-
60
,
east
=-
58
,
depth
=
[
100
,
2000
],
xy_res
=
71
,
**
kwargs
)
geo
=
calc_spl
(
freq
=
100
,
south
=
44
,
north
=
46
,
west
=-
60
,
east
=-
58
,
depth
=
[
100
,
2000
],
xy_res
=
71
,
**
kwargs
)
spl
=
geo
[
'spl'
]
x
=
geo
[
'x'
]
y
=
geo
[
'y'
]
...
...
@@ -57,14 +57,14 @@ def test_geophony_flat_seafloor():
assert
np
.
all
(
np
.
diff
(
y
)
==
71e3
)
# try again, but this time for specific location
kwargs
=
{
'load_bathymetry'
:
10000
,
'load_wind_uv'
:
1.0
,
'ssp'
:
1480
,
'angular_bin'
:
90
,
'dr'
:
1000
,
'dz'
:
1000
,
'propagation_range'
:
50
}
geo
=
geophony
(
freq
=
100
,
lat
=
45
,
lon
=-
59
,
depth
=
[
100
,
2000
],
**
kwargs
)
geo
=
calc_spl
(
freq
=
100
,
lat
=
45
,
lon
=-
59
,
depth
=
[
100
,
2000
],
**
kwargs
)
def
test_
geophony
_in_canyon
(
bathy_canyon
):
""" Check that we can execute the
geophony
method for a
def
test_
calc_spl
_in_canyon
(
bathy_canyon
):
""" Check that we can execute the
calc_spl
method for a
canyon-shaped bathymetry and uniform sound speed profile"""
kwargs
=
{
'load_bathymetry'
:
bathy_canyon
,
'load_wind_uv'
:
1.0
,
'ssp'
:
1480
,
'angular_bin'
:
90
,
'dr'
:
1000
,
'dz'
:
1000
}
z
=
[
100
,
1500
,
3000
]
geo
=
geophony
(
freq
=
10
,
south
=
43
,
north
=
46
,
west
=
60
,
east
=
62
,
depth
=
z
,
xy_res
=
71
,
**
kwargs
)
geo
=
calc_spl
(
freq
=
10
,
south
=
43
,
north
=
46
,
west
=
60
,
east
=
62
,
depth
=
z
,
xy_res
=
71
,
**
kwargs
)
spl
=
geo
[
'spl'
]
x
=
geo
[
'x'
]
y
=
geo
[
'y'
]
...
...
@@ -82,15 +82,15 @@ def test_geophony_in_canyon(bathy_canyon):
idx
=
np
.
nonzero
(
xyz
<
bathy
)
assert
np
.
all
(
~
np
.
isnan
(
spl
[
idx
]))
def
test_
geophony
_in_canyon_with_land
(
bathy_canyon_with_land
):
""" Check that we can execute the
geophony
method for a
def
test_
calc_spl
_in_canyon_with_land
(
bathy_canyon_with_land
):
""" Check that we can execute the
calc_spl
method for a
canyon-shaped bathymetry and uniform sound speed profile,
with some areas having negative bathymetry, and check that
those areas are not included in the source sum"""
kwargs
=
{
'load_bathymetry'
:
bathy_canyon_with_land
,
'load_wind_uv'
:
1.0
,
'ssp'
:
1480
,
'angular_bin'
:
90
,
'dr'
:
100
,
'dz'
:
100
}
z
=
[
20
,
50
,
100
]
geo1
=
geophony
(
freq
=
10
,
lat
=
43.95
,
lon
=
61
,
propagation_range
=
10
,
depth
=
z
,
**
kwargs
)[
'spl'
][
0
,
0
,
0
]
geo2
=
geophony
(
freq
=
10
,
lat
=
43.95
,
lon
=
61
,
propagation_range
=
10
,
depth
=
z
,
neg_inf_on_land
=
False
,
**
kwargs
)[
'spl'
][
0
,
0
,
0
]
geo1
=
calc_spl
(
freq
=
10
,
lat
=
43.95
,
lon
=
61
,
propagation_range
=
10
,
depth
=
z
,
**
kwargs
)[
'spl'
][
0
,
0
,
0
]
geo2
=
calc_spl
(
freq
=
10
,
lat
=
43.95
,
lon
=
61
,
propagation_range
=
10
,
depth
=
z
,
neg_inf_on_land
=
False
,
**
kwargs
)[
'spl'
][
0
,
0
,
0
]
assert
geo1
<
geo2
#check that sum is larger when land areas are included in summation
def
test_transmission_loss_real_world_env
():
...
...
@@ -105,7 +105,7 @@ def test_transmission_loss_real_world_env():
src
=
dict
(
load_bathymetry
=
'gebco'
,
load_temp
=
'hycom'
,
load_salinity
=
'hycom'
)
sound_source
=
{
'freq'
:
200
,
'lat'
:
43.8
,
'lon'
:
-
59.04
,
'source_depth'
:
12
}
seafloor
=
{
'sound_speed'
:
1700
,
'density'
:
1.5
,
'attenuation'
:
0.5
}
transm_loss
=
create_transm_loss_calc
(
seafloor
=
seafloor
,
propagation_range
=
20
,
**
src
,
**
bounds
,
**
sound_source
,
dr
=
100
,
angular_bin
=
45
,
dz
=
50
)
transm_loss
=
create_transm_loss_calc
ulator
(
seafloor
=
seafloor
,
propagation_range
=
20
,
**
src
,
**
bounds
,
**
sound_source
,
dr
=
100
,
angular_bin
=
45
,
dz
=
50
)
tl_h
,
ax_h
,
tl_v
,
ax_v
=
transm_loss
.
calc
(
vertical
=
True
)
...
...
@@ -135,7 +135,7 @@ def test_transmission_loss_real_world_env():
def
test_transmission_loss_flat_seafloor
():
""" Check that we can initialize a transmission loss object
for a flat seafloor and uniform sound speed profile """
transm_loss
=
create_transm_loss_calc
(
freq
=
100
,
source_depth
=
75
,
propagation_range
=
0.5
,
load_bathymetry
=
2000
,
ssp
=
1480
,
angular_bin
=
10
)
transm_loss
=
create_transm_loss_calc
ulator
(
freq
=
100
,
source_depth
=
75
,
propagation_range
=
0.5
,
load_bathymetry
=
2000
,
ssp
=
1480
,
angular_bin
=
10
)
tl_h
,
ax_h
,
tl_v
,
ax_v
=
transm_loss
.
calc
(
vertical
=
True
)
answ
=
np
.
genfromtxt
(
os
.
path
.
join
(
path_to_assets
,
'lloyd_mirror_f100Hz_SD75m.csv'
),
delimiter
=
","
)
assert
answ
.
shape
==
tl_v
[
0
,:,:,
0
].
shape
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help