-
Notifications
You must be signed in to change notification settings - Fork 280
Fix issue with lengthscales in coterminal angle calculations #1299
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
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1299 +/- ##
==========================================
- Coverage 82.30% 82.30% -0.01%
==========================================
Files 165 165
Lines 25244 25241 -3
==========================================
- Hits 20778 20775 -3
Misses 4466 4466 ☔ View full report in Codecov by Sentry. |
Rename the test function to be more descriptive and add a docstring.
santisoler
left a comment
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.
Thanks @domfournier for this, and sorry leaving you waiting for this review.
I think this is ready to be merged. I just pushed a small change to improve the test function: now it runs the same test in the three orientations, not only on "y". I also renamed the function to be more descriptive.
Let me know what do you think. If you like it, ping me so I can merge this.
BTW, I just opened #1333 that it's related to this. If you can take a look at it, that would be great.
Looks good man. I pushed a small fix to address your question on #1333 . Result looks good. Good to go on this end. |
SimPEG/utils/mat_utils.py
Outdated
|
|
||
| sub = theta[np.abs(theta) >= np.pi] | ||
| sub = -np.sign(sub) * (2 * np.pi - np.abs(sub)) | ||
| sub = np.sign(sub) * (2 * np.pi - np.abs(sub)) |
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.
I don't think this will give you correct values now, simple testing:
>>> coterminal(np.pi + np.pi/4)
2.356194490192345 #3pi/4
it should give you -3pi/4.
I think the cleanest solution to this is to write the whole function as:
def coterminal(theta):
return (theta + np.pi) % (2 * np.pi) - np.pi
Which will give you back a number on the domain of [-\pi, \pi)
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.
I agree that using the mod is the cleanest way to solve this.
I would like to see that bugfix in another PR though. I think one of the reasons why this wasn't caught before was due to lack of tests, so besides the fix we should add more tests for it. And also update the docstrings for that function.
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.
And why would it be negative you think? That's what it was returning before.
I guess my initial implementation was to return the negative angle of the complement, thinking that if the gradient between two angles is large, we would want to force the model update to reduce both. But now I am not so sure if that logic works. We definitely get a different result with the example - just not convinced which one is best.
|
I get a line search failure with this @jcapriot I don't think that's quite it, since the modulo in python takes the sign of the dividor. For example But would expect -pi/4 But this works |
|
|
Why did you put a negative in front there?: instead of |
|
Forget about the negative sign. I think we need to preserve the sign of the incoming angle. We can argue all day about what the true coterminal should be mathematically, in the end we need the example in |
|
What layer are you cutting this at? Just so I can compare locally later this evening. I think I understand what you’re saying regarding what needs to happen during minimization. Just need to test a few things. |
|
Also probably the easiest way to “undo” the cell difference would be to just use |
|
I sliced it at the same index, but Z axis. Also adjusted the limits to [-75, 75] for close up. |
Sounds good. Done. |
|
So these are the current results I'm getting on main: |
I totally agree that the ultimate goal is to penalize non-smoothness in the neighboring angles in the model. That's also why I suggested of fixing the bug in I think the problem here is that we need to compute angles differences for each neighboring pair, and having a single array of coterminal angles moved to For example, if we have I think the solution is to have a function that can compute the difference between two angles that's smaller or equal than |
I think it's important to point out that we are already computing the coterminal angle after taking differences. |
|
In the meantime, this looks fine to me now, only issue is that the second order smoothness isn't being tested here (but it wasn't before either). |
|
Ok so can we move this one forward, and battle it out further on #1334 ? |
The top plot is the smooth Cartesian result, no problem there. This what the smooth Spherical looks like on main |
Co-authored-by: Joseph Capriotti <[email protected]>










Summary
The initial implementation of coterminal angles used an average of cell sizes to determine the cell centered length. Those distances are slightly different (by 88%) than the cell gradient distances used by the
regularization_mesh.cell_gradient_operators on octree changes.PR Checklist
expect style.
to a Pull Request
@simpeg/simpeg-developerswhen ready for review.What does this implement/fix?
Fixes large gradients computed on the -pi/pi transition, resulting in artifacts in the model.
Current results from
examples\03-magnetics\plot_inv_mag_MVI_Sparse_TreeMesh.py.:Title should be L2 Spherical model...
After fix: