Ejemplo n.º 1
0
def main():
    """ Main function that sets up, runs and saves CA"""
    # Get the config object from set up
    config = setup(sys.argv[1:])

    #sets default num of ticks for chaparral and forest to ignite
    chap_ignition = np.zeros(config.grid_dims)
    chap_ignition.fill(2)
    forest_ignition = np.zeros(config.grid_dims)
    forest_ignition.fill(6)

    #sets default fuel for chaparral and other states can be adjusted later
    fuel_reserves = np.zeros(config.grid_dims)
    fuel_reserves.fill(10)

    # Create grid object using parameters from config + transition function
    #added forest_ignition and fuel_reserves as arguements
    grid = Grid2D(
        config,
        (transition_function, chap_ignition, forest_ignition, fuel_reserves))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()
    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 2
0
def main():
    """ Main function that sets up, runs and saves CA"""
    # Get the config object from set up
    config = setup(sys.argv[1:])

    # Create grid object using parameters from config + transition function
    grid = Grid2D(config, transition_function)

    global fuel_grid, ignition_grid, wind_NS, wind_WE

    fn_fuel = partial(switcheroo, value_key="fuel_capacity", default=1)
    fuel_grid = grid_mapper(fn_fuel, grid.grid)

    fn_ignition = partial(switcheroo,
                          value_key="ignition_threshold",
                          default=0)
    ignition_grid = grid_mapper(fn_ignition, grid.grid)

    wind_NS = 1
    wind_WE = -1

    #

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()

    # Save timeline to file
    utils.save(timeline, config.timeline_path)
def main():
    """ Main function that sets up, runs and saves CA"""
    # Get the config object from set up
    config = setup(sys.argv[1:])

    # Create grid object using parameters from config + transition function
    fire_chance_chap = np.zeros(config.grid_dims)
    fire_chance_df = np.zeros(config.grid_dims)
    fire_chance_canyon = np.zeros(config.grid_dims)
    burnt_up_chap = np.zeros(config.grid_dims)
    burnt_up_chap.fill(100)
    burnt_up_df = np.zeros(config.grid_dims)
    burnt_up_df.fill(100)
    burnt_up_canyon = np.zeros(config.grid_dims)
    burnt_up_canyon.fill(100)
    wind = np.zeros(config.grid_dims)
    grid = Grid2D(config, (transition_function, fire_chance_chap,
                           fire_chance_df, fire_chance_canyon, burnt_up_chap,
                           burnt_up_df, burnt_up_canyon, wind))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()
    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 4
0
def main():
    """ Main function that sets up, runs and saves CA"""
    global args
    args = parser.parse_args()
    wind = np.array(args.wind).reshape((8,1,1))

    # Get the config object from set up
    config = setup([args.config, *args.system])

    # Create grid object using parameters from config + transition function
    data = config.initial_grid.astype(int)
    grid = Grid2D(config,
        (transition_function,
        data == Terrain.BURNING,
        np.array([0, 0, 0, 8.0, 48.0, 720.0])[data], # Fuel
        np.array([0, 0, 0, .41, .40, .03])[data], # Ignition probability
        wind
        ))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()
    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 5
0
def main():
    """ Main function that sets up, runs and saves CA"""
    # Get the config object from set up
    config = setup(sys.argv[1:])

    decaygrid = np.zeros(config.grid_dims)

    decaygrid.fill(20 / (coef * coef))

    decaygrid[5 * coef:35 * coef, 32 * coef:35 * coef] = (4 / (coef * coef))
    decaygrid[30 * coef:41 * coef, 15 * coef:25 * coef] = (300 / (coef * coef))

    # Set up fuel probability for each cell
    fuelgrid = np.random.random(config.grid_dims)

    # Multiply fuel probality with decay constant
    fuel_prob_grid = np.multiply(decaygrid, fuelgrid)
    fuel_prob_grid = np.round(fuel_prob_grid, 0)

    print(fuel_prob_grid)

    # Create grid object using parameters from config + transition function
    grid = Grid2D(config, (transition_function, fuel_prob_grid))

    # Run the CA, save grid state every generation to line
    timeline = grid.run()

    # Save updated config to file
    config.save()

    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 6
0
def main():
    # Open the config object
    config = setup(sys.argv[1:])
    chaparral = np.zeros(config.grid_dims)
    area1 = np.zeros(config.grid_dims)
    area2 = np.zeros(config.grid_dims)
    decay_grid = np.zeros(config.grid_dims)
    # decay grid -100 = lake
    decay_grid[:, :] = 40
    decay_grid[0:3, 197:200] = 10
    decay_grid[40:60, 20:60] = -100
    decay_grid[120:160, 60:100] = 320
    decay_grid[20:140, 130:140] = 8
    print(decay_grid)
    print(decay_grid.shape)
    # Create grid object
    grid = Grid2D(config, (transition_func, chaparral, decay_grid))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # save updated config to file
    config.save()
    # save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 7
0
def main():
    # Open the config object
    config = setup(sys.argv[1:])

    #Define fuel parameter matrix ( 1 = 1.5hours )
    fuel_parameter = np.full((200, 200), 34)  #2.1 days
    for i in range(128, 144):
        for j in range(20, 144):
            fuel_parameter[j][i] = 4  #6 hours
    #Setting fuel for  forest.
    #Extending dense forest in 4 direcions.
    #The appropriate lines of code need to be commented out.
    #for i in range(17, 104): #Extend East ( overlaps canyon )
    #for i in range(60, 147): #Extend West
    for i in range(60, 104):  #No extention W/E
        #for j in range(72, 168): #Extend north
        #for j in range(120, 200): #Extend south ( cannot double area )
        for j in range(120, 168):  #No extention N/S
            fuel_parameter[j][i] = 400  #25 days
    for i in range(196, 200):
        for j in range(0, 8):
            fuel_parameter[i][j] = 1

    #Define water break coordinate matrix
    water_break = np.zeros((200, 200))
    #for i in range(0,41):
    for i in range(155, 195):
        for j in range(5, 46):
            #for j in range(140,181):
            water_break[j][i] = 1

    #Define fire break coordinate matrix
    fire_break = np.zeros((200, 200))
    for i in range(190, 195):
        for j in range(0, 20):
            fire_break[i][j] = 1
    for i in range(190, 200):
        for j in range(20, 25):
            fire_break[i][j] = 1

    # Create grid object
    grid = Grid2D(config,
                  (transition_func, fuel_parameter, water_break, fire_break))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # save updated config to file
    config.save()

    # save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 8
0
def main():
    """ Main function that sets up, runs and saves CA"""
    # get the config object
    config = setup(sys.argv[1:])

    # create the grid
    grid = Grid1D(config, transition_function)

    # run the grid and save each timestep to timeline
    timeline = grid.run()
    # save timeline and config
    utils.save(timeline, config.timeline_path)
    config.save()
def main():
    # Open the config object
    config = setup(sys.argv[1:])

    # Initilise decay grid
    decaygrid = np.zeros(config.grid_dims)

    # Initilise wind grid
    windgrid = np.zeros(config.grid_dims)

    delaygrid = np.ones(config.grid_dims)
    for y in range(120, 161):
        for x in range(60, 101):
            delaygrid[y][x] = 0.02

    #Random Grid
    randomgrid = np.zeros(config.grid_dims)
    for x in range(randomgrid.shape[0]):
        for y in range(randomgrid.shape[0]):
            randomgrid[x][y] = random.random()

    probabilitygrid = np.zeros(config.grid_dims)

    #Terrain Grid
    terraingrid = np.zeros(config.grid_dims)

    for y in range(40, 61):
        for x in range(20, 61):
            terraingrid[y][x] = 1

# gollum lives in this forest
    for y in range(120, 161):
        for x in range(60, 101):
            terraingrid[y][x] = 2

    for y in range(20, 141):
        for x in range(128, 141):
            terraingrid[y][x] = 3

    # Create grid object
    grid = Grid2D(config, (transition_func, decaygrid, randomgrid, terraingrid,
                           probabilitygrid, windgrid, delaygrid))
    #grid = Grid2D(config, transition_func)

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # save updated config to file
    config.save()
    # save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 10
0
def main():

    config = setup(sys.argv[1:])
    ext_grid = [[ext_val[i] for i in j]
                  for j in start_grid.astype(int)]
    ext_grid = np.array(ext_grid)

    ignition_grid = np.zeros((GRID_SIZE, GRID_SIZE))
    ignition_grid = ignition_grid.astype(int)
    grid = Grid2D(config, (transition_function, ext_grid))
    timeline = grid.run()

    config.save()
    utils.save(timeline, config.timeline_path) 
Ejemplo n.º 11
0
def main():
    config = setup(sys.argv[1:])

    rulebool = utils.int_to_binary(config.rule_num) * True

    grid = Grid1D(num_generations=config.num_generations,
                  states=config.states,
                  neighbourhood=config.neighbourhood(),
                  transition_func=(transition_function, rulebool),
                  initial_grid=config.initial_grid)

    timeline = grid.run()
    utils.save(timeline, config.timeline_path)
    config.save()
Ejemplo n.º 12
0
def main():
    # Open the config object
    config = setup(sys.argv[1:])

    # Create grid object
    grid = Grid2D(config, transition_func)

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # save updated config to file
    config.save()
    # save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 13
0
def main():
    config = setup(sys.argv[1:])

    # Translate rule numer to boolean array:
    # 30 -> [0,0,0,1,1,1,1,0] -> [F,F,F,T,T,T,T,F]
    rulebool = utils.int_to_binary(config.rule_num) * True

    # Create grid object
    # passing transition function and rulebool as tuple to
    # keep track of rulebool
    grid = Grid1D(config, (transition_function, rulebool))

    timeline = grid.run()
    utils.save(timeline, config.timeline_path)
    config.save()
Ejemplo n.º 14
0
def main():
    """ Main function that sets up, runs and saves CA"""
    # Get the config object from set up
    config = setup(sys.argv[1:])

    # Create grid object using parameters from config + transition function
    grid = Grid2D(config, transition_function)

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()
    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 15
0
def main():

    # NOTE: set the wind here if doing it programatically
    # Default: light prevaling wind southward
    wind_x = 0.0
    wind_y = -0.2
    # if passed extra command-line args, assumed it's for custom wind
    if (len(sys.argv) == 4):
        wind_x = float(sys.argv[2])
        wind_y = float(sys.argv[3])

    # Open the config object
    config = setup(sys.argv[1:])

    ignition_level = np.zeros((grid_axis, grid_axis))
    fuel_level = np.zeros((grid_axis, grid_axis))

    #Set fuel resource for each cell based on terrain
    fuel_level = np.vectorize(terrain_fuel_level.get,
                              otypes=['float64'])(terrain_numbers)

    #Set ignition Threshold for each cell based on terrain
    ignition_level = np.vectorize(terrain_ignition_threshold.get,
                                  otypes=['float64'])(terrain_numbers)

    #Set starting point of fire
    if power_plant: terrain_numbers[0 + offset, 0 + offset] = 5
    if incinerator: terrain_numbers[0 + offset, 49 + offset] = 5

    #Setup water water drop params ((x1,y1,x2,y2), start_timestep, end_timestep)
    water_drops = [
        ((5 + offset, 0 + offset, 15 + offset, 8 + offset), 97, 107),
        ((20 + offset, 10 + offset, 25 + offset, 20 + offset), 230, 240)
    ]
    timestep = np.array([0])

    # Create grid object
    grid = Grid2D(config, (get_transition_func(
        wind_x, wind_y), ignition_level, fuel_level, water_drops, timestep))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # save updated config to file
    config.save()
    # save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 16
