Source code documentation

mission

Mission class module

A Mission a basically a list of repetitive dives. It could also be called a ‘DiveTrip’ for example

class dipplanner.mission.Mission(dive_or_divelist=None, tank_or_tankdict=None, description=None)[source]

Mission Class

a Mission represent all repetitive dives for a given set of time. the Mission will keep consistency between repetitive dives

An isolated dive is a Mission with only one dive inside

Attributes:
tanks:(dict) – list of each individual tank used (at least once) during the mission.
dives:(list) – list of Dive object of the same mission
description:(str) – description of the mission (OPTIONAL)
status:(str) – actual status of the mission. Could be either:
  • STATUS_NONE: not calculated

  • STATUS_CHANGED: changed (calculated, but something in input or

    parameter has changed and recalculation is needed)

  • STATUS_OK: calculated (calculation is up to date)

Todo

Insert dive(s) in a certain position

Todo

change dive order, permutations, etc...

Todo

decide if we define a common list of tanks for a given mission in this case, each dive will be able to pickup some tank

Todo

decide if settings is included in Mission object or remains global

__init__(dive_or_divelist=None, tank_or_tankdict=None, description=None)[source]

Mission constructor

Initialize the Mission object if no parameter is given, instantiate an ‘empty’ Mission

Keyword Arguments:
dive_or_divelist:
 – either a Dive object or a list of Dive object
tank_or_tankdict:
 – either a Tank object or a dict of tanks
description:(str)– description of the Mission
Return:
<nothing>
Raise:
TypeError: if dive_or_divelist contains another type than Dive
__iter__()[source]

iterable

see dipplanner.mission.Mission._forward() )

_forward()[source]

forward generator, used for iteration

__len__()[source]

calculate and return len of Session object

usage example:

print(len(my_mission))
Args:
<none>
Returns:
int:number of Dives in this mission
dumps_dict()[source]

dumps the Mission object in json format

Keyword arguments:
<none>
Returns:
dict – json dumps of Tank object
Raise:
TypeError : if Mission is not serialisable
loads_json(input_json)[source]

loads a json structure and update the mission object with the new values.

This method can be used in http PUT method to update object value

Keyword arguments:
input_json:(string) – the json structure to be loaded
Returns:
<none>
Raise:
  • ValueError : if json is not loadable
clean(what='all')[source]

clean the mission

Keyword arguments:
what:(str) – what the method should clean by default: all (clean all) Values allowed: [‘all’, ‘dives’, ‘description’, ]
Returns:
<none>
Raise:
  • ValueError : if wrong status code is given
change_status(status=None)[source]

Change the status of the mission

if no status is given in args, toggle the status from OK to CHANGED else, update the status with the given value

Keyword arguments:
status:(str) – status code (optionnal)
Returns:
<none>
Raise:
  • ValueError : if wrong status code is given
add_dive(dive_or_divelist)[source]

add a Dive or a list of dive to the Mission

they will be added at the end of the list

Keyword Arguments:
dive_or_divelist:
 – either a Dive object or a list of Dive objects
Return:
<nothing>
Raise:
TypeError: if dive_or_divelist contains another type than Dive
add_tank(tank_or_tankdict)[source]

add a Tank or a dict of tanks to the Mission

if a tank already exists in the dict with the same name, the new one will not be added.

Keyword Arguments:
tank_or_tanklist:
 – either a Tank object or a list of Tank objects
Return:
<nothing>
Raise:
TypeError: if tank_or_tanklist contains another type than Tank
calculate()[source]

Calculate all the decompression planning for all dives in this mission

__str__

x.__str__() <==> str(x)

dive

dive class module

Each Dive represent one dive (and only one) For successive dives, it is possible to provide the parameters of the previous dive in order to calculate the next one.

exception dipplanner.dive.NothingToProcess(description='')[source]

raised when the is no input segments to process

__init__(description='')[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
exception dipplanner.dive.InstanciationError(description='')[source]

raised when the Dive constructor encounters a problem. In this case, it can not continue

__init__(description='')[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
exception dipplanner.dive.ProcessingError(description='')[source]

raised when the is no input segments to process

__init__(description='')[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
exception dipplanner.dive.InfiniteDeco(description='')[source]

raised when the deco time becomes enourmous (like infinite)

__init__(description='')[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
class dipplanner.dive.Dive(mission, known_segments=None, known_tanks=None, previous_profile=None)[source]

Conducts dive based on inputSegments, knownGases, and an existing model. Iterates through dive segments updating the Model. When all dive segments are processed then calls ascend(0.0) to return to the surface.

The previous_profile (Model) can be either null in which case a new model is created, or can be an existing model with tissue loadings.

Gas switching is done on the final ascent if OC deco or bailout is specified.

Outputs profile to a List of dive segments

Attributes:

  • mission – (Mission) Mission object the dive belongs to
  • name – (str) name of the dive
  • input_segments – (list) Stores enabled input dive segment objects
  • output_segments – (list) Stores output segments produced by this class
  • tanks – (list) Stores enabled dive tank objects
  • current_tank – current tank object
  • current_depth – current dive depth
  • current_f_he – current gas fraction of He
  • current_f_n2 – current gas fraction of N2
  • current_f_o2 – current gas fraction of O2
  • model – model used for this dive
  • run_time – runTime
  • pp_o2 – CCR ppO2, if OC : 0.0
  • is_closed_circuit – Flag to store CC or OC
  • in_final_ascent – flag for final ascent
  • is_repetitive_dive – Flag for repetitive dives
  • surface_interval – for surf. int. in seconds
  • no_flight_time_value – calculated no flight time
  • metadata – description for the dive
__init__(mission, known_segments=None, known_tanks=None, previous_profile=None)[source]

Constructor for Profile class

For fist dive, instanciate the profile class with no model (profile will create one for you) For repetative dives, instanciate profile class with the previous model

Keyword Arguments:
mission:(Mission) – mission object the dive belongs to
known_segments:– list of input segments
known_tanks:– list of tanks for this dive
previous_profile:
 (Model) – model object of the precedent dive
Return:
<nothing>

Note

the constructor should not fail. If something if wrong, it MUST still instantiate itself, with errors in his own object

__str__()[source]

Return a human readable name of the segment

Keyword Arguments:
<none>
Return:
str – a string with the result of the calculation of the dives
using the default template
Raise:
<nothing>
__unicode__()[source]

Return a human readable name of the segment in unicode

Keyword Arguments:
<none>
Return:
ustr – an unicode string with the result of the calculation of
the dives using the default template
Raise:
<nothing>
__cmp__(otherdive)[source]

Compare a dive to another dive, based on run_time

Keyword arguments:
otherdive:(Dive) – another dive object
Returns:
Integer – result of cmp()
Raise:
<nothing>
add_input_segment(segment_or_segmentlist)[source]

add a Segment or a list of Segments to the Dive’s input_segments list. They will be added at the end of the list

Keyword Arguments:
segment_or_segmentlist:
 – either a Segment object or a list of Segment objects
Return:
<nothing>
Raise:
TypeError: if segment_or_segmentlist contains another type than
Segment*
dumps_dict()[source]

dumps the Dive object in dict format for later json conversion

Keyword arguments:
<none>
Returns:
string – dict dumps of Dive object
Raise:
TypeError : if Mission is not serialisable
loads_json(input_json)[source]

loads a json structure and update the tank object with the new values.

This method can be used in http PUT method to update object value

TODO: do something with automatic_tank_refill: global or local (dive) parameter ?

Keyword arguments:
input_json:(string) – the json structure to be loaded
Returns:
<none>
Raise:
  • ValueError : if json is not loadable
set_repetitive(previous_dive)[source]

Make this dive a repetitive dive by cloning the previous model history into the current dive

Keyword Arguments:
previous_dive:(Dive) – previous dive profile
Return:
<nothing>
Raise:
<nothing>
output(template=None)[source]

Returns the dive profile calculated, using the template given in settings or command lines. (and not only the default template)

Keyword Arguments:
<none>
Return:
str – a string with the result of the calculation of the dives
using the choosen template
Raise:
<nothing>
do_surface_interval(time=None)[source]

Conducts a surface interval by performing a constant depth calculation on air at zero meters

Keyword Arguments:
time:(int) – duration of the interval, in seconds if not provided, uses the surface_interval defined in this dive
Returns:
<nothing>
Raise:
<Exceptions from model>
get_surface_interval()[source]

Returns surface interval in mm:ss format

Keyword Arguments:
<nothing>
Returns:
str – surface interval time in mmm:ss format
Raise:
<nothing>
refill_tanks()[source]

refile all tanks defined in this dive it is used for repetitive dives

Keyword Arguments:
<none>
Returns:
<nothing>
Raise:
<nothing>
is_dive_segments()[source]

Returns true if there are loaded dive segments else false means there is nothing to process

Keyword Arguments:
<none>
Returns:
True (bool) – if there is at least one input
dive segment to process

False (bool) – if there is no dive segment to process

Raise:
<nothing>
do_dive_without_exceptions()[source]

Call do_dive, and handle exceptions internally : do not raise any “dive related” exception : add the exception inside self.dive_exceptions instead.

Keyword Arguments:
<none>
Return:
<nothing>
Raise:
<nothing>
do_dive()[source]

Process the dive

Keyword Arguments:
<none>
Return:
<nothing>
Raise:
NothingToProcess – if there is no input segment to process or <Exceptions from model>
get_no_flight_hhmmss()[source]

Returns no flight time (if calculated) in hhmmss format instead of an int in seconds

Note

This method does not calculate no_flight_time you need to call no_flight_time() or no_flight_time_wo_exception() before.

Keyword Arguments:
<none>
Returns:
str – “hh:mm:ss” no flight time str – “” if no flight time is not calculated
no_flight_time_wo_exception(altitude=2450, tank=None)[source]

Call no_flight_time, and handle exceptions internally: do not raise any “dive related” exception: add the exception inside self.dive_exceptions instead.

Keyword Arguments:
altitude:(int) – in meter : altitude used for the calculation
flight_ascent_rate:
 (float) – in m/s
tank:(Tank) – optionnal: it is possible to provide a tank while calling no_flight_time to force “no flight deco” with another mix than air. In this case, we will ‘consume’ the tank When the tank is empty, it automatically switch to air
Returns:
int – no fight time in seconds
Raise:
<nothing>
no_flight_time(altitude=2450, tank=None)[source]

Evaluate the no flight time by ‘ascending’ to the choosen flight altitude. Ascending will generate the necessary ‘stop’ at the current depth (which is 0m). The stop time represents the no flight time

Keyword Arguments:
altitude:(int) – in meter : altitude used for the calculation
flight_ascent_rate:
 (float) – in m/s
tank:(Tank) – optionnal: it is possible to provide a tank while calling no_flight_time to force “no flight deco” with another mix than air. In this case, we will ‘consume’ the tank When the tank is empty, it automatically switch to air
Returns:
int – no fight time in seconds
Raise:
InfiniteDeco - if the no flight time can not achieve enough
decompression to be able to go to give altitude
ascend(target_depth)[source]

Ascend to target depth, decompressing if necessary. If inFinalAscent then gradient factors start changing, and automatic gas selection is made.

This method is called by do_dive()

Keyword Arguments:
target_depth:(float) – in meter, target depth for the ascend

Returns: <nothing>

Raise: <Exceptions from model>

do_gas_calcs()[source]

Estimate gas consumption for all output segments and set this into the respective gas objects

Keyword Arguments:
<none>
Returns:
<nothing>
Raise:
<Exceptions from tank>
set_deco_gas(depth)[source]

Select appropriate deco gas for the depth specified Returns true if a gas switch occured

Keyword Arguments:
depth:(float) – target depth to make the choice
Returns:
True – if gas swich occured False – if no gas switch occured
Raise:
<Exceptions from tank>

segment

Segment classes A segment is a portion of a dive in the same depth (depth + duration)

exception dipplanner.segment.UnauthorizedMod(description)[source]

raised when the MOD is not possible according to the depth(s) of the segment

__init__(description)[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
class dipplanner.segment.Segment[source]

Base class for all types of segments

Attributes:
  • dive (Dive) – Dive object the segment belongs to

  • type (str) – type of segment

    types of segments can be :

    • const = “Constant Depth”
    • ascent = “Ascent”
    • descent = “Descent”
    • deco = “Decompression”
    • waypoint = “Waypoint”
    • surf = “Surface”
  • in_use (boolean) – True if segment is used

  • depth (float) – depth of this segment, in meter

  • time (float) – duration of this segment, in seconds

  • run_time (float) – runtime (displayed in profile informations)

  • setpoint (float) – setpoint for CCR

  • tank (Tank) – refer to tank object used in this segment

__init__()[source]

constructor for Segment base class, just defines all the parameters

Keyword arguments:
<none>
Returns:
<nothing>
Raise:
<nothing>
__str__()[source]

Return a human readable name of the segment

Keyword arguments:
<none>
Returns:
str – representation of the segment in the form: (see __repr__)
Raise:
<nothing>
__unicode__()[source]

Return a human readable name of the segment in unicode

Keyword arguments:
<none>
Returns:
str – representation of the segment in the form: (see __repr__)
Raise:
<nothing>
dumps_dict()[source]

dumps the Segment object in json format

Keyword arguments:
<none>
Returns:
string – json dumps of Segment object
Raise:
TypeError : if Tank is not serialisable
loads_json(input_json)[source]

loads a json structure and update the segment object with the new values.

This method can be used in http PUT method to update object value

Keyword arguments:
input_json:(string) – the json structure to be loaded
Returns:
<none>
Raise:
  • ValueError : if json is not loadable

  • InvalidGas – When proportions of gas exceed

    100% for example (or negatives values)

  • InvalidMod – if mod > max mod based on max_ppo2

    or ABSOLUTE_MAX_MOD.

    ABSOLUTE_MAX_MOD is a global settings which can not be exceeded.

  • InvalidTank – when pressure or tank size exceed maximum

    values or are incorrect (like negatives) values

check()[source]

check if it’s a valid segment Should be executed before calculating dives

the check does not return anything if nok, but raises Exceptions

Keyword arguments:
<none>
Returns:
True (bool) – if check is ok
Raise:
<DiveExceptions>
check_mod(max_ppo2=None)[source]

checks the mod for this segment according to the used tank.

Keyword arguments:
max_ppo2:(float) – max tolerated ppo2
Returns:
True (bool) – if check is ok
Raise:
UnauthorizedMod – if segments goes below max mod or upper min mod
check_min_od()[source]

checks the minimum od for this segment according to the used tank. (hypoxic cases)

Keyword arguments:
<none>
Returns:
True (bool) – if check is ok
Raise:
UnauthorizedMod – if segments goes below max mod or upper min mod
get_time_str()[source]

returns segment time in the form MMM:SS

Keyword Arguments:
<none>
Returns:
string – segment time in the form MMM:SS
Raise:
<nothing>
get_run_time_str()[source]

returns runtime in the form MMM:SS

Keyword Arguments:
<none>
Returns:
string – segment time in the form MMM:SS
Raise:
<nothing>
get_p_absolute(method='complex')[source]

returns the absolute pression in bar (1atm = 1ATA = 1.01325 bar = 14.70psi)

Simple method : 10m = +1 bar Complex method : use real density of water, T°, etc...

Keyword arguments:
method – ‘simple’ or ‘complex’
Returns:
float – indicating the absolute pressure in bar
Raise:
ValueError – when providing a bad method
get_end()[source]

Calculates and returns E.N.D : Equivalent Narcosis Depth

Instead of Mvplan, it uses a ‘calculation method’ based on narcosis effet of all gas used, assuming there is no trace of other gases (like argon) in the breathing gas, but compare the narcotic effect with surface gas, wich is ‘air’ and contains a small amount of argon

Keyword arguments:
<none>
Returns:
integer – Equivalent Narcosis Depth in meter
Raise:
<nothing>
gas_used()[source]

returns the quantity (in liter) of gas used for this segment

(this method is empty)

class dipplanner.segment.SegmentDive(depth=None, time=None, tank=None, setpoint=0)[source]

Specialisation of segment class for dive segments

__init__(depth=None, time=None, tank=None, setpoint=0)[source]

Constructor for SegmentDive class. Look at base class for more explanations

Keyword arguments:
depth:(float) – in meter, the (constant) depth for this segment
time:(float) – in second, duration of this segment
tank:(Tank) – object instance of Tank class : describe the tank used in this segment
setpoint:(float) – for CCR, setpoint used for this segment for OC : setpoint should be zero
Returns:
<nothing>
Raise:
UnauthorizedMod – if depth is incompatible
with either min or max mod
gas_used()[source]

calculates returns the quantity (in liter) of gas used for this segment

Keyword arguments:
<none>
Returns:
float – in liter, quantity of gas used
__str__()

Return a human readable name of the segment

Keyword arguments:
<none>
Returns:
str – representation of the segment in the form: (see __repr__)
Raise:
<nothing>
__unicode__()

Return a human readable name of the segment in unicode

Keyword arguments:
<none>
Returns:
str – representation of the segment in the form: (see __repr__)
Raise:
<nothing>
check()

check if it’s a valid segment Should be executed before calculating dives

the check does not return anything if nok, but raises Exceptions

Keyword arguments:
<none>
Returns:
True (bool) – if check is ok
Raise:
<DiveExceptions>
check_min_od()

checks the minimum od for this segment according to the used tank. (hypoxic cases)

Keyword arguments:
<none>
Returns:
True (bool) – if check is ok
Raise:
UnauthorizedMod – if segments goes below max mod or upper min mod
check_mod(max_ppo2=None)

checks the mod for this segment according to the used tank.

Keyword arguments:
max_ppo2:(float) – max tolerated ppo2
Returns:
True (bool) – if check is ok
Raise:
UnauthorizedMod – if segments goes below max mod or upper min mod
dumps_dict()

dumps the Segment object in json format

Keyword arguments:
<none>
Returns:
string – json dumps of Segment object
Raise:
TypeError : if Tank is not serialisable
get_end()

Calculates and returns E.N.D : Equivalent Narcosis Depth

Instead of Mvplan, it uses a ‘calculation method’ based on narcosis effet of all gas used, assuming there is no trace of other gases (like argon) in the breathing gas, but compare the narcotic effect with surface gas, wich is ‘air’ and contains a small amount of argon

Keyword arguments:
<none>
Returns:
integer – Equivalent Narcosis Depth in meter
Raise:
<nothing>
get_p_absolute(method='complex')

returns the absolute pression in bar (1atm = 1ATA = 1.01325 bar = 14.70psi)

Simple method : 10m = +1 bar Complex method : use real density of water, T°, etc...

Keyword arguments:
method – ‘simple’ or ‘complex’
Returns:
float – indicating the absolute pressure in bar
Raise:
ValueError – when providing a bad method
get_run_time_str()

returns runtime in the form MMM:SS

Keyword Arguments:
<none>
Returns:
string – segment time in the form MMM:SS
Raise:
<nothing>
get_time_str()

returns segment time in the form MMM:SS

Keyword Arguments:
<none>
Returns:
string – segment time in the form MMM:SS
Raise:
<nothing>
loads_json(input_json)

loads a json structure and update the segment object with the new values.

This method can be used in http PUT method to update object value

Keyword arguments:
input_json:(string) – the json structure to be loaded
Returns:
<none>
Raise:
  • ValueError : if json is not loadable

  • InvalidGas – When proportions of gas exceed

    100% for example (or negatives values)

  • InvalidMod – if mod > max mod based on max_ppo2

    or ABSOLUTE_MAX_MOD.

    ABSOLUTE_MAX_MOD is a global settings which can not be exceeded.

  • InvalidTank – when pressure or tank size exceed maximum

    values or are incorrect (like negatives) values

class dipplanner.segment.SegmentDeco(depth, time, tank, setpoint=0)[source]

Specialisation of segment class for deco segments

__init__(depth, time, tank, setpoint=0)[source]

Constructor for SegmentDeco class. Look at base class for more explanations

In deco segment, we also have to manage some new parameters :

  • gf_used : which gradient factor is used
  • control_compartment : who is the control compartement
  • mv_max : max M-value for the compartment
Keyword arguments:
depth:(float) – in meter, the (constant) depth for this segment
time:(float) – in second, duration of this segment
tank:(Tank) – object instance of Tank class : describe the tank used in this segment
setpoint:(float) – for CCR, setpoint used for this segment for OC : setpoint should be zero
Returns:
<nothing>
Raise:
UnauthorizedMod – if depth is incompatible
with either min or max mod
gas_used()[source]

calculates returns the quantity (in liter) of gas used for this segment

Keyword arguments:
<none>
Returns:
float – in liter, quantity of gas used
__str__()

Return a human readable name of the segment

Keyword arguments:
<none>
Returns:
str – representation of the segment in the form: (see __repr__)
Raise:
<nothing>
__unicode__()

Return a human readable name of the segment in unicode

Keyword arguments:
<none>
Returns:
str – representation of the segment in the form: (see __repr__)
Raise:
<nothing>
check()

check if it’s a valid segment Should be executed before calculating dives

the check does not return anything if nok, but raises Exceptions

Keyword arguments:
<none>
Returns:
True (bool) – if check is ok
Raise:
<DiveExceptions>
check_min_od()

checks the minimum od for this segment according to the used tank. (hypoxic cases)

Keyword arguments:
<none>
Returns:
True (bool) – if check is ok
Raise:
UnauthorizedMod – if segments goes below max mod or upper min mod
check_mod(max_ppo2=None)

checks the mod for this segment according to the used tank.

Keyword arguments:
max_ppo2:(float) – max tolerated ppo2
Returns:
True (bool) – if check is ok
Raise:
UnauthorizedMod – if segments goes below max mod or upper min mod
dumps_dict()

dumps the Segment object in json format

Keyword arguments:
<none>
Returns:
string – json dumps of Segment object
Raise:
TypeError : if Tank is not serialisable
get_end()

Calculates and returns E.N.D : Equivalent Narcosis Depth

Instead of Mvplan, it uses a ‘calculation method’ based on narcosis effet of all gas used, assuming there is no trace of other gases (like argon) in the breathing gas, but compare the narcotic effect with surface gas, wich is ‘air’ and contains a small amount of argon

Keyword arguments:
<none>
Returns:
integer – Equivalent Narcosis Depth in meter
Raise:
<nothing>
get_p_absolute(method='complex')

returns the absolute pression in bar (1atm = 1ATA = 1.01325 bar = 14.70psi)

Simple method : 10m = +1 bar Complex method : use real density of water, T°, etc...

Keyword arguments:
method – ‘simple’ or ‘complex’
Returns:
float – indicating the absolute pressure in bar
Raise:
ValueError – when providing a bad method
get_run_time_str()

returns runtime in the form MMM:SS

Keyword Arguments:
<none>
Returns:
string – segment time in the form MMM:SS
Raise:
<nothing>
get_time_str()

returns segment time in the form MMM:SS

Keyword Arguments:
<none>
Returns:
string – segment time in the form MMM:SS
Raise:
<nothing>
loads_json(input_json)

loads a json structure and update the segment object with the new values.

This method can be used in http PUT method to update object value

Keyword arguments:
input_json:(string) – the json structure to be loaded
Returns:
<none>
Raise:
  • ValueError : if json is not loadable

  • InvalidGas – When proportions of gas exceed

    100% for example (or negatives values)

  • InvalidMod – if mod > max mod based on max_ppo2

    or ABSOLUTE_MAX_MOD.

    ABSOLUTE_MAX_MOD is a global settings which can not be exceeded.

  • InvalidTank – when pressure or tank size exceed maximum

    values or are incorrect (like negatives) values

class dipplanner.segment.SegmentAscDesc(start_depth, end_depth, rate, tank, setpoint=0)[source]

Specialisation of segment class for Ascent or Descent segments

__init__(start_depth, end_depth, rate, tank, setpoint=0)[source]

Constructor for SegmentAscDesc class. Look at base class for more explanations in this segment, we do not specify time, but rate (of ascending or descending) and start_depth and end_depth The comparaison between start and end depth determine if asc or desc rate is given in m/min

Keyword arguments:
start_depth:(float) – in meter, the starting depth for this segment
end_depth:(float) – in meter, the ending depth for this segment
rate:(float) – in m/s, rate of ascending or descending
tank:(Tank) – object instance of Tank class : describe the tank used in this segment
setpoint:(float) – for CCR, setpoint used for this segment for OC : setpoint should be zero
Returns:
<nothing>
Raise:
UnauthorizedMod – if depth is incompatible
with either min or max mod
check_mod(max_ppo2=None)[source]

checks the mod for this segment according to the used tank.

Keyword arguments:
max_ppo2:(float) – max tolerated ppo2
Returns:
<nothing>
Raise:
UnauthorizedMod – if segments goes below max mod or upper min mod
check_min_od()[source]

checks the minimum od for this segment according to the used tank. (hypoxic cases)

Keyword arguments:
<none>
Returns:
<nothing>
Raise:
UnauthorizedMod – if segments goes below max mod or upper min mod
__str__()

Return a human readable name of the segment

Keyword arguments:
<none>
Returns:
str – representation of the segment in the form: (see __repr__)
Raise:
<nothing>
__unicode__()

Return a human readable name of the segment in unicode

Keyword arguments:
<none>
Returns:
str – representation of the segment in the form: (see __repr__)
Raise:
<nothing>
check()

check if it’s a valid segment Should be executed before calculating dives

the check does not return anything if nok, but raises Exceptions

Keyword arguments:
<none>
Returns:
True (bool) – if check is ok
Raise:
<DiveExceptions>
dumps_dict()

dumps the Segment object in json format

Keyword arguments:
<none>
Returns:
string – json dumps of Segment object
Raise:
TypeError : if Tank is not serialisable
gas_used()[source]

calc. and returns the quantity (in liter) of gas used in this segment because it’s ascend or descent, the gas is not used at the same rate during the segment Because the rate is the same during all the segment, we can use the consumption at the average depth of the segment

Keyword arguments:
<none>
Returns:
float – in liter, quantity of gas used
get_end()

Calculates and returns E.N.D : Equivalent Narcosis Depth

Instead of Mvplan, it uses a ‘calculation method’ based on narcosis effet of all gas used, assuming there is no trace of other gases (like argon) in the breathing gas, but compare the narcotic effect with surface gas, wich is ‘air’ and contains a small amount of argon

Keyword arguments:
<none>
Returns:
integer – Equivalent Narcosis Depth in meter
Raise:
<nothing>
get_p_absolute(method='complex')

returns the absolute pression in bar (1atm = 1ATA = 1.01325 bar = 14.70psi)

Simple method : 10m = +1 bar Complex method : use real density of water, T°, etc...

Keyword arguments:
method – ‘simple’ or ‘complex’
Returns:
float – indicating the absolute pressure in bar
Raise:
ValueError – when providing a bad method
get_run_time_str()

returns runtime in the form MMM:SS

Keyword Arguments:
<none>
Returns:
string – segment time in the form MMM:SS
Raise:
<nothing>
get_time_str()

returns segment time in the form MMM:SS

Keyword Arguments:
<none>
Returns:
string – segment time in the form MMM:SS
Raise:
<nothing>
loads_json(input_json)

loads a json structure and update the segment object with the new values.

This method can be used in http PUT method to update object value

Keyword arguments:
input_json:(string) – the json structure to be loaded
Returns:
<none>
Raise:
  • ValueError : if json is not loadable

  • InvalidGas – When proportions of gas exceed

    100% for example (or negatives values)

  • InvalidMod – if mod > max mod based on max_ppo2

    or ABSOLUTE_MAX_MOD.

    ABSOLUTE_MAX_MOD is a global settings which can not be exceeded.

  • InvalidTank – when pressure or tank size exceed maximum

    values or are incorrect (like negatives) values

tank

Contains a Tank Class

Note

in MVPlan, this class was the ‘Gas’ class

exception dipplanner.tank.InvalidGas(description)[source]

Exception raised when the gas informations provided for the Tank are invalid

__init__(description)[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
exception dipplanner.tank.InvalidTank(description)[source]

Exception raised when the tank infos provided are invalid

__init__(description)[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
exception dipplanner.tank.InvalidMod(description)[source]

Exception raised when the given MOD is incompatible with the gas provided for the tank

__init__(description)[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
exception dipplanner.tank.EmptyTank(description)[source]

Exception raised when trying to consume more gas in tank than the remaining gas

__init__(description)[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
class dipplanner.tank.Tank(f_o2=0.21, f_he=0.0, max_ppo2=1.6, mod=None, volume=12.0, pressure=200, rule='30b', name=None)[source]

This class implements a representation of dive tanks wich contains breathing Gas We provide proportion of N2, O2, He, calculates MOD and volumes during the dives We can also (optionally) provide the type of tanks :

  • volume
  • pressure
  • remaining gas warning rule

Note

About imperial unit conversion

In ‘imperial’ countries (North America), it’s common to describe a tank with the volume of air stored in the cylinder at its working pressure (if you where to release it at the surface), instead of (internal volume * pressure).

This make difficult if not impossible to switch between the two units without any approximation or implementation choices.

eg: 80-cubic-foot aluminium cylinder (AL80)

TODO: continuer le texte explicatif

Attributes:

  • f_o2 (float) – fraction of oxygen in the gas in % (>= 0.0 & <= 1.0)

  • f_he (float) – fraction of helium in the gas in % (>= 0.0 & <= 1.0)

  • f_n2 (float) – fraction of nitrogen in the gas in %

    (>= 0.0 & <= 1.0)

  • max_ppo2 (float) – maximum tolerated ppo2 for this tank

  • volume (float) – volume of tank in liter

  • pressure (float) – pressure of tank in bar

  • rule (str) – tank rule for minimum gas calculation

  • mod (float) – maximum operating depth of the tank

  • in_use (boolean) – is the tank used for the dive of not

  • total_gas (float) – total gas volume of the tank in liter

  • used_gas (float) – used gas in liter

  • remaining_gas (float) – remaining gas in liter

  • min_gas (float) – minimum remaining gas in liter

  • name (str) – name of the Tank if not provided,

    try to set it automatically

__init__(f_o2=0.21, f_he=0.0, max_ppo2=1.6, mod=None, volume=12.0, pressure=200, rule='30b', name=None)[source]

Constructor for Tank class

If nothing is provided, create a default ‘Air’ with 12l/200b tank and max_ppo2 to 1.6 (used to calculate mod) if mod not provided, mod is calculed based on max tolerable ppo2

Keyword arguments:
f_o2:

(float) – Fraction of O2 in the gaz in % value between 0.0 and 1.0

f_he:

(float) – Fraction of He in the gaz in % value between 0.0 and 1.0

max_ppo2:

(float) – sets the maximum ppo2 you want for this tank (default: settings.DEFAULT_MAX_PPO2)

mod:

(float) – Specify the mod you want. if not provided, calculates the mod based on max_ppo2

if provided and not compatible

with max_ppo2: raise InvalidMod

volume:

(float) – Volume of the tank in liter

pressure:

(float) – Pressure of the tank, in bar

rule:

– rule for warning in the tank consumption must be either : ‘xxxb’ or ‘1/x’.

Note

xxxb (ex: 50b) means 50 bar minimum at the end of the dive

Note

1/x (ex : 1/3 for rule of thirds: 1/3 for way in, 1/3 for way out, 1/3 remains at the end of the dive)

ex2: 1/6 rule: 1/6 way IN,1/6 way OUT, 2/3 remains

name:

(str) – set a specific name for the Tank. if not given, it will be generated automatically based on the gas.

Returns:
<nothing>

Raise:

  • InvalidGas – see validate()

  • InvalidMod – if mod > max mod based on

    max_ppo2 and see validate()

  • InvalidTank – see validate()

_set_min_gas()[source]

sets the minimum gas volume for this tank based on the min_gas rule provided

Keyword Arguments:
<none>
Returns:
float – minimum gas volume in liter
Raise:
<nothing>
__deepcopy__(memo)[source]

deepcopy method will be called by copy.deepcopy

Used for “cloning” the object into another new object.

Keyword Arguments:
memo:– not used here
Returns:
Tank – Tank object copy of itself
Raise:
<nothing>
calculate_real_volume(volume=None, pressure=None, f_o2=None, f_he=None, temp=15)[source]

Calculate the real gas volume of the tank (in liter) based on Van der waals equation: (P+n2.a/V2).(V-n.b)=n.R.T

Keyword arguments:
volume:(float) – Volume of the tank in liter optional : if not provided, use self.volume
pressure:(float) – Pressure of the tank in bar optional : if not provided, use self.pressure
f_o2:(float) – fraction of O2 in the gas optional : if not provided, use self.f_o2
f_he:(float) – fraction of He in the gas optional : if not provided, use self.f_he
Returns:
float – total gas volume of the tank in liter
Raise:
<nothing>
__str__()[source]

Return a human readable name of the tank

Keyword arguments:
<none>
Returns:
str – name of the tank in the form:
“Air” “Nitrox 80” ...
Raise:
<nothing>
__unicode__()[source]

Return a human readable name of the tank in unicode

Keyword arguments:
<none>
Returns:
str – name of the tank in the form:
“Air” “Nitrox 80” ...
Raise:
<nothing>
__cmp__(othertank)[source]

Compare a tank to another tank, based on MOD

Keyword arguments:
othertank (Tank) – another tank object
Returns:
integer – result of cmp()
Raise:
<nothing>
dumps_dict()[source]

dumps the Tank object in json format

Keyword arguments:
<none>
Returns:
string – json dumps of Tank object
Raise:
TypeError : if Tank is not serialisable
loads_json(input_json)[source]

loads a json structure and update the tank object with the new values.

This method can be used in http PUT method to update object value

Keyword arguments:
input_json:(string) – the json structure to be loaded
Returns:
<none>
Raise:
  • ValueError : if json is not loadable

  • InvalidGas – When proportions of gas exceed

    100% for example (or negatives values)

  • InvalidMod – if mod > max mod based on max_ppo2

    or ABSOLUTE_MAX_MOD.

    ABSOLUTE_MAX_MOD is a global settings which can not be exceeded.

  • InvalidTank – when pressure or tank size exceed maximum

    values or are incorrect (like negatives) values

_calculate_mod(max_ppo2)[source]

calculate and returns mod for a given ppo2 based on this tank info result in meter

Keyword arguments:
max_ppo2:– maximum ppo2 accepted (float). Any value accepted, but should be > 0.0
Returns:
integer – Maximum Operating Depth in meter
Raise:
<nothing>
_validate()[source]

Test the validity of the tank informations inside this object if validity check fails raise an Exception ‘InvalidTank’

Keyword arguments:
<nothing>
Returns:
<nothing>
Raise:
  • InvalidGas – When proportions of gas exceed

    100% for example (or negatives values)

  • InvalidMod – if mod > max mod based on max_ppo2

    or ABSOLUTE_MAX_MOD.

    ABSOLUTE_MAX_MOD is a global settings which can not be exceeded.

  • InvalidTank – when pressure or tank size exceed maximum

    values or are incorrect (like negatives) values

automatic_name()[source]

returns a Human readable name for the gaz and tanks Different possibilities: Air, Nitrox, Oxygen, Trimix, Heliox

Keyword arguments:
<none>
Returns:
str – name of the tank in the form:
“Air” “Nitrox” ...
Raise:
<nothing>
get_tank_info()[source]

returns tank infos : size, remaining vol example of tank info: 15l-90% (2800/3000l)

Keyword arguments:
<none>
Returns:
str – infos of the tank in the form:
“12.0l-100.0% (2423.10/2423.10l)” ...
Raise:
<nothing>
get_mod(max_ppo2=None)[source]

return mod (maximum operating depth) in meter if no argument provided, return the mod based on the current tank (and configured max_ppo2) if max_ppo2 is provided, returns the (new) mod based on the given ppo2

Keyword arguments:
max_ppo2:(float) – ppo2 for mod calculation
Returns:
float – mod in meter
Raise:
<nothing>
get_min_od(min_ppo2=0.16)[source]

return in meter the minimum operating depth for the gas in the tank return 0 if diving from/to surface is ok with this gaz

Keyword arguments:
min_ppo2:(float) – minimum tolerated ppo2
Returns:
float – minimum operating depthin meter
Raise:
<nothing>
get_mod_for_given_end(end)[source]

calculate a mod based on given end and based on gaz inside the tank

Note

end calculation is based on narcotic index for all gases.

By default, dipplanner considers that oxygen is narcotic (same narcotic index than nitrogen)

All narcotic indexes can by changed in the config file, in the [advanced] section

Keyword arguments:
end:(int) – equivalent narcotic depth in meter
Returns:
int – mod: depth in meter based on given end
Raise:
<nothing>
get_end_for_given_depth(depth)[source]

calculate end (equivalent narcotic depth) based on given depth and based on gaz inside the tank

Note

end calculation is based on narcotic index for all gases.

By default, dipplanner considers that oxygen is narcotic (same narcotic index than nitrogen)

All narcotic indexes can by changed in the config file, in the [advanced] section

Keyword arguments:
depth – int – in meter
Returns:
end – int – equivalent narcotic depth in meter
Raise:
<nothing>
consume_gas(gas_consumed)[source]

Consume gas inside this tank

Keyword arguments:
gas_consumed:(float) – gas consumed in liter
Returns:
float – remaining gas in liter
Raise:
<nothing>
refill()[source]

Refill the tank

Keyword arguments:
<none>
Returns:
float – remaining gas in liter
Raise:
<nothing>
check_rule()[source]

Checks the rule agains the remaining gas in the tank

Keyword arguments:
gas_consumed:(float) – gas consumed in liter
Returns:
bool – True is rule OK
False if rule Not OK
Raise:
<nothing>

model: buhlmann

Exceptions

Defines Exceptions for buhlmann model

exception dipplanner.model.buhlmann.model_exceptions.ModelException(description)[source]

Generic Model Exception

__init__(description)[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>
exception dipplanner.model.buhlmann.model_exceptions.ModelStateException(description)[source]

Model State Exception

__init__(description)[source]

constructor : call the upper constructor and set the logger

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>

compartment

Defines a Buhlmann compartment

class dipplanner.model.buhlmann.compartment.Compartment(h_he=None, h_n2=None, a_he=None, b_he=None, a_n2=None, b_n2=None)[source]

Buhlmann compartment class

Attributes:
  • h_he: helium halftime
  • h_n2: nitrogen halftime
  • a_he: helium : a coefficient
  • a_n2: nitrogen : a coefficient
  • b_he: helium : b coefficient
  • b_n2: nitrogen : b coefficient
  • k_he: helium : k coefficient (calculated)
  • k_n2: nitrogen : k coefficient (calculated)
  • pp_he: partial pressure of helium
  • pp_n2: partial pressure of nitrogen
__init__(h_he=None, h_n2=None, a_he=None, b_he=None, a_n2=None, b_n2=None)[source]

Constructor for Compartment can be called without params, in this case, does not initiate anything can be called with time params and coef and in this case initate the compartment time constants

Keyword arguments:
h_he:(float) – helium halftime
h_n2:(float) – nitrogen halftime
a_he:(float) – helium: a coefficient
b_he:(float) – helium: b coefficient
a_n2:(float) – nitrogen: a coefficient
b_n2:(float) – nitrogen: b coefficient
Returns:
<nothing>
Raise:
see set_compartment_time_constants method
__deepcopy__(memo)[source]

deepcopy method will be called by copy.deepcopy

Used for “cloning” the object into another new object.

Keyword Arguments:
memo:– not used here
Returns:
Compartment – Compartment object copy of itself
Raise:
<nothing>
__str__()[source]

Return a human readable name of the segment

Keyword Arguments:
<none>
Returns:
str – string representation of the compartment
ex: “He:0.0 N2:19.9991340314 gf:0.3 mv_at:2.98611129437 max_amb:15.8731803417 MV:6.6973840088”
Raise:
<nothing>
__unicode__()[source]

Return a human readable name of the segment in unicode

Keyword Arguments:
<none>
Returns:
ustr – unicode string representation of the compartment
ex: u”He:0.0 N2:19.9991340314 gf:0.3 mv_at:2.98611129437 max_amb:15.8731803417 MV:6.6973840088”
Raise:
<nothing>
set_compartment_time_constants(h_he, h_n2, a_he, b_he, a_n2, b_n2)[source]

Sets the compartment’s time constants

Keyword arguments:
h_he:(float) – Helium Halftime
h_n2:(float) – Nitrogen Halftime
a_he:(float) – Helium : a coefficient
b_he:(float) – Helium : b coefficient
a_n2:(float) – Nitrogen : a coefficient
b_n2:(float) – Nitrogen : b coefficient
Returns:
<nothing>
Raise:
<nothing>
set_pp(pp_he, pp_n2)[source]

Sets partial pressures of He and N2

Keyword arguments:
pp_he:(float) – partial pressure of Helium
pp_n2:(float) – partial pressure of Nitrogen
Return:
<nothing>
Raise:
<nothing>
const_depth(pp_he_inspired, pp_n2_inspired, seg_time)[source]

Constant depth calculations. Uses instananeous equation: P = Po + (Pi - Po)(1-e^-kt) store the new values in self.pp_he and self.pp_n2

Keyword arguments:
pp_he_inspired:(float) – partial pressure of inspired helium
pp_n2_inspired:(float) – partial pressure of inspired nitrogen
seg_time:(float) – segment time in seconds
Return:
<nothing>
Raise:
ModelStateException – if pp or time < 0
asc_desc(pp_he_inspired, pp_n2_inspired, rate_he, rate_n2, seg_time)[source]

Ascend or descent calculations. Uses equation : P=Pio+R(t -1/k)-[Pio-Po-(R/k)]e^-kt store the new values in self.pp_he and self.pp_n2

Keyword arguments:
pp_he_inspired:(float) – partial pressure of inspired helium
pp_n2_inspired:(float) – partial pressure of inspired nitrogen
rate_he:(float) – rate of change of pp_he
rate_n2:(float) – rate of change of pp_n2
seg_time:(float) – segment time in seconds
Return:
<nothing>
Raise:
ModelStateException – if pp or time < 0
get_m_value_at(pressure)[source]

Gets M-Value for given ambient pressure using the Buhlmann equation Pm = Pa/b +a where:

  • Pm = M-Value pressure,
  • Pa = ambiant pressure
  • a,b co-efficients

Note

Not used for decompression but for display of M-value limit line

Note

this method does not use gradient factors.

Keyword arguments:
pressure:(float) – ambient pressure (in bar)
Return:
float – M_value: maximum tolerated pressure in bar
Raise:
<nothing>
get_max_amb(gf)[source]

Gets Tolerated Absolute Pressure for the compartment for current pp of He and N2

Keyword arguments:
gf:(float) – gradient factor : 0.1 to 1.0, typical 0.2 - 0.95
Return:
float – maximum tolerated pressure (absolute) in bar
Raise:
<nothing>
get_mv(p_amb)[source]

Gets M-Value for a compartment, given an ambient pressure

Keyword arguments:
p_amb:(float) – ambiant pressure
Return:
float – M-value
Raise:
<nothing>

gradient

gradient module

class dipplanner.model.buhlmann.gradient.Gradient(gf_low, gf_high)[source]

Defines a Gradient Factor object

A GF Object maintains a low and high setting and is able to determine a GF for any depth between its initialisation depth (see setGfAtDepth()) and the surface.

Attributes (self.):
  • gf_low (float) – low Gradient factor, from 0.0 to 1.0
  • gf_high (float) – high Gradient factor, from 0.0 to 1.0
  • gf (float) – current gf
  • gf_slope (float) – slope of the linear equation
  • gf_set (float) – Indicates that gf Slope has been initialised
__init__(gf_low, gf_high)[source]

Constructor for Gradient object

Keyword arguments:
gf_low:(float) – low Gradient factor, from 0.0 to 1.0
gf_high:(float) – high Gradient factor, from 0.0 to 1.0
Returns:
<nothing>
Raise:
ValueError – if either gf_low of gf_high has wrong value
__deepcopy__(memo)[source]

deepcopy method will be called by copy.deepcopy

Used for “cloning” the object into another new object.

Keyword Arguments:
memo:– not used here
Returns:
Gradient – Gradient object copy of itself
Raise:
<nothing>
get_gradient_factor()[source]

Returns current GF with bounds checking if gf < gf_low, returns gf_low

Keyword arguments:
<none>
Returns:
float – gf
Raise:
<nothing>
set_gf_at_depth(depth)[source]

Sets the gf for a given depth. Must be called after setGfSlope() has initialised slope

Keyword arguments:
depth:(float) – current depth, in meter
Returns:
<nothing>
Raise:
<nothing>
set_gf_slope_at_depth(depth)[source]

Set gf Slope at specified depth. Typically called once to initialise the GF slope.

Keyword arguments:
depth:(float) – current depth, in meter
Returns:
<nothing>
Raise:
<nothing>
set_gf_low(value)[source]

Sets gf low setting

Keyword arguments:
value:(float) – low Gf, between 0.0 and 1.0
Returns:
<nothing>
Raise:
ValueError – if either gf_low of gf_high has wrong value
set_gf_high(value)[source]

Sets gf high setting

Keyword arguments:
value:(float) – high Gf, between 0.0 and 1.0
Returns:
<nothing>
Raise:
ValueError – if gf_high has wrong value
__str__

x.__str__() <==> str(x)

oxygen toxicity

Oxygen Toxicity model

class dipplanner.model.buhlmann.oxygen_toxicity.OxTox[source]

Defines a Oxygen Toxicity model

Attributes:
__init__()[source]

Constructor for OxTox class

Keyword arguments:
<none>
Returns:
<nothing>
Raise:
<nothing>
__deepcopy__(memo)[source]

deepcopy method will be called by copy.deepcopy

Used for “cloning” the object into another new object.

Keyword Arguments:
memo:– not used here
Returns:
Gradient – Gradient object copy of itself
Raise:
<nothing>
add_o2(time, pp_o2)[source]

Adds oxygen load into model.

Uses NOAA lookup table to add percentage based on time and ppO2. Calculate OTU using formula OTU= T * (0.5/(pO2-0.5))^-(5/6)

this OTU formula need T (time) in minutes, so we need to convert the time in second to minutes while using this formula

Keyword arguments:
pp_o2:(float) – partial pressure of oxygen
time:(float) – time of segment (in seconds)
Returns:
<nothing>
Raise:
<nothing>
remove_o2(time)[source]

Removes oxygen load from model during surface intervals

Keyword arguments:
time:(float) – time of segment (in seconds)
Returns:
<nothing>
Raise:
<nothing>
__str__

x.__str__() <==> str(x)

model

Buhlmann model module

Contains: Model – class

class dipplanner.model.buhlmann.model.Model[source]

Represents a Buhlmann model. Composed of a tissue array of Compartment[] Has an OxTox and Gradient object

Can throw a ModelStateException propagated from a Compartment if pressures or time is out of bounds.

Models are initialised by initModel() if they are new models, or validated by validateModel() if they are rebuild from a saved model.

The model is capable of ascending or descending via ascDec() using the ascDec() method of Compartment, or accounting for a constant depth using the constDepth() method of Compartment.

Attributes:
  • tissues (list)– a list of Compartments
  • gradient (Gradient) – gradient factor object
  • ox_tox (OxTox) – OxTox object
  • metadata (str) – Stores infos about where the model was created
  • deco_model (str) – name of the deco model
  • units (str) – only ‘metric’ allowed
  • COMPS (int) – static info : number of compartments
  • MODEL_VALIDATION_SUCCESS (int) – static const for validation success
  • MODEL_VALIDATION_FAILURE (int) – static const for validation failure
__init__()[source]

Constructor for model class

Keyword arguments:
<none>
Returns:
<nothing>
Raise:
<nothing>
__deepcopy__(memo)[source]

deepcopy method will be called by copy.deepcopy

Used for “cloning” the object into another new object.

Keyword Arguments:
memo:– not used here
Returns:
Model – Model object copy of itself
Raise:
<nothing>
__str__()[source]

Return a human readable name of the segment

Keyword Arguments:
<none>
Returns:
str – string representation of the model
Raise:
<nothing>
__unicode__()[source]

Return a human readable name of the segment in unicode

Keyword Arguments:
<none>
Returns:
ustr – unicode string representation of the model
Raise:
<nothing>
init_gradient()[source]

Initialise the gradient attribute uses the default settings parameters for gf_low and high

Keyword arguments:
<none>
Returns:
<nothing>
Raise:
<nothing>
set_time_constants(deco_model='ZHL16c')[source]

Initialize time constants in buhlmann tissue list Only for metric values

Keyword arguments:
deco_model:(str) – “ZHL16b” or “ZHL16c”
Returns:
<nothing>
Raise:
<nothing>
validate_model()[source]

Validate model - checks over the model and looks for corruption

This is needed to check a model that has been loaded from XML Resets time constants

Keyword arguments:
<none>
Returns:
self.MODEL_VALIDATION_SUCCESS – if OK self.MODEL_VALIDATION_FAILURE – if not OK
Raise:
<nothing>
control_compartment()[source]

Determine the controlling compartment at ceiling (1-16)

Keyword arguments:
<none>
Returns:
integer – reference number of the controlling
compartment (between 1 to 16)
Raise:
<nothing>
ceiling()[source]

Determine the current ceiling depth

Keyword arguments:
<none>
Returns:
float – ceiling depth in meter
Raise:
<nothing>
ceiling_in_pabs()[source]

Determine the current ceiling

Keyword arguments:
<none>
Returns:
float – ceiling in bar (absolute pressure)
Raise:
<nothing>
m_value(pressure)[source]

Determine the maximum M-Value for a given depth (pressure)

Keyword arguments:
pressure:(float) – in bar
Returns
float – max M-Value
Raise:
<nothing>
const_depth(pressure, seg_time, f_he, f_n2, pp_o2)[source]

Constant depth profile. Calls Compartment.constDepth for each compartment to update the model.

Keyword arguments:

pressure:(float)– pressure of this depth of segment in bar
seg_time:(float) – Time of segment in seconds
f_he:(float) – fraction of inert gas Helium in inspired gas mix
f_n2:(float) – fraction of inert gas Nitrogen in inspired gas mix
pp_o2:(float) – For CCR mode, partial pressure of oxygen in bar. If == 0.0, then open circuit
Returns:
<nothing>
Raise:
ModelStateException
asc_desc(start, finish, rate, f_he, f_n2, pp_o2)[source]

Ascend/Descend profile. Calls Compartment.asc_desc to update compartments

Keyword arguments:

start:(float) – start pressure of this segment in bar (WARNING: not meter ! it’s a pressure)
finish:(float) – finish pressure of this segment in bar (WARNING: not meter ! it’s a pressure)
rate:(float) – rate of ascent or descent in m/s
f_he:(float) – Fraction of inert gas Helium in inspired gas mix
f_n2:(float) – Fraction of inert gas Nitrogen in inspired gas mix
pp_o2:(float) – For CCR mode, partial pressure of oxygen in bar. If == 0.0, then open circuit
Returns:
<nothing>
Raise:
ModelStateException

Exceptions

Base Class for exceptions for dipplanner module

exception dipplanner.dipp_exception.DipplannerException(description)[source]

Base exception class for dipplanner

__init__(description)[source]

DipplannerException constructor

Keyword Arguments:
description:(str) – text describing the error
Return:
<nothing>
Raise:
<nothing>
__str__()[source]

String representing the object

Keyword Arguments:
<none>
Return:
str – a string describing the Exception
Raise:
<nothing>
__unicode__()[source]

unicode string representing the object

Keyword Arguments:
<none>
Return:
ustr – a unicode string describing the Exception
Raise:
<nothing>

tools

tools modules

This modules contains some utility functions like unit conversions, etc...

dipplanner.tools.safe_eval_calculator(text_to_eval)[source]

Small an safe eval function usable only for simple calculation (only the basic operators)

Keyword Arguments:
text_to_eval:(str) – the text (formula) that should be evaluated
Returns:
float – the result of the calculation.
Raise:
ValueError: when given expression is not constitued of only
numbers and operators

SyntaxError: when the given expression is incorrect

dipplanner.tools.seconds_to_mmss(seconds)[source]

Convert a value in seconds into a string representing the time in minutes and seconds (like 2:06) It does returns only minutes and seconds, not hours, minutes and seconds

Keyword Arguments:
seconds:(float) – the duration in seconds
Returns:
str – the time in minutes and seconds
ex: ” 23:45” “112:33” ...
Raise:
ValueError: when bad time values
dipplanner.tools.seconds_to_hhmmss(seconds)[source]

Convert a value in seconds into a string representing the time in hour:minutes and seconds like 22:34:44

Keyword Arguments:
seconds:(float) – the duration in seconds
Returns:
str – the time in hour - minutes and seconds
ex: “00:23:45” “01:52:33”
Raise:
ValueError: when bad time values is given
dipplanner.tools.altitude_or_depth_to_absolute_pressure(altitude_or_depth)[source]

output absolute pressure for give “depth” in meter.

  • If depth is positive it’s considered altitude depth
  • If depth is negative it’s considered depth in water
Keyword Arguments:
altitude_or_depth:
 (float (signed)) – in meter
Returns:
float – resulting absolute pressure in bar
Raise:
ValueError if altitude > 10000m
dipplanner.tools.altitude_to_pressure(altitude)[source]

Convert a given altitude in pressure in bar uses the formula: p = 101325.(1-2.25577.10^-5.h)^5.25588

Keyword Arguments:
altitude:(float) – current altitude in meter
Returns:
float – resulting pressure in bar
Raise:
ValueError: when bad altitude is given (bad or <0 or > 10000 m)
dipplanner.tools.depth_to_pressure(depth, method='complex')[source]

Calculates depth pressure based on depth using a more complex method than only /10

Keyword Arguments:
depth:(float) – in meter
Returns:
float – depth pressure in bar
Raise:
<nothing>
dipplanner.tools.pressure_to_depth(pressure, method='complex')[source]

Calculates depth based on give pressure using a more complex method than only x10

Keyword Arguments:
pressure:(float) – pressure in bar
Returns:
float – depth in meter
Raise:
<nothing>
dipplanner.tools.calculate_pp_h2o_surf(temperature=20)[source]

Calculates and return vapor pressure of water at surface using Antoine equation (http://en.wikipedia.org/wiki/Vapour_pressure_of_water)

Keyword Arguments:
temperature:(float) [OPTIONNAL] – in ° Celcius
Returns:
float – ppH2O in bar
Raise:
ValueError – when temperature exceed maximum value for calculation
(>=374 °C)
dipplanner.tools.convert_bar_to_psi(value)[source]

SI –> imperial pressure conversion function

Keyword Arguments:
value:(float) – pressure in bar
Returns:
float – pressure in psi
Raise:
<nothing>
dipplanner.tools.convert_psi_to_bar(value)[source]

imperial –> SI pressure conversion function

Keyword Arguments:
value:(float) – pressure in psi
Returns:
float – pressure in bar
Raise:
<nothing>
dipplanner.tools.convert_liter_to_cubicfeet(value)[source]

SI –> imperial volume conversion function

Keyword Arguments:
value:(float) – volume in liter
Returns:
float – volume in cubicfeet
Raise:
<nothing>
dipplanner.tools.convert_cubicfeet_to_liter(value)[source]

imperial –> SI volume conversion function

Keyword Arguments:
value:(float) – volume in cubicfeet
Returns:
float – volume in liter
Raise:
<nothing>
dipplanner.tools.convert_meter_to_feet(value)[source]

SI –> imperial distance conversion function

Keyword Arguments:
value:(float) – volume in cubicfeet
Returns:
float – volume in liter
Raise:
<nothing>
dipplanner.tools.convert_feet_to_meter(value)[source]

imperial –> SI distance conversion function

Keyword Arguments:
value:(float) – volume in cubicfeet
Returns:
float – volume in liter
Raise:
<nothing>

main

main dipplanner module for command line usage.

This module is used by the only “executable” of the project: bin/dipplanner (which is an empty shell)

runs in command line and output resulting dive profile also initiate log files

Todo

logger.tutu(“message %s”, allo) au lieu de logger.tutu(“message %s” % allo)

dipplanner.main.activate_debug()[source]

setup the default debug parameters

it’s mainly used for test cases who needs also logging to be set

Keyword Arguments:
<none>
Return:
<nothing>
Raise:
<nothing>
dipplanner.main.activate_debug_for_tests()[source]

setup the default debug parameters

it’s mainly used for test cases who needs also logging to be set

Keyword Arguments:
<none>
Return:
<nothing>
Raise:
<nothing>
dipplanner.main.main(cli_arguments=['/home/docs/checkouts/readthedocs.org/user_builds/dipplanner/envs/pyconfr/bin/sphinx-build', '-E', '-b', 'html', '.', '_build/html'])[source]

main uses the parameters, tanks and dives given in config file(s) and/or command line, calculates the dives and return the output in stdout.

Keyword Arguments:
arguments (list of string) – list of arguments, like sys.argv
Return:
<nothing>
Raise:
<nothing>

settings

Global settings for dipplannerand their default values

All the settings can be changed by dipplanner command-line documentation and/or dipplanner config file documentation

dipplanner.settings.FRESH_WATER_DENSITY = 1.0

water density kg/l

dipplanner.settings.SEA_WATER_DENSITY = 1.03

water density kg/l

dipplanner.settings.ABSOLUTE_MAX_PPO2 = 2.0

in bar

dipplanner.settings.ABSOLUTE_MIN_PPO2 = 0.16

in bar

dipplanner.settings.ABSOLUTE_MAX_TANK_PRESSURE = 300

in bar

dipplanner.settings.ABSOLUTE_MAX_TANK_SIZE = 40

in liter

dipplanner.settings.SURFACE_TEMP = 20

Temperature at surface. Used to calculate PP_H2O_SURFACE

dipplanner.settings.HE_NARCOTIC_VALUE = 0.23

helium narcotic value

dipplanner.settings.N2_NARCOTIC_VALUE = 1.0

nitrogen narcotic value

dipplanner.settings.O2_NARCOTIC_VALUE = 1.0

oxygen narcotic value

dipplanner.settings.AR_NARCOTIC_VALUE = 2.33

argon narcotic value

dipplanner.settings.STOP_DEPTH_INCREMENT = 3

in meter

dipplanner.settings.LAST_STOP_DEPTH = 3

in meter : last stop before surfacing

dipplanner.settings.STOP_TIME_INCREMENT = 1

in second

dipplanner.settings.FORCE_ALL_STOPS = True

once deco stop begun, force to stop to each deco depth stop

dipplanner.settings.AMBIANT_PRESSURE_SEA_LEVEL = 1.01325

surface pressure (in bar)

dipplanner.settings.METHOD_FOR_DEPTH_CALCULATION = 'complex'

either simple (/10) or complex

dipplanner.settings.TRAVEL_SWITCH = 'late'

“late” or “early”

dipplanner.settings.FLIGHT_ALTITUDE = 2450

in meter practicly, this value can not be bigger than about 2850m because breathing air at 0m will only ‘prepare the body’ to a decompression until this value. To go higher, another ‘stop’ is needed between.

dipplanner.settings.TEMPLATE = 'default-color.tpl'

template should be in templates/ directory

dipplanner.settings.DECO_MODEL = 'ZHL16c'

ZHL16c or ZHL16b

dipplanner.settings.WATER_DENSITY = 1.03

water density kg/l

dipplanner.settings.AMBIANT_PRESSURE_SURFACE = 1.01325

surface pressure (in bar)

dipplanner.settings.DEFAULT_MAX_PPO2 = 1.6

in bar

dipplanner.settings.DEFAULT_MIN_PPO2 = 0.21

in bar

dipplanner.settings.DEFAULT_MAX_END = 30

in meter

dipplanner.settings.DIVE_CONSUMPTION_RATE = 0.2833333333333333

liter/s

dipplanner.settings.DECO_CONSUMPTION_RATE = 0.2

liter/s

dipplanner.settings.DESCENT_RATE = 0.3333333333333333

m/s

dipplanner.settings.ASCENT_RATE = 0.16666666666666666

m/s

dipplanner.settings.RUN_TIME = True

Warning

if RUN-TIME is True, the segment duration must include descent time

if the duration is too small dipplanner will raise an error if True: segments represents runtime, if false, segments represents segtime

dipplanner.settings.USE_OC_DECO = True

if True, use enabled gases of decomp in oc or bailout

dipplanner.settings.GF_LOW = 0.3

% between 0.0 and 1.0

dipplanner.settings.GF_HIGH = 0.8

% between 0.0 and 1.0

dipplanner.settings.MULTILEVEL_MODE = False

TO CHECK

dipplanner.settings.AUTOMATIC_TANK_REFILL = True

automatic refill of tanks between dives

gui

dipplanner GUI module.

Starts the GUI

Todo

uniquely name the tanks (in addition of tank_id (int) AND handle Tank references (from tank list) to: current_tank and segment.tank

Actually: each tank is separated

WORK IN PROGRESS (reste en cours: les dumps_dict a modifier)

dipplanner.gui.instanciates_app(mission=None)[source]

defines all the routes and others parameters for the app

dipplanner.gui.start_gui(mission=None, http_host='locahost', http_port=8080)[source]

Starts the html GUI server

REST Api base object

class dipplanner.gui.rest_main_api.ApiBottle[source]

Main API for bottle

REST Api for Mission object

class dipplanner.gui.rest_mission.MissionApiBottle(mission=None)[source]

At this time, there is only one Mission at a time for a dipplanner session (if the user need to work on another mission, he MUST close the current Mission first).

The API reflects this current limitation

get()[source]

GET method for the Mission object Api

returns a json dumps of the mission object.

Keyword Arguments:
<none>
Returns:
resp – response object with the json dump of the mission object
Raise:
<nothing>

Sample usage:

curl -H "Content-Type: application/json" http://localhost:8080/api/v1/mission/
get_status()[source]

returns the actual status of the mission

returns a json object with the current status of the Mission object.

ex:

{ 'status': 'Calculated and Up to date' }
Keyword Arguments:
<none>
Returns:
resp – response object with the status
Raise:
<nothing>
post()[source]

POST method for the Mission object Api

create a new mission an new mission may only be created if the existing mission is empty (api user MUST call DELETE before calling POST)

if a json structure is POSTed with the request, dipplanner will try to load this stucture inside the mission object. A full structure may be given.

Keyword Arguments:
<nothing>
Returns:
resp – response object with the json dump of the newly
created object
Raise:
<nothing>
patch()[source]

PATCH method for the Mission object Api

update the mission object

Keyword Arguments:
<none>
Returns:
resp – response object - HTTP 200 + the patched mission object
Raise:
<nothing>
calculate()[source]

launch the calculation of the mission

returns a json object with the current status of the Mission object (after calculation).

ex:

{ 'status': 'Calculated and Up to date' }
Keyword Arguments:
<none>
Returns:
resp – response object with the status
Raise:
<nothing>
delete(resource_id=None)[source]

DELETE method for the Mission object Api

Keyword Arguments:
<none>
Returns:
resp – response object (empty)
Raise:
<nothing>

REST Api for Dive object

class dipplanner.gui.rest_dive.DiveApiBottle(mission=None)[source]

api for dives inside the mission object

get(resource_id=None)[source]

GET method for the Dive object Api

returns a json dumps of the dives in the current mission object.

Keyword Arguments:
resource_id:(str) – either a number representing the position of the dive (first dive is dive 1) or the name of the dive
Returns:
resp – response object with the json dump of the dives
Raise:
<nothing>
post()[source]

POST method for the Dive object Api

create a new dive for this mission

if a json structure is POSTed with the request, dipplanner will try to load this structure while instanciating the new dive A full dive structure may be given, but a partial structure will also be allowed. (all non given parameters will use the default values)

Keyword Arguments:
<nothing>
Returns:
resp – response object with the json dump of the newly
created object
Raise:
<nothing>
patch(resource_id=None)[source]

PATCH method for the Dive object Api

update the dive object

if no resource_id is given, returns 404 if resource_id is given, try to patch the resource and returns the entive patched Dive with code 200 OK

Keyword Arguments:
resource_id:–str : number of the dive, starting by 1
Returns:
resp – response object - HTTP 200 + the list of remaining dives
after the deletion
Raise:
<nothing>
delete(resource_id=None)[source]

DELETE method for the Dive object Api

if no resource_id is given, all the dives will be deleted. If resource_id is given and exists, only one dive will be deleted

Keyword Arguments:
resource_id:–str : number of the dive, starting by 1
Returns:
resp – response object - HTTP 200 + the list of remaining dives
after the deletion
Raise:
<nothing>

REST Api for Tank object

class dipplanner.gui.rest_tank.TankApiBottle(mission=None)[source]

api for dives inside the mission object

get(tank_id=None)[source]

GET method for the Tank object Api

returns a json dumps of the tanks in the current mission object.

Keyword Arguments:
resource_id:(int) – number of the dive, first dive is dive 1
Returns:
resp – response object with the json dump of the dives
Raise:
<nothing>
post()[source]

POST method for the Tank object Api

create a new tank for this dive

if a json structure is POSTed with the request, dipplanner will try to load this structure while instanciating the new tank A full Tank structure may be given, but a partial structure will also be allowed. (all non given parameters will use the default values)

Keyword Arguments:
<nothing>
Returns:
resp – response object with the json dump of the newly
created object
Raise:
<nothing>
patch(tank_id=None)[source]

PATCH method for the Tank object Api

update the tank object

if no tank_id is given, returns 404 if tank_id is given, try to patch the resource and returns the entive patched Tank with code 200 OK

Keyword Arguments:
dive_id:– (str): number of the tank, starting by 1
tank_id:–str : number of the dive, starting by 1
Returns:
resp – response object - HTTP 200 + the list of remaining dives
after the deletion
Raise:
<nothing>
delete(tank_id=None)[source]

DELETE method for the Tank object Api

if no resource_id is given, all the tanks will be deleted. If resource_id is given and exists, only one tank will be deleted

Keyword Arguments:
tank_id:–str : number of the tank, starting by 1
Returns:
resp – response object - HTTP 200 + the list of remaining tanks
after the deletion
Raise:
<nothing>

bottle HTTP error handling

class dipplanner.gui.error_api.ErrorApiBottle[source]

Error API for bottle

error404(code)[source]

Handle 404 error and returns a json structure instead of classic html structure

error405(code)[source]

Handle 405 error (method not allowed) and returns a json structure instead of classic html structure