Skip to content

Commit

Permalink
Mon Feb 26 18:36:57 MST 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Buscombe committed Feb 27, 2018
1 parent cffc932 commit b9d7c1b
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 51 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,10 @@ if __name__ == '__main__':
```

## Version History

v. 0.1. 2/26/2018. Initial public release




3 changes: 2 additions & 1 deletion prism/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
# |b|y| |D|a|n|i|e|l| |B|u|s|c|o|m|b|e|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# |d|a|n|i|e|l|.|b|u|s|c|o|m|b|e|@|n|a|u|.|e|d|u|
# https://github.com/dbuscombe-usgs/prism

__version__ = '0.0.21'
__version__ = '0.1'

#-----------------------------------------------------------------------------
# Imports
Expand Down
8 changes: 6 additions & 2 deletions prism/common_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# |b|y| |D|a|n|i|e|l| |B|u|s|c|o|m|b|e|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# |d|a|n|i|e|l|.|b|u|s|c|o|m|b|e|@|n|a|u|.|e|d|u|
# https://github.com/dbuscombe-usgs/prism

##-------------------------------------------------------------
from __future__ import division
Expand All @@ -24,7 +25,7 @@
##-------------------------------------------------------------
def get_X(img, Lc):
"""
This function ...
This function computes distributions of backscatter according to each unique substrate
"""
D = []
counter = 0
Expand All @@ -51,7 +52,10 @@ def get_X(img, Lc):
##-------------------------------------------------------------
def get_sparse_labels(bs, bed, buff):
"""
This function ...
This function generates a sparse label map by assigning
unique numeric codes to portions of a matrix of identical
size to the backscatter inputs, according to the locations
of bed observations and a buffer distance
"""
## make sparse labels
Lc = np.zeros(np.shape(bs[0]['bs']))+99
Expand Down
17 changes: 11 additions & 6 deletions prism/crf_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# |b|y| |D|a|n|i|e|l| |B|u|s|c|o|m|b|e|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# |d|a|n|i|e|l|.|b|u|s|c|o|m|b|e|@|n|a|u|.|e|d|u|
# https://github.com/dbuscombe-usgs/prism

##-------------------------------------------------------------
from __future__ import division
Expand All @@ -28,7 +29,7 @@
##-------------------------------------------------------------
def set_unary_from_labels(fp, lp, prob, labels):
"""
This function ...
This function sets unary potentials according to the label matrix
"""
H = fp.shape[0]
W = fp.shape[1]
Expand All @@ -43,7 +44,8 @@ def set_unary_from_labels(fp, lp, prob, labels):
##-------------------------------------------------------------
def set_feats_both(d, fp, scol, compat_col, sspat, compat_spat):
"""
This function ...
This function generates features according to both spatial and
amplitude kernels
"""

d = set_feats_spat(d, sspat, compat_spat, mode)
Expand All @@ -54,7 +56,7 @@ def set_feats_both(d, fp, scol, compat_col, sspat, compat_spat):
##-------------------------------------------------------------
def set_feats_spat(d, sspat, compat_spat):
"""
This function ...
This function generates features according to spatial kernel
"""

d.addPairwiseGaussian(sxy=sspat, compat=compat_spat)
Expand All @@ -64,7 +66,7 @@ def set_feats_spat(d, sspat, compat_spat):
##-------------------------------------------------------------
def set_feats_col(fp, d, scol, compat_col):
"""
This function ...
This function generates features according to amplitude kernel
"""

scale = 1
Expand All @@ -88,7 +90,10 @@ def set_feats_col(fp, d, scol, compat_col):
##-------------------------------------------------------------
def inference(d, n_iter, H, W, labels):
"""
This function ...
This function carries out the CRF inference, generating a MAP
substrate matrix, a conservative probabilistic map based on
frequentist principles, and a probability per substrate based on
the CRF inference
"""
R = [] ;
Q, tmp1, tmp2 = d.startInference()
Expand All @@ -115,7 +120,7 @@ def inference(d, n_iter, H, W, labels):
##-------------------------------------------------------------
def apply_CRF(fp, lp, labels, n_iter, prob_thres, scol, compat_col):
"""
This function ...
This function generates CRF-derived substrate map and probability map
"""

prob = 0.51 # initial probability of unary labels
Expand Down
6 changes: 6 additions & 0 deletions prism/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Two data sets are provided with the toolbox for users to experiment with. The data come from 1) Patricia Bay, British Columbia, Canada, and 2) lower Portsmouth Harbor, New Hampshire, USA. All example backscatter data (.tiff files) originate from data collected by R2Sonic and distributed for use as part of the R2Sonic 2017 Multispectral Backscatter competition. Bed observation data from Patricia Bay are digitized from data presented in:

B. Biffard. Seabed remote sensing by single-beam echosounder: models, methods and applications. Doctoral dissertation, University of Victoria, Canada, 2011.
Bed observation data from Portsmouth (NEWBEX) are digitized from data presented in:

T. Weber, and L. Ward. Observations of backscatter from sand and gravel seafloors between 170 and 250 kHz. Journal of the Acoustical Society of America, vol. 138, no. 4, pp. 2169 - 2180, 2015.
5 changes: 3 additions & 2 deletions prism/eval_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# |b|y| |D|a|n|i|e|l| |B|u|s|c|o|m|b|e|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# |d|a|n|i|e|l|.|b|u|s|c|o|m|b|e|@|n|a|u|.|e|d|u|
# https://github.com/dbuscombe-usgs/prism

##-------------------------------------------------------------
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -66,7 +67,7 @@ def plot_confusion_matrix(cm, classes,
##-------------------------------------------------------------
def plot_confmatGMM(y_pred, Lc, bed, prefix):
"""
This function ...
This function generates and plots a confusion matrix for GMM model
"""

#base = '..'+os.sep+'outputs'+os.sep+prefix+'_'
Expand Down Expand Up @@ -112,7 +113,7 @@ def plot_confmatGMM(y_pred, Lc, bed, prefix):
##-------------------------------------------------------------
def plot_confmatCRF(y_pred, Lc, bed, prefix):
"""
This function ...
This function generates and plots a confusion matrix for CRF model
"""

#base = '..'+os.sep+'outputs'+os.sep+prefix+'_'
Expand Down
8 changes: 6 additions & 2 deletions prism/gmm_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# |b|y| |D|a|n|i|e|l| |B|u|s|c|o|m|b|e|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# |d|a|n|i|e|l|.|b|u|s|c|o|m|b|e|@|n|a|u|.|e|d|u|
# https://github.com/dbuscombe-usgs/prism

##-------------------------------------------------------------
from __future__ import division
Expand All @@ -31,7 +32,8 @@
##-------------------------------------------------------------
def fit_GMM(img, Lc, test_size, covariance, tol):
"""
This function ...
This function fits a simple GMM model to the backscatter data
and associated labels
"""
D, l = get_X(img, Lc)

Expand All @@ -55,8 +57,10 @@ def fit_GMM(img, Lc, test_size, covariance, tol):
##-------------------------------------------------------------
def apply_GMM(g, img, prob_thres):
"""
This function ...
This function fits applies a GMM model to generate a substrate and
associated probability map
"""

print('Estimating substrates ...')
if np.ndim(img)>2: #multispectral

Expand Down
Loading

0 comments on commit b9d7c1b

Please sign in to comment.