def combine(): with h5.HDFStore('samples.h5', mode='a') as store: # (model, SAT, sample) that are already in `store`. store_idx = store.get_index().droplevel(_index).unique() for model in os.listdir(_path): path_model = os.path.join(_path, model) for SAT in map(int, sorted(os.listdir(path_model))): path_SAT = os.path.join(path_model, str(SAT)) # Sort in integer order. for filename in sorted(os.listdir(path_SAT), key=_get_sample_number): sample = _get_sample_number(filename) if (model, SAT, sample) not in store_idx: path_sample = os.path.join(path_SAT, filename) recarray = numpy.load(path_sample) df = pandas.DataFrame.from_records(recarray, index=_index) run._prepend_index_levels(df, model=model, SAT=SAT, sample=sample) print('Inserting ' + ', '.join((f'model={model}', f'SAT={SAT}', f'sample={sample}')) + '.') store.put(df, min_itemsize=run._min_itemsize)
def run_population_size(model, SAT, population_size, tmax, nruns, hdfstore): if population_size == 1000: _copy_run(model, SAT, population_size, nruns, hdfstore) else: p = herd.Parameters(model=model, SAT=SAT) p.population_size = population_size logging_prefix = (', '.join( (f'model {model}', f'SAT {SAT}', f'population_size {population_size}')) + ', ') df = run.run_many(p, tmax, nruns, logging_prefix=logging_prefix) run._prepend_index_levels(df, model=model, SAT=SAT, population_size=population_size) hdfstore.put(df, min_itemsize=run._min_itemsize)
def run_start_time(model, SAT, start_time, tmax, nruns, hdfstore): if start_time == 0.5: _copy_run(model, SAT, start_time, nruns, hdfstore) else: p = herd.Parameters(model=model, SAT=SAT) p.start_time = start_time logging_prefix = (', '.join( (f'model {model}', f'SAT {SAT}', f'start_time {start_time}')) + ', ') df = run.run_many(p, tmax, nruns, logging_prefix=logging_prefix) run._prepend_index_levels(df, model=model, SAT=SAT, start_time=start_time) hdfstore.put(df, min_itemsize=run._min_itemsize)
def run_initial_conditions(model, SAT, initial_conditions, tmax, nruns, hdfstore): if initial_conditions == SAT: _copy_run(model, SAT, initial_conditions, nruns, hdfstore) else: p = herd.Parameters(model=model, SAT=SAT, _initial_conditions=initial_conditions) logging_prefix = (', '.join( (f'model {model}', f'SAT {SAT}', f'initial_conditions {initial_conditions}')) + ', ') df = run.run_many(p, tmax, nruns, logging_prefix=logging_prefix) run._prepend_index_levels(df, model=model, SAT=SAT, initial_conditions=initial_conditions) hdfstore.put(df, min_itemsize=run._min_itemsize)
def run_birth_seasonality(model, SAT, birth_seasonality_scaling, tmax, nruns, hdfstore): p = herd.Parameters(model=model, SAT=SAT) p.birth_seasonal_coefficient_of_variation *= birth_seasonality_scaling bscov = p.birth_seasonal_coefficient_of_variation if birth_seasonality_scaling == 1: _copy_run(model, SAT, bscov, nruns, hdfstore) else: logging_prefix = (', '.join( (f'model {model}', f'SAT {SAT}', f'birth_seasonality_scaling {birth_seasonality_scaling}')) + ', ') df = run.run_many(p, tmax, nruns, logging_prefix=logging_prefix) run._prepend_index_levels( df, model=model, SAT=SAT, birth_seasonal_coefficient_of_variation=bscov) hdfstore.put(df, min_itemsize=run._min_itemsize)