Skip to content

Commit 10c069d

Browse files
authored
Merge pull request #264 from mtremmel/BH_merger_logcache_fix
BH merger logcache fix
2 parents ea583f0 + 457a48e commit 10c069d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

docs/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ or, for pre-release versions (for example if you are working with pynbody v2) us
2424
```
2525
pip install --pre tangos
2626
```
27-
or, for the latest version from the repository use
27+
or, for the latest version from the repository use
2828
```
2929
pip install git+https://github.com/pynbody/tangos.git
3030
```
@@ -51,7 +51,7 @@ pip install -e .[test]
5151
```
5252

5353
The `[test]` specified ensures that additional packages needed for testing are installed. This includes _pynbody_ and _yt_,
54-
as well as _pytest_.
54+
as well as _pytest_.
5555

5656
Once installed, you should check that _tangos_ is functioning correctly by entering the `tests` folder and
5757
typing `pytest`. You should see a bunch of text scrolling by, ultimately finishing with the simple message `OK`.

tangos/input_handlers/changa_bh.py

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def get_existing_or_new(cls, filename):
2828
name, stepnum = re.match(r"^(.*)\.(0[0-9]*)$", filename).groups()
2929
obj = cls._cache.get(name, None)
3030
if obj is not None:
31+
import pynbody
32+
f = pynbody.load(filename)
33+
obj.boxsize = float(f.properties['boxsize'].in_units('kpc', a=f.properties['a']))
34+
logger.info("Found cached log information. Updating physical boxsize to %f", obj.boxsize)
3135
return obj
3236

3337
obj = cls(filename)

tangos/tools/changa_bh_importer.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def _timelink_black_holes(self):
6363
def _generate_halolinks(self, pairs):
6464
for ts1, ts2 in parallel_tasks.distributed(pairs):
6565
if BlackHolesLog.can_load(ts2.filename):
66-
bh_log = BlackHolesLog(ts2.filename)
66+
bh_log = BlackHolesLog.get_existing_or_new(ts2.filename)
6767
elif ShortenedOrbitLog.can_load(ts2.filename):
68-
bh_log = ShortenedOrbitLog(ts2.filename)
68+
bh_log = ShortenedOrbitLog.get_existing_or_new(ts2.filename)
6969
else:
7070
logger.error("Warning! No orbit file found!")
7171

@@ -106,9 +106,16 @@ def _generate_halolinks(self, pairs):
106106
logger.info("Generated %d tracker links between steps %r and %r", len(links), ts1, ts2)
107107

108108
logger.info("Generating BH Merger information for steps %r and %r", ts1, ts2)
109+
#get information needed from simulation to convert time from simulation units
110+
import pynbody
111+
f = pynbody.load(ts1.filename)
112+
tunits = f.infer_original_units('Gyr')
113+
gyr_ratio = pynbody.units.Gyr.ratio(tunits)
109114
for l in open(self._bhmerger_filename):
110115
l_split = l.split()
111-
t = float(l_split[6])
116+
#convert time to Gyr and account for negative times
117+
#(for "fake" mergers but we'd still want them if the BHs actually make it to the database)
118+
t = np.abs(float(l_split[6]))/gyr_ratio
112119
bh_dest_id = int(l_split[0])
113120
bh_src_id = int(l_split[1])
114121
ratio = float(l_split[4])
@@ -196,7 +203,7 @@ def _get_bh_halo_assignments(self, pynbody_snapshot):
196203
iteration_count += 1
197204

198205
# find the parent halos of the bh_cen_halos
199-
bh_halos_new = [pynbody_halos.get_dummy_halo(i).properties['hostHalo'] for i in bh_halos]
206+
bh_halos_new = [pynbody_halos.get_dummy_halo(i).properties['hostHalo'] if i!=-1 else -1 for i in bh_halos]
200207

201208
# if the parent is -1, we have definitely found the top level halos
202209
continue_searching = not all([bhi==-1 for bhi in bh_halos_new])

0 commit comments

Comments
 (0)