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

yt code_length unit inconsistent with Ramses unit_l #4787

Open
fredt00 opened this issue Jan 24, 2024 · 4 comments
Open

yt code_length unit inconsistent with Ramses unit_l #4787

fredt00 opened this issue Jan 24, 2024 · 4 comments
Assignees
Labels
bug code frontends Things related to specific frontends units

Comments

@fredt00
Copy link

fredt00 commented Jan 24, 2024

Bug report

Bug summary
I experience the same issue as #2866: the unit length conversion for a non cosmological simulation is off by a factor of the boxlength.

Code for reproduction

print(ds.arr(1,"code_density").in_cgs().value/ds.parameters['unit_d'])
print(ds.arr(1,"code_length").in_cgs().value/ds.parameters['unit_l'])
print(ds.parameters['boxlen'])

Actual outcome

The length conversion is off by a factor of 150, the value of the box length. However, the density conversion seems to be correct...

1.0
150.0
150.0

I was wondering if anyone had a simple work around for this? I don't think I can just multiply any results with length units by factors of the box length since the density conversion is correct and includes length**3.

Version Information

  • Operating System: macOS Sonoma 14.1.1
  • Python Version: 3.11.6
  • yt version: 4.3.0 (installed via pip)
Copy link

welcome bot commented Jan 24, 2024

Hi, and welcome to yt! Thanks for opening your first issue. We have an issue template that helps us to gather relevant information to help diagnosing and fixing the issue.

@matthewturk
Copy link
Member

Thanks for bringing this up -- I am sorry we didn't address it before! Perhaps @cphyc can provide some insight?

@matthewturk matthewturk added bug code frontends Things related to specific frontends units labels Jan 24, 2024
@cphyc
Copy link
Member

cphyc commented Jan 24, 2024

I'm happy to help but I'm 200% busy until February 9 and won't have time until then. Most likely, these two lines are the right entry points:

setdefaultattr(self, "length_unit", self.quan(length_unit * boxlen, "cm"))

self.domain_right_edge = np.ones(3, dtype="float64")

The first sets the length_unit, so 1 * length_unit equals the box size. The second sets the size of the box.
I wonder if the fix is simply to replace the latter by

        self.domain_right_edge = np.full(3, self.parameters["boxlen"], dtype="float64")

Could you try and let us know if this works? If it does, we'd be happy for you to submit a PR, or I can do it in a couple of weeks.

@fredt00
Copy link
Author

fredt00 commented Jan 24, 2024

Hi,

Thanks for the quick reply. I tried changing the line you suggested, and this does mean the correct domain_right_edge is returned when loading the data:

yt : [INFO     ] 2024-01-24 16:11:33,248 Parameters: domain_right_edge         = [150. 150. 150.]

However, the ratio code_length/unit_l is still incorrect by a factor of boxlen and I get the same offset in my plots.

I also tried removing the factor of boxlen in line 977 to give:

setdefaultattr(self, "length_unit", self.quan(length_unit , "cm")) 

I'm completely new to both Ramses and yt so I'm not sure if it was logical to do this, but this seems to completely break any plots I make of the gas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug code frontends Things related to specific frontends units
Projects
None yet
Development

No branches or pull requests

3 participants