def generate_rainfall_from_temperature(nodes): from everett.features.climate import whittaker import noise for node in nodes: temperature_to_consider = node.get_feature(['surface', 'temperature']) min_rainfall, max_rainfall = whittaker.rainfall_range(temperature_to_consider) if min_rainfall is None or max_rainfall is None: node.set_feature(['precipitation', 'mm'], 0.0) else: # noise_point = 0.5*(noise.pnoise2(b.longitude/180.0, b.latitude/90.0) + 1.0) # noise_point = random.uniform(0.0, 1.0) noise_point = 0.5*(1.0+noise.snoise3(node.x, node.y, node.z)) node.set_feature(['precipitation', 'mm'], (noise_point * (max_rainfall - min_rainfall) + min_rainfall))
for b in w.all_boundary_nodes: if b.biome in biomes: biomes[b.biome] += 1 else: biomes[b.biome] = 1 print("Number of biomes: {}".format(len(biomes.keys()))) print(biomes) elif interrogation == "biome graph": plt.plot([b.get_feature(['surface', 'temperature']) for b in w.all_boundary_nodes], [b.get_feature(['precipitation', 'mm']) for b in w.all_boundary_nodes], 'ro') plt.show() elif interrogation == "temperature graph": plt.plot([b.latitude for b in w.all_boundary_nodes], [b.get_feature(['surface', 'temperature']) for b in w.all_boundary_nodes], 'ro') plt.show() elif interrogation == "whittaker": r = [0.1 * i for i in range(-140, 360)] plt.plot(r, [whittaker.rainfall_range(x)[0] for x in r], 'bo', r, [whittaker.rainfall_range(x)[1] for x in r], 'ro') plt.show() elif interrogation == "last" and len(n_list): print_node(n_list[-1]) elif interrogation == "first" and len(n_list): print_node(n_list[0]) elif "where" in interrogation and interrogation.split() == 4: where, feature, comparator, value = interrogation.split(None, 4) try: feature_list = feature.strip().split('_') value = float(value.strip()) comparator = comparator.strip() n_list = [b for b in w.all_boundary_nodes if getattr(operator, comparator)(b.get_feature(feature_list), value)] print("{} nodes found".format(len(n_list))) except: print("where <feature> gt/ge/eq/ne/le/lt <value>")