gnome.spills.initializers

Utilities for initializing data arrays associated with the elements

This code is kept separately here to make it easier to mix and match for various release and substance types.

Module Contents

Classes

InitBaseClass

All Init* classes will define the _state attribute, so just do so in a

InitWindages

All Init* classes will define the _state attribute, so just do so in a

InitMassFromPlume

Initialize the 'mass' array based on mass flux from the plume spilled

DistributionBase

Define a base class for all initializers that contain a distribution.

InitRiseVelFromDist

Define a base class for all initializers that contain a distribution.

InitRiseVelFromDropletSizeFromDist

Define a base class for all initializers that contain a distribution.

Functions

plume_initializers([distribution_type, distribution, ...])

Helper function returns an ElementType object containing 'rise_vel'

plume_from_model_initializers([distribution_type, ...])

Helper function returns an ElementType object containing 'rise_vel'

class gnome.spills.initializers.InitBaseClass(*args, **kwargs)

Bases: gnome.gnomeobject.GnomeId

All Init* classes will define the _state attribute, so just do so in a base class.

It also documents that all initializers must implement an initialize method

initialize(num_new_particles, spill, data_arrays, substance)

all classes that derive from Base class must implement an initialize method.

This method should initialize the appropriate data in the data arrays dict.

See subclasses for examples.

class gnome.spills.initializers.InitWindages(windage_range=(0.01, 0.04), windage_persist=900, *args, **kwargs)

Bases: InitBaseClass

All Init* classes will define the _state attribute, so just do so in a base class.

It also documents that all initializers must implement an initialize method

Initializes the windages, windage_range, windage_persist data arrays. Initial values for windages use infinite persistence. These are updated by the PointWindMover for particles with non-zero persistence.

Optional arguments:

Parameters:
  • windage_range (tuple: (min, max)) – the windage range of the elements. Default is (0.01, 0.04) from 1% to 4%.

  • windage_persist (integer seconds) – Default is 900s, so windage is updated every 900 seconds. -1 means the persistence is infinite so it is only set at the beginning of the run.

_schema
__repr__()

Return repr(self).

to_dict(json_=None)

Returns a dictionary representation of this object. Uses the schema to determine which attributes are put into the dictionary. No extra processing is done to each attribute. They are presented as is.

The json_ parameter is ignored in this base class. ‘save’ is passed in when the schema is saving the object. This allows an override of this function to do any custom stuff necessary to prepare for saving.

initialize(num_new_particles, data_arrays, substance)

Since windages exists in data_arrays, so must windage_range and windage_persist if this initializer is used/called

class gnome.spills.initializers.InitMassFromPlume

Bases: InitBaseClass

Initialize the ‘mass’ array based on mass flux from the plume spilled

update array_types

_schema
initialize(num_new_particles, data_arrays, substance)

all classes that derive from Base class must implement an initialize method.

This method should initialize the appropriate data in the data arrays dict.

See subclasses for examples.

class gnome.spills.initializers.DistributionBase(*args, **kwargs)

Bases: InitBaseClass

Define a base class for all initializers that contain a distribution. Keep the code to serialize/deserialize distribution objects here so we only have to write it once.

_schema
class gnome.spills.initializers.InitRiseVelFromDist(distribution=None, **kwargs)

Bases: DistributionBase

Define a base class for all initializers that contain a distribution. Keep the code to serialize/deserialize distribution objects here so we only have to write it once.

Set the rise velocity parameters to be sampled from a distribution.

Parameters:

distribution (DistributionBase) – An initialized distribution object. It should return values in m/s

See gnome.utilities.distribution for details

Right now, we have:

  • UniformDistribution

  • NormalDistribution

  • LogNormalDistribution

  • WeibullDistribution

New distribution classes could be made. The only requirement is they need to have a set_values() method which accepts a NumPy array. (presumably, this function will also modify the array in some way)

initialize(num_new_particles, data_arrays, substance)

all classes that derive from Base class must implement an initialize method.

This method should initialize the appropriate data in the data arrays dict.

See subclasses for examples.

class gnome.spills.initializers.InitRiseVelFromDropletSizeFromDist(distribution=None, water_density=1020.0, water_viscosity=1e-06, **kwargs)

Bases: DistributionBase

Define a base class for all initializers that contain a distribution. Keep the code to serialize/deserialize distribution objects here so we only have to write it once.

Set the droplet size from a distribution. Use the C++ get_rise_velocity function exposed via cython (rise_velocity_from_drop_size) to obtain rise_velocity from droplet size. Even though the droplet size is not changing over time, it is still stored in data array, as it can be useful for post-processing (called ‘droplet_diameter’)

Parameters:

distribution – An object capable of generating a probability distribution.

Right now, we have:

  • UniformDistribution

  • NormalDistribution

  • LogNormalDistribution

  • WeibullDistribution

New distribution classes could be made. The only requirement is they need to have a set_values() method which accepts a NumPy array. (presumably, this function will also modify the array in some way)

Parameters:
  • water_density (float) – 1020.0 [kg/m3]

  • water_viscosity (float) – 1.0e-6 [m^2/s]

initialize(num_new_particles, data_arrays, substance)

Update values of ‘rise_vel’ and ‘droplet_diameter’ data arrays for new particles. First create a droplet_size array sampled from specified distribution, then use the cython wrapped (C++) function to set the ‘rise_vel’ based on droplet size and properties like LE_density, water density and water_viscosity: gnome.cy_gnome.cy_rise_velocity_mover.rise_velocity_from_drop_size()

gnome.spills.initializers.plume_initializers(distribution_type='droplet_size', distribution=None, windage_range=(0.01, 0.04), windage_persist=900, **kwargs)

Helper function returns an ElementType object containing ‘rise_vel’ and ‘windages’ initialized with user specified parameters for distribution.

Parameters:
  • distribution_type (str) – type of distribution, ‘droplet_size’ or ‘rise_velocity’

  • distribution=None (gnome.utilities.distributions) –

  • windage_range (tuple-of-floats) – minimum and maximum windage

  • windage_persist (int) – persistence of windage in seconds

  • substance_name=None (str) –

  • density=None (float) –

  • density_units='kg/m^3' (str) –

Distribution type available options:

  • ‘droplet_size’: Droplet size is sampled from the specified distribution.

    No droplet size is computed.

  • ‘rise_velocity’: Rise velocity is directly sampled from the specified

    distribution. Rise velocity is calculated.

Distributions - An object capable of generating a probability distribution.

Right now, we have:

  • UniformDistribution

  • NormalDistribution

  • LogNormalDistribution

  • WeibullDistribution

New distribution classes could be made. The only requirement is they need to have a set_values() method which accepts a NumPy array. (presumably, this function will also modify the array in some way)

Note

substance_name or density must be provided

gnome.spills.initializers.plume_from_model_initializers(distribution_type='droplet_size', distribution=None, windage_range=(0.01, 0.04), windage_persist=900, **kwargs)

Helper function returns an ElementType object containing ‘rise_vel’ and ‘windages’ initializer with user specified parameters for distribution.