Example #1
0
def update_habitat_water_depth(h: Habitat, x=0):
    """
    Simulate change in habitat's characteristics (water depth) over time
    TODO: docs
    """
    if h.id == C.LAGOON_ORANGE_SM:
        h.props['w'] = -0.00002 * x**2 + 0.064 * x + 10.034
    elif h.id == C.LAGOON_ORANGE_LG:
        h.props['w'] = -0.0001 * x**2 + 0.0987 * x + 6.1176
    elif h.id == C.LAGOON_BLUE:
        h.props['w'] = -0.00003 * x**2 + 0.0636 * x + 34.114
    elif h.id == C.LAGOON_GREEN:
        h.props['w'] = -0.00005 * x**2 + 0.061 * x + 97.442
Example #2
0
    def __init__(self, env_x, env_y, env_size_x, env_size_y, habitat_side_length = 10, cell_side_length = 1):
        self.env_x = env_x
        self.env_y = env_y
        self.env_size_x = env_size_x
        self.env_size_y = env_size_y
        self.habitat_side_length = habitat_side_length
        self.cell_side_length = cell_side_length
        
        row_hab_id = 0
        col_hab_id = 0

        self.habitat_cell_grid = []
        
        self.habitat_array = []

        for row in range(int(self.env_size_y) // int(self.cell_side_length)):
            self.habitat_cell_grid.append([])
            if row % (int(self.habitat_side_length) // int(self.cell_side_length)) == 0 and row != 0:
                # inside a new habitat
                row_hab_id = col_hab_id + 1

            col_hab_id = row_hab_id
            
            for col in range(int(self.env_size_x) // int(self.cell_side_length)):
                hab_x = env_x + col * cell_side_length
                hab_y = env_y + row * cell_side_length

                if col % (int(self.habitat_side_length) // int(self.cell_side_length))== 0:
                    if col != 0:
                        # inside a new habitat
                        col_hab_id += 1
                    if row % (int(self.habitat_side_length) // int(self.cell_side_length)) == 0:
                        # need to add a new habitat into the habitat array
                        self.habitat_array.append(Habitat(hab_x, hab_y, col_hab_id, self.habitat_side_length))

                self.habitat_cell_grid[row].append(HabitatCell(hab_x, hab_y, col_hab_id, side_length = self.cell_side_length))
Example #3
0
def create_patches():
    habitats = []
    verts, props = C.DEFAULTS['verts'], C.DEFAULTS['props']

    # prepare static patches (habitats and human settlements)
    orange_sm = Habitat(C.LAGOON_ORANGE_SM, C.LAGOON_TYPE_ORANGE,
                        C.COLORS[C.LAGOON_ORANGE_SM])
    orange_sm.verts = verts[C.LAGOON_ORANGE_SM]
    orange_sm.props = props[C.LAGOON_ORANGE_SM]
    orange_sm.label = C.LABELS[C.LAGOON_ORANGE_SM]
    orange_sm.build()
    habitats.append(orange_sm)

    orange_lg = Habitat(C.LAGOON_ORANGE_LG, C.LAGOON_TYPE_ORANGE,
                        C.COLORS[C.LAGOON_ORANGE_LG])
    orange_lg.verts = verts[C.LAGOON_ORANGE_LG]
    orange_lg.props = props[C.LAGOON_ORANGE_LG]
    orange_lg.label = C.LABELS[C.LAGOON_ORANGE_LG]
    orange_lg.build()
    habitats.append(orange_lg)

    blue = Habitat(C.LAGOON_BLUE, C.LAGOON_TYPE_BLUE, C.COLORS[C.LAGOON_BLUE])
    blue.verts = verts[C.LAGOON_BLUE]
    blue.props = props[C.LAGOON_BLUE]
    blue.label = C.LABELS[C.LAGOON_BLUE]
    blue.build()
    habitats.append(blue)

    green = Habitat(C.LAGOON_GREEN, C.LAGOON_TYPE_GREEN,
                    C.COLORS[C.LAGOON_GREEN])
    green.verts = verts[C.LAGOON_GREEN]
    green.props = props[C.LAGOON_GREEN]
    green.label = C.LABELS[C.LAGOON_GREEN]
    green.build()
    habitats.append(green)

    human1 = Habitat(C.HUMAN_SETTLEMENT, C.HUMAN_SETTLEMENT,
                     C.COLORS[C.HUMAN_SETTLEMENT])
    human1.verts = verts[C.HUMAN_SETTLEMENT + '1']
    human1.label = C.LABELS[C.HUMAN_SETTLEMENT]
    human1.build(fill=True)
    habitats.append(human1)

    human2 = Habitat(C.HUMAN_SETTLEMENT, C.HUMAN_SETTLEMENT,
                     C.COLORS[C.HUMAN_SETTLEMENT])
    human2.verts = verts[C.HUMAN_SETTLEMENT + '2']
    human2.label = C.LABELS[C.HUMAN_SETTLEMENT]
    human2.build(fill=True)
    habitats.append(human2)

    human3 = Habitat(C.HUMAN_SETTLEMENT, C.HUMAN_SETTLEMENT,
                     C.COLORS[C.HUMAN_SETTLEMENT])
    human3.verts = verts[C.HUMAN_SETTLEMENT + '3']
    human3.label = C.LABELS[C.HUMAN_SETTLEMENT]
    human3.build(fill=True)
    habitats.append(human3)
    return habitats
Example #4
0
  #### LOAD human locations
  
  humans = fiona.open("C:\\Users\\Sjors\\Dropbox\\GIMAMasterThesis\\Data\\human_v2.shp")
  for feat in humans:  
      human = Human(feat['geometry']['coordinates'][0],feat['geometry']['coordinates'][1], feat['properties']['age'])
      human.SEI.totalInfections = feat['properties']['prev_infec']
      human.SEI.totalInfections = 0
      if random.randint(1,2) == 2: 
          human.SEI.currentState = I()
      myModel.agentContainer['humanContainer'].append(human)
  
  #### LOAD HABITATS
  habitats = fiona.open("C:\\Users\\Sjors\\Dropbox\\GIMAMasterThesis\\Data\\habitat.shp")
 
  for feat in habitats:   
      habitat = Habitat(feat['geometry']['coordinates'][0],feat['geometry']['coordinates'][1])
      habitat.size = 50
      myModel.agentContainer['habitatContainer'].append(habitat)
      
  # Create mosquitos 
  for i in xrange(500):   #500 initial mozzies
      myModel.agentContainer['mosquitoContainer'].append(Mosquito())
      myModel.agentContainer['mosquitoContainer'][i].age = np.random.randint(0,40) #initial age between 0 and 40 days
      myModel.agentContainer['mosquitoContainer'][i].x = np.random.randint(0,1250)
      myModel.agentContainer['mosquitoContainer'][i].y = np.random.randint(0,1250)
      if (i % 2) == 0:
          myModel.agentContainer['mosquitoContainer'][i].SEI.currentState = I()
          
  ## Load in temperature data
  myModel.fieldContainer['climate'] = read_csv('C:\\Users\\Sjors\\Dropbox\\GIMAMasterThesis\\OOMscripts\\climateBoboDioulassov2.csv', sep=';', index_col='name')
  
Example #5
0
class Penguin(Walking, Swimming):
    def __init__(self, name):
        self.name = name

    def run(self):
        print(f"{self.name} the Penguin waddles")


if __name__ == "__main__":

    # Create a penguin
    bob = Penguin("Bob")

    # Create a habitat
    SeaWorld = Habitat("Jerry")
    SeaWorld.add_animal(bob)

    print(SeaWorld.animals)


class PaintedDog(Walking):
    def __init__(self, name):
        self.name = name


if __name__ == "__main__":

    bob = Penguin("Bob")
    ralph = PaintedDog("Ralph")
Example #6
0
import sys
from habitat import Habitat

h = Habitat()

#h.test_feeder(1,1000,1,0)

h.start_experiment("test", "10_05", 5)

for i in range(4):
    h.close_door(i)

for i in range(4):
    r = h.open_door(i)

for i in range(4):
    r = h.close_door(i)

for e in range(3):
    print(h.feeder_reached(1))
    for x in range(-20, 21):
        print(h.track("mouse", x, 0))
    print(h.feeder_reached(2))
print(h.finish_experiment())

print("ALL TEST FINISHED OK")
Example #7
0
import unittest
from habitat import Habitat

try:
    test_habitat = Habitat()

except NameError:
    test_habitat = False

class Habitat_test(unittest.TestCase):
  def test_habitat_is_defined(self):
    """ 
    See if the object has been created
    """
    self.assertTrue(test_habitat)
    """ 
    See if created object is an instance of Habitat
    """
    self.assertIsInstance(test_habitat, Habitat)

  
if __name__ == '__main__':
    unittest.main()
Example #8
0
 def is_pangolin(self, animal):
     Habitat()
     return animal
Example #9
0
        # retrieving habitat data from characteristics at www.bfn.de
        # retrieving contents of html page
        hab_url = ''.join((URL_PREFIX, sitecode))
        hab_conn = urllib2.urlopen(hab_url)
        hab_doc = lxml.html.parse(hab_conn).getroot()
        contents = hab_doc.get_element_by_id('content')

        # finding name data (incl. sitecode, name, ...)
        hab_name_data = contents.xpath('*/div/h2')[0].text_content().encode('utf-8')
        match = re.search(NAME_REGEX, hab_name_data)

        if match is not None:
            hab_name = match.group(1)

            # creating new habitat
            hab = Habitat(sitecode, hab_name)
            # find further habitat data
            other_data = contents.findall('div/div/p')

            # containing administrative area
            fed_state = other_data[0].text_content().encode('utf-8')
            try:
                nuts_code = NUTS_CODES[fed_state]
            except:
                nuts_code = ''

            # biogreophical region and size
            region = other_data[1].text_content().encode('utf-8')
            # separating region and size
            region_size_match = re.search(REGION_SIZE_REGEX, region)
            if region_size_match is not None: