Skip to content

Commit

Permalink
Merge branch 'ahfv1_backward_compat_fix' into BH_merger_logcache_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mtremmel committed Dec 17, 2024
2 parents fa61c06 + 0515f38 commit d530f3c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
run: |
python -c "import tangos"
- name: Install pynbody and yt
run: python -m pip install pynbody yt --no-build-isolation
run: python -m pip install pynbody 'yt<4.4.0' --no-build-isolation
- name: Set up MySQL
if: ${{ matrix.TANGOS_TESTING_DB_BACKEND == 'mysql+pymysql' }}
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
run: python -m pip install --pre pynbody
# Or: python -m pip install git+https://github.com/pynbody/pynbody.git

- name: Install latest yt
run: python -m pip install yt
- name: Install yt
run: python -m pip install 'yt<4.4.0'

- name: Build test database
working-directory: test_tutorial_build
Expand Down
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ ci:

repos:
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
rev: v2.7.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: no-commit-to-branch
args: [--branch, master]
- id: check-shebang-scripts-are-executable
- id: check-executables-have-shebangs
- id: check-yaml
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -28,7 +27,7 @@ repos:
hooks:
- id: rst-backticks
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.4
rev: 1.9.1
hooks:
- id: nbqa-pyupgrade
args: [--py37-plus]
Expand Down
33 changes: 3 additions & 30 deletions tangos/input_handlers/pynbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,37 +615,12 @@ def available_object_property_names_for_timestep(self, ts_extension, object_type
)


def _get_map_child_subhalos(self, ts_extension):
h = self.get_catalogue(ts_extension, 'halo')
halo_children = defaultdict(list)
for halo in h:
iparent = halo.properties["hostHalo"] # Returns the unique ID (NOT the halo_id index) of the host
if iparent == -1: # If halo is its own host (i.e. -1), move on to next object
continue

halo_children[iparent].append(halo.properties["halo_id"]) # Otherwise store the halo_id index of the host
return halo_children


def _get_map_IDs_to_halo_ids(self, ts_extension):
# IDs and halo_ids are usually related by ID = halo_id - 1,
# but they can be entirely independent when using specific AHF options or running with MPI
# This allows to map between one and the other
h = self.get_catalogue(ts_extension, 'halo')
return {
halo.properties["ID"]: halo.properties["halo_id"] for halo in h
}

def iterate_object_properties_for_timestep(self, ts_extension, object_typetag, property_names):
h = self.get_catalogue(ts_extension, object_typetag)

h.physical_units()

if "child" in property_names:
map_child_parent = self._get_map_child_subhalos(ts_extension)

if "parent" in property_names:
map_ID_to_halo_id = self._get_map_IDs_to_halo_ids(ts_extension)
# Manually mapping IDs etc used to be setup here, but should no longer be required with pynbody v2

for halo in h:
# Tangos expect us to yield first the finder offset (index in the pynbody catalogue, halo_id in our case)
Expand All @@ -659,7 +634,7 @@ def iterate_object_properties_for_timestep(self, ts_extension, object_typetag, p
if parent_ID != -1:
# If halo is not its own parent, link to parent
data = proxy_object.IncompleteProxyObjectFromFinderId(
map_ID_to_halo_id[parent_ID],
parent_ID,
'halo'
)
else:
Expand All @@ -668,12 +643,10 @@ def iterate_object_properties_for_timestep(self, ts_extension, object_typetag, p
halo_props['halo_id'],
'halo'
)


elif k == "child":
data = [
proxy_object.IncompleteProxyObjectFromFinderId(ichild, 'halo')
for ichild in map_child_parent[halo_props["ID"]]
for ichild in halo_props['children']
]
elif k == "shrink_center":
data = np.array([halo_props[k] for k in ("Xc", "Yc", "Zc")])
Expand Down

0 comments on commit d530f3c

Please sign in to comment.