From 636b488890d4263e8dc0105121b85f70b8f2d19d Mon Sep 17 00:00:00 2001 From: Michael Ryan Date: Thu, 27 Jul 2023 13:17:31 -0400 Subject: [PATCH 1/3] Updates to the _parse_parameter_file function following PR 4470 --- yt/frontends/gadget/data_structures.py | 37 +++++++++----------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/yt/frontends/gadget/data_structures.py b/yt/frontends/gadget/data_structures.py index e8ee428fcfa..a8bb0175c7a 100644 --- a/yt/frontends/gadget/data_structures.py +++ b/yt/frontends/gadget/data_structures.py @@ -363,24 +363,20 @@ 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. + self.cosmological_simulation = 0 # Hubble is set below for Omega Lambda = 0. # According to the Gadget manual, OmegaLambda will be zero for @@ -389,12 +385,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"] @@ -409,20 +402,14 @@ 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], - ) - ) + prefix = os.path.join(self.directory, self.basename.split(".", 1)[0]) if hvals["NumFiles"] > 1: for t in ( From 3bc804b34fb4986f8d12ff03886f0931ca51f72a Mon Sep 17 00:00:00 2001 From: mtryan83 Date: Fri, 28 Jul 2023 11:54:47 -0400 Subject: [PATCH 2/3] Update yt/frontends/gadget/data_structures.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Robert --- yt/frontends/gadget/data_structures.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yt/frontends/gadget/data_structures.py b/yt/frontends/gadget/data_structures.py index a8bb0175c7a..9192f2b0955 100644 --- a/yt/frontends/gadget/data_structures.py +++ b/yt/frontends/gadget/data_structures.py @@ -409,7 +409,8 @@ def _parse_parameter_file(self): ) self.parameters = hvals - prefix = os.path.join(self.directory, self.basename.split(".", 1)[0]) + basename, _, _ = self.basename.partition(".") + prefix = os.path.join(self.directory, basename) if hvals["NumFiles"] > 1: for t in ( From 20b5b59f40896ce13aa7f8087a1dbd419a00b67b Mon Sep 17 00:00:00 2001 From: Michael Ryan Date: Fri, 28 Jul 2023 18:49:08 -0400 Subject: [PATCH 3/3] Additional comment about change in omega_matter value --- yt/frontends/gadget/data_structures.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yt/frontends/gadget/data_structures.py b/yt/frontends/gadget/data_structures.py index 9192f2b0955..f7c828203d6 100644 --- a/yt/frontends/gadget/data_structures.py +++ b/yt/frontends/gadget/data_structures.py @@ -376,6 +376,8 @@ def _parse_parameter_file(self): # If these are not set it is definitely not a cosmological dataset. self.omega_lambda = 0.0 self.omega_matter = 0.0 # Just in case somebody asks for it. + # 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.