def generate_genes(): """ Generates genes for a new individual to be placed within a population. :return: new individual: list list of WRF model physics parameters """ new_individual = wrfparams.flexible_generate() return new_individual
def seed_initial_population(input_csv): """ Reads the input csv file, which contains the dates and/or parameter combinations that you would like to see in the initial population. The CSV file should be formatted as follows (i.e., this function looks for these column names): Line 1: start_date, mp_physics, ra_lw_physics, ra_sw_physics, sf_surface_physics, bl_pbl_physics, cu_physics Line 2: Feb 28 2011, 1, 24, 99, 4, 11, 2 Line 3: Aug 31 2011, 28, 4, 5, 2, 10, 93 Line 4: Dec 10 2011, 7, 24, 3, 4, 9, 4 Line 5: Jul 22 2011, 11, 24, 2, 1, 4, 10 Line 6: May 23 2011, 1, 4, 5, 2, 10, 93 Line 7: Mar 31 2011, 28, 24, 99, 4, 11, 2 . . . :param input_csv: string defines the file name from which dates/parameters will be read. :return intial population: list of Chromosome instances made from the information specified in the input file. """ initial_population = [] try: with open(input_csv, newline='') as csvfile: reader = csv.DictReader(csvfile) for row in reader: start_date = row['start_date'] param_ids = wrfparams.flexible_generate(generate_params=False, mp=int(row['mp_physics']), lw=int(row['ra_lw_physics']), sw=int(row['ra_sw_physics']), lsm=int(row['sf_surface_physics']), pbl=int(row['bl_pbl_physics']), cu=int(row['cu_physics'])) start_date, end_date = simplega.generate_random_dates(input_start_date=start_date) initial_population.append(Chromosome(param_ids, start_date, end_date)) except IOError: print(f'IOEror in seed_initial_population: {input_csv} does not exist.') return initial_population return initial_population
def test_update_sim(): """Checks to make sure that entries in the database can be updated.""" # Generate a random set of parameters, a random start date, and a Chromosome r_start_date, r_end_date = sga.generate_random_dates() r_param_ids = wp.flexible_generate() individual = sga.Chromosome(r_param_ids, fitness=100, start_date=r_start_date, end_date=r_end_date) # Put individual in the database db_conn = conn_to_db('optwrf_repeat.db') owp.insert_sim(individual, db_conn) print_database(db_conn) # Generate a new random start date and a Chromosome r_start_date, r_end_date = sga.generate_random_dates() individual = sga.Chromosome(r_param_ids, fitness=50, start_date=r_start_date, end_date=r_end_date) # Update the individual in the database database owp.update_sim(individual, db_conn) print_database(db_conn)
else: setup_yaml = 'dirpath.yml' # Set the number of domains to user specification, or default to a single domain. if args.d is not None and args.d > 0: n_domains = int(args.d) else: n_domains = 3 # Format the forecast start/end and determine the total time. start_date = args.s end_date = args.e # Generate a parameter combination of the 6 core parameters if the user has specified this option. # Otherwise, use specified input parameters and use defaults for the remaining paramters. param_ids = flexible_generate(generate_params, mp, lw, sw, lsm, pbl, cu, in_yaml) wrf_sim = WRFModel(param_ids, start_date, end_date, bc_data=bc_data, n_domains=n_domains, setup_yaml=setup_yaml) # Next, get boundary condition data for the simulation # ERA is the only supported data type right now. vtable_sfx = wrf_sim.get_bc_data() # Setup the working directory to run the simulation wrf_sim.wrfdir_setup(vtable_sfx)