-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add reference Sphere class #42
Conversation
@leouieda I was thinking that maybe we would like to add some coordinate conversions capabilities to the new |
@santisoler do you mean adding a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sphere looks good @santisoler! Some comments there, particularly about checking the flattening on the ellipsoid.
Co-authored-by: Leonardo Uieda <[email protected]>
Co-authored-by: Leonardo Uieda <[email protected]>
Co-authored-by: Leonardo Uieda <[email protected]>
Co-authored-by: Leonardo Uieda <[email protected]>
Raise a warning rather than raising an error if flattening is equal to zero or too close to zero.
Add test functions to check inherited methods and properties. Override parent methods that failed due to singularities caused by zero flattening. Add functions for overridden methods.
@leouieda After the talk we had today, I've redefined Luckily, only two methods from the original |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@santisoler made a suggestion for defining the sphere attributes but after that this looks good to go. It will be good to test the gravity values against published ones when we have the Moon ellipsoid later.
We really need to get #23 done 🙁 |
@MarkWieczorek does this look OK to you? |
Co-authored-by: Leonardo Uieda <[email protected]>
I just browsed through the code and have a couple of comments: First, I think that the check in Second, the normal gravity returns a result in units of mGals. Maybe this is ok, but I would probably prefer to have the default be SI, and then give an option to return mGals. I know that if you plot results you will always use mGals, but when you do calculations, it is usually easier just to assume that all quantities are SI and then do the conversion at the end. Third, for the "units" suggestion: I don't have much experience with this, but there is also the |
Thanks @MarkWieczorek for the feedback!
This is tricky. We defined a new
I totally agree to keep everything in SI. For some reason we've been breaking this rule for gravity accelerations, using mGal. This dates from Fatiando 0.5 and has been inherited by Harmonica, which returns gravity accelerations in mGal. I would keep them in mGal just for my convenience, but I cannot find a better argument, so I'm open to change it if we agree to do so. @leouieda do you have a very strong reason why we should stick with mGal?
Great @MarkWieczorek! We've been delaying it for quite a long time, so would be nice to implement it. BTW, Harmonica could also make a good use of it, but as Boule is a thinner package, it seems a better place for experimentation. |
Hi @MarkWieczorek thanks for input!
I'm not too keen on this since we should be able to trust the users to know what they're doing. We don't actually expect end users to instantiate The check is added as a warning so that it's more of a suggestion that the gravity calculations might not work. But a lot of other things would if you really wanted to make an Ellipsoid with tiny flattening. The tricky part with assuming that 0 flattening means a Sphere is floating point round off. How small do we consider to be close enough to 0? @santisoler maybe we should remove that from this PR and leave it for when we tackle #43 instead? Then we can discuss the sanity checks all in one place.
Yeah, I agree that maybe we should stick with SI for everything. I wouldn't want to include an option for conversion since then we go down the rabbit hole of which units do we support. It would be best to say that for now everything is SI and when we have a units package, then you can do whatever you want.
There are 3 main projects out there for unit support:
|
What I would probably do is something like this when Ellispoid is called:
By definition f=0.0 is a Sphere. The problem is, if f is small, should we return a sphere instead of an ellipsoid? I would say no. I would just give a warning when f is "small", and let the user proceed with caution. They could set
For the Earth, perhaps that is true, but there are a lot of planets and moons! As for mGals: what you could do is keep your current convention (so that nothing breaks) and then add an option like |
That could work, but it would depend on the design decisions we make on the |
Not at all! It's easier in the long run to have these discussions before we commit to a particular API. This is a PR at its best.
That is true. But it would be strange to instantiate a
We'll have ALL of those 🙂
That is what I don't really want to do since we already plan on adding unit support. But if this is something that would be useful to have, we could add
@santisoler what do you mean? Those checks are independent of the |
True. But if Ellipsoid was a superclass that only was used to instantiate subclasses, then it would make more sense. Eventually, I think it would be useful to have a triaxial ellipsoid class because all of the moons of our solar system are triaxial. So it might be interesting to convert the current Ellipsoid to BiAxialEllipsoid. Then you would have a structure like: Ellipsoid
|
Ok, I think my first draft of this PR used to raise an error under zero flattening. So if we really make users to use
Yes and no, the checks are independent of the BTW I opened #45 for checking parameter values, independent of the choice we make on how to handle zero flattening. |
Ah OK, I see your point now. This type of thing is better suited to "factory functions" which are basically what you described but in a function instead of class. The main advantage is that a class version of this requires some Python black magic while the function is pretty straight-forward. But this can be for a later PR I guess when we have the triaxial case as well. @MarkWieczorek would you mind opening an issue for the triaxial ellipsoid? I suspect this will be a lot more challenging for gravity and coordinate conversions so it might take some digging to find the proper equations.
I'm fine with leaving it like that for now and then revisit in #45. I created #46 to track the discussion about SI units. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@santisoler unless you have anything else to add, I think this is good to go. We have some TODOs open in new issues to moving forward.
Ok, I agree.
Sure, I can merge it right away. |
Add a new
Sphere
class to represent reference ellipsoids with zero flattening.The
Sphere
class is a subclass ofEllipsoid
, inheriting its methods and properties.Some methods were overridden to avoid division by zero errors due to singularities caused by zero flattening.
Override
normal_gravity
method for computing the normal gravity generated by the sphere as the self gravitational field plus the centrifugal term.Raise warning when initializing an
Ellipsoid
with zero (or almost zero) flattening.Update
Ellipsoid
class example: replace sphere with an oblate ellipsoid.Add test functions for the overridden and inherited methods.
Fixes #18
Reminders:
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
and the base__init__.py
file for the package.AUTHORS.md
file (if you haven't already) in case you'd like to be listed as an author on the Zenodo archive of the next release.