Skip to content

Commit

Permalink
Merge pull request #4722 from neutrinoceros/hotfix_amu
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros authored Nov 1, 2023
2 parents 7026229 + dd96251 commit bdd96bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions yt/fields/species_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _create_number_density_func(ftype, species):

def _number_density(field, data):
weight = formula.weight # This is in AMU
weight *= data.ds.units.physical_constants.amu_cgs
weight *= data.ds.quan(1.0, "amu").in_cgs()
return data[ftype, f"{species}_density"] / weight

return _number_density
Expand Down Expand Up @@ -252,7 +252,7 @@ def add_nuclei_density_fields(registry, ftype):
def _default_nuclei_density(field, data):
ftype = field.name[0]
element = field.name[1][: field.name[1].find("_")]
amu_cgs = data.ds.units.physical_constants.amu_cgs
amu_cgs = data.ds.quan(1.0, "amu").in_cgs()
if element == "El":
# This is for determining the electron number density.
# If we got here, this assumes full ionization!
Expand All @@ -273,15 +273,15 @@ def _nuclei_density(field, data):
return (
data[(ftype, nuclei_mass_field)]
/ ChemicalFormula(element).weight
/ data.ds.units.physical_constants.amu_cgs
/ data.ds.quan(1.0, "amu").in_cgs()
)
metal_field = f"{element}_metallicity"
if (ftype, metal_field) in data.ds.field_info:
return (
data[ftype, "density"]
* data[(ftype, metal_field)]
/ ChemicalFormula(element).weight
/ data.ds.units.physical_constants.amu_cgs
/ data.ds.quan(1.0, "amu").in_cgs()
)

field_data = np.zeros_like(
Expand Down
4 changes: 2 additions & 2 deletions yt/fields/tests/test_species_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_default_species_fields():
# Test fully ionized case
dsi = fake_random_ds(32, default_species_fields="ionized")
spi = dsi.sphere("c", (0.2, "unitary"))
amu_cgs = dsi.units.physical_constants.amu_cgs
amu_cgs = dsi.quan(1.0, "amu").in_cgs()

mueinv = 1.0 * _primordial_mass_fraction["H"] / ChemicalFormula("H").weight
mueinv *= spi["index", "ones"]
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_default_species_fields():

dsn = fake_random_ds(32, default_species_fields="neutral")
spn = dsn.sphere("c", (0.2, "unitary"))
amu_cgs = dsn.units.physical_constants.amu_cgs
amu_cgs = dsn.quan(1.0, "amu").in_cgs()

assert ("gas", "El_number_density") not in ds.derived_field_list

Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/arepo/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _h_p1_fraction(field, data):
# try first to use the H_fraction, but otherwise we assume the
# cosmic value for hydrogen to generate the H_number_density
if (ptype, "NeutralHydrogenAbundance") not in self.field_list:
m_u = self.ds.units.physical_constants.amu_cgs
m_u = self.ds.quan(1.0, "amu").in_cgs()
A_H = ChemicalFormula("H").weight
if (ptype, "GFM_Metals_00") in self.field_list:

Expand Down

0 comments on commit bdd96bc

Please sign in to comment.