gliderflight package

Submodules

gliderflight.gliderflight module

class gliderflight.gliderflight.Calibrate(xtol=0.0001)

Bases: object

Generic class providing the calibration machinery for steady-state and dynamic flight models

Basic steps are to

  • set input data using the set_inputdata() method,
  • mask data that should not take part in the minimisation routine (data near the dive apices, at the start of the dive, pycnoclines, etc.
  • run the calibration.

Logical operators are used to mask data:

OR, AND, and NAND are implemented, and work on the mask

Parameters:xtol (float) – tolerance in error in the parameters to be minimised.
AND(mask)

Logical AND

The new mask is the intersection (AND) of the existing mask and supplied mask

Parameters:mask (array of bool or bool) –
NAND(mask)

Logical NAND

The new mask is the inverted intersection of the existing mask and the supplied mask. :param mask: :type mask: array of bool or bool

OR(mask)

Logical OR

The new mask is the union (OR) of the existing mask and the supplied mask.

Parameters:mask (array of bool or bool) –
calibrate(*p, constraints=('dhdt', ), weights=None, verbose=False)

Calibrate model

Given one or more model coefficients and specifications of measurements to use, this method calibrates the model, using the self.cost_funtion() method. The interface is flexible so any parameter that is used in the model description can be optimised for. Also the velocity component or combination of components can be set.

Parameters:
  • p (variable length parameters) – variable length of parameter names to be optimised.
  • constraints (list/tuple of str) – names of measured velocities against which glider flight is evaluated. These must be present in the dictionary supplied by the set_input_data() method.
  • weights (None or array-like) – weights. If more than one constraint is provided, weights sets their relative importance.
  • verbose (bool) – prints intermediate results during optimising
Returns:

rv – the result of the optimisation routine

Return type:

dict

Examples

>>> # calibrating for mass and drag coefficient (implicitly using depth-rate) and printing
>>> # intermediate results (mainly for debugging/progress monitoring)
>>> results = gm.calibrate("mg", "Cd0", verbose=True)
>>> print(results)
    {'mg': 70.00131, 'Cd0':0.145343}
>>>
>>> # Also calibrating the lift coefficient using measured incident water velocity
>>> results = gm.calibrate("mg", "Cd0", "ah", constraints=('dhdt', 'U_relative'), weights=(0.5, 0.5), verbose = True)
>>> print(results)
    {'mg': 70.00131, 'Cd0':0.145343, 'ah':3.78787}

Notes

The default measurement to evaluate the model against is the depth rate dhdt. If not specified when setting the input data using the set_input_data() method, it is computed automatically. Other velocity components that are to be used to calibrate the model have to be set specifically.

cost_function(x, parameters, constraints, weights, verbose)

Cost-function used to optimise parameters

This method first sets the parameters which are to be optimised for, and then computes the glider flight. A “cost” is computed from relatively weighted constraints.

Parameters:
  • x (array) – values of the parameters to be varied
  • parameters (list of str) – parameter names
  • constraints (tuple or list of str) – names of measured velocities against which glider flight is evaluated. These must be present in the dictionary supplied by the set_input_data() method.
  • weights (None or array-like of float) – weights of constraints. If more than one constraint is provided, weights sets their relative importance.
  • verbose (bool) – print intermediate results during optimising if set True
Returns:

mse – RMS value of exposed measurements (not masked)

Return type:

float

Different constraints can be applied, and if more than one, their relative contribution is set with weights.

Valid options:

dhdt : the error is computed from the difference between modelled w and observed dhdt w_relative : the error is computed from the difference between modelled w and w_relative (set separately to data dictionary) u_relative : the error is computed from the difference between modelled u and u_relative (set separately to data dictionary) U_relative : the error is computed from the difference between modelled U and U_relative (set separately to data dictionary)

depth : (experimental) the error is computed from the modelled and observed glider depth.

set_input_data(time, pressure, pitch, buoyancy_change, density, dhdt=None, u_relative=None, w_relative=None, U_relative=None, **kwds)

Sets the input data time pressure pitch buoyancy_change in-situ density and optionally u_relative and w_relative

Parameters:
  • time (array) – time (s)
  • pressure (array) – pressure (Pa)
  • pitch (array) – pitch (rad)
  • buoyancy_change (array) – buoyancy change reported by the glider (cc)
  • ensity (array) – in-situ density (kg m${-3}$)
  • dhdt (array, optional) – depth rate m s$^{-1}$ (if not given it is computed from pressure)
  • u_relative (array, optional) – measured horizontal speed m s$^{-1}$
  • w_relative (array, optional) – measured vertical speed m s$^{-1}$
  • U_relative (array) – measured speed through water m s$^{-1}$

Notes

A mask is automatically created (including all data) when this method is called.

set_mask(mask)

Set a mask

Masks those data that should not be used to calibrate.

Parameters:mask (array of bool or bool) –

Notes

If already set ones (after set_input_data(), then mask can be True or False to set all elements in mask.

class gliderflight.gliderflight.Diagnostics(t, rho, U, FB, FD, FL)

Bases: tuple

FB

Alias for field number 3

FD

Alias for field number 4

FL

Alias for field number 5

U

Alias for field number 2

rho

Alias for field number 1

t

Alias for field number 0

class gliderflight.gliderflight.DynamicCalibrate(rho0=None, k1=0.02, k2=0.92, dt=None, alpha_linear=90, alpha_stall=90, max_depth_considered_surface=0.5, max_CPUs=None)

Bases: gliderflight.gliderflight.DynamicGliderModel, gliderflight.gliderflight.Calibrate

Dynamic glider flight model, with calibration interface

class gliderflight.gliderflight.DynamicGliderModel(dt=None, rho0=None, k1=0.2, k2=0.92, alpha_linear=90, alpha_stall=90, max_depth_considered_surface=0.5, max_CPUs=None)

Bases: gliderflight.gliderflight.ModelParameters, gliderflight.gliderflight.GliderModel

Dynamic glider model implementation

This class inherits from ModelParameters and GliderModel. The physcis are provided by GliderModel. Interacting with ModelParameters is done through methods provided by ModelParameters.

Parameters:
  • dt (float or None) – time step (s)
  • rho0 (float) – background density (kg m$^{-3}$)
  • k1 (float) – added mass fraction in longitudinal direction
  • k2 (float) – added mass fraction perpendicular to longitudinal direction
  • alpha_linear (float) – angle (rad) up to which the parameterisation is considered linear
  • alpha_stall (float) – angle (rad) up to which no lift will be generated (stalling angle)
  • max_depth_considered_surface (float) – depth as reported by the pressure sensor which is considered the surface (u=w=0)
  • max_CPUs (int) – maximum number of CPUs to use (clips at system availabel CPUs)

The only method provided by this class that is of interest to the user is solve(). The input to solve is a dictionary with time, pressure, pitch, buoyancy change density.

Methods inherited from ModelParameters can be used to define/set model coefficients, and to copy settings from another model instance.

After solving the model results are available as properties (t, U, wg, w, alpha)

The dynamic model solves the force balances including the intertial forces by numerical integration using a Runge-Kutta scheme. The inertial terms include the added mass terms. The relevant parameters can be set when creating an instance of this class.

Added mass

Added mass terms are specified by the coefficients k1 and k2, which refer to the added mass terms along the principle glider axis (k1) and vertically perpendicular (k2), where k1 and k2 are given as fraction of the glider mass mg.

Examples

>>>dm = DynamicGliderModel(rho0=1024, k1=0.2, k2=0.92, mg=70) >>>dm.define(mg=70) >>>dm.define(Vg=68, Cd0=0.15) >>>dm.solve(dict(time=tctd, pressure=P, pitch=pitch, buoyancy_change=buoyancy_drive, density=density)) >>>print(dm.U)

RK4(h, M, FBg, pitch, rho, at_surface, Cd0, u, w)

Runge-Kutta integration method

Implementation to solve the model using the classic Runge-Kutta integration method.

Parameters:
  • h (float) – time step (s)
  • M (matrix (2x)) – mass (and added mass matrix, inverted)
  • FBg (array) – nett buoyancy force
  • pitch (array) – pitch as recored by glider (rad)
  • rho (array) – in-situ density (kg m$^{-3}$)
  • at_surface (array of bool) – condition whether or not at the surface
  • u (array) – horizontal glider velocity (m s$^{-1}$)
  • w (array) – vertical glider velocity (m s$^{-1}$)
  • Cd0 (array) – Lift coefficient per time step

Notes

The results are not returned as such. The parameters u and w are updated in place.

assemble_results(results, intervals)
compute_inverted_mass_matrix(pitch)

Computes the inverse of the mass matrix

not to be called directly

integrate(data)

integrate system

not to be called directly

process_fun(interval, **arg_funs)
solve(data=None)

Solve the model

Solves the flight model.

Parameters:data (dict or None) – environment data (see Notes)
Returns:modelresult – model result (named tuple with arrays of computed results)
Return type:Modelresult

Notes

The data supplied should contain at least time, pressure, pitch, buoyancy_change and density, as reported by the glider. Depth rate (dhdt) will be added if not already present. Other data are ignored.

The intergration of the model maps the results on the time vector. For this to work successfully it is essential that there are no time duplicates or time reversals. The latter can occur when the system clock is updated with GPS time.

Use the methods remove_duplicate_time_entries() and ensure_monotonicity().

Examples

>>> dm = DynamciGliderModel(dt=1, k1=0.2, k2=0.98, rho0=1024)
>>> dm.define(mg=70, Vg=68)
>>> data = dict(time=time, pressure=P, pitch=pitch, buoyancy_change=vb, density=rho)
>>> dm.solve(data)
>>> plot(dm.U)
stall_factor(alpha)
class gliderflight.gliderflight.GliderModel(rho0=None)

Bases: object

Common glider model class

This class, meant to be subclassed, implements the physical glider model description

G = 9.81
RHO0 = 1024
U

incident water velocity (m s$^{-1}$)

alpha

angle of attack (rad)

compute_FB_and_Fg(pressure, rho, Vbp, mg=None, Vg=None)

Computes the vertical forces FB and Fg

Parameters:
  • pressure (array-like or float) – pressure (Pa)
  • rho (array-like or float) – in-situ density (kg m$^{-3}$)
  • Vbp (array-like or float) – volume of buoyancy change (m$^{-3}$)
  • mg (array-like, float or None) – mass of glider (kg). If None (default), then self.mg is used for the computation
  • Vg (array-like, float or None) – Volume of glider (m$^{3}$). If None (default), then self.Vg is used for the computation
Returns:

  • FB (Buoyancy force) – array-like or float
  • Fg (Gravity force) – float

compute_dhdt(time, pressure)

Compute the depth rate from the pressure

Parameters:
  • time (array-like) – time in s
  • pressure (array-like) – pressure (Pa)
Returns:

depth-rate (m/s)

Return type:

array-like

Notes

The density used to convert pressure into depth is given by self.RHO0

compute_lift_and_drag(alpha, U, rho, Cd0=None)

Compute lift and drag forces

Computes lift and drag forces using parameterised functions

Parameters:
  • alpha (array-like or float) – angle of attack
  • U (array-like or float) – incident water velocity
  • rho (array-like or float) – in-situ density
  • Cd0 (array-like, float or None) – parasite drag coefficient (-). If None (default), then self.Cd0 is used for the computation
Returns:

  • q (array-like or float) – dynamic pressure (Pa)
  • L (array-like or float) – lift force (Pa)
  • D (array-like or float) – drag force (Pa)

convert_pressure_Vbp_to_SI(m_water_pressure, m_de_oil_vol)

converts units of glider sensor data into SI data

Parameters:
  • m_water_pressure (array-like or float) – water pressure in bar
  • m_de_oil_vol (array-like or float) – buoyancy change reported by glider in cc
Returns:

  • pressure (array-like or float) – pressure (Pa)
  • Vbp (array-like or float) – volume of bulyancy change (m^3)

ensure_monotonicity(data, T_search_span=600)

Ensure monotonicity of the data series.

Parameters:
  • data (dict) – dictionary with environment data.
  • T_search_span (float (600)) – time span to search back in time for time gaps
Returns:

dictionary with updated environment data.

Return type:

dict

Notes

Some times the glider clock gets corrected when it deviates too much from the GPS time. This happens of course at the surface. It can be that time is stepped backwards, which means that the timestamps are not monotonic any more. The strategy we adopt here is, because it happens at the surface, we look if there is a time gap (due to data transmission for example) in the interval 10 minutes prior the time shift. Then we simply move this section of time backwards as well. If this is not possible, we undo the time correction and move all timeseries forward in time.

pitch

pitch angle (rad)

remove_duplicate_time_entries(data)
stall_factor(alpha, **kwds)
t

time (s)

w

vertical water velocity (m s$^{-1}$)

wg

vertical velocity of glider relative to surface (m s$^{-1}$)

exception gliderflight.gliderflight.ModelParameterError

Bases: BaseException

class gliderflight.gliderflight.ModelParameters(parameterised_parameters_dict)

Bases: object

Configuration class for glider model parameters

This class defines the configuration parameters of the glider model. The class is meant to be subclassed from model implementations.

Parameters:parameterised_parameters_dict (dict) – dictionary of parameters that should be computed rather then being set explicitly

Methods defined in this class:

  • define(): define or set a parameter
  • show_settings(): prints the current settings
  • copy_settings(): updates model parameter settings from another model
  • undefined_parameters(): returns which parameters have not been set yet.
  • cd1_estimate(): estimates the induced drag coefficient
  • aw_estimate: estimates the lift coefficient due to the wings using a parameterisation
awEstimate()

Parameterisation for aw

Computes aw using a parameterisation

Returns:aw_param – parameterised value of aw
Return type:float

Notes

If aw is set by using define, the set value takes precedence.

cd1Estimate()

Parameterisation for Cd1

Computes Cd1 using a parameterisation.

Returns:Cd1_param – parameterised value of Cd1
Return type:float

Notes

If Cd1 is set by using define, the set value takes precedence.

copy_settings(other)

Copy model parameters

Copy model parameters from a different instance of ModelParameters and apply it to to self.

Parameters:other (ModelParameters) – an other instance of this class (or subclassing this class)

Examples

>>> dynamic_model.copy_settings(steady_state_model)
define(**kw)

Define (set) one or more glider configuration parameters.

Parameters:kw (dict) – keywords with parameter name and values

Examples

>>> glidermodel.define(Cd0=0.24)
>>> glidermodel.define(Vg=50e-3, mg=60)
get_settings()

Get model settings

Return a dictionary with model coefficient settings

Returns:settings – a dictionary with the current parameter setting
Return type:dict
has_aoa_parameter_changed()

test whether any of the parameters that appear in the angle of attack estimate have changed

Returns:rv – test result
Return type:bool
show_settings()

Prints model parameters

undefined_parameters()

Returns undefined parameters

Checks all model coefficients for having been set. All coeficients set to None are returned.

Returns:list – list of undefined parametrs
Return type:list-comprehension
class gliderflight.gliderflight.Modelresult(t, u, w, U, alpha, pitch, ww, depth)

Bases: tuple

U

Alias for field number 3

alpha

Alias for field number 4

depth

Alias for field number 7

pitch

Alias for field number 5

t

Alias for field number 0

u

Alias for field number 1

w

Alias for field number 2

ww

Alias for field number 6

class gliderflight.gliderflight.SteadyStateCalibrate(rho0=None)

Bases: gliderflight.gliderflight.SteadyStateGliderModel, gliderflight.gliderflight.Calibrate

Steady-state glider flight model, with calibration interface

class gliderflight.gliderflight.SteadyStateGliderModel(rho0=None)

Bases: gliderflight.gliderflight.ModelParameters, gliderflight.gliderflight.GliderModel

Steady-state implementation

This class inherits from ModelParameters and GliderModel. The physcis are provided by GliderModel. Interacting with ModelParameters is done through methods provided by ModelParameters.

Parameters:rho0 (float) – background in-situ density

The only method provided by this class that is of interest to the user is solve(). The input to solve is a dictionary with time, pressure, pitch, buoyancy change density.

Methods inherited from ModelParameters can be used to define/set model coefficients, and to copy settings from another model instance.

After solving the model results are available as properties (t, U, wg, w, alpha)

Examples

>>> gm = SteadyStateGliderModel(rho0=1024)
>>> gm.define(mg=70)
>>> gm.define(Vg=68, Cd0=0.15)
>>> gm.solve(dict(time=tctd, pressure=P, pitch=pitch, buoyancy_change=buoyancy_drive, density=density))
>>> print(gm.U)
model_fun(x, m_pitch, Cd0)

implicit function of the angle of attack

Parameters:
  • m_pitch (float or array of floats) – measured pitch
  • Cd0 (float) –
  • is a parameter that might change during a mission, so self.Cd0 is set as an (Cd0) –
  • this function needs to take Cd0 as a float at the appropriate time. It is (array,) –
  • responsibility of the caller function to pass the value of Cd0. (the) –
reset()

Resets angle of attack interpolation function

solve(data=None)

Solve the model

Solves the flight model.

Parameters:data (dict) – environment data (see Notes)
Returns:modelresult – model result (named tuple with arrays of computed results)
Return type:Modelresult

Notes

The data supplied should contain at least time, pressure, pitch, buoyancy_change and density, as reported by the glider. Depth rate (dhdt) will be added if not already present. Other data are ignored.

Examples

>>> gm = SteadyStateGliderModel()
>>> gm.define(mg=70, Vg=68)
>>> data = dict(time=time, pressure=P, pitch=pitch, buoyancy_change=vb, density=rho)
>>> gm.solve(data)
>>> plot(gm.U)
solve_for_angle_of_attack(pitch)

Solves for the angle of attack

Solves angle of attack using an interative method.

Parameters:pitch (array-like or float) – pitch (rad)
Returns:aoa – angle of attack (rad)
Return type:array-like or float

Notes

This method uses an interpolating function. If any parameter on which this calculation depends, changes, the interpolating function is recomputed. Whether any of these parameters is changed, is tracked by the ModelParameters.define() method.

solve_model(rho, FB, pitch, Fg)

Solves first for angle of attack and then incident velocity

Not intended to be called directly.

gliderflight.glidertrim module

Module contents