Calculate the ocean, the sea depth and the elevation thresholds
    :param world: a world having elevation but not thresholds
    :param ocean_level: the elevation representing the ocean level
    :return: nothing, the world will be changed
191091
def initialize_ocean_and_thresholds(world, ocean_level=1.0):
    
    e = world.layers['elevation'].data
    ocean = fill_ocean(e, ocean_level)
    hl = find_threshold_f(e, 0.10)  # the highest 10% of all (!) land are declared hills
    ml = find_threshold_f(e, 0.03)  # the highest 3% are declared mountains
    e_th = [('sea', ocean_level),
            ('plain', hl),
            ('hill', ml),
            ('mountain', None)]
    harmonize_ocean(ocean, e, ocean_level)
    world.ocean = ocean
    world.elevation = (e, e_th)
    world.sea_depth = sea_depth(world, ocean_level)
955657
def get_mesh(sitecol, complete=True):
    
    sc = sitecol.complete if complete else sitecol
    if sc.at_sea_level():
        mesh = numpy.zeros(len(sc), [('lon', F64), ('lat', F64)])
        mesh['lon'] = sc.lons
        mesh['lat'] = sc.lats
    else:
        mesh = numpy.zeros(len(sc), [('lon', F64), ('lat', F64),
                                     ('depth', F64)])
        mesh['lon'] = sc.lons
        mesh['lat'] = sc.lats
        mesh['depth'] = sc.depths
    return mesh
1315329
def level(self, lvl=None):
        ''''''
        if not lvl:
            return self._lvl
        self._lvl = self._parse_level(lvl)
        self.stream.setLevel(self._lvl)
        logging.root.setLevel(self._lvl)
132243
public static AffineTransform getWorldToPixel( Envelope worldEnvelope, Rectangle pixelRectangle ) {
        double width = pixelRectangle.getWidth();
        double worldWidth = worldEnvelope.getWidth();
        double height = pixelRectangle.getHeight();
        double worldHeight = worldEnvelope.getHeight();

        AffineTransform translate = AffineTransform.getTranslateInstance(-worldEnvelope.getMinX(), -worldEnvelope.getMinY());
        AffineTransform scale = AffineTransform.getScaleInstance(width / worldWidth, height / worldHeight);
        AffineTransform mirror_y = new AffineTransform(1, 0, 0, -1, 0, pixelRectangle.getHeight());
        AffineTransform world2pixel = new AffineTransform(mirror_y);
        world2pixel.concatenate(scale);
        world2pixel.concatenate(translate);
        return world2pixel;
    }
900530
def set_world(self, world):
        '''
        
        '''
        if world.get_entity_by_tag(self._tag) and self._tag != '':
            raise NonUniqueTagError(self._tag)
        else:
            self._world = world
            world.add_entity(self, True)
195683
def intersect(self, **kwargs):
        
        end_point = kwargs.pop('end_point')
        depth = self.get_depth(location=end_point)
        # Bathymetry and a particle's depth are both negative down
        if depth < 0 and depth > end_point.depth:
            inter = True
        else:
            inter = False
        return inter
878946
def _calculate(seed, world):
        """"""
        rng = numpy.random.RandomState(seed)  # create our own random generator
        base = rng.randint(0, 4096)

        curve_gamma = world.gamma_curve
        curve_bonus = world.curve_offset
        height = world.height
        width = world.width
        border = width / 4
        precipitations = numpy.zeros((height, width), dtype=float)

        octaves = 6
        freq = 64.0 * octaves

        n_scale = 1024 / float(height) #This is a variable I am adding. It exists
                                       #so that worlds sharing a common seed but
                                       #different sizes will have similar patterns

        for y in range(height):#TODO: numpy
            for x in range(width):
                n = snoise2((x * n_scale) / freq, (y * n_scale) / freq, octaves, base=base)

                # Added to allow noise pattern to wrap around right and left.
                if x < border:
                    n = (snoise2( (x * n_scale) / freq, (y * n_scale) / freq, octaves,
                                 base=base) * x / border) + (
                        snoise2(( (x * n_scale) + width) / freq, (y * n_scale) / freq, octaves,
                                base=base) * (border - x) / border)

                precipitations[y, x] = n

        #find ranges
        min_precip = precipitations.min()
        max_precip = precipitations.max()
        min_temp = world.layers['temperature'].min()
        max_temp = world.layers['temperature'].max()
        precip_delta = (max_precip - min_precip)
        temp_delta = (max_temp - min_temp)
        
        #normalize temperature and precipitation arrays
        t = (world.layers['temperature'].data - min_temp) / temp_delta
        p = (precipitations - min_precip) / precip_delta
        
        #modify precipitation based on temperature

        #--------------------------------------------------------------------------------
        #
        # Ok, some explanation here because why the formula is doing this may be a
        # little confusing. We are going to generate a modified gamma curve based on 
        # normalized temperature and multiply our precipitation amounts by it.
        #
        # numpy.power(t,curve_gamma) generates a standard gamma curve. However
        # we probably don't want to be multiplying precipitation by 0 at the far
        # side of the curve. To avoid this we multiply the curve by (1 - curve_bonus)
        # and then add back curve_bonus. Thus, if we have a curve bonus of .2 then
        # the range of our modified gamma curve goes from 0-1 to 0-.8 after we
        # multiply and then to .2-1 after we add back the curve_bonus.
        #
        # Because we renormalize there is not much point to offsetting the opposite end
        # of the curve so it is less than or more than 1. We are trying to avoid
        # setting the start of the curve to 0 because f(t) * p would equal 0 when t equals
        # 0. However f(t) * p does not automatically equal 1 when t equals 1 and if we
        # raise or lower the value for f(t) at 1 it would have negligible impact after
        # renormalizing.
        #
        #--------------------------------------------------------------------------------
        
        curve = (numpy.power(t, curve_gamma) * (1-curve_bonus)) + curve_bonus
        precipitations = numpy.multiply(p, curve)

        #Renormalize precipitation because the precipitation 
        #changes will probably not fully extend from -1 to 1.
        min_precip = precipitations.min()
        max_precip = precipitations.max()
        precip_delta = (max_precip - min_precip)
        precipitations = (((precipitations - min_precip) / precip_delta) * 2) - 1
        
        return precipitations