0
def main():
    """ Main function that sets up, runs and saves CA"""

    # declare global grids information
    global fuel_grid, ignition_grid, neighbour_multipliers, counter
    counter = 0

    print("Start of new simulation")
    # Get the config object from set up
    config = setup(sys.argv[1:])

    # Create grid object using parameters from config + transition function
    grid = Grid2D(config, transition_function)

    # create grid containing all cells' fuel capacities
    fn_fuel = partial(switcheroo, value_key="fuel_capacity", default=1)
    fuel_grid = grid_mapper(fn_fuel, grid.grid)

    # create grid containing all cells' ignition thresholds
    # (or flammability values)
    fn_ignition = partial(switcheroo,
                          value_key="ignition_threshold",
                          default=0)
    ignition_grid = grid_mapper(fn_ignition, grid.grid)

    # set the maximum value of neighbours for the fire spread multiplier
    neighbour_multipliers = np.zeros((GRID_SIZE, GRID_SIZE))
    neighbour_multipliers.fill(6)
    neighbour_multipliers[0].fill(4)
    neighbour_multipliers[GRID_SIZE - 1].fill(4)
    for row in range(0, GRID_SIZE):
        if row == 0 or row == GRID_SIZE - 1:
            neighbour_multipliers[row][0] = 2.5
            neighbour_multipliers[row][GRID_SIZE - 1] = 2.5
        else:
            neighbour_multipliers[row][0] = 4
            neighbour_multipliers[row][GRID_SIZE - 1] = 4

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()

    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 17
0
def main():
    #take the config path
    config = setup(sys.argv[1:])

    #Create grid object
    grid = Grid2D(gridsize=config.grid_dims,
                  states=config.states,
                  neighbourhood=config.neighbourhood(),
                  transition_func=transition_func,
                  initial_grid=config.initial_grid)

    #Run the CA, save grid state every generation to timeline
    timeline = grid.run(config.num_generations)

    #save updated config to file
    config.save()
    #save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 18
0
def main():
    """ Main function that sets up, runs and saves CA"""
    # Get the config object from set up
    config = setup(sys.argv[1:])
    # Create grid object using parameters from config + transition function
    decaygrid = np.zeros(config.grid_dims)

    decaygrid.fill(4000)
    firegrid = np.zeros(config.grid_dims)
    firegrid.fill(1)

    grid = Grid2D(config, (transition_function, decaygrid, firegrid))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()
    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 19
0
def main():
    """ Main function that sets up, runs and saves CA"""
    # Get the config object from set up
    config = setup(sys.argv[1:])



    initial = config.initial_grid
    decaygrid = fuelConfig(initial, config)
    fgrid = flamConfig(initial, config)
    mgrid = moisConfig(initial, config)

    # Create grid object using parameters from config + transition function
    grid = Grid2D(config, (transition_function, decaygrid, fgrid, mgrid))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()
    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 20
0
def main():
    # Open the config object
    windSpeed = 2 # initial arbitrary value 
    config = setup(sys.argv[1:])
    fuelCount = np.zeros(config.grid_dims)
    fuelCount.fill(-1)
    windBias = np.zeros(config.grid_dims) 
    
    moisture = np.zeros(config.grid_dims) 
    
    
    # Create grid object
    grid = Grid2D(config, (transition_func, fuelCount, windBias, windSpeed, moisture))
    #fuelCount = np.zeros(grid.shape[0], grid.shape[1])
    
    #print("GRID", type(grid))
    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()
    #print("TIMELINE", timeline)
    # save updated config to file
    config.save()
    # save timeline to file
    utils.save(timeline, config.timeline_path)
