Sambuca Documentation

Build Status Documentation Status

Spatial application of the Semi-Analytical Model for Bathymetry, Un-mixing, and Concentration Assessment (SAMBUCA).

Installation

pip install sambuca

For everything else, please refer to the project documentation.

Contents

Usage

To use Sambuca in a project:

import sambuca

Or:

import sambuca as sb

Tutorial

For a basic tutorial on using Sambuca, please see the IPython Notebooks.

To Do

  • Write a tutorial as an IPython Notebook
  • Place it somewhere
  • Link to here

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

Bug reports

When reporting a bug please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • The Sambuca package version.
  • Detailed steps to reproduce the bug.

Documentation improvements

Sambuca could always use more documentation, whether as part of the official Sambuca docs, in docstrings, or even on the web in blog posts, articles, and such.

Note

This project uses Google-style docstrings. Contributed code should follow the same conventions. For examples, please see the Napoleon examples, or the Google Python Style Guide.

Feature requests and feedback

The best way to send feedback is to file an issue

If you are proposing a feature:

  • Explain in detail how it would work.
  • Keep the scope as narrow as possible, to make it easier to implement.
  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Or, implement the feature yourself and submit a pull request.

Development

  1. Fork the sambuca repo on GitHub.

  2. Clone your fork locally.

  3. Create a feature branch.

  4. When you’re done making changes, run all the tests, doc builder and pylint checks:

    py.test
    tox
    pylint ./src/sambuca/
    sphinx-build -b html docs build/docs
    

    Or, using the project makefile:

    make clean lint tests html
    tox
    
  5. Commit your changes and push your branch to GitHub.

  6. Submit a pull request through the GitHub website.

There is a makefile in the project root with targets for the most common development operations such as lint checks, running unit tests, building the documentation, and installing packages.

Bumpversion is used to manage the package version numbers. This ensures that the version number is correctly incremented in all required files. Please see the bumpversion documentation for usage instructions, and do not edit the version strings directly.

Note

Sphinx requires a working LaTeX installation to build the pdf documentation.

Pull Request Guidelines

If you need some code review or feedback while you’re developing the code just make the pull request.

For merging, you should:

  1. Include passing tests (run py.test).
  2. Update documentation when there’s new API, functionality etc.
  3. Add a note to CHANGELOG.rst about the changes.
  4. Add yourself to AUTHORS.rst.

Authors

Changelog

0.1.0 (2014-12-19)

  • Minimal Sambuca model based on the cut-down Matlab code.

0.3.0 (2015-12-24)

  • Working single-threaded demo of Sambuca minimisation on a raster in the New Sambuca.ipynb notebook.

0.4.0 (Wednesday June 13, 2018)

  • First release to GitHub. No code changes, just documentation updates, config, Travis CI setup, Read the Docs setup, and stripping out test files.

Licence

CSIRO Open Source Software Licence Agreement (variation of the BSD / MIT License)

Copyright (c) 2014, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230. All rights reserved. CSIRO is willing to grant you a licence to use Sambuca on the following terms, except where otherwise indicated for third party material. Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of CSIRO nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of CSIRO.

EXCEPT AS EXPRESSLY STATED IN THIS AGREEMENT AND TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED “AS-IS”. CSIRO MAKES NO REPRESENTATIONS, WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE.

TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL CSIRO BE LIABLE ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION FOR BREACH OF CONTRACT, NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER LIABILITY HOWSOEVER INCURRED. WITHOUT LIMITING THE SCOPE OF THE PREVIOUS SENTENCE THE EXCLUSION OF LIABILITY SHALL INCLUDE: LOSS OF PRODUCTION OR OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT, ACCESS OF THE SOFTWARE OR ANY OTHER DEALINGS WITH THE SOFTWARE, EVEN IF CSIRO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS, DAMAGES OR OTHER LIABILITY.

APPLICABLE LEGISLATION SUCH AS THE AUSTRALIAN CONSUMER LAW MAY APPLY REPRESENTATIONS, WARRANTIES, OR CONDITIONS, OR IMPOSES OBLIGATIONS OR LIABILITY ON CSIRO THAT CANNOT BE EXCLUDED, RESTRICTED OR MODIFIED TO THE FULL EXTENT SET OUT IN THE EXPRESS TERMS OF THIS CLAUSE ABOVE “CONSUMER GUARANTEES”. TO THE EXTENT THAT SUCH CONSUMER GUARANTEES CONTINUE TO APPLY, THEN TO THE FULL EXTENT PERMITTED BY THE APPLICABLE LEGISLATION, THE LIABILITY OF CSIRO UNDER THE RELEVANT CONSUMER GUARANTEE IS LIMITED (WHERE PERMITTED AT CSIRO’S OPTION) TO ONE OF FOLLOWING REMEDIES OR SUBSTANTIALLY EQUIVALENT REMEDIES:

  1. THE REPLACEMENT OF THE SOFTWARE, THE SUPPLY OF EQUIVALENT SOFTWARE, OR SUPPLYING RELEVANT SERVICES AGAIN;
  2. THE REPAIR OF THE SOFTWARE;
  3. THE PAYMENT OF THE COST OF REPLACING THE SOFTWARE, OF ACQUIRING EQUIVALENT SOFTWARE, HAVING THE RELEVANT SERVICES SUPPLIED AGAIN, OR HAVING THE SOFTWARE REPAIRED.

IN THIS CLAUSE, CSIRO INCLUDES ANY THIRD PARTY AUTHOR OR OWNER OF ANY PART OF THE SOFTWARE OR MATERIAL DISTRIBUTED WITH IT. CSIRO MAY ENFORCE ANY RIGHTS ON BEHALF OF THE RELEVANT THIRD PARTY.

API Reference

sambuca.AllParameters

sambuca.all_parameters.create_fixed_parameter_set(wavelengths, a_water, a_ph_star, substrates, substrate_fraction=1, chl=None, cdom=None, nap=None, depth=None, a_cdom_slope=0.0168052, a_nap_slope=0.00977262, bb_ph_slope=0.878138, bb_nap_slope=None, lambda0cdom=550.0, lambda0nap=550.0, lambda0x=546.0, x_ph_lambda0x=0.00157747, x_nap_lambda0x=0.0225353, a_cdom_lambda0cdom=1.0, a_nap_lambda0nap=0.00433, bb_lambda_ref=550, water_refractive_index=1.33784, theta_air=30.0, off_nadir=0.0, q_factor=3.141592653589793)[source]

Get an AllParameters tuple with Sambuca default values for use as a fixed parameter set.

Note that if the (wavelength, value) tuples returned from the sambuca_core spectra loading functions are passed to this function, only the value arrays are stored in order to match the expectations of sambuca_core.forward_model.

class sambuca.all_parameters.AllParameters(chl, cdom, nap, depth, wavelengths, a_water, a_ph_star, num_bands, substrate_fraction, substrates, substrate_combinations, a_cdom_slope, a_nap_slope, bb_ph_slope, bb_nap_slope, lambda0cdom, lambda0nap, lambda0x, x_ph_lambda0x, x_nap_lambda0x, a_cdom_lambda0cdom, a_nap_lambda0nap, bb_lambda_ref, water_refractive_index, theta_air, off_nadir, q_factor)

namedtuple containing all sambuca-core forward_model parameters.

chl

float – Concentration of chlorophyll (algal organic particulates).

cdom

float – Concentration of coloured dissolved organic particulates (CDOM).

nap

float – Concentration of non-algal particulates (NAP).

depth

float – Water column depth.

substrates

array-like – A list of benthic substrates.

wavelengths

array-like – Central wavelengths of the modelled spectral bands.

a_water

array-like – Absorption coefficient of pure water

a_ph_star

array-like – Specific absorption of phytoplankton.

num_bands

int – The number of spectral bands.

substrate_fraction

float – Substrate proportion, used to generate a convex combination of two substrate members.

substrate_combinations

array-like – The index in substrates for all combintations of pairs in substrates

a_cdom_slope

float, optional – slope of CDOM absorption

a_nap_slope

float, optional – slope of NAP absorption

bb_ph_slope

float, optional – Power law exponent for the phytoplankton backscattering coefficient.

bb_nap_slope

float, optional – Power law exponent for the NAP backscattering coefficient. If no value is supplied, the default behaviour is to use the bb_ph_slope value.

lambda0cdom

float, optional – Reference wavelength for CDOM absorption.

lambda0nap

float, optional – Reference wavelength for NAP absorption.

lambda0x

float, optional – Backscattering reference wavelength.

x_ph_lambda0x

float, optional – Specific backscatter of chlorophyl at lambda0x.

x_nap_lambda0x

float, optional – Specific backscatter of NAP at lambda0x.

a_cdom_lambda0cdom

float, optional – Absorption of CDOM at lambda0cdom.

a_nap_lambda0nap

float, optional – Absorption of NAP at lambda0nap.

bb_lambda_ref

float, optional – Reference wavelength for backscattering coefficient.

water_refractive_index

float, optional – refractive index of water.

theta_air

float, optional – solar zenith angle in degrees.

off_nadir

float, optional – off-nadir angle.

q_factor

float, optional – q value for producing the R(0-) values from modelled remotely-sensed reflectance (rrs) values.

sambuca.error

class sambuca.error.ErrorTerms(alpha, alpha_f, f, lsq)

namedtuple containing the error terms.

alpha

float – TODO

alpha_f

float – TODO

f

float – TODO

lsq

float – TODO

Sambuca Error Functions.

Used when assessing model closure during parameter estimation.

sambuca.error.error_all(observed_rrs, modelled_rrs, nedr=None)[source]

Calculates all common error terms.

Parameters:
  • observed_rrs (array-like) – The observed reflectance(remotely-sensed).
  • modelled_rrs (array-like) – The modelled reflectance(remotely-sensed).
  • nedr (array-like) – Noise equivalent difference in reflectance.
Returns:

The error terms.

Return type:

ErrorTerms

sambuca.error.distance_alpha(observed_rrs, modelled_rrs, nedr=None)[source]

Calculates TODO

Parameters:
  • observed_rrs – The observed reflectance(remotely-sensed).
  • modelled_rrs – The modelled reflectance(remotely-sensed).
  • noise – Optional spectral noise values.

Returns: TODO

sambuca.error.distance_f(observed_rrs, modelled_rrs, nedr=None)[source]

Calculates TODO

Parameters:
  • observed_rrs – The observed reflectance(remotely-sensed).
  • modelled_rrs – The modelled reflectance(remotely-sensed).
  • noise – Optional spectral noise values.

Returns: TODO

sambuca.error.distance_alpha_f(observed_rrs, modelled_rrs, nedr=None)[source]

Calculates TODO

Parameters:
  • observed_rrs – The observed reflectance(remotely-sensed).
  • modelled_rrs – The modelled reflectance(remotely-sensed).
  • noise – Optional spectral noise values.

Returns: TODO

sambuca.error.distance_lsq(observed_rrs, modelled_rrs, nedr=None)[source]

Calculates TODO

Parameters:
  • observed_rrs – The observed reflectance(remotely-sensed).
  • modelled_rrs – The modelled reflectance(remotely-sensed).
  • noise – Optional spectral noise values.

Returns: TODO

sambuca.FreeParameters

class sambuca.free_parameters.FreeParameters(chl, cdom, nap, depth, substrate_fraction)

namedtuple containing the default Sambuca free parameters.

chl

float – Concentration of chlorophyll (algal organic particulates).

cdom

float – Concentration of coloured dissolved organic particulates (CDOM).

nap

float – Concentration of non-algal particulates (NAP).

depth

float – Water column depth.

substrate_fraction

float – relative proportion of substrate1 and substrate2.

Objective Functions

class sambuca.scipy_objective.SciPyObjective(sensor_filter, fixed_parameters, error_function=<function distance_f>, nedr=None)[source]

Configurable objective function for Sambuca parameter estimation, intended for use with the SciPy minimisation methods.

observed_rrs

array-like – The observed remotely-sensed reflectance. This attribute must be updated when you require the objective instance to use a different value.

id

integer – The index of the substrate pair combination. This attribute must be updated when you require the objective instance to use a different substrate pair.

Pixel Result Handlers

Pixel result handlers are called by the parameter estimator with the final result for a pixel. Subclasses can implement various functionality, such as writing results to memory structures or files.

class sambuca.pixel_result_handler.PixelResultHandler[source]

Pixel result handler base class.

Pixel result handlers are called by the parameter estimator with the final result for a pixel. Subclasses can implement various functionality, such as writing results to memory structures or files.

class sambuca.array_result_writer.ArrayResultWriter(width, height, sensor_filter, nedr, fixed_parameters)[source]

Pixel result handler that writes pixel model outputs to in-memory numpy arrays.

Note that the current implementation is writing a hard-coded set of outputs for the alpha implementation. The intention is to replace this with a data-driven system that only captures the outputs specified by the user.

In the short-term, this class could be modified to add additional outputs, but this is not an ideal long-term solution.

The intent is that this class is used to capture model outputs of interest during raster processing. Once processing is complete, these outputs can then be used in various ways, such as writing to file (HDF, NetCDF, multi-band raster etc), plotting, or communication via message passing to a parallel processing manager. Each of these uses can be built on top of the basic array capture implemented in this class.

sambuca.sambuca

Sambuca module

Indices and tables