Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions yt/frontends/gizmo/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,16 @@ def _metal_density_field(data):
setup_magnetic_field_aliases(self, ptype, magnetic_field)

def setup_star_particle_fields(self, ptype):
def _creation_time(data):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chummels can you keep the signature as only data here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chummels just pinging on this again

def _creation_time(field, data):
t_form = data[ptype, "StellarFormationTime"]

if t_form.size == 0:
return data.ds.arr([], data.ds.unit_system["time"])

if data.ds.cosmological_simulation:
a_form = data[ptype, "StellarFormationTime"]
z_form = 1 / a_form - 1
z_form = 1 / t_form - 1
creation_time = data.ds.cosmology.t_from_z(z_form)
else:
t_form = data[ptype, "StellarFormationTime"]
creation_time = data.ds.arr(t_form, "code_time")
return creation_time

Expand Down
28 changes: 28 additions & 0 deletions yt/frontends/gizmo/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,31 @@ def test_star_particle_fields():
derived_fields = ["creation_time", "age"]
for field in derived_fields:
assert (ptype, field) in ds.derived_field_list


@requires_module("h5py")
@requires_file("FIRE_M12i_ref11/snapshot_600.hdf5")
def test_gizmo_creation_time_handles_empty_particle_chunks():
ds = yt.load("FIRE_M12i_ref11/snapshot_600.hdf5")

def young_stars(pfilter, data):
age = data[pfilter.filtered_type, "age"]
return age.in_units("Myr") <= 10

yt.add_particle_filter(
"young_stars",
function=young_stars,
filtered_type="PartType4",
requires=["age"],
)

ds.add_particle_filter("young_stars")

ad = ds.all_data()
com = ad.quantities.center_of_mass(
use_gas=False,
use_particles=True,
particle_type="young_stars",
)

assert com.shape == (3,)