Skip to content

Commit

Permalink
Perform cosmologial corrections the right way around, thanks @wmfw23
Browse files Browse the repository at this point in the history
  • Loading branch information
JBorrow committed Nov 18, 2020
1 parent 8b6b793 commit 7533846
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 4 additions & 2 deletions swiftsimio/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ def __new__(
flag to indicate whether using comoving coordinates
"""

cosmo_factor: cosmo_factor

try:
obj = super().__new__(
self,
Expand Down Expand Up @@ -346,7 +348,7 @@ def convert_to_comoving(self) -> None:
# Best to just modify values as otherwise we're just going to have
# to do a convert_to_units anyway.
values = self.d
values *= self.cosmo_factor.a_factor
values /= self.cosmo_factor.a_factor
self.comoving = True

def convert_to_physical(self) -> None:
Expand All @@ -357,7 +359,7 @@ def convert_to_physical(self) -> None:
# Best to just modify values as otherwise we're just going to have
# to do a convert_to_units anyway.
values = self.d
values /= self.cosmo_factor.a_factor
values *= self.cosmo_factor.a_factor
self.comoving = False
else:
return
Expand Down
4 changes: 1 addition & 3 deletions tests/test_physical_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ def test_convert(filename):
coords = data.gas.coordinates
coords_physical = coords.to_physical()

assert array_equal(
coords / data.gas.coordinates.cosmo_factor.a_factor, coords_physical
)
assert array_equal(coords * data.metadata.a, coords_physical)
return

0 comments on commit 7533846

Please sign in to comment.