def main():

    config = setup(sys.argv[1:])
    s = -10000
    decay_grid = [[decay_values[i] for i in row]
                  for row in initial_grid.astype(int)]
    decay_grid = np.array(decay_grid)
    water_decay_values = [s, s, s, s, s]
    water_decay_grid = np.array([[water_decay_values[i] for i in row]
                                 for row in initial_grid.astype(int)])

    #Select section of grid to drop water
    water_decay_grid[120:160, 80:120] = 0  #drop water after this time
    ignition_grid = np.zeros((grid_size, grid_size))
    ignition_grid = ignition_grid.astype(int)
    grid = Grid2D(config, (transition_function, decay_grid, water_decay_grid))

    # Create grid object using parameters from config + transition function
    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    config.save()  # Save updated config to file
    utils.save(timeline, config.timeline_path)  # Save timeline to file
Ejemplo n.º 22
0
def main():
    # Open the config object
    config = setup(sys.argv[1:])

    #create intial matrix values
    numValues = np.zeros(config.grid_dims)
    initNumValues = np.zeros(config.grid_dims)

    # setting base numbers
    forestl, forestr = 60, 30
    canl, canr = 10, 64
    townl, townr = 98, 0

    numValues.fill(0.2)
    numValues[forestl:forestl + 20, forestr:forestr + 22] = 1.9
    numValues[canl:canl + 60, canr:canr + 6] = 1.4
    numValues[townl:townl + 2, townr:townr + 5] = -2
    initNumValues = numValues

    #Creating the water drop matrix
    waterDrop = np.zeros(config.grid_dims)
    waterDrop.fill(-1)

    reactionTime = 100
    #specify the location and time of the water drop
    waterDrop[0:40, 20] = reactionTime

    grid = Grid2D(config,
                  (transition_func, numValues, waterDrop, initNumValues))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # save updated config to file
    config.save()
    # save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 23
0
def main():
    # Open the config object
    config = setup(sys.argv[1:])

    # time until the burning square is burnt out
    decaygrid_for_chaparral = np.zeros(config.grid_dims)
    decaygrid_for_chaparral.fill(120)

    decaygrid_for_grassland = np.zeros(config.grid_dims)
    decaygrid_for_grassland.fill(250)

    decaygrid_for_forest = np.zeros(config.grid_dims)
    decaygrid_for_forest.fill(800)


    grid = Grid2D(config, (transition_func, decaygrid_for_chaparral, decaygrid_for_grassland, decaygrid_for_forest))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # save updated config to file
    config.save()
    # save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 24
0
def main():
    """ Main function that sets up, runs and saves CA"""
    # Get the config object from set up
    config = setup(sys.argv[1:])

    grid_attribs = np.zeros((*config.grid_dims, 5))

    # 0: Height - Scalar value
    # 1: Wind/Magnitude - East to West
    # 2: Flammability
    # 3: Humidity?
    # 4: Fuel
    grid_attribs[...] = (0, 0.1, 0.1, 0, 1)

    # Create grid object using parameters from config + transition function
    grid = Grid2D(config, (transition_function, grid_attribs))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()
    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 25
0
def main():
    """ Main function that sets up, runs and saves CA"""
    config = setup(sys.argv[1:])
    wind_x = 0.001
    wind_y = 0.001
    grid_attribs = np.zeros((*config.grid_dims, 20))

    time_to_drop = np.array([295])
    # 0: Height - Scalar value
    # 1: Flammability
    # 2: Humidity?
    # 3: Fuel
    # 4-12: wind_spread_weights
    grid_attribs[:, :, 0] = 0
    grid_attribs[:, :, 1] = 1
    grid_attribs[:, :, 2] = 0
    grid_attribs[:, :, 3] = 20
    grid_attribs[:, :, 4:12] = cal_wind_spread_vectors(wind_x, wind_y)

    config.initial_grid = np.ones(config.grid_dims)
    size_y, size_x = config.initial_grid.shape

    #Ariel drop

    #Pond
    config.initial_grid[int(0.2 * size_y):int(0.3 * size_y),
                        int(0.1 * size_x):int(0.3 * size_x)] = 6

    #Fire
    config.initial_grid[0, 0] = 4

    #Town
    town_x_coords = [0, int(0.05 * size_x)]
    town_y_coords = [int(0.95 * size_y), size_y - 1]
    config.initial_grid[town_y_coords[0]:town_y_coords[1],
                        town_x_coords[0]:town_x_coords[1]] = 5

    #Dense Forest
    d_forest_x_coords = [int(0.3 * size_x), int(0.5 * size_x)]
    d_forest_y_coords = [int(0.6 * size_y), int(0.81 * size_y)]
    config.initial_grid[d_forest_y_coords[0]:d_forest_y_coords[1],
                        d_forest_x_coords[0]:d_forest_x_coords[1]] = 2
    grid_attribs[d_forest_y_coords[0]:d_forest_y_coords[1],
                 d_forest_x_coords[0]:d_forest_x_coords[1], 1] = 0.2
    grid_attribs[d_forest_y_coords[0]:d_forest_y_coords[1],
                 d_forest_x_coords[0]:d_forest_x_coords[1], 3] = 30

    #Scrubland
    scrubland_x_coords = [int(0.65 * size_x), int(0.7 * size_x)]
    scrubland_y_coords = [int(0.1 * size_y), int(0.7 * size_y)]
    config.initial_grid[scrubland_y_coords[0]:scrubland_y_coords[1],
                        scrubland_x_coords[0]:scrubland_x_coords[1]] = 3
    grid_attribs[scrubland_y_coords[0]:scrubland_y_coords[1],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 1] = 3
    grid_attribs[scrubland_y_coords[0]:scrubland_y_coords[1],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 3] = 10

    #top slope of cayon
    grid_attribs[scrubland_y_coords[0] + 5:scrubland_y_coords[0],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -1
    grid_attribs[scrubland_y_coords[0] + 4:scrubland_y_coords[0],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -125.75
    grid_attribs[scrubland_y_coords[0] + 3:scrubland_y_coords[0],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -250.5
    grid_attribs[scrubland_y_coords[0] + 2:scrubland_y_coords[0],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -375.25
    grid_attribs[scrubland_y_coords[0] + 1:scrubland_y_coords[0],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -500
    #bottom slope of cayon
    grid_attribs[scrubland_y_coords[1] - 1:scrubland_y_coords[1],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -1
    grid_attribs[scrubland_y_coords[1] - 2:scrubland_y_coords[1],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -125.75
    grid_attribs[scrubland_y_coords[1] - 3:scrubland_y_coords[1],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -250.5
    grid_attribs[scrubland_y_coords[1] - 4:scrubland_y_coords[1],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -375.25
    grid_attribs[scrubland_y_coords[1] - 5:scrubland_y_coords[1],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -500
    #sides of cayon
    grid_attribs[scrubland_y_coords[0]:scrubland_y_coords[1],
                 scrubland_x_coords[0]:scrubland_x_coords[1], 0] = -500

    transitions = [[1, 1], [0, 1], [-1, 1], [1, 0], [0, -1], [1, -1], [0, -1],
                   [-1, -1]]
    height_neighbours = np.zeros((*config.grid_dims, 8))

    for i in range(grid_attribs.shape[0]):
        for j in range(grid_attribs.shape[1]):
            for k in range(len(transitions)):
                x_coord = j - transitions[k][0]
                y_coord = i - transitions[k][1]
                if (0 <= x_coord < 200) and (0 <= y_coord < 200):
                    height_neighbours[i][j][k] = grid_attribs[y_coord, x_coord,
                                                              0]

    grid_attribs[:, :, 12:] = height_neighbours

    # Create grid object using parameters from config + transition function
    grid = Grid2D(config, (transition_function, time_to_drop, grid_attribs))

    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    # Save updated config to file
    config.save()
    # Save timeline to file
    utils.save(timeline, config.timeline_path)
Ejemplo n.º 26
0
 def save(self):
     save(self, self.path)
Ejemplo n.º 27
0
def main():
    # Open the config object
    config = setup(sys.argv[1:])
    fuelCount = np.zeros(config.grid_dims)
    fuelCount.fill(-1)
    fuelCount[(config.initial_grid == 1)] = 45000
    #windBias = np.zeros(config.grid_dims)

    #print(config.grid_dims)
    # low and high wind speed
    windSpeed = 2

    moisture = np.zeros(config.grid_dims)

    terrainBias = np.zeros(config.grid_dims)

    #NW, N, NE, W, E, SW, S, SE = neighbourstates

    w1 = 2  # next closest to wind direction
    w2 = 3  # in the direction of wind
    w3 = 0.9  # next closes to opposite
    w4 = 0.4  # parralel with wind
    w5 = 0.7  # the opposite from the direction

    # North
    #windBias = [w1, w2, w1, w4, w4, w3, w5, w3]
    # South
    windBias = [w3, w5, w3, w4, w4, w1, w2, w1]
    # West
    #windBias = [w1, w4, w3, w2, w5, w1, w4, w3]
    #East
    #windBias = [w3, w4, w1, w5, w2, w3, w4, w1]

    # NW
    #windBias = [w2, w1, w4, w1, w3, w4, w3, w5]
    # NE
    #windBias = [w4, w1, w2, w3, w1, w5, w3, w4]
    # SW
    #windBias = [w4, w3, w5, w1, w3, w2, w1, w4]
    # SE
    #windBias = [w5, w3, w4, w3, w1, w4, w1, w2]

    #windBias = [1,1,1,1,1,1,1,1]

    #if(wind == 'NE'):
    #windBias = windBias[-1:] + windBias[:-1]
    #elif('W'):
    #windBias = windBias[-2:] + windBias[:-2]
    #elif('E'):
    #windBias = windBias[-3:] + windBias[:-3]
    #elif('SW'):
    #windBias = windBias[-4:] + windBias[:-4]
    #elif('S'):
    #windBias = windBias[-5:] + windBias[:-5]
    #elif('SE'):
    #windBias = windBias[-6:] + windBias[:-6]
    #elif('NW'):
    #windBias = windBias[-7:] + windBias[:-7]

    #print(windBias)

    # Create grid object
    grid = Grid2D(config, (transition_func, fuelCount, windBias, moisture,
                           config.initial_grid, terrainBias, windSpeed))
    #fuelCount = np.zeros(grid.shape[0], grid.shape[1])

    #print("GRID", type(grid))
    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()
    #print("TIMELINE", timeline)
    # save updated config to file
    config.save()
    # save timeline to file
    utils.save(timeline, config.timeline_path)
    return np.exp(0.1783 * speed * np.cos(np.deg2rad(angle)))


def main():

    config = setup(sys.argv[1:])
    s = -10000
    decay_grid = [[decay_values[i] for i in row]
                  for row in initial_grid.astype(int)]
    decay_grid = np.array(decay_grid)
    water_decay_values = [s, s, s, s, s]
    water_decay_grid = np.array([[water_decay_values[i] for i in row]
                                 for row in initial_grid.astype(int)])

    #Select section of grid to drop water
    water_decay_grid[120:160, 80:120] = 0  #drop water after this time
    ignition_grid = np.zeros((grid_size, grid_size))
    ignition_grid = ignition_grid.astype(int)
    grid = Grid2D(config, (transition_function, decay_grid, water_decay_grid))

    # Create grid object using parameters from config + transition function
    # Run the CA, save grid state every generation to timeline
    timeline = grid.run()

    config.save()  # Save updated config to file
    utils.save(timeline, config.timeline_path)  # Save timeline to file


if __name__ == "__main__":
    main()