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

split off astronomical constants from units #1059

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

rieder
Copy link
Member

@rieder rieder commented Jun 14, 2024

Astronomical constants have changed, this is part of an effort to make these easier updateable.
units.py should not contain changeable values anymore.

@rieder rieder requested a review from a team as a code owner June 14, 2024 13:08
LourensVeen
LourensVeen previously approved these changes Jun 19, 2024
Copy link
Collaborator

@LourensVeen LourensVeen left a comment

Choose a reason for hiding this comment

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

Looks good! Metallicity also sounds quite astronomical to me, but it doesn't have an associated constant. Maybe we should have a look at splitting up the units, probably in conjunction with reintegrating OMUSE...

@rieder
Copy link
Member Author

rieder commented Jun 20, 2024

There is no constant for metallicity. The closest would be 'solar metallicity', but even for that there isn't a generally accepted constant value.
Splitting up the units might be a good idea.

@LourensVeen
Copy link
Collaborator

Yeah, and it's a fraction anyway, right? It just occurred to me that metallicity was at the bottom of the file, amidst degrees and grams and centimeters which are not discipline-specific. Anyway, something for later. Will you merge this?

@rieder
Copy link
Member Author

rieder commented Jul 8, 2024

There's a remaining issue: names are used both for the constants and for the unit based on the constant.
So we need to rethink this or be very careful with namespaces.
Something that does from amuse.units.constants import * will now cause problems - as is the case in one of the tests (test_pickle.py). Then again of course, this is /exactly/ the reason why you should never import *...

@rieder
Copy link
Member Author

rieder commented Jul 8, 2024

(Of course I'm violating that "rule" myself in a commit only minutes after posting this...)

pickled_km = pickle.dumps(km)
unpickled_km = pickle.loads(pickled_km)
self.assertEqual(1000, unpickled_km.value_in(m))
kilometer = 1000 * m
Copy link
Member Author

Choose a reason for hiding this comment

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

renaming it here since 'km' is already defined... could probably just as easily use the pre-defined 'km' unit, but maybe there was a reason not to?



au = 149597870691.0 | m
parsec = au / np.tan(np.pi / (180 * 60 * 60))
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that both 'au' and 'parsec' are also defined as units... Be careful, this may clash!
For Lsun etc below, note that here they only have one capital letter, the unit has LSun etc... This is to be more in line with Astropy etc, which only have one capital letter. Still, it may be better to be consistent within AMUSE?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow, that's a really subtle problem actually. Having a unit and a constant with almost the same name but different capitalisation seems like asking for trouble, because how do you remember which is which? Perhaps the best solution is to have a single object that can be used in both ways? But that would probably require some major redesign....

Copy link
Member Author

Choose a reason for hiding this comment

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

normally it wouldn't be a problem, since units would be used as units.(unitname) rather than being directly imported. But I don't exactly like it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are constants that can also be units actually ever used as anything else than units?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not. Except for making the units.

Copy link
Member Author

Choose a reason for hiding this comment

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

So... We could in principle make the names here (way) more descriptive, e.g.:

distance_parsec = ...
distance_au = ...
luminosity_sun = ...
radius_sun = ...

That would solve this issue. It's very verbose but since you're always using the unit form that should not be a problem.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, they could still have the same names actually, as long as no one directly uses the amuse.units.amuse_2010.astronomical_constants module. It should only be used in the modules that define the units then, and we could even name it _astronomical_constants to mark it as private.

Then in the modules where the units are defined, we could import amuse.units.amuse_2010.astronomical_constants as ac and write ac.au and the like everywhere to clearly point out where they're coming from and that these are the constants and not the units. I think that's what I'd do.

Copy link

stale bot commented Sep 6, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 28 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issues that have been around for a while without updates label Sep 6, 2024
@rieder rieder added feature request and removed stale Issues that have been around for a while without updates labels Sep 6, 2024
def get_translator(self):
f = open(os.path.join(self.directory, 'translator.txt'), 'r')
f = open(os.path.join(self.directory, "translator.txt"), "r")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please keep real changes and formatting changes from black in separate commits, can't see the forest for the trees here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants