def test_minimal_island(): """Island of single jungle cell""" BioSim(island_geography="OOO\nOJO\nOOO", initial_population=[], seed=1)
def test_invalid_boundary(bad_boundary): """Non-ocean boundary must raise error""" with pytest.raises(ValueError): BioSim(island_map="{}WW\nWLW\nWWW".format(bad_boundary), ini_pop=[], seed=1)
def test_inconsistent_length(): """Inconsistent line length must raise error""" with pytest.raises(ValueError): BioSim(island_map="WWW\nWLLW\nWWW", ini_pop=[], seed=1)
def plain_sim(): """Return a simple island for used in various tests below""" return BioSim(island_map="WWWW\nWLHW\nWWWW", ini_pop=[], seed=1)
def test_minimal_island(): """Island of single jungle cell""" BioSim(island_map="WWW\nWLW\nWWW", ini_pop=[], seed=1)
def test_all_types(): """All types of landscape can be created""" BioSim(island_map="OOOO\nOJSO\nOMDO\nOOOO", ini_pop=[], seed=1)
"pop": [{ "species": "Herbivore", "age": 5, "weight": 20 } for _ in range(150)], }] ini_carns = [{ "loc": (10, 10), "pop": [{ "species": "Carnivore", "age": 5, "weight": 20 } for _ in range(40)], }] sim = BioSim(island_map=geogr, ini_pop=ini_herbs, seed=123456) sim.set_animal_parameters("Herbivore", {"zeta": 3.2, "xi": 1.8}) sim.set_animal_parameters( "Carnivore", { "a_half": 70, "phi_age": 0.5, "omega": 0.3, "F": 65, "DeltaPhiMax": 9.0, }, ) sim.set_landscape_parameters("J", {"f_max": 700})
OJOJOJOJOO OOJOJOJOJO OJOJOJOJOO OOOOOOOOOO """ checker_map = textwrap.dedent(checker_map) checker_map2 = """ OOOOOOOOOO ODJDJDJDJO OJDJDJDJDO ODJDJDJDJO OJDJDJDJDO ODJDJDJDJO OJDJDJDJDO ODJDJDJDJO OJDJDJDJDO OOOOOOOOOO """ checker_map2 = textwrap.dedent(checker_map2) sim = BioSim(island_map=checker_map, ini_pop=default_population, img_base='checker_map_ocean', ymax_animals=500, cmax_animals={ 'Herbivore': 100, 'Carnivore': 80 }) sim.simulate(100) sim.make_movie()
desert_landscape = """ OOOOOOOOOOOOO ODSSSDDDSDSDO ODSDSDDSDSSDO ODDDDDDDDSSDO ODDDMMDSDDDDO ODDMMSMMDSSDO ODDDMDSDSSDDO ODDDMMDMDSDDO ODDSDSSMSDSDO ODSDDMMMDDSDO ODDDDSMDDDSDO ODDSDSSDSDDDO OOOOOOOOOOOOO """ desert_landscape = textwrap.dedent(desert_landscape) sim = BioSim(island_map=desert_landscape, ini_pop=default_population, ymax_animals=800, cmax_animals={'Herbivore':40, 'Carnivore':30}) sim.set_animal_parameters('Herbivore', {'mu': 0.5, 'eta': 0.1}) sim.set_animal_parameters('Carnivore', {'eta': 0.075, 'F': 20, 'mu': 0.5, 'DeltaPhiMax': 0.75}) sim.simulate(1000) sim.make_movie()
def test_simulation_set_animal_parameters(): """Test to see that incorrect species string gives ValueError""" sim = BioSim(island_map="OO\nOO", ini_pop=[], seed=1) with pytest.raises(ValueError): sim.set_animal_parameters("Omnivore", {"w_birth": 8.0})
def test_simulation_set_landscape_parameters(): """Test to see that incorrect landscape string gives ValueError""" sim = BioSim(island_map="OO\nOO", ini_pop=[], seed=1) with pytest.raises(ValueError): sim.set_landscape_parameters("D", {"fodder": 8.0})
def test_inconsistent_length(): """Inconsistent line length must raise error""" with pytest.raises(ValueError): BioSim(island_geography="OOO\nOJJO\nOOO", initial_population=[], seed=1)
def test_invalid_landscape(): """Invalid landscape type must raise error""" with pytest.raises(ValueError): BioSim(island_geography="OOO\nORO\nOOO", initial_population=[], seed=1)
def test_all_types(): """All types of landscape can be created""" BioSim(island_geography="OOOO\nOJSO\nOMDO\nOOOO", initial_population=[], seed=1)
def plain_sim(): """Return a simple island for used in various tests below""" return BioSim(island_map="OOOO\nOJSO\nOOOO", ini_pop=[], seed=1)
from biosim.simulation import BioSim from biosim.logic import season_migration if __name__ == '__main__': this_fucking_thing = BioSim(island_map = "WWWW\nWLLW\nWWWW", ini_pop = [{'loc':(2,2) , 'pop':[ {"species":"herbivore","age":5,"weight":20} for _ in range(10)] } ] , seed = 1234) the_map = this_fucking_thing.island illigal_moves = this_fucking_thing.illigal_coord for _ in range(30): season_migration(the_map,illigal_moves) for cell in the_map: print("coord:",the_map[cell].coord,"animals:",the_map[cell].herb_default) for C in the_map[cell].herb_default: print(C.var["coord"], C.var["a"])
def test_minimal_island(): """Island of single jungle cell""" BioSim(island_map="OOO\nOJO\nOOO", ini_pop=[], seed=1)
} for _ in range(1000)] }] kart = """\ WWWWWWWWWW WDDDDDDDDW WDDDDDDDDW WDDDDDDDDW WDDDDDDDDW WDDDDDDDDW WDDDDDDDDW WDDDDDDDDW WDDDDDDDDW WWWWWWWWWW""" b = BioSim(seed=123, ini_pop=ini_herbs, island_map=kart) b.set_animal_parameters('Herbivore', { 'mu': 1, 'omega': 0, 'gamma': 0, 'a_half': 10000 }) b.set_animal_parameters('Carnivore', { 'mu': 1, 'omega': 0, 'gamma': 0, 'F': 0, 'a_half': 10000 }) b.add_population(ini_carn)
OSSSSSJJJJJJJJJJJJOOO OSSSSSJJJDDJJJSJJJOOO OSSJJJJJDDDJJJSSSSOOO OOSSSSJJJDDJJJSOOOOOO OSSSJJJJJDDJJJJJJJOOO OSSSSJJJJDDJJJJOOOOOO OOSSSSJJJJJJJJOOOOOOO OOOSSSSJJJJJJJOOOOOOO OOOOOOOOOOOOOOOOOOOOO""" geogr = textwrap.dedent(geogr) ini_herbs = [{'loc': (10, 10), 'pop': [{'species': 'Herbivore', 'age': 5, 'weight': 20} for _ in xrange(150)]}] ini_carns = [{'loc': (10, 10), 'pop': [{'species': 'Carnivore', 'age': 5, 'weight': 20} for _ in xrange(40)]}] sim = BioSim(island_map=geogr, ini_pop=ini_herbs + ini_carns, seed=656412) sim.simulate(num_steps=100, vis_steps=1, img_steps=2000) sim.add_population(population=ini_carns) sim.simulate(num_steps=100, vis_steps=1, img_steps=2000) raw_input('Press ENTER')
def test_set_plot_limits(): """Test that y-axis and color limits for plots can be set.""" BioSim(island_map='W', ini_pop=[], seed=1, ymax_animals=20, cmax_animals={'Herbivore': 10, 'Carnivore': 20})
# -*- coding: utf-8 -*- """ Island with single jungle cell, first herbivores only, later carnivores. """ __author__ = 'Hans Ekkehard Plesser, NMBU' import textwrap from biosim.simulation import BioSim geogr = """\ WWW WLW WWW""" geogr = textwrap.dedent(geogr) ini_herbs = [{'loc': (2, 2), 'pop': [{'species': 'Herbivore', 'age': 5, 'weight': 20} for _ in range(50)]}] for seed in range(100, 103): sim = BioSim(geogr, ini_herbs, seed=seed, img_dir='results', img_base=f'mono_ho_{seed:05d}', img_years=300) sim.simulate(301)
def test_configure_histograms(prop, config): """Test that y-axis and color limits for plots can be set.""" BioSim(island_map='W', ini_pop=[], seed=1, ymax_animals=20, cmax_animals={'Herbivore': 10, 'Carnivore': 20}, hist_specs={prop: config})
def test_empty_island(): """Empty island can be created""" BioSim(island_map="WW\nWW", ini_pop=[], seed=1)
# -*- coding: utf-8 -*- """ """ __author__ = "Jon-Mikkel Korsvik & Petter Bøe Hørtvedt" __email__ = "[email protected] & [email protected]" from biosim.simulation import BioSim default_population = [{ "loc": (1, 1), "pop": [{ "species": "Herbivore", "age": 5, "weight": 20 } for _ in range(150)], }, { "loc": (1, 1), "pop": [{ "species": "Carnivore", "age": 5, "weight": 20 } for _ in range(40)], }] sim = BioSim(island_map='OOOOOO\nOJJJJO\nOJJJJO\nOJJJJO\nOJJJJO\nOOOOOO', ini_pop=default_population, img_base='even_island', ymax_animals=3000) sim.simulate(100) sim.make_movie()
def test_all_types(): """All types of landscape can be created""" BioSim(island_map="WWWW\nWLHW\nWWDW\nWWWW", ini_pop=[], seed=1)
for _ in range(150)]}] ini_carns = [{'loc': (10, 10), 'pop': [{'species': 'Carnivore', 'age': 5, 'weight': 20} for _ in range(40)]}] ini_snake = [{'loc': (4, 15), 'pop': [{'species': 'Snake', 'age': 5, 'weight': 20} for _ in range(40)]}] sim = BioSim(island_map=geogr, ini_pop=ini_herbs, seed=123456, hist_specs={'fitness': {'max': 1.0, 'delta': 0.05}, 'age': {'max': 60.0, 'delta': 2}, 'weight': {'max': 60, 'delta': 2}}, ) sim.set_animal_parameters('Herbivore', {'zeta': 3.2, 'xi': 1.8}) sim.set_animal_parameters('Carnivore', {'a_half': 70, 'phi_age': 0.5, 'omega': 0.3, 'F': 65, 'DeltaPhiMax': 9.}) sim.set_landscape_parameters('L', {'f_max': 700}) sim.simulate(num_years=100, vis_years=1, img_years=2000) new_map = """\ WWWWWWWWWWWWWWWWWWWWW WWWWWWWWHWWWWLLLLLLLW WWHHHHLLLLWWLLLLLLLWW
def test_invalid_landscape(): """Invalid landscape type must raise error""" with pytest.raises(ValueError): BioSim(island_map="WWW\nWRW\nWWW", ini_pop=[], seed=1)
"loc": (10, 10), "pop": [{"species": "Herbivore", "age": 5, "weight": 20} for _ in range(150)], } ] ini_carns = [ { "loc": (10, 10), "pop": [{"species": "Carnivore", "age": 5, "weight": 20} for _ in range(40)], } ] sim = BioSim( island_map=geogr, ini_pop=ini_herbs, seed=123456, hist_specs={ "fitness": {"max": 1.0, "delta": 0.05}, "age": {"max": 60.0, "delta": 2}, "weight": {"max": 60, "delta": 2}, }, ) sim.set_animal_parameters("Herbivore", {"zeta": 3.2, "xi": 1.8}) sim.set_animal_parameters( "Carnivore", {"a_half": 70, "phi_age": 0.5, "omega": 0.3, "F": 65, "DeltaPhiMax": 9.0} ) sim.set_landscape_parameters("L", {"f_max": 700}) sim.simulate(num_years=100, vis_years=1, img_years=2000) sim.add_population(population=ini_carns) sim.simulate(num_years=100, vis_years=1, img_years=2000)
def test_set_param_landscape(lscape, params): """Parameters can be set on landscape classes""" BioSim(island_map="W", ini_pop=[], seed=1).set_landscape_parameters(lscape, params)
def test_empty_island(): """Empty island can be created""" BioSim(island_geography="OO\nOO", initial_population=[], seed=1)