Skip to content

Commit

Permalink
removed Cythonized traced profile
Browse files Browse the repository at this point in the history
  • Loading branch information
giumas committed Jul 28, 2019
1 parent 5901aba commit f2ade91
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 79 deletions.
38 changes: 22 additions & 16 deletions examples/soundspeed/profile/ex_tracedprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,56 @@

from datetime import datetime
import numpy as np
from matplotlib import pyplot as plt

from hyo2.abc.lib.logging import set_logging
from hyo2.soundspeed.profile.profile import Profile
from hyo2.soundspeed.profile.dicts import Dicts
from hyo2.soundspeed.profile.profilelist import ProfileList
from hyo2.soundspeed.profile.ray_tracing.tracedprofile import TracedProfile

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)
set_logging()


# create an example profile for testing
def make_fake_ssp(bias=0.0):
ssp = Profile()
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)
ssp.init_proc(d.size)
ssp.proc.depth = d
ssp.proc.speed = vs
ssp.proc.temp = t
ssp.proc.sal = s
ssp.proc.flag[40:50] = Dicts.flags['user']
ssp.proc.flag[50:70] = Dicts.flags['filtered']
ssp.meta.latitude = 43.13555
ssp.meta.longitude = -70.9395
ssp.meta.utc_time = datetime.utcnow()
return ssp
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.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 = 70.0
half_swath_angle = 65.0
ssp = make_fake_ssp(bias=0.0)
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("api:\n%s" % dir(profile))
logger.debug("rays:\n%s" % profile.str_rays())
2 changes: 1 addition & 1 deletion hyo2/soundspeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed"
__version__ = '2019.2.1'
__version__ = '2019.3.0'
__copyright__ = 'Copyright 2019 University of New Hampshire, Center for Coastal and Ocean Mapping'

lib_info = LibInfo()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
cimport numpy
import numpy
from scipy.interpolate import interp1d
import numpy as np
import math
from cpython cimport datetime
import logging
from scipy.interpolate import interp1d

logger = logging.getLogger(__name__)

from hyo2.soundspeed.profile.dicts import Dicts


cdef class TracedProfile:

cpdef public double avg_depth
cpdef public double half_swath
cpdef public list rays
cpdef public list harmonic_means
cpdef public datetime.datetime date_time
cpdef public double latitude
cpdef public double longitude
cpdef public list data
class TracedProfile:

def __init__(self, ssp, double half_swath=70, double avg_depth=10000, tss_depth=None, tss_value=None):
def __init__(self, ssp, half_swath=65, avg_depth=10000, tss_depth=None, tss_value=None):
# PyDateTime_IMPORT
self.avg_depth = avg_depth
self.half_swath = half_swath

# select samples for the ray tracing (must be deeper than the transducer depth)
depths = list()
if tss_depth is not None:
depths.append(tss_depth)
speeds = list()
if tss_value is not None:
if (tss_depth is not None) and (tss_value is not None):
depths.append(tss_depth)
speeds.append(tss_value)

vi = ssp.proc_valid
Expand Down Expand Up @@ -66,7 +52,7 @@ def __init__(self, ssp, double half_swath=70, double avg_depth=10000, tss_depth=
# ray-trace a few angles (ref: Lurton, An Introduction to UA, p.50-52)
self.rays = list()
self.harmonic_means = list()
for angle in numpy.arange(0, int(math.ceil(self.half_swath + 1))):
for angle in np.arange(0, int(math.ceil(self.half_swath + 1))):

# ray angles
beta = list()
Expand Down Expand Up @@ -149,34 +135,64 @@ def __init__(self, ssp, double half_swath=70, double avg_depth=10000, tss_depth=

# interpolate between 0 and 5000 meters with decimetric resolution
if len(depths) > 1:
interp_z = numpy.linspace(0, 5000, num=25001, endpoint=True)
fx = interp1d(total_z, total_x, kind='cubic', bounds_error=False, fill_value=-1)
interp_z = np.linspace(0, 5000, num=25001, endpoint=True)
fx = interp1d(total_z, total_x, kind='cubic', bounds_error=False, fill_value=np.nan)
interp_x = fx(interp_z)
ft = interp1d(total_z, total_t, kind='cubic', bounds_error=False, fill_value=-1)
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

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

logger.debug("rays: %d (%d samples per-ray)" % (len(self.rays), len(self.rays[0][0])))
self.date_time = ssp.meta.utc_time
self.latitude = ssp.meta.latitude
self.longitude = ssp.meta.longitude
self.data = [depths, speeds]

def str_rays(self):
msg = str()
for ang in range(len(self.rays)):
msg += "[%d]\n" % ang

for idx in range(len(self.rays[ang][0])):
msg += "%10.2f %10.2f %10.2f\n" \
% (self.rays[ang][0][idx], self.rays[ang][1][idx], self.rays[ang][2][idx])
return msg
def debug_rays(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))
return

logger.debug("[%d]" % ray_idx)
logger.debug("t | x | z |")
for idx in range(len(self.rays[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):
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))
return

from matplotlib import pyplot as plt

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

plt.subplot(131) # time
plt.plot(self.data[1], self.data[0])
plt.gca().invert_yaxis()
plt.grid(True)
plt.title('profile')

plt.subplot(132) # time
plt.plot(self.rays[ray_idx][0], self.rays[ray_idx][2])
plt.gca().invert_yaxis()
plt.grid(True)
plt.title('z vs. time')

plt.subplot(133) # x
plt.plot(self.rays[ray_idx][1], self.rays[ray_idx][2])
plt.gca().invert_yaxis()
plt.grid(True)
plt.title('z vs. x')

def __repr__(self):
msg = "<%s>\n" % self.__class__.__name__
Expand All @@ -186,7 +202,7 @@ def __repr__(self):
msg += " <longitude: %.7f>\n" % self.longitude
msg += " <avg depth: %.3f>\n" % self.avg_depth
msg += " <half swatch: %.1f>\n" % self.half_swath
msg += " <profile valid samples: %d>" % len(self.data[0])
msg += " <profile valid samples: %d>\n" % len(self.data[0])
msg += " <rays: %d>\n" % len(self.rays)
msg += " <samples per ray: %d>\n" % len(self.rays[0][0])

Expand Down
10 changes: 0 additions & 10 deletions hyo2/soundspeed/profile/ray_tracing/tracedprofile.pyxbld

This file was deleted.

2 changes: 1 addition & 1 deletion hyo2/soundspeedmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed Manager"
__version__ = "2019.2.1"
__version__ = "2019.3.0"
__copyright__ = "Copyright 2019 University of New Hampshire, Center for Coastal and Ocean Mapping"

app_info = AppInfo()
Expand Down
2 changes: 1 addition & 1 deletion hyo2/soundspeedsettings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger.addHandler(logging.NullHandler())

name = "Sound Speed Settings"
__version__ = '2019.2.1'
__version__ = '2019.3.0'
__copyright__ = 'Copyright 2019 University of New Hampshire, Center for Coastal and Ocean Mapping'

app_info = AppInfo()
Expand Down
16 changes: 1 addition & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import codecs
import os
import re
import numpy as np

# Always prefer setuptools over distutils
from setuptools import setup, find_packages, Extension
from Cython.Build import cythonize
from setuptools import setup, find_packages

# ------------------------------------------------------------------
# HELPER FUNCTIONS
Expand Down Expand Up @@ -62,18 +60,6 @@ def find_version(*file_paths):
"scipy",
"basemap" # you may also need: conda install -c conda-forge basemap-data-hires
],
ext_modules=cythonize([
Extension("hyo2.soundspeed.profile.ray_tracing.tracedprofile",
sources=["hyo2/soundspeed/profile/ray_tracing/tracedprofile.pyx"],
include_dirs=[np.get_include()],
language='c++',
# extra_compile_args=["-Zi", "/Od"],
# extra_link_args=["-debug"],
),
],
annotate=True,
compiler_directives={'language_level': '3'}
),
python_requires='>=3.5',
entry_points={
"gui_scripts": [
Expand Down

0 comments on commit f2ade91

Please sign in to comment.