Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to the _parse_parameter_file function following PR 4470 #4605

Merged
merged 3 commits into from
Jul 29, 2023
Merged
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
40 changes: 15 additions & 25 deletions yt/frontends/gadget/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,22 @@ def _parse_parameter_file(self):
self.domain_dimensions = np.ones(3, "int32")
self._periodicity = (True, True, True)

self.cosmological_simulation = 1
self.current_redshift = hvals.get("Redshift", 0.0)
if "Redshift" not in hvals:
mylog.info("Redshift is not set in Header. Assuming z=0.")

try:
self.current_redshift = hvals["Redshift"]
except KeyError:
# Probably not a cosmological dataset, we should just set
# z = 0 and let the user know
self.current_redshift = 0.0
only_on_root(mylog.info, "Redshift is not set in Header. Assuming z=0.")

try:
if "OmegaLambda" in hvals:
self.omega_lambda = hvals["OmegaLambda"]
self.omega_matter = hvals["Omega0"]
self.hubble_constant = hvals["HubbleParam"]
except KeyError:
self.cosmological_simulation = self.omega_lambda != 0.0
else:
# If these are not set it is definitely not a cosmological dataset.
self.omega_lambda = 0.0
self.omega_matter = 1.0 # Just in case somebody asks for it.
self.omega_matter = 0.0 # Just in case somebody asks for it.
Comment on lines -383 to +378
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change this to 0.0, instead if 1.0? This would imply there's nothing in the volume.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From @neutrinoceros

non-cosmological datasets normally have omega_matter set to 0.0. Is there a reason not to follow the convention here ?

in PR #4470

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, so it was changed for consistency with other frontends? That's ok, but maybe warrants changing the comment from 'Just incase somebody asks for it' to 'Changed to 0.0 for consistency with non-cosmological frontends' in case somebody comes looking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point. The comment was actually left unchanged from the previous code (and I believe is just referencing that omega_matter is being set, not necessarily it's value), I had only changed the numerical value here.

I've added your comment, though I left the original as well, since it does describe why omega_matter is being set at all.

# omega_matter has been changed to 0.0 for consistency with
# non-cosmological frontends
self.cosmological_simulation = 0
# Hubble is set below for Omega Lambda = 0.

# According to the Gadget manual, OmegaLambda will be zero for
Expand All @@ -389,12 +387,9 @@ def _parse_parameter_file(self):
# which case we may be doing something incorrect here.
# It may be possible to deduce whether ComovingIntegration is on
# somehow, but opinions on this vary.
if self.omega_lambda == 0.0:
only_on_root(
mylog.info, "Omega Lambda is 0.0, so we are turning off Cosmology."
)
if not self.cosmological_simulation:
mylog.info("Omega Lambda is 0.0, so we are turning off Cosmology.")
self.hubble_constant = 1.0 # So that scaling comes out correct
self.cosmological_simulation = 0
self.current_redshift = 0.0
# This may not be correct.
self.current_time = hvals["Time"]
Expand All @@ -409,20 +404,15 @@ def _parse_parameter_file(self):
omega_lambda=self.omega_lambda,
)
self.current_time = cosmo.lookback_time(self.current_redshift, 1e6)
only_on_root(
mylog.info,
mylog.info(
"Calculating time from %0.3e to be %0.3e seconds",
hvals["Time"],
self.current_time,
)
self.parameters = hvals

prefix = os.path.abspath(
os.path.join(
os.path.dirname(self.parameter_filename),
os.path.basename(self.parameter_filename).split(".", 1)[0],
)
)
basename, _, _ = self.basename.partition(".")
prefix = os.path.join(self.directory, basename)

if hvals["NumFiles"] > 1:
for t in (
Expand Down