OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
hico.value_locate Namespace Reference

Functions

def value_locate (refx, x)
 

Variables

list refx = [2, 4, 6, 8, 10]
 
list x = [-1, 1, 2, 3, 5, 5, 5, 8, 12, 30]
 
def res = value_locate(refx, x)
 

Detailed Description

Created on Feb 9, 2016

@author: rhealy
retrieved from https://github.com/marcelhaas/python/blob/master/value_locate.py

Function Documentation

◆ value_locate()

def hico.value_locate.value_locate (   refx,
  x 
)
VALUE_LOCATE locates the positions of given values within a
reference array.  The reference array need not be regularly
spaced.  This is useful for various searching, sorting and
interpolation algorithms.
The reference array should be a monotonically increasing or
decreasing list of values which partition the real numbers.  A
reference array of NBINS numbers partitions the real number line
into NBINS+1 regions, like so:
REF:           X[0]         X[1]   X[2] X[3]     X[NBINS-1]
    <----------|-------------|------|---|----...---|--------------->
INDICES:  -1           0          1    2       3        NBINS-1
VALUE_LOCATE returns which partition each of the VALUES falls
into, according to the figure above.  For example, a value between
X[1] and X[2] would return a value of 1.  Values below X[0] return
-1, and above X[NBINS-1] return NBINS-1.  Thus, besides the value
of -1, the returned INDICES refer to the nearest reference value
to the left of the requested value.

Example:
>>> refx = [2, 4, 6, 8, 10]
>>> x = [-1, 1, 2, 3, 5, 5, 5, 8, 12, 30]
>>> print value_locate(refx, x)
array([-1, -1,  0,  0,  1,  1,  1,  3,  4,  4])


This implementation is likely no the most efficient one, as there is
a loop over all x, which will in practice be long. As long as x is
shorter than 1e6 or so elements, it should still be fast (~sec).

Definition at line 11 of file value_locate.py.

Variable Documentation

◆ refx

list refx = [2, 4, 6, 8, 10]

Definition at line 63 of file value_locate.py.

◆ res

def res = value_locate(refx, x)

Definition at line 66 of file value_locate.py.

◆ x

int x = [-1, 1, 2, 3, 5, 5, 5, 8, 12, 30]

Definition at line 64 of file value_locate.py.