Return the closest zoom level for a given resolution
        Parameters:
            resolution -- max. resolution
            unit -- unit for output (default='meters')
10904
def getClosestZoom(self, resolution, unit='meters'):
        
        lo, hi = self._getZoomLevelRange(resolution, unit)
        if lo == 0:
            return lo
        if hi == len(self.RESOLUTIONS):
            return hi - 1
        before = self.RESOLUTIONS[lo - 1]
        if abs(self.RESOLUTIONS[lo] - resolution) < abs(before - resolution):
            return lo
        return lo - 1
500237
def _getMinMax(img):
    '''
    
    '''
    av = np.mean(img)
    std = np.std(img)
    # define range for segmentation:
    mn = av - 3 * std
    mx = av + 3 * std

    return max(img.min(), mn, 0), min(img.max(), mx)
1113940
def prox_max(X, step, thresh=0):
    
    thresh_ = _step_gamma(step, thresh)
    above = X - thresh_ > 0
    X[above] = thresh_
    return X
1220177
private static boolean closerToZoomIn(double[] lengths, double length,
			int lengthIndex) {

		// Zoom level distance to the zoomed in length
		double zoomInDistance = Math.log(length / lengths[lengthIndex - 1])
				/ Math.log(2);

		// Zoom level distance to the zoomed out length
		double zoomOutDistance = Math.log(length / lengths[lengthIndex])
				/ Math.log(.5);

		boolean zoomIn = zoomInDistance < zoomOutDistance;

		return zoomIn;
	}
974353
def getScale(self, zoom):
        """"""
        if self.unit == 'degrees':
            resolution = self.getResolution(zoom) * EPSG4326_METERS_PER_UNIT
        else:
            resolution = self.getResolution(zoom)
        return resolution / STANDARD_PIXEL_SIZE
1203874
def _get_dst_resolution(self, dst_res=None):
        """"""
        if dst_res is None:
            dst_res = min(self._res_indices.keys())
        return dst_res
572393
def _get_distance_scaling(self, C, dists, mag):
        
        r_h = self._get_rh(C, dists)
        return (C["c1"] + C["c2"] * (mag - self.CONSTANTS["mref"])) *\
            np.log(r_h / self.CONSTANTS["rref"]) +\
            C["c3"] * (r_h - self.CONSTANTS["rref"])
1049214
function(resolution) {
      
        if (this.resolutions != null) {
            return OpenLayers.Layer.prototype.getZoomForResolution.apply(this, arguments);
        } else {
            var extent = OpenLayers.Layer.prototype.getExtent.apply(this, []);
            return this.getZoomForExtent(extent);
        }
    }
1031076
def _get_distance_scaling(self, C, mag, rhypo):
        
        return (C["a3"] * np.log(rhypo)) + (C["a4"] + C["a5"] * mag) * rhypo
313181
def bounds(self):
        
        return [scipy.stats.lognorm.interval(self.i, s, loc=0, scale=em) for s, em in zip(self.sigma, self.emu)]
481414
def zoom_out_frag(self, curr_frag):
        
        level = curr_frag[1]
        frag = curr_frag[0]
        output = []
        if level > 0:
            str_level = str(level)
            high_frag = self.spec_level[str_level]["fragments_dict"][frag][
                "super_index"
            ]
            new_level = level + 1
            output = (high_frag, new_level)
        else:
            output = curr_frag
        return output
51165
public int getResolutionIndex(double resolution) {
		double maximumResolution = getMaximumResolution();
		if (resolution >= maximumResolution) {
			return 0;
		}
		double minimumResolution = getMinimumResolution();
		if (resolution <= minimumResolution) {
			return resolutions.size() - 1;
		}

		for (int i = 0; i < resolutions.size(); i++) {
			double upper = resolutions.get(i);
			double lower = resolutions.get(i + 1);
			if (resolution < upper && resolution >= lower) {
				if (Math.abs(upper - resolution) >= Math.abs(lower - resolution)) {
					return i + 1;
				} else {
					return i;
				}
			}
		}
		return 0;
	}
