Skip to content

Commit

Permalink
Merge pull request #265 from pynbody/ahf-mapping-pynbody
Browse files Browse the repository at this point in the history
Remove manual mapping of AHF IDs, since this is now done by pynbody beta
  • Loading branch information
apontzen authored Nov 22, 2024
2 parents 13dd0e2 + a1c8255 commit e67fb95
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 34 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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: no-commit-to-branch
args: [--branch, master]
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 e67fb95

Please sign in to comment.