1219686
def _check_scalar_vertical_extents(self, ds, z_variable):
        '''
        
        '''
        vert_min = ds.geospatial_vertical_min
        vert_max = ds.geospatial_vertical_max
        msgs = []
        total = 2

        zvalue = ds.variables[z_variable][:].item()
        if not np.isclose(vert_min, vert_max):
            msgs.append("geospatial_vertical_min != geospatial_vertical_max for scalar depth values, %s != %s" % (
                vert_min,
                vert_max
            ))

        if not np.isclose(vert_max, zvalue):
            msgs.append("geospatial_vertical_max != %s values, %s != %s" % (
                z_variable,
                vert_max,
                zvalue
            ))

        return Result(BaseCheck.MEDIUM,
                      (total - len(msgs), total),
                      'geospatial_vertical_extents_match',
                      msgs)
820161
private int calculateEndLevel() {

        int result = 0;
        if (m_navRootPath != null) {
            // where are we? (start level)

            StringTokenizer counter = new StringTokenizer(m_navRootPath, "/", false);
            // one less as level 0 nav elements accepted is one level (depth 1).
            result = counter.countTokens() - 1;
            if (!CmsResource.isFolder(m_navRootPath)) {
                // cut stuff like system/workpalce/locale/de/help/index.html
                result--;
            }
            result += m_depth;
        }
        if (result < 0) {
            result = 0;
        }
        return result;
    }
171843
def levels(self):
        
        ret = [[] for i in range(self.height)]
        for node in self.subtree:
            ret[node.level - self.level].append(node)
        return ret
887704
def layer_height(self, layer_int):
        
        if layer_int == self.n_layers:
            if self.height is None:
                return None
            return self.height - self.layer_depth(layer_int)
        else:
            return self.layer_depth(layer_int + 1) - self.layer_depth(layer_int)
920283
def river_erosion(self, river, world):
        

        # erosion around river, create river valley
        for r in river:
            rx, ry = r
            radius = 2
            for x in range(rx - radius, rx + radius):
                for y in range(ry - radius, ry + radius):
                    if not self.wrap and not world.contains(
                            (x, y)):  # ignore edges of map
                        continue
                    x, y = overflow(x, world.width), overflow(y, world.height)
                    curve = 1.0
                    if [x, y] == [0, 0]:  # ignore center
                        continue
                    if [x, y] in river:  # ignore river itself
                        continue
                    if world.layers['elevation'].data[y, x] <= world.layers['elevation'].data[ry, rx]:
                        # ignore areas lower than river itself
                        continue
                    if not in_circle(radius, rx, ry, x,
                                     y):  # ignore things outside a circle
                        continue

                    adx, ady = math.fabs(rx - x), math.fabs(ry - y)
                    if adx == 1 or ady == 1:
                        curve = 0.2
                    elif adx == 2 or ady == 2:
                        curve = 0.05

                    diff = world.layers['elevation'].data[ry, rx] - world.layers['elevation'].data[y, x]
                    newElevation = world.layers['elevation'].data[y, x] + (
                        diff * curve)
                    if newElevation <= world.layers['elevation'].data[ry, rx]:
                        print('newElevation is <= than river, fix me...')
                        newElevation = world.layers['elevation'].data[r, x]
                    world.layers['elevation'].data[y, x] = newElevation
        return
915719
def draw_rivers_on_image(world, target, factor=1):
    

    for y in range(world.height):
        for x in range(world.width):
            if world.is_land((x, y)) and (world.layers['river_map'].data[y, x] > 0.0):
                for dx in range(factor):
                    for dy in range(factor):
                        target.set_pixel(x * factor + dx, y * factor + dy, (0, 0, 128, 255))
            if world.is_land((x, y)) and (world.layers['lake_map'].data[y, x] != 0):
                for dx in range(factor):
                    for dy in range(factor):
                        target.set_pixel(x * factor + dx, y * factor + dy, (0, 100, 128, 255))
914928
def _onGlobal(self, name, line, pos, absPosition, level):
        """"""
        # level is ignored
        for item in self.globals:
            if item.name == name:
                return
        self.globals.append(Global(name, line, pos, absPosition))
610373
def calculate_bucket_level(k, b):
    
    assert k >= 2
    if k == 2:
        return log2floor(b+1)
    v = (k - 1) * (b + 1) + 1
    h = 0
    while k**(h+1) < v:
        h += 1
    return h
112442
function(coords){
			var keys = geolib.getKeys(coords[0]);
			var elevation = keys.elevation;
			var rise = Math.abs(coords[coords.length-1][elevation] - coords[0][elevation]);
			var run = geolib.getPathLength(coords);
			return Math.floor((rise/run)*100);
		}
485523
def setExpertLevel(self):
        
        g = get_root(self).globals
        level = g.cpars['expert_level']

        # now set whether buttons are permanently enabled or not
        if level == 0 or level == 1:
            self.load.setNonExpert()
            self.save.setNonExpert()
            self.unfreeze.setNonExpert()
            self.start.setNonExpert()
            self.stop.setNonExpert()

        elif level == 2:
            self.load.setExpert()
            self.save.setExpert()
            self.unfreeze.setExpert()
            self.start.setExpert()
            self.stop.setExpert()