81921
protected void findLocalScaleSpaceMax(PyramidFloat<T> ss, int layerID) {
		int index0 = spaceIndex;
		int index1 = (spaceIndex + 1) % 3;
		int index2 = (spaceIndex + 2) % 3;

		List<Point2D_I16> candidates = maximums[index1];
		ImageBorder_F32 inten0 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index0], 0);
		GrayF32 inten1 = intensities[index1];
		ImageBorder_F32 inten2 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index2], 0);

		float scale0 = (float) ss.scale[layerID - 1];
		float scale1 = (float) ss.scale[layerID];
		float scale2 = (float) ss.scale[layerID + 1];

		float sigma0 = (float) ss.getSigma(layerID - 1);
		float sigma1 = (float) ss.getSigma(layerID);
		float sigma2 = (float) ss.getSigma(layerID + 1);

		// not sure if this is the correct way to handle the change in scale
		float ss0 = (float) (Math.pow(sigma0, scalePower)/scale0);
		float ss1 = (float) (Math.pow(sigma1, scalePower)/scale1);
		float ss2 = (float) (Math.pow(sigma2, scalePower)/scale2);

		for (Point2D_I16 c : candidates) {
			float val = ss1 * inten1.get(c.x, c.y);

			// find pixel location in each image's local coordinate
			int x0 = (int) (c.x * scale1 / scale0);
			int y0 = (int) (c.y * scale1 / scale0);

			int x2 = (int) (c.x * scale1 / scale2);
			int y2 = (int) (c.y * scale1 / scale2);

			if (checkMax(inten0, val / ss0, x0, y0) && checkMax(inten2, val / ss2, x2, y2)) {
				// put features into the scale of the upper image
				foundPoints.add(new ScalePoint(c.x * scale1, c.y * scale1, sigma1));
			}
		}
	}
1169319
private double checkResolution(double resolution, ZoomOption zoomOption) {
		double allowedResolution = resolution;
		double maximumResolution = getMaximumResolution();
		double minimumResolution = getMinimumResolution();
		if (allowedResolution > maximumResolution) {
			allowedResolution = maximumResolution;
		} else if (allowedResolution < minimumResolution) {
			allowedResolution = minimumResolution;
		}

		if (zoomOption == ZoomOption.FREE) {
			return allowedResolution;
		}

		for (int i = 0; i < resolutions.size() - 1; i++) {
			double upper = resolutions.get(i);
			double lower = resolutions.get(i + 1);

			if (allowedResolution == upper) {
				return upper;
			} else if (allowedResolution == lower) {
				return lower;
			} else if (allowedResolution < upper && allowedResolution > lower) {
				switch (zoomOption) {
					case LEVEL_FIT:
						return upper;
					case LEVEL_CLOSEST:
						if (Math.abs(upper - allowedResolution) < Math.abs(allowedResolution - lower)) {
							return upper;
						} else {
							return lower;
						}
					default:
						return allowedResolution;
				}
			}
		}
		return allowedResolution;
	}
615221
def mouse_zoom(self, inc):
        '''

        '''
        # Square Distance from pivot
        dsq = np.linalg.norm(self.position - self.pivot)
        minsq = 1.0**2  # How near can we be to the pivot
        maxsq = 7.0**2 # How far can we go 

        scalefac = 0.25

        if dsq > maxsq and inc < 0: 
            # We're going too far
            pass
        elif dsq < minsq and inc > 0:
            # We're going too close
            pass
        else:
            # We're golden
            self.position += self.c*inc*scalefac
787138
def zoom_in_frag(self, curr_frag):
        
        level = curr_frag[1]
        frag = curr_frag[0]
        output = []
        if level > 0:
            str_level = str(level)
            sub_low = self.spec_level[str_level]["fragments_dict"][frag][
                "sub_low_index"
            ]
            sub_high = self.spec_level[str_level]["fragments_dict"][frag][
                "sub_high_index"
            ]
            new_level = level - 1
            for i in range(sub_low, sub_high + 1):
                output.append((i, new_level))
        else:
            output.append(curr_frag)
        return output
117496
def ground_resolution(lat, level):
        """"""
        lat = TileSystem.clip(lat, TileSystem.LATITUDE_RANGE)
        return cos(lat * pi / 180) * 2 * pi * TileSystem.EARTH_RADIUS / TileSystem.map_size(level)