当前位置: 首页>>代码示例>>Python>>正文


Python GridUtil.getSpatialDomain方法代码示例

本文整理汇总了Python中ucar.unidata.data.grid.GridUtil.getSpatialDomain方法的典型用法代码示例。如果您正苦于以下问题:Python GridUtil.getSpatialDomain方法的具体用法?Python GridUtil.getSpatialDomain怎么用?Python GridUtil.getSpatialDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ucar.unidata.data.grid.GridUtil的用法示例。


在下文中一共展示了GridUtil.getSpatialDomain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: highPass2DFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def highPass2DFilter(sdataset, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Two dimensional high pass filter from McIDAS-X.
    
    Equation for each sdataset element is 
    (sdataset - (sample average) + (sample midpoint))
    
    Args:
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    newData = sdataset.clone()
    stretch = user_stretchval
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    for t in xrange(newData.getDomainSet().getLength()):
        rangeObject = newData.getSample(t)
        vals = rangeObject.getFloats(0)
        in_hi = max(vals[0])
        in_low = min(vals[0])
        domain = GridUtil.getSpatialDomain(rangeObject)
        [element_size, line_size] = domain.getLengths()
        
        # first and last 2 lines of the image do not change
        firstLine = vals[0][0:element_size]
        last2Lines = vals[0][(line_size - 2) * element_size:line_size * element_size]
        
        # do the filter using 3 lines at a time
        for i in range(line_size)[:-3]:
            for j in range(element_size)[1:-1]:
                midValue = vals[0][(i + 1) * element_size + j]
                
                val = (vals[0][(i + 2) * element_size + j] + vals[0][i * element_size + j] + \
                      vals[0][(i + 1) * element_size + j + 1] + vals[0][(i + 1) * element_size + j - 1]) - \
                      4 * midValue
                
                if (val < midValue):
                    vals[0][i * element_size + j] = scaleOutsideVal(midValue - val, britlo, brithi)
                else:
                    vals[0][i * element_size + j] = 0
                    
        vals[0][0:line_size * element_size] = firstLine + vals[0][0:(line_size - 3) * element_size] + last2Lines
        
        for i in range(line_size):
            for j in range(element_size):
                vals[0][i * element_size + j] = scaleOutsideVal(vals[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, britlo, brithi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            h = makeHistogram(vals, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals = modify(vals, element_size, line_size, filt_low, lookup)
        rangeObject.setSamples(vals)
        
    return newData
开发者ID:jon4than,项目名称:mcidasv,代码行数:62,代码来源:imageFilters.py

示例2: shotFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def shotFilter(sdataset, user_bline='Default', user_eline='Default', user_pdiff=15, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """ shot noise filter from McIDAS-X
        bline - beginning line in the source image to clean (default=first line)
        eline - ending line in the source image to clean (default = last line)
        pdiff - maximum percentage of the product range to allow before a new value for the pixel is derived using the
                average of two adjacent pixels
        user_britlo    - minimum brightness value for the calibration
        user_brithi    - maximum brightness value for the calibration
    """
    newData = sdataset.clone()
    bline = user_bline
    eline = user_eline
    britlo = int(user_britlo)
    brithi = int(user_brithi)
       
    if bline != 'Default':
        bline = int(bline)
    else:
        bline = 0
        
    if eline != 'Default':
        eline = int(eline)
      
    filter_diff = int(user_pdiff)
    stretch = user_stretchval
    
    for t in range(newData.getDomainSet().getLength()):
        rangeObject = newData.getSample(t)
        vals = rangeObject.getFloats(0)
        in_hi = int(max(vals[0]))
        in_low = int(min(vals[0]))
        """ the next four lines are to make sure the point_diff value is floored """
        p = (in_hi - in_low + 1) * (filter_diff / 100.0)
        a = field((p,))
        b = a.floor().getValues(0)
        point_diff = b[0]
        
        domain = GridUtil.getSpatialDomain(rangeObject)
        [element_size, line_size] = domain.getLengths()
        if (eline == 'Default'):
            eline = line_size
            
        vals = shotMain(vals, bline, eline, element_size, line_size, point_diff)
        
        for i in range(line_size):
            for j in range(element_size):
                vals[0][i * element_size + j] = scaleOutsideVal(vals[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, britlo, brithi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            h = makeHistogram(vals, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, britlo, brithi, h)
            
        vals = modify(vals, element_size, line_size, filt_low, lookup)
        rangeObject.setSamples(vals)
        
    return newData
开发者ID:RickKohrs,项目名称:mcidasv,代码行数:62,代码来源:imageFilters.py

示例3: holeFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def holeFilter(sdataset, user_brkpoint1=0, user_brkpoint2=1, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """ hole filter from McIDAS-X - searches for missing data and fills the holes
          using the surrounding element values
        brkpoint1 - low end breakpoint value (default = minimum sdataset value)
        brkpoint2 - high end breakpoint value (default = maximum sdataset value)
        user_britlo    - minimum brightness value for the calibration
        user_brithi    - maximum brightness value for the calibration
    """
    
    data = sdataset.clone()
    brkpoint1 = int(user_brkpoint1)
    brkpoint2 = int(user_brkpoint2)
    stretch = user_stretchval
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    for t in xrange(data.getDomainSet().getLength()):
        rangeObject = data.getSample(t)
        vals = rangeObject.getFloats(0)
        in_low = min(vals[0])
        in_hi = max(vals[0])
        minVal = min([brkpoint1, brkpoint2])
        maxVal = max([brkpoint1, brkpoint2])
        domain = GridUtil.getSpatialDomain(rangeObject)
        [element_size, line_size] = domain.getLengths()
        
        for i in range(line_size):
            for j in range(element_size)[1:-1]:
                curVal = vals[0][i * element_size + j]
                """ search line for bad values """
                if curVal >= minVal and curVal <= maxVal:
                    """ look for the next good value """
                    doFill = 0
                    for k in range(element_size)[j:]:
                        nextVal = vals[0][i * element_size + k]
                        if nextVal < minVal or nextVal > maxVal:
                            doFill = 1
                            break
                            
                    if doFill == 1:
                        for fill in range(element_size)[j:k]:
                            vals[0][i * element_size + fill] = (vals[0][i * element_size + j - 1] + vals[0][i * element_size + k]) / 2
                            
        for i in range(line_size):
            for j in range(element_size):
                vals[0][i * element_size + j] = scaleOutsideVal(vals[0][i * element_size + j], britlo, brithi)
                   
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, britlo, brithi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            h = makeHistogram(vals, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals = modify(vals, element_size, line_size, filt_low, lookup)
        rangeObject.setSamples(vals)
        
    return data
开发者ID:RickKohrs,项目名称:mcidasv,代码行数:62,代码来源:imageFilters.py

示例4: printVals

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def printVals(sdataset):
    data = sdataset.clone()
    
    for t in xrange(data.getDomainSet().getLength()):
        rangeObj = data.getSample(t)
        vals = rangeObj.getFloats(0)
        domain = GridUtil.getSpatialDomain(rangeObj)
        [element_size, line_size] = domain.getLengths()
        
        for i in range(line_size):
            for j in range(element_size):
                print i, j, vals[0][i * element_size + j]
开发者ID:RickKohrs,项目名称:mcidasv,代码行数:14,代码来源:imageFilters.py

示例5: printValueDiff

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def printValueDiff(sdataset1, sdataset2):
    data1 = sdataset1.clone()
    data2 = sdataset2.clone()
    
    for t in xrange(data1.getDomainSet().getLength()):
        rangeObj1 = data1.getSample(t)
        rangeObj2 = data2.getSample(t)
        vals1 = rangeObj1.getFloats(0)
        """ vals2 = rangeObj1.getFloats(0)  TODO: bug? """
        vals2 = rangeObj2.getFloats(0)
        domain = GridUtil.getSpatialDomain(rangeObj1)
        [element_size, line_size] = domain.getLengths()
        
        for i in xrange(line_size):
            for j in xrange(element_size):
                print i, j, vals1[0][i * element_size + j] - vals2[0][i * element_size + j]
开发者ID:RickKohrs,项目名称:mcidasv,代码行数:18,代码来源:imageFilters.py

示例6: printValueDiff

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def printValueDiff(sdataset1, sdataset2):
    """Debug function that prints value differences between two datasets."""
    data1 = sdataset1.clone()
    data2 = sdataset2.clone()
    
    for t in xrange(data1.getDomainSet().getLength()):
        rangeObj1 = data1.getSample(t)
        rangeObj2 = data2.getSample(t)
        vals1 = rangeObj1.getFloats(0)
        # vals2 = rangeObj1.getFloats(0)  TODO: bug?
        vals2 = rangeObj2.getFloats(0)
        domain = GridUtil.getSpatialDomain(rangeObj1)
        [element_size, line_size] = domain.getLengths()
        
        for i in xrange(line_size):
            for j in xrange(element_size):
                print i, j, vals1[0][i * element_size + j] - vals2[0][i * element_size + j]
开发者ID:jon4than,项目名称:mcidasv,代码行数:19,代码来源:imageFilters.py

示例7: gradientFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def gradientFilter(sdataset, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Gradient filter from McIDAS-X.
    
    Args:
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    newData = sdataset.clone()
    stretch = user_stretchval
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    for t in range(newData.getDomainSet().getLength()):
        rangeObject = newData.getSample(t)
        vals = rangeObject.getFloats(0)
        in_hi = max(vals[0])
        in_low = min(vals[0])
        domain = GridUtil.getSpatialDomain(rangeObject)
        
        [element_size, line_size] = domain.getLengths()
        
        for i in range(line_size):
            for j in range(element_size)[:-1]:
                vals[0][i * element_size + j] = int(abs(vals[0][i * element_size + j] - vals[0][i * element_size + j + 1]))
                
            # set last value to zero
            vals[0][i * element_size + j + 1] = 0
            
        for i in range(line_size):
            for j in range(element_size):
                vals[0][i * element_size + j] = scaleOutsideVal(vals[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, britlo, brithi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            h = makeHistogram(vals, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals = modify(vals, element_size, line_size, filt_low, lookup)
        rangeObject.setSamples(vals)
        
    return newData
开发者ID:jon4than,项目名称:mcidasv,代码行数:46,代码来源:imageFilters.py

示例8: lowPass2DFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def lowPass2DFilter(sdataset, user_linecoef=0.5, user_elecoef=0.5, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Two dimensional low pass filter from McIDAS-X.
    
    Args:
        user_linecoef: Line coefficient: 0.0 < linecoef < 1.0.
        user_elecoef: Element coefficient: 0.0 < elecoef < 1.0.
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    newData = sdataset.clone()
    lcoef = float(user_linecoef)
    ecoef = float(user_elecoef)
    stretch=user_stretchval
    l1 = 1.0 - lcoef
    e1 = 1.0 - ecoef
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    for t in xrange(newData.getDomainSet().getLength()):
        rangeObject = newData.getSample(t)
        vals = rangeObject.getFloats(0)
        in_hi = max(vals[0])
        in_low = min(vals[0])
        domain = GridUtil.getSpatialDomain(rangeObject)
        [element_size, line_size] = domain.getLengths()
        
        # save the first line
        realLine = vals[0][0:element_size].tolist()
        
        for i in range(line_size):
            # left to right filter along line
            val = vals[0][i * element_size]
            for j in range(element_size):
                if vals[0][i * element_size + j] > 0:
                    val = ecoef * val + e1 * vals[0][i * element_size + j]
                vals[0][i * element_size + j] = lowPass2DRound(val+0.0000001)
                
            # right to left filter along line
            val = vals[0][i * element_size + (element_size - 1)]
            
            # second argument of -1 ensures that the 0th element is done
            for j in xrange(element_size - 1, -1, -1):
                val = ecoef * val + e1 * vals[0][i * element_size + j]
                vals[0][i * element_size + j] = lowPass2DRound(val) 
                
            # filter along the elements
            for j in range(element_size):
                val = lcoef * realLine[j] + l1 * vals[0][i * element_size + j]
                vals[0][i * element_size + j] = lowPass2DRound(val) 
                
            realLine = vals[0][i * element_size:i * element_size + element_size].tolist()
            
        # filter along the lines going through the image up the elements
        # save the last line
        realLine = vals[0][(line_size - 1) * element_size:line_size * element_size].tolist()
        
        # second argument of -1 ensures that the 0th line is done
        for i in xrange(line_size - 1, -1, -1):
            for j in range(element_size):
                val = lcoef * realLine[j] + l1 * vals[0][i * element_size + j]
                vals[0][i * element_size + j] = lowPass2DRound(val) 
                
            realLine = vals[0][i * element_size:i * element_size + element_size].tolist()
            
        for i in range(line_size):
            for j in range(element_size):
                vals[0][i * element_size + j] = scaleOutsideVal(vals[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, britlo, brithi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            # h = hist(field(vals), [0], [post_hi - post_low])
            h = makeHistogram(vals, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals = modify(vals, element_size, line_size, filt_low, lookup)
        rangeObject.setSamples(vals)
        
    return newData
开发者ID:jon4than,项目名称:mcidasv,代码行数:84,代码来源:imageFilters.py

示例9: cloudFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def cloudFilter(sdataset1, sdataset2, user_replace='Default', user_constant=0, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Cloud filter from McIDAS-X - requires 2 source datasets.
    
    Args:
        user_replace: Replacement value (default=minimum value in either 
                      sdataset1 or sdataset2)
        user_constant: Additive constant (default=0)
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    data1 = sdataset1.clone()
    data2 = sdataset2.clone()
    replace = user_replace
    constant = int(user_constant)
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    if replace != 'Default':
        replace = int(replace)
    stretch = user_stretchval
    
    for t in range(data1.getDomainSet().getLength()):
        range1 = data1.getSample(t)
        vals1 = range1.getFloats(0)
        min1 = min(vals1[0])
        max1 = max(vals1[0])
        range2 = data2.getSample(t)
        vals2 = range2.getFloats(0)
        min2 = min(vals2[0])
        max2 = max(vals2[0])
        in_low = min([min1, min2])
        in_hi = max([max1, max2])
        if replace == 'Default':
            replace = in_low
            
        domain = GridUtil.getSpatialDomain(range1)
        [element_size, line_size] = domain.getLengths()
        
        for i in range(line_size):
            for j in range(element_size):
                line1 = vals1[0][i * element_size + j]
                line2 = vals2[0][i * element_size + j]
                
                if line1 <= (line2 + constant):
                    vals1[0][i * element_size + j] = replace
                    
        for i in range(line_size):
            for j in range(element_size):
                vals1[0][i * element_size + j] = scaleOutsideVal(vals1[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min([min(vals1[0]), min2]))
        filt_hi = int(max([max(vals1[0]), max2]))
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, in_low, in_hi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            # make a histogram from both datasets
            v = []
            v.append(vals1[0])
            v.append(vals2[0])
            h = makeHistogram(v, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals1 = modify(vals1, element_size, line_size, filt_low, lookup)
        range1.setSamples(vals1)
        
    return data1
开发者ID:jon4than,项目名称:mcidasv,代码行数:68,代码来源:imageFilters.py

示例10: replaceFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def replaceFilter(sdataset, user_replaceVal=0, user_sourceval='Default', user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Replace filter from McIDAS-X.
    
    Args:
        user_replace : Replacement value  (default=0)
        user_sourceval: Source image values in the region to replace 
                        user_replace; specify values in the list format, 
                        e.g. val1 val2 val3 etc., or a range format, e.g. 
                        bval-eval (default=0-255)
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    newData = sdataset.clone()
    replaceVal = int(user_replaceVal)
    stretch = user_stretchval
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    # sourceVal can either be specified in list format: val1 val2 val3
    # or in a range format, bval-eval (default = 0-255) 
    if user_sourceval != 'Default':
        if '-' in user_sourceval:
            tempVal1 = [int(m) for m in user_sourceval.split('-')]
            tempVal = range(tempVal1[0], tempVal1[1] + 1)
        else:
            tempVal = user_sourceval.split()
    else:
        tempVal = range(0, 256)
        
    sourceVal = [float(m) for m in tempVal]
    
    for t in range(newData.getDomainSet().getLength()):
        rangeObject = newData.getSample(t)
        vals = rangeObject.getFloats(0)
        in_low = int(min(vals[0]))
        in_hi = int(max(vals[0]))
        domain = GridUtil.getSpatialDomain(rangeObject)
        
        [element_size, line_size] = domain.getLengths()
        
        for i in range(line_size):
            for j in range(element_size):
                line = vals[0][i * element_size + j]
                if (line in sourceVal):
                    line = replaceVal
                vals[0][i * element_size + j] = line
                
        for i in range(line_size):
            for j in range(element_size):
                vals[0][i * element_size + j] = scaleOutsideVal(vals[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, britlo, brithi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            h = makeHistogram(vals, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals = modify(vals, element_size, line_size, filt_low, lookup)
        rangeObject.setSamples(vals)
        
    return newData
开发者ID:jon4than,项目名称:mcidasv,代码行数:65,代码来源:imageFilters.py

示例11: passFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def passFilter(sdataset, user_passname, user_radius=50, user_leak=100, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Used by one-dimensional low-pass and high-pass filters from McIDAS-X.
    
    Args:
        user_passname: Either 'High' or 'Low'.
        user_radius: Sample length surrounding the source element; used for 
                     sample average.
        user_leak: Filter efficiency.
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    newData = sdataset.clone()
    radius = int(user_radius)
    leak = int(user_leak)
    stretch = user_stretchval
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    ntot = 2 * radius + 1
    nmod = radius + 1
    
    for t in xrange(len(newData)):
        rangeObject = newData.getSample(t)
        vals = rangeObject.getFloats()
        in_hi = max(vals[0])
        in_low = min(vals[0])
        midpoint = (in_hi - in_low) / 2 + in_low
        domain=GridUtil.getSpatialDomain(rangeObject)
        [element_size, line_size] = domain.getLengths()
        radiusArray = range(nmod)
        
        for i in xrange(line_size):
            nr = 1 + radius
            
            if nr > element_size:
                nr = element_size
                
            k = vals[0][i * element_size: i * element_size + nr].tolist()
            
            for p in range(len(k)):
                k[p] = int(k[p])
                
            radiusArray = radius * [int(vals[0][i * element_size])] + k
            nsum = sum(radiusArray)
            
            nright = radius
            for j in xrange(element_size):
                curVal = vals[0][i * element_size + j]
                average = int((leak * nsum) / (100 * ntot))
                
                if user_passname.startswith('High'):
                    vals[0][i * element_size + j] = scaleOutsideVal(curVal - average + midpoint, britlo, brithi)
                    
                if user_passname.startswith('Low'):
                    vals[0][i * element_size + j] = scaleOutsideVal(average, britlo, brithi)
                    
                # move the radius array one element to the right and 
                # recalculate the sum
                radiusArray.pop(0)
                nright = nright + 1
                mright = nright
                
                if mright > element_size - 1:
                    mright = element_size - 1
                    
                radiusArray.append(int(vals[0][i * element_size + mright]))
                nsum = sum(radiusArray)
                
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, britlo, brithi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            h = makeHistogram(vals, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals = modify(vals, element_size, line_size, filt_low, lookup)
        rangeObject.setSamples(vals)
        
    return newData
开发者ID:jon4than,项目名称:mcidasv,代码行数:83,代码来源:imageFilters.py

示例12: mergeFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def mergeFilter(sdataset1, sdataset2, user_brkpoint1='Default', user_brkpoint2='Default', user_constant=0, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Merge filter from McIDAS-X.
    
    Requires 2 source datasets; merges them if the sdataset1 value is between 
    the specified breakpoints, otherwise it selects the sdataset2 value minus 
    the specified constant.
    
    Args:
        user_brkpoint1: sdataset1 breakpoint value.
                        (default=minimum value in either source dataset)
        user_brkpoint2: sdataset2 breakpoint value.
                        (default=maximum value in either source dataset)
        user_constant: Subtractive constant.
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    data1 = sdataset1.clone()
    data2 = sdataset2.clone()
    brkpoint1 = user_brkpoint1
    brkpoint2 = user_brkpoint2
    constant = int(user_constant)
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    if brkpoint1 != 'Default':
        brkpoint1 = int(brkpoint1)
        
    if brkpoint2 != 'Default':
        brkpoint2 = int(brkpoint2)
        
    stretch = user_stretchval
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    for t in range(data1.getDomainSet().getLength()):
        range1 = data1.getSample(t)
        range2 = data2.getSample(t)
        vals1 = range1.getFloats(0)
        max1 = max(vals1[0])
        min1 = min(vals1[0])
        vals2 = range2.getFloats(0)
        max2 = max(vals2[0])
        min2 = min(vals2[0])
        in_low = min([min1, min2])
        in_hi = max([max1, max2])
        
        if brkpoint1 == 'Default':
            brkpoint1 = in_low
            
        if brkpoint2 == 'Default':
            brkpoint2 = in_hi
            
        domain = GridUtil.getSpatialDomain(range1)
        [element_size, line_size] = domain.getLengths()
        for i in range(line_size):
            for j in range(element_size):
                if vals1[0][i * element_size + j] < brkpoint1 or vals1[0][i * element_size + j] > brkpoint2:
                    vals1[0][i * element_size + j] = vals2[0][i * element_size + j] - constant
                    
        for i in range(line_size):
            for j in range(element_size):
                vals1[0][i * element_size + j] = scaleOutsideVal(vals1[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min([min(vals1[0]), min2]))
        filt_hi = int(max([max(vals1[0]), max2]))
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, in_low, in_hi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            # make a histogram from both datasets
            v = []
            v.append(vals1[0])
            v.append(vals2[0])
            h = makeHistogram(v, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals1 = modify(vals1, element_size, line_size, filt_low, lookup)
        range1.setSamples(vals1)
        
    return data1
开发者ID:jon4than,项目名称:mcidasv,代码行数:81,代码来源:imageFilters.py

示例13: discriminateFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def discriminateFilter(sdataset1, sdataset2, user_brkpoint1='Default', user_brkpoint2='Default', user_brkpoint3='Default', user_brkpoint4='Default', user_replace='Default', user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Discriminate filter from McIDAS-X.
    
    Requires 2 source datasets; used to mask off a portion of the first 
    source image.
    
    Args:
        user_brkpoint1: Low end breakpoint value for sdataset1.
                        (default=minimum value in either source dataset)
        user_brkpoint2: High end breakpoint value for sdataset1.
                        (default=maximum value in either source dataset)
        user_brkpoint3: Low end breakpoint value for sdataset2.
                        (default=minimum value in either source dataset)
        user_brkpoint4: High end breakpoint value for sdataset2.
                        (default=maximum value in either source dataset)
        user_replace: Failure condition replacement value 
                      (default=minimum value in either source dataset)
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    data1 = sdataset1.clone()
    data2 = sdataset2.clone()
    brkpoint1 = user_brkpoint1
    brkpoint2 = user_brkpoint2
    brkpoint3 = user_brkpoint3
    brkpoint4 = user_brkpoint4
    replace = user_replace
    stretch = user_stretchval
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    if brkpoint1 != 'Default':
        brkpoint1 = int(brkpoint1)
        
    if brkpoint2 != 'Default':
        brkpoint2 = int(brkpoint2)
        
    if brkpoint3 != 'Default':
        brkpoint3 = int(brkpoint3)
        
    if brkpoint4 != 'Default':
        brkpoint4 = int(brkpoint4)
        
    if replace != 'Default':
        replace = int(replace)
        
    for t in range(data1.getDomainSet().getLength()):
        range1 = data1.getSample(t)
        range2 = data2.getSample(t)
        vals1 = range1.getFloats(0)
        max1 = max(vals1[0])
        min1 = min(vals1[0])
        vals2 = range2.getFloats(0)
        max2 = max(vals2[0])
        min2 = min(vals2[0])
        in_low = int(min([min1, min2]))
        in_hi = int(max([max1, max2]))
        
        if brkpoint1 == 'Default':
            brkpoint1=in_low
            
        if brkpoint2 == 'Default':
            brkpoint2=in_hi
            
        if brkpoint3 == 'Default':
            brkpoint3=in_low
            
        if brkpoint4 == 'Default':
            brkpoint4 = in_hi
            
        if replace == 'Default':
            replace = in_low
            
        domain = GridUtil.getSpatialDomain(range1)
        [element_size, line_size] = domain.getLengths()
        for i in range(line_size):
            for j in range(element_size):
                if vals1[0][i * element_size + j] < brkpoint1 or vals1[0][i * element_size + j] > brkpoint2 or vals2[0][i * element_size + j] < brkpoint3 or vals2[0][i * element_size + j] > brkpoint4:
                    vals1[0][i * element_size + j]=replace
                    
        if stretch == 'Contrast':
            lookup = contrast(in_low, in_hi, britlo, brithi, in_low, in_hi)
        elif stretch == 'Histogram':
            """ make a histogram from the first dataset """
            h = makeHistogram(vals1, element_size, line_size, in_low, brithi - britlo)
            lookup = histoStretch(in_low, in_hi, britlo, brithi, h)
            
        vals1 = modify(vals1, element_size, line_size, in_low, lookup)
        range1.setSamples(vals1)
        
    return data1
开发者ID:jon4than,项目名称:mcidasv,代码行数:93,代码来源:imageFilters.py

示例14: coreFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def coreFilter(sdataset1, sdataset2, user_brkpoint1='Default', user_brkpoint2='Default', user_replace1='Default', user_replace2='Default', user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Core filter from McIDAS-X.
    
    Requires 2 source datasets; resulting image has only 2 values.
    
    Args:
        user_brkpoint1: Sdataset1 breakpoint value.
                        (default=minimum value in either source dataset)
        user_brkpoint2: Sdataset2 breakpoint value.
                        (default=maximum value in either source dataset)
        user_replace1: Success condition replacement value.
                       (default=maximum value in either source dataset)
        user_replace2: Failure condition replacement value.
                       (default=minimum vlaue in either source dataset)
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    data1 = sdataset1.clone()
    data2 = sdataset2.clone()
    brkpoint1 = user_brkpoint1
    brkpoint2 = user_brkpoint2
    replace1 = user_replace1
    replace2 = user_replace2
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    if brkpoint1 != 'Default':
        brkpoint1=int(brkpoint1)
        
    if brkpoint2 != 'Default':
        brkpoint2=int(brkpoint2)
        
    if replace1 != 'Default':
        replace1=int(replace1)
        
    if replace2 != 'Default':
        replace2 = int(replace2)
        
    stretch = user_stretchval
    
    for t in range(data1.getDomainSet().getLength()):
        range1 = data1.getSample(t)
        range2 = data2.getSample(t)
        vals1 = range1.getFloats(0)
        max1 = max(vals1[0])
        min1 = min(vals1[0])
        vals2 = range2.getFloats(0)
        max2 = max(vals2[0])
        min2 = min(vals2[0])
        in_low = min([min1, min2])
        in_hi = max([max1, max2])
        
        if brkpoint1 == 'Default':
            brkpoint1 = in_low
            
        if brkpoint2 == 'Default':
            brkpoint2 = in_hi
            
        if replace1 == 'Default':
            replace1 = brkpoint2
            
        if replace2 == 'Default':
            replace2 = brkpoint1
            
        domain = GridUtil.getSpatialDomain(range1)
        [element_size, line_size] = domain.getLengths()
        for i in range(line_size):
            for j in range(element_size):
                if (vals1[0][i * element_size + j] > brkpoint1 and vals2[0][i * element_size + j] > brkpoint2):
                    vals1[0][i * element_size + j] = replace1
                else:
                    vals1[0][i * element_size + j]=replace2
                    
        for i in range(line_size):
            for j in range(element_size):
                vals1[0][i * element_size + j] = scaleOutsideVal(vals1[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min([min(vals1[0]), min2]))
        filt_hi = int(max([max(vals1[0]), max2]))
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, in_low, in_hi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            # make a histogram from both datasets
            v = []
            v.append(vals1[0])
            v.append(vals2[0])
            h = makeHistogram(v, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, in_low, in_hi, h)
            
        vals1 = modify(vals1, element_size, line_size, filt_low, lookup)
        range1.setSamples(vals1)
        
    return data1
开发者ID:jon4than,项目名称:mcidasv,代码行数:95,代码来源:imageFilters.py

示例15: cleanFilter

# 需要导入模块: from ucar.unidata.data.grid import GridUtil [as 别名]
# 或者: from ucar.unidata.data.grid.GridUtil import getSpatialDomain [as 别名]
def cleanFilter(sdataset, user_fill='Average', user_bline='Default', user_eline='Default', user_pdiff=15, user_ldiff=15, user_stretchval='Contrast', user_britlo=0, user_brithi=255):
    """Clean filter from McIDAS-X.
    
    Args:
        user_fill: 'Average': average of surrounding values (default)
                   'Min'    : source dataset minimum value
                   'Max'    : source dataset maximum value
        user_bline: Beginning line in the source image to clean.
                    (default=first line)
        user_eline: Ending line in the source image to clean.
                    (default = last line)
        user_pdiff: Absolute difference between an element's value and value 
                    of the element on either side.
        user_ldiff: Percentage difference between a line's average value and 
                    the average value of the line above and below.
        user_britlo: Minimum brightness value for the calibration.
        user_brithi: Maximum brightness value for the calibration.
    """
    newData = sdataset.clone()
    
    filter_fill = user_fill
    bline = user_bline
    eline = user_eline
    britlo = int(user_britlo)
    brithi = int(user_brithi)
    
    if bline != 'Default':
        bline = int(bline)
    else:
        bline = 0
    if eline != 'Default':
        eline = int(eline)
        
    filter_diff = int(user_pdiff)
    l_diff = int(user_ldiff)
    stretch = user_stretchval
    
    for t in range(newData.getDomainSet().getLength()):
        rangeObject = newData.getSample(t)
        vals = rangeObject.getFloats(0)
        in_hi = int(max(vals[0]))
        in_low = int(min(vals[0]))
        point_diff = (in_hi - in_low + 1) * (filter_diff / 100.0)
        line_diff = (in_hi - in_low + 1) * (l_diff / 100.0)
        domain = GridUtil.getSpatialDomain(rangeObject)
        [element_size, line_size] = domain.getLengths()
        if eline == 'Default':
            eline = line_size
            
        vals = shotMain(vals, bline, eline, element_size, line_size, point_diff)
        for i in range(line_size):
            for j in range(element_size):
                vals[0][i * element_size + j] = scaleOutsideVal(vals[0][i * element_size + j], britlo, brithi)
                
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        
        vals = badLineFilter(vals, bline, eline, element_size, line_size, filter_fill, line_diff, filt_low, filt_hi)
        
        # update the min/max of the image after the removal of the bad lines
        filt_low = int(min(vals[0]))
        filt_hi = int(max(vals[0]))
        
        if stretch == 'Contrast':
            lookup = contrast(filt_low, filt_hi, britlo, brithi, filt_low, filt_hi)
        elif stretch == 'Histogram':
            h = makeHistogram(vals, element_size, line_size, filt_low, brithi - britlo)
            lookup = histoStretch(filt_low, filt_hi, britlo, brithi, h)
            
        vals = modify(vals, element_size, line_size, filt_low, lookup)
        rangeObject.setSamples(vals)
        
    return newData
开发者ID:jon4than,项目名称:mcidasv,代码行数:75,代码来源:imageFilters.py


注:本文中的ucar.unidata.data.grid.GridUtil.getSpatialDomain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。