def check_runs(self, rel_tol=1E-3): for dl_dir in toolbox_basic.subdir_list(self.root_dir, 'detail_level_*'): run_dirs = toolbox_basic.subdir_list(dl_dir) for run_dir in run_dirs: if os.path.basename(run_dir) == 'mesh': continue cell_file = os.path.join(run_dir, 'cell_rates.xml') if os.path.isfile(cell_file): cell_file = SimulationResultsFile(path=cell_file, read_only=True) rel_diff = cell_file.get_relative_difference() if rel_diff > rel_tol: print('%s has rel_diff = %f'%(run_dir, rel_diff)) else: print('%s has no cell_rates.xml file'%(run_dir))
def get_sif_names(self, detail_level): dl_dir = self.get_detail_level_dir(detail_level) out = [] for subdir in toolbox_basic.subdir_list(dl_dir): base_name = os.path.basename(subdir) sif_path = os.path.join(subdir, base_name+'.sif') if os.path.exists(sif_path): out.append(base_name) return out
def assemble_optima(superset_dir_path, attribute, dir_group_process, set_dir_type='*', higher_is_fitter=True, starting_time=2400): results_file_path = os.path.join(superset_dir_path, 'results.xml') results_output = results.ResultsOutput(path=results_file_path) attributes = {'name':'optimum '+attribute, 'starting_time':str(starting_time), 'header':'directory,mean,std'} optima_set = results.ResultSet(results_output, attributes) if len(optima_set.members) > 0: return optimum_set set_dir_paths = basic.subdir_list(superset_dir_path, dirtype=set_dir_type) for set_dir_path in set_dir_paths: optimum_set = get_optima(set_dir_path, attribute, dir_group_process, higher_is_fitter=higher_is_fitter, starting_time=starting_time) for single_result in optimum_set.members: optima_set.members.append(single_result) optima_set.update_results_output() results_output.write(results_file_path) return optima_set
def settle_competition(set_dir_path): set_dir_path = basic.check_path(set_dir_path) attributes = {'name' : 'competition', 'header' : 'speciesAwashout,speciesBwashout,numSims,pValue'} results_file_path = os.path.join(set_dir_path, 'results.xml') results_output = results.ResultsOutput(path=results_file_path) result_set = results.ResultSet(results_output, attributes) if len(result_set.members) > 0: return result_set dir_list = basic.subdir_list(set_dir_path) dir_result = results.SingleResult() washoutA = 0 washoutB = 0 for dir_name in dir_list: last_path = os.path.join(dir_name, 'lastIter', 'agent_Sum(last).xml') last_output = results.AgentOutput(path=last_path) species_names = last_output.get_species_names() if not len(species_names) == 2: basic.error_message('There should be 2 species for a competition', last_path) last_speciesA = results.SpeciesOutput(last_output, name=species_names[0]) populationA = float(last_speciesA.members[0].vars['population']) last_speciesB = results.SpeciesOutput(last_output, name=species_names[1]) populationB = float(last_speciesB.members[0].vars['population']) if populationA < 1 and populationB > 0: washoutA += 1 if populationB < 1 and populationA > 0: washoutB += 1 if populationA < 1 and populationB < 1: basic.error_message('Both species washed out in', last_path) dir_result.vars['speciesAwashout'] = washoutA dir_result.vars['speciesBwashout'] = washoutB dir_result.vars['numSims'] = len(dir_list) dir_result.vars['pValue'] = \ stats.binom.cdf(min(washoutA,washoutB),(washoutA+washoutB),0.5) result_set.members.append(dir_result) result_set.update_results_output() results_output.write(results_file_path) return result_set
def collate_mean_attributes(set_dir_path, attribute, output_type, file_process, starting_time=2400): set_dir_path = basic.check_path(set_dir_path) attributes = {'name':attribute, 'starting_time':str(starting_time), 'header':'directory,mean,std'} results_file_path = os.path.join(set_dir_path, 'results.xml') results_output = results.ResultsOutput(path=results_file_path) result_set = results.ResultSet(results_output, attributes) if len(result_set.members) > 0: return result_set dir_list = basic.subdir_list(set_dir_path) for dir_name in dir_list: dir_result = results.SingleResult() dir_result.vars['directory'] = os.path.basename(dir_name) mean, std = calc_mean_attribute(dir_name, attribute, output_type, file_process, starting_time=starting_time) dir_result.vars['mean'] = mean dir_result.vars['std'] = std result_set.members.append(dir_result) result_set.update_results_output() results_output.write(results_file_path) return result_set
def group_dirs_by_a_m_s(set_dir_path): groupA = basic.subdir_list(set_dir_path, 'a*') groupM = basic.subdir_list(set_dir_path, 'm*') groupS = basic.subdir_list(set_dir_path, 's*') return [groupA, groupM, groupS]
def get_replicate_simulations(replicates_dir): return [Simulation(d) for d in toolbox_basic.subdir_list(replicates_dir)]