Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
giumas committed Jul 31, 2019
1 parent f2ade91 commit 8e6ecbd
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 47 deletions.
4 changes: 3 additions & 1 deletion examples/soundspeed/profile/ex_plot_bias_tracedprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

import numpy as np

from hyo2.abc.lib.logging import set_logging
from hyo2.soundspeed.profile.profile import Profile
from hyo2.soundspeed.profile.profilelist import ProfileList
from hyo2.soundspeed.profile.ray_tracing.tracedprofile import TracedProfile
from hyo2.soundspeed.profile.ray_tracing.diff_tracedprofiles import DiffTracedProfiles
from hyo2.soundspeed.profile.ray_tracing.plot_tracedprofiles import PlotTracedProfiles

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
set_logging(ns_list=["hyo2.soundspeed", ])


# create an example profile for testing
Expand Down Expand Up @@ -52,3 +53,4 @@ def make_fake_ssp(bias=0.0):

plot = PlotTracedProfiles(diff_tps=diff)
plot.make_bias_plots()
plot.make_comparison_plots()
42 changes: 25 additions & 17 deletions examples/soundspeed/profile/ex_tracedprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,54 @@


logger = logging.getLogger(__name__)
set_logging()
set_logging(ns_list=["hyo2.soundspeed", ])


# create an example profile for testing
def make_fake_ssp(bias=0.0):
def make_fake_ssp(bias=0.0, nr_samples=100):
p = Profile()
d = np.arange(0.0, 100.0, 0.5)
vs = np.arange(1450.0 + bias, 1550.0 + bias, 0.5)
t = np.arange(0.0, 100.0, 0.5)
s = np.arange(0.0, 100.0, 0.5)
d = np.linspace(0.0, 16.0, nr_samples)
vs_up = int(nr_samples / 4)
vs_down = nr_samples - 3 * vs_up
vs = np.concatenate([
np.linspace(1535.0 + bias, 1532.0 + bias, vs_up),
np.linspace(1532.0 + bias, 1528.0 + bias, vs_up),
np.linspace(1528.0 + bias, 1523.0 + bias, vs_up),
np.linspace(1523.0 + bias, 1500.0 + bias, vs_down)
])
t = np.linspace(10.0, 20.0, nr_samples)
s = np.linspace(34.0, 35.0, nr_samples)
p.init_proc(d.size)
p.proc.depth = d
p.proc.speed = vs
p.proc.temp = t
p.proc.sal = s
p.proc.flag[40:50] = Dicts.flags['user']
p.proc.flag[50:70] = Dicts.flags['filtered']
p.proc.flag[40:42] = Dicts.flags['user']
p.proc.flag[50:52] = Dicts.flags['filtered']
p.meta.latitude = 43.13555
p.meta.longitude = -70.9395
p.meta.utc_time = datetime.utcnow()
return p


tss_depth = 5.0
tss_value = 1500.0
avg_depth = 1000.0
half_swath_angle = 65.0
tss_depth = 1.0
tss_value = 1534.0
avg_depth = 100.0
half_swath_angle = 90.0
ssp = make_fake_ssp(bias=0.0)
# ssp.proc_debug_plot()
# plt.show()
ssp_list = ProfileList()
ssp_list.append_profile(ssp)
ssp_list.debug_plot()
plt.show()

start_time = datetime.now()
profile = TracedProfile(tss_depth=tss_depth, tss_value=tss_value,
avg_depth=avg_depth, # half_swath=half_swath_angle,
avg_depth=avg_depth, half_swath=half_swath_angle,
ssp=ssp_list.cur)
end_time = datetime.now()
logger.debug("timing: %s" % (end_time - start_time))

logger.debug("traced profile:\n%s" % profile)
logger.debug("api:\n%s" % dir(profile))
logger.debug("rays:\n%s" % profile.str_rays())
# profile.debug_rays(ray_idx=45)
profile.debug_plot(ray_idx=90)
plt.show()
12 changes: 8 additions & 4 deletions hyo2/soundspeed/profile/oceanography.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,22 @@ def in_situ_temp(cls, s, t, p, pr):
return t

temp = t
new_pot_t = cls.pot_temp(s=s, t=t, p=p, pr=pr)
new_pot_t = cls.pot_temp(s=s, t=temp, p=p, pr=pr)
# logger.debug("p: %s, pr: %s" % (p, pr))
if new_pot_t < t:
sign = 1
else:
sign = -1

dt = new_pot_t - temp
dt = new_pot_t - t
new_dt = new_pot_t - t

while np.abs(dt) > 0.001:
while abs(new_dt) > 0.001:
if abs(new_dt) > abs(dt):
sign = -sign
temp += sign * 0.001
new_pot_t = cls.pot_temp(s=s, t=temp, p=p, pr=pr)
dt = new_pot_t - t
new_dt = new_pot_t - t

return temp

Expand Down
4 changes: 2 additions & 2 deletions hyo2/soundspeed/profile/ray_tracing/diff_tracedprofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def calc_diff(self):
# first retrieve common areas for both profiles (and reset the 0 values)
for idx in range(len(ray_new[0])):

if ray_new[0][idx] == -1:
if np.isnan(ray_new[0][idx]):
continue
if ray_old[0][idx] == -1:
if np.isnan(ray_old[0][idx]):
continue

if not init_done:
Expand Down
60 changes: 42 additions & 18 deletions hyo2/soundspeed/profile/ray_tracing/plot_tracedprofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,39 @@ def make_comparison_plots(self):
svp_ax.grid(True)

# calculate limits
z_max = max(max(self._d.new_rays[-1][2]),
max(self._d.old_rays[-1][2]))
t_idx_max = max(np.nanargmax(self._d.new_rays[-1][0]),
np.nanargmax(self._d.old_rays[-1][0]))
z_max = self._d.new_rays[-1][2][t_idx_max]
x_max = max(max(self._d.new_rays[-1][1]),
max(self._d.old_rays[-1][1]))
logger.debug("z max: %s, x max: %s" % (z_max, x_max))

old_last_ray_x = self._d.old_rays[-1][1]
new_last_ray_x = self._d.new_rays[-1][1]
old_last_ray_z = self._d.old_rays[-1][2]
new_last_ray_z = self._d.new_rays[-1][2]
old_x_ends = [ray[1][-1] for ray in self._d.old_rays]
new_x_ends = [ray[1][-1] for ray in self._d.new_rays]
old_z_ends = [ray[2][-1] for ray in self._d.old_rays]
new_z_ends = [ray[2][-1] for ray in self._d.new_rays]
up_tol = [(ray[2][-1] - ray[2][-1] * self._d.variable_allowable_error - self._d.fixed_allowable_error)
for ray in self._d.new_rays]
down_tol = [(ray[2][-1] + ray[2][-1] * self._d.variable_allowable_error + self._d.fixed_allowable_error)
for ray in self._d.new_rays]
new_t_max = np.nanmax(self._d.new_rays[-1][0])
old_t_idx_max = np.nanargmin(np.abs(self._d.old_rays[-1][0] - new_t_max))
old_last_ray_x = self._d.old_rays[-1][1][:old_t_idx_max]
old_last_ray_z = self._d.old_rays[-1][2][:old_t_idx_max]

new_x_ends = list()
new_z_ends = list()
old_x_ends = list()
old_z_ends = list()
up_tol = list()
down_tol = list()
for ray_idx, new_ray in enumerate(self._d.new_rays):
old_ray = self._d.old_rays[ray_idx]
new_t_idx_max = np.nanargmax(new_ray[0])
new_x_ends.append(new_ray[1][new_t_idx_max])
new_z_ends.append(new_ray[2][new_t_idx_max])
new_t_max = new_ray[0][new_t_idx_max]
old_t_idx_max = np.nanargmin(np.abs(old_ray[0] - new_t_max))
old_x_ends.append(old_ray[1][old_t_idx_max])
old_z_ends.append(old_ray[2][old_t_idx_max])
up_tol.append(new_ray[2][new_t_idx_max] - new_ray[2][new_t_idx_max] * self._d.variable_allowable_error -
self._d.fixed_allowable_error)
down_tol.append(new_ray[2][new_t_idx_max] + new_ray[2][new_t_idx_max] * self._d.variable_allowable_error +
self._d.fixed_allowable_error)

# error plot axis
err_ax = fig.add_subplot(1, 2, 2)
Expand Down Expand Up @@ -138,10 +154,12 @@ def make_bias_plots(self):

start_time = datetime.now()

z_max = max(max(self._d.new_rays[-1][2]),
max(self._d.old_rays[-1][2]))
x_max = max(max(self._d.new_rays[-1][1]),
max(self._d.old_rays[-1][1]))
t_idx_max = max(np.nanargmax(self._d.new_rays[-1][0]),
np.nanargmax(self._d.old_rays[-1][0]))
z_max = self._d.new_rays[-1][2][t_idx_max]
x_max = max(np.nanmax(self._d.new_rays[-1][1]),
np.nanmax(self._d.old_rays[-1][1]))
logger.debug("z max: %s, x max: %s" % (z_max, x_max))

xi, zi = np.mgrid[0:x_max:1000j, 0:z_max:1000j]

Expand Down Expand Up @@ -175,6 +193,11 @@ def make_bias_plots(self):
logger.debug("skipping idx %s" % idx)
continue

if np.isnan(ray[0][idx]) or np.isnan(ray[1][idx]):
continue
if np.isnan(self._d.old_rays[ang][0][idx]) or np.isnan(self._d.old_rays[ang][1][idx]):
continue

t1 = np.append(t1, ray[0][idx])
x1 = np.append(x1, ray[1][idx])
z1 = np.append(z1, ray[2][idx])
Expand All @@ -190,10 +213,11 @@ def make_bias_plots(self):
logger.debug("timing: %s" % (datetime.now() - start_time))

# noinspection PyTypeChecker
dxi = interpolate.griddata((x1, z1), dx, (xi, zi), method='linear')
dxi = interpolate.griddata((x1, z1), dx, (xi, zi), method='cubic')
logger.debug("dxi: %s, min: %s, max: %s" % (dxi.shape, np.nanmin(dxi), np.nanmax(dxi)))
# noinspection PyTypeChecker
dzi = interpolate.griddata((x1, z1), dz, (xi, zi), method='linear')
dzi = interpolate.griddata((x1, z1), dz, (xi, zi), method='cubic')
logger.debug("dzi: %s, min: %s, max: %s" % (dzi.shape, np.nanmin(dzi), np.nanmax(dzi)))

logger.debug("timing: %s" % (datetime.now() - start_time))

Expand Down
7 changes: 4 additions & 3 deletions hyo2/soundspeed/profile/ray_tracing/tracedprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ def __init__(self, ssp, half_swath=65, avg_depth=10000, tss_depth=None, tss_valu
interp_x = fx(interp_z)
ft = interp1d(total_z, total_t, kind='cubic', bounds_error=False, fill_value=np.nan)
interp_t = ft(interp_z)

elif len(depths) == 1:
interp_z = total_z
interp_x = total_x
interp_t = total_t
else:
raise RuntimeError("invalid profile with zero valid depth values")

self.rays.append(np.array([interp_t, interp_x, interp_z]))

Expand All @@ -166,7 +167,7 @@ def debug_rays(self, ray_idx=0):
logger.debug("%10.4f %10.3f %10.2f"
% (self.rays[ray_idx][0][idx], self.rays[ray_idx][1][idx], self.rays[ray_idx][2][idx]))

def plot(self, ray_idx=0):
def debug_plot(self, ray_idx=0):
nr_rays = len(self.rays)
if (ray_idx < 0) or (ray_idx >= nr_rays):
logger.warning("invalid ray index: %d (total rays: %d)" % (ray_idx, nr_rays))
Expand All @@ -176,7 +177,7 @@ def plot(self, ray_idx=0):

plt.figure("Traced Profile", dpi=120)

plt.subplot(131) # time
plt.subplot(131) # profile
plt.plot(self.data[1], self.data[0])
plt.gca().invert_yaxis()
plt.grid(True)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[bdist_wheel]
universal = 0
universal = 1
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def find_version(*file_paths):
setup_requires=[
"setuptools",
"wheel",
"cython",
],
install_requires=[
"hyo2.abc",
Expand Down

0 comments on commit 8e6ecbd

Please sign in to comment.