From bc2e93790fa4c81bfa77485282b41f667f0423bd Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Tue, 28 Jan 2020 00:04:11 +0000 Subject: [PATCH] added population example script --- examples/example_population.py | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 examples/example_population.py diff --git a/examples/example_population.py b/examples/example_population.py new file mode 100644 index 000000000..955e1e04f --- /dev/null +++ b/examples/example_population.py @@ -0,0 +1,63 @@ +import os + +# import json +# import time +# import sys + +from binarycpython.utils.grid import Population +from binarycpython.utils.functions import get_help_all, get_help + + +######################################################### +# This file serves as an example for running a population. +# The use of help(<function>) is a good way to inspect what parameters are there to use +######################################################### + +# Create population object +example_pop = Population() + +# If you want verbosity, set this before other things +example_pop.set(verbose=0) + +# Setting values can be done via .set(<parameter_name>=<value>) +# Values that are known to be binary_c_parameters are loaded into bse_options. +# Those that are present in the default grid_options are set in grid_options +# All other values that you set are put in a custom_options dict +example_pop.set( + # + M_1=10, # bse_options + separation=0, # bse_options + orbital_period=4580, # bse_options + max_evolution_time=15000, # bse_options + eccentricity=0.02, # bse_options + # + amt_cores=1, # grid_options + # + data_dir=os.path.join( + os.environ["BINARYC_DATA_ROOT"], "example_python" + ), # custom_options + base_filename="example_pop.dat", # custom_options +) + +# Custom logging +# TODO: show different ways +example_pop.set( + C_auto_logging={ + "MY_HEADER_LINE": ["star[0].mass", "star[1].mass", "model.probability"] + } +) +example_pop.set( + C_logging_code='Printf("MY_STELLAR_DATA time=%g mass=%g radius=%g\\n", stardata->model.time, stardata->star[0].mass, stardata->star[0].radius);' +) + +example_pop.set_custom_logging() + + +# Exporting of all the settings can be done with .export_all_info() +# on default it exports everything, but can be supressed by turning it off: +# population settings (bse_options, grid_options, custom_options), turn off with include_population_settings=False +# binary_c_defaults (all the commandline arguments that binary c accepts, and their defaults). turn off with include_binary_c_defaults=False +# include_binary_c_version_info (all the compilation info, and information about the compiled parameters), turn off with include_binary_c_version_info=False +# include_binary_c_help_all (all the help information for all the binary_c parameters), turn off with include_binary_c_help_all=Fase +# On default it will write this to the custom_options['data_dir'], but that can be overriden by setting use_datadir=False and providing an outfile=<> +example_pop.export_all_info() -- GitLab