def linearscale(input, boundfrom, boundto, extrema=None):
        """
        Rescale the data in the range 'boundfrom' to the range 'boundto'.
        """

        minfrom,maxfrom = boundfrom
        minto,maxto = boundto

        ### default from bounds are min,max of the input
        if minfrom is None:
                if extrema:
                        minfrom = extrema[0]
                else:
                        minfrom = arraystats.min(input)
        if maxfrom is None:
                if extrema:
                        maxfrom = extrema[1]
                else:
                        maxfrom = arraystats.max(input)

        rangefrom = maxfrom - minfrom
        if rangefrom == 0:
                # if min==max, do simple thresholding
                output = numpy.where(input>maxfrom, maxto, minto)
        else:
                rangeto = maxto - minto
                scale = float(rangeto) / rangefrom
                offset = minfrom * scale
                output = input * scale - offset

        return output
def linearscale(input, boundfrom, boundto, extrema=None):
	"""
	Rescale the data in the range 'boundfrom' to the range 'boundto'.
	"""

	minfrom,maxfrom = boundfrom
	minto,maxto = boundto
	if minfrom is not None and maxfrom is not None:
		if minfrom == maxfrom:
			raise RuntimeError('Invalid range: %s' % (boundfrom,))

	### default from bounds are min,max of the input
	if minfrom is None:
		if extrema:
			minfrom = extrema[0]
		else:
			minfrom = arraystats.min(input)
	if maxfrom is None:
		if extrema:
			maxfrom = extrema[1]
		else:
			maxfrom = arraystats.max(input)

	rangefrom = maxfrom - minfrom
	rangeto = maxto - minto

	scale = float(rangeto) / rangefrom
	offset = minfrom * scale
	output = input * scale - offset

	return output
示例#3
0
def linearscale(input, boundfrom, boundto, extrema=None):
    """
	Rescale the data in the range 'boundfrom' to the range 'boundto'.
	"""

    minfrom, maxfrom = boundfrom
    minto, maxto = boundto
    if minfrom is not None and maxfrom is not None:
        if minfrom == maxfrom:
            raise RuntimeError('Invalid range: %s' % (boundfrom, ))

    ### default from bounds are min,max of the input
    if minfrom is None:
        if extrema:
            minfrom = extrema[0]
        else:
            minfrom = arraystats.min(input)
    if maxfrom is None:
        if extrema:
            maxfrom = extrema[1]
        else:
            maxfrom = arraystats.max(input)

    rangefrom = maxfrom - minfrom
    rangeto = maxto - minto

    scale = float(rangeto) / rangefrom
    offset = minfrom * scale
    output = input * scale - offset

    return output
示例#4
0
def linearscale(input, boundfrom, boundto, extrema=None):
    """
	Rescale the data in the range 'boundfrom' to the range 'boundto'.
	"""

    minfrom, maxfrom = boundfrom
    minto, maxto = boundto

    ### default from bounds are min,max of the input
    if minfrom is None:
        if extrema:
            minfrom = extrema[0]
        else:
            minfrom = arraystats.min(input)
    if maxfrom is None:
        if extrema:
            maxfrom = extrema[1]
        else:
            maxfrom = arraystats.max(input)

    rangefrom = maxfrom - minfrom
    if rangefrom == 0:
        # if min==max, do simple thresholding
        output = numpy.where(input > maxfrom, maxto, minto)
    else:
        rangeto = maxto - minto
        scale = float(rangeto) / rangefrom
        offset = minfrom * scale
        output = input * scale - offset

    return output