Skip to content

Commit

Permalink
add TNGCluster test snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
cbyrohl committed Jul 10, 2023
1 parent 61d2321 commit b42397e
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .github/actions/get-testdata-all/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ runs:
outputfolder: ${{ inputs.outputfolder }}
filename: minimal_FIRE2_simulation.tar.gz
url: https://heibox.uni-heidelberg.de/f/99a6c5fe31eb430f90e2/?dl=1
- uses: ./.github/actions/get-testdata
with:
outputfolder: ${{ inputs.outputfolder }}
filename: minimal_TNG-Cluster_snapshot_z0.hdf5
url: https://heibox.uni-heidelberg.de/f/fe582fbe745445d7a448/?dl=1
1 change: 1 addition & 0 deletions src/scida/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from scida.customs.arepo.dataset import ArepoSnapshot
from scida.customs.arepo.MTNG.dataset import MTNGArepoSnapshot
from scida.customs.arepo.series import ArepoSimulation
from scida.customs.arepo.TNGcluster.dataset import TNGClusterSnapshot
from scida.customs.gadgetstyle.dataset import GadgetStyleSnapshot, SwiftSnapshot
from scida.customs.gizmo.dataset import GizmoSnapshot
from scida.customs.gizmo.series import GizmoSimulation
Expand Down
1 change: 1 addition & 0 deletions src/scida/customs/arepo/TNGcluster/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# We need a dedicated class, so we can add functions to deal with the "stiching" of TNG-Cluster zoom-ins
40 changes: 38 additions & 2 deletions src/scida/customs/arepo/TNGcluster/dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
import os
from typing import Union

from scida import ArepoSnapshot
from scida.discovertypes import CandidateStatus
from scida.io import load_metadata


class TNGClusterSnapshot(ArepoSnapshot):
_fileprefix_catalog = "fof_subhalo_tab"
_fileprefix = "snapshot_" # underscore is important!
_fileprefix_catalog = "fof_subhalo_tab_"
_fileprefix = "snap_"

@classmethod
def validate_path(
cls, path: Union[str, os.PathLike], *args, **kwargs
) -> CandidateStatus:
tkwargs = dict(
fileprefix=cls._fileprefix, fileprefix_catalog=cls._fileprefix_catalog
)
tkwargs.update(**kwargs)
valid = super().validate_path(path, *args, **tkwargs)
if valid == CandidateStatus.NO:
return valid
metadata_raw = load_metadata(path, **tkwargs)

matchingattrs = True

parameters = metadata_raw["/Parameters"]
if "InitCondFile" in parameters:
matchingattrs &= parameters["InitCondFile"] == "various"
else:
return CandidateStatus.NO

Check warning on line 32 in src/scida/customs/arepo/TNGcluster/dataset.py

View check run for this annotation

Codecov / codecov/patch

src/scida/customs/arepo/TNGcluster/dataset.py#L32

Added line #L32 was not covered by tests
header = metadata_raw["/Header"]
matchingattrs &= header["BoxSize"] == 680000.0
matchingattrs &= header["NumPart_Total"][1] == 1944529344
matchingattrs &= header["NumPart_Total"][2] == 586952200

if matchingattrs:
valid = CandidateStatus.YES
else:
valid = CandidateStatus.NO
return valid
7 changes: 4 additions & 3 deletions src/scida/customs/arepo/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ def load_catalog(self, kwargs):
self.merge_data(self.catalog)

# first snapshots often do not have groups
ngkeys = self.catalog.data["Group"].keys()
if len(ngkeys) > 0:
self.add_catalogIDs()
if "Group" in self.catalog.data:
ngkeys = self.catalog.data["Group"].keys()
if len(ngkeys) > 0:
self.add_catalogIDs()

# merge hints from snap and catalog
self.merge_hints(self.catalog)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_discovery.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib
from typing import Type

from scida import ArepoSnapshot, MTNGArepoSnapshot
from scida import ArepoSnapshot, MTNGArepoSnapshot, TNGClusterSnapshot
from scida.customs.arepo.dataset import ArepoCatalog
from scida.customs.arepo.MTNG.dataset import MTNGArepoCatalog
from scida.customs.arepo.series import ArepoSimulation
Expand Down Expand Up @@ -33,6 +33,8 @@ def return_intended_dstype(name, simconf=False) -> Type[Dataset]:
return MTNGArepoCatalog
else:
return MTNGArepoSnapshot
elif any([k in name for k in ["tng-cluster", "tngcluster"]]):
return TNGClusterSnapshot
elif any(k in name for k in ["tng", "illustris", "auriga"]):
if "group" in name:
return ArepoCatalog
Expand Down
2 changes: 2 additions & 0 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def customfunc(dens, vol, fieldnames=["Density", "Masses"]):
@require_testdata("illustrissnapshot_withcatalog")
def test_areposnapshot_load_withcatalog(testdata_illustrissnapshot_withcatalog):
snp = testdata_illustrissnapshot_withcatalog
if snp.redshift >= 20.0: # hacky... (no catalog at high redshifts)
return

Check warning on line 195 in tests/test_interface.py

View check run for this annotation

Codecov / codecov/patch

tests/test_interface.py#L195

Added line #L195 was not covered by tests
parttypes = {
"PartType0",
"PartType1",
Expand Down
7 changes: 7 additions & 0 deletions tests/testdata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ testdata:
- rockstar
fn: "rockstar_star.hdf5"

TNGCluster_snapshot_z0_minimal:
types:
- interface
- areposnapshot
- tngclustersnapshot
# - areposnapshot_withcatalog|F|0|2
fn: minimal_TNG-Cluster_snapshot_z0.hdf5



Expand Down

0 comments on commit b42397e

Please sign in to comment.