Skip to content

Commit

Permalink
Merge pull request #107 from TomWagg/ini
Browse files Browse the repository at this point in the history
Allow the use of `ini` files to specify `BSE_settings`
  • Loading branch information
TomWagg authored Apr 24, 2024
2 parents c0bdad8 + 0942114 commit a5fabe1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
3 changes: 0 additions & 3 deletions cogsworth/hydro/pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ def __repr__(self):
f"SFH={self.sfh_model.__name__}>")

def __getitem__(self, ind):
if self._initC is not None and "particle_id" not in self._initC.columns:
self._initC["particle_id"] = self._initial_binaries["particle_id"]

# convert any Pandas Series to numpy arrays
ind = ind.values if isinstance(ind, pd.Series) else ind

Expand Down
11 changes: 7 additions & 4 deletions cogsworth/pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from cosmic.sample.initialbinarytable import InitialBinaryTable
from cosmic.evolve import Evolve
from cosmic.checkstate import set_checkstates
from cosmic.utils import parse_inifile
import gala.potential as gp
import gala.dynamics as gd
from gala.potential.potential.io import to_dict as potential_to_dict, from_dict as potential_from_dict
Expand Down Expand Up @@ -62,7 +63,9 @@ class Population():
timestep_size : :class:`~astropy.units.Quantity` [time], optional
Size of timesteps to use in galactic evolution, by default 1*u.Myr
BSE_settings : `dict`, optional
Any BSE settings to pass to COSMIC
Any BSE settings to pass to COSMIC, superseded by `ini_file` if provided
ini_file : `str`, optional
Path to an ini file to use for the COSMIC stellar evolution, supersedes `BSE_settings` by default None
bcm_timestep_conditions : List of lists, optional
Any timestep conditions to pass to COSMIC evolution. This will affect the rows that are output in the
the BCM table, by default only the first and last timesteps are output. For more details check out the
Expand Down Expand Up @@ -119,8 +122,8 @@ class Population():
def __init__(self, n_binaries, processes=8, m1_cutoff=0, final_kstar1=list(range(16)),
final_kstar2=list(range(16)), sfh_model=sfh.Wagg2022, sfh_params={},
galactic_potential=gp.MilkyWayPotential(), v_dispersion=5 * u.km / u.s,
max_ev_time=12.0*u.Gyr, timestep_size=1 * u.Myr, BSE_settings={}, sampling_params={},
bcm_timestep_conditions=[], store_entire_orbits=True):
max_ev_time=12.0*u.Gyr, timestep_size=1 * u.Myr, BSE_settings={}, ini_file=None,
sampling_params={}, bcm_timestep_conditions=[], store_entire_orbits=True):

# require a sensible number of binaries if you are not targetting total mass
if not ("sampling_target" in sampling_params and sampling_params["sampling_target"] == "total_mass"):
Expand Down Expand Up @@ -183,7 +186,7 @@ def __init__(self, n_binaries, processes=8, m1_cutoff=0, final_kstar1=list(range
'ST_cr': 1, 'ST_tide': 1, 'bdecayfac': 1, 'rembar_massloss': 0.5, 'kickflag': 0,
'zsun': 0.014, 'bhms_coll_flag': 0, 'don_lim': -1, 'acc_lim': -1, 'binfrac': 0.5,
'rtmsflag': 0, 'wd_mass_lim': 1}
self.BSE_settings.update(BSE_settings)
self.BSE_settings.update(BSE_settings if ini_file is None else parse_inifile(ini_file)[0])

self.sampling_params = {'primary_model': 'kroupa01', 'ecc_model': 'sana12', 'porb_model': 'sana12',
'qmin': -1, 'keep_singles': False}
Expand Down
10 changes: 5 additions & 5 deletions cogsworth/tests/prep_data.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os

# get the dustmap file if necessary
import dustmaps.bayestar
from dustmaps.std_paths import data_dir
bayestar_path = os.path.join(data_dir(), 'bayestar', '{}.h5'.format("bayestar2019"))
if not os.path.exists(bayestar_path):
dustmaps.bayestar.fetch()
# import dustmaps.bayestar
# from dustmaps.std_paths import data_dir
# bayestar_path = os.path.join(data_dir(), 'bayestar', '{}.h5'.format("bayestar2019"))
# if not os.path.exists(bayestar_path):
# dustmaps.bayestar.fetch()

# set up directory for gaiaunlimited
home_dir = os.path.expanduser('~')
Expand Down
3 changes: 3 additions & 0 deletions cogsworth/tests/test_hydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test_pop_init(self):
pop = cogsworth.hydro.pop.HydroPopulation(init_particles, galactic_potential=pot,
subset=subset, snapshot_type="FIRE")
self.assertEqual(len(pop._subset_inds), length)
self.assertTrue("star particles" in pop.__repr__())

# also test citations
it_broke = False
Expand All @@ -77,6 +78,8 @@ def test_pop_sample_and_mask(self):
max_ev_time=100 * u.Myr, snapshot_type="FIRE", processes=1)
p.create_population()

self.assertTrue("star particles" in p.__repr__() and "evolved systems" in p.__repr__())

p.disrupted
p.final_bpp

Expand Down
3 changes: 2 additions & 1 deletion cogsworth/tests/test_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def test_interface(self):

# test that observable table is done right (with or without extinction)
p.observables
p.get_observables(filters=["G", "BP", "RP", "J", "H", "K"], assume_mw_galactocentric=True)
p.get_observables(filters=["G", "BP", "RP", "J", "H", "K"],
assume_mw_galactocentric=True, ignore_extinction=True)
obs.get_photometry(filters=["G", "BP", "RP", "J", "H", "K"], final_bpp=p.final_bpp,
final_pos=p.final_pos, assume_mw_galactocentric=True, ignore_extinction=True)
p.observables
Expand Down
4 changes: 4 additions & 0 deletions docs/tutorials/observables/photometry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,10 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
},
"execution": {
"allow_errors": true,
"timeout": 300
}
},
"nbformat": 4,
Expand Down

0 comments on commit a5fabe1

Please sign in to comment.