In [1]:
import deco
import numpy
import untangle
from bokeh.plotting import figure, output_notebook, show

output_notebook()


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-0837ac807d82> in <module>()
      2 import numpy
      3 import untangle
----> 4 from bokeh.plotting import figure, output_notebook, show
      5 
      6 output_notebook()

ImportError: No module named 'bokeh'

In [ ]:
# Globals
settings = deco.deco_settings(
    last_stop = 6,
    gf_low = 0.1,
    gf_high = 0.90)
precision = numpy.float32
profile_time_factor = 1.0
sac_bottom = 18
sac_deco = 15
xml_file = "profiles/2015_12_27T15_42_48.uddf"

In [ ]:
doc = untangle.parse(xml_file)

In [ ]:
mix_ctx = deco_mix.deco_mix_ctx()

gasmixes = dict()

imix = 0
for mix in doc.uddf.gasdefinitions.mix:
    try:
        switchdepth = int(mix.switchdepth.cdata)
    except:
        switchdepth = 0
    gasmixes.update({ mix['id']: {
        'imix': imix,
        'f_he': float(mix.he.cdata),
        'f_o2': float(mix.o2.cdata),
        'f_n2': 1 - float(mix.o2.cdata) - float(mix.he.cdata) }})
    mix_ctx.set_mix(
        imix,
        deco_mix.deco_mix(f_o2 = float(mix.o2.cdata),
        f_he = float(mix.he.cdata),
        switch_depth = switchdepth,
        enabled = True))
    imix += 1

#print(gasmixes)
#print(mix_ctx)

In [ ]:
# Initialize decompression context
try:
    p_surface_in = float(doc.uddf.profiledata.repetitiongroup.dive.informationbeforedive.surfacepressure.cdata) / 100000
except:
    p_surface_in = 1.0

deco_ctx = deco.deco_zhl16b(
    settings = settings,
    mix_ctx = mix_ctx,
    p_surface = p_surface_in,
    salinity = 1.0)

#print(deco_ctx)

In [ ]:
dive_profile = deco_helper.profile(
        runtime = 0,
        ctx = deco_ctx,
        maxentries = len(doc.uddf.profiledata.repetitiongroup.dive.samples.waypoint))

# Read profile
runtime = 0
depth = 0
lastruntime = 0
lastdepth = 0
for waypoint in doc.uddf.profiledata.repetitiongroup.dive.samples.waypoint:
    try:
        activemix = waypoint.switchmix['ref']
        # eventually switch mix
        dive_profile.ctx.mix_ctx.set_active_mix(gasmixes[activemix]['imix'])
        #print("switch mix: %s" % (dive_profile.ctx.mix_ctx.get_mix(dive_profile.ctx.mix_ctx.get_active_mix())))
    except:
        pass
    
    runtime = float(waypoint.divetime.cdata) / 60.0 * profile_time_factor
    depth = float(waypoint.depth.cdata)

    #print("runtime: %.1f min. depth: %.1f m lastdepth %.1f m" % (runtime, depth, lastdepth))
    
    if (depth != 0 and runtime - lastruntime > 0):
        #%lprun -s -m deco dive_profile.update(time = runtime - lastruntime, depth_begin = lastdepth, depth_end = depth, sac = sac_bottom)
        dive_profile.update(
            time = runtime - lastruntime,
            depth_begin = lastdepth,
            depth_end = depth,
            sac = sac_bottom)
                
    lastruntime = runtime
    lastdepth = depth

# Strip data array to number of actually valid records
dive_profile.strip()

#print(dive_profile.di)
#print(dive_profile.ctx.mix_ctx)

In [ ]:
data = dive_profile.data

In [ ]:
p = figure(
    title = 'ZHL16B-GF {:d}/{:d}'.format(int(ctx.gf_low * 100), int(ctx.gf_high * 100)),
    x_axis_label = 'Time in min.',
    y_axis_label = 'Pressure in mfw / GF',
    plot_width = 1024,
    plot_height = 600)

p.line(
    data['time'], data['depth'],
    legend = "Depth",
    line_width = 1,
    line_color = 'blue')

p.line(
    data['time'],
    data['p_ceiling'] * 10 - 10,
    legend = "Ceiling",
    line_width = 2,
    line_color = 'red')

p.line(
    data['time'],
    data['gf_allowed'] * 100,
    legend = "Permitted GF",
    line_width = 2,
    line_color = 'purple')

p.line(
    data['time'], 
    data['gf_current'] * 100,
    legend = "Current GF",
    line_width = 1,
    line_color = 'purple')

show()