Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kehrl-kobold
Copy link
Contributor

@kehrl-kobold kehrl-kobold commented Mar 25, 2024

Summary

Fix a bug in the distance calculation in convert_survey_3d_to_2d_lines. Distance is calculated along the survey line from the first point, r0. Currently, r0[0], which is just the x component, is being subtracted from both the x and y components for all points to calculate the distance. Instead, r0 should be subtracted. Update tests so they fail without the bugfix.

PR Checklist

  • If this is a work in progress PR, set as a Draft PR
  • Linted my code according to the style guides.
  • Added tests to verify changes to the code.
  • Added necessary documentation to any new functions/classes following the
    expect style.
  • Marked as ready for review (if this is was a draft PR), and converted
    to a Pull Request
  • Tagged @simpeg/simpeg-developers when ready for review.

What does this implement/fix?

See above.

@codecov
Copy link

codecov bot commented Mar 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.54%. Comparing base (aa0a258) to head (5423bf9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1390   +/-   ##
=======================================
  Coverage   82.54%   82.54%           
=======================================
  Files         168      168           
  Lines       25706    25706           
=======================================
  Hits        21220    21220           
  Misses       4486     4486           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@santisoler
Copy link
Member

Hi @kehrl-kobold! Thanks a lot for opening this PR. From just reading the code, those changes look right. Did you run into this bug while using this function? Do you have any minimal example that can be used to reproduce the bug?

I'm asking this because it would be nice to add some tests checking that this bug has been fixed. Basically, a test function that should fail if we run it with the current code in main, but not with this fix. There's no need for you to write if you're too busy, we can help you with that.

Thanks again for your contribution, it's greatly appreciated!

@thibaut-kobold
Copy link
Contributor

@santisoler : just an FYI, the function is used in one tutorial: https://docs.simpeg.xyz/content/tutorials/05-dcr/plot_gen_3_3d_to_2d.html. We should at least rerun the tutorial with the update.

@santisoler
Copy link
Member

Thanks @thibaut-kobold! You're right, the tutorial will be rerun after we get the updated merged. And in the next release the updated docs will be deployed to the website.

I just ran a similar example to the one in the tutorial and can confirm that the fix is correctly setting the first coordinate of the south-north lines (the first coordinate in the 2D survey): instead of setting them to -650 or -1350 (as you can see in the final figures in that tutorial), it's setting them to zero, as described in the docstring.

So, a nice test for this would be to create a simple 3d DC survey with a west-east and a south-north lines, and check if the dipoles in the 2D survey are correctly, with the first coordinate of the first dipole being equal to zero.

Is this something you are interested in doing @kehrl-kobold?

@kehrl-kobold
Copy link
Contributor Author

I ran into the bug when setting up a rather complex survey in UTM coordinates, so it's definitely not a good example for a test case. I'm happy to set up a test case, but it may take me a bit of time. Would this be the correct file for a test?

@kehrl-kobold
Copy link
Contributor Author

I ran into the bug when setting up a rather complex survey in UTM coordinates, so it's definitely not a good example for a test case. I'm happy to set up a test case, but it may take me a bit of time. Would this be the correct file for a test?

I just noticed your PR above with the test case. Thanks!

@santisoler
Copy link
Member

santisoler commented Mar 27, 2024

Sounds great! We don't have any rush to merge this, since it's not super critical, so feel free to take your time.

Would this be the correct file for a test?

Yes, that file looks like a nice place for these tests.

I just noticed your PR above with the test case. Thanks!

Great. Feel free to use those as inspiration. I think these tests will need a more complex 3d survey than the one built in those, but the basic structure of the tests shouldn't be too different.

Let me know if you need any assistance. And feel free to push changes while you're working on them. There's no need to wait until the work is done to push them to this branch. And actually, is easier for us to provide help when we can see the code.

Thanks again for taking the time to tackle this.

kehrl-kobold and others added 3 commits April 23, 2024 10:07
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@kehrl-kobold
Copy link
Contributor Author

@santisoler I added the tests for convert_survey_3d_to_2d_lines. Let me know if you have any feedback and if there is anything else I can do to help get this merged. Thanks!

Copy link
Member

@santisoler santisoler left a comment

Choose a reason for hiding this comment

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

Thanks a lot @kehrl-kobold for pushing these changes. I've run the tests with these new changes against the code in main and it fails, therefore the new tests are able to properly catch the bug. Nicely done.

I think this is ready to be merged. I just left two minor comments below, which are not critical for the PR, just some minor improvements to the style.

Thanks again for your contribution. Looking forward to merge this!

@lheagy lheagy added this to the 0.21.0 milestone Apr 24, 2024
@kehrl-kobold
Copy link
Contributor Author

Thanks for the suggestions! I've made the updates.

@santisoler
Copy link
Member

Thanks @kehrl-kobold! I've just updated this branch to get the latest changes in main. I'll merge it after CI passes. Thanks again for spotting this bug and also fixing it!

@santisoler santisoler removed this from the 0.21.0 milestone May 6, 2024
@santisoler santisoler added this to the 0.22.0 milestone May 6, 2024
@santisoler santisoler changed the title fix distance calculation in convert_survey_3d_to_2d_lines Fix distance calculation in convert_survey_3d_to_2d_lines May 6, 2024
@santisoler santisoler merged commit fe444e2 into simpeg:main May 6, 2024
@santisoler
Copy link
Member

Merged! 🚀

Thanks again for your contribution @kehrl-kobold! Feel free to open a PR to add yourself to the AUTHORS.rst if you desire.

thibaut-kobold added a commit to KoBoldMetals/simpeg that referenced this pull request May 8, 2024
…e_simpeg_021

* commit 'fe444e2d714ab1a3f1541575a9f8c4ad1e74894b': (73 commits)
  Fix distance calculation in `convert_survey_3d_to_2d_lines` (simpeg#1390)
  Rename spontaneous potential to self potential (simpeg#1422)
  Lowercase simpeg for generating coverage on Azure (simpeg#1443)
  Replace SimPEG for simpeg across docstrings (simpeg#1438)
  Update copyright year in __init__.py (simpeg#1436)
  Move to a PEP8 compliant package name. (simpeg#1430)
  Fix rst syntax in release notes for v0.21.0 (simpeg#1434)
  Replace use of `refine_tree_xyz` in DCIP tutorials (simpeg#1381)
  Add new Issue template for making a release (simpeg#1410)
  Safely run reviewdog on `pull_request_target` events (simpeg#1427)
  Use reviewdog to annotate PR's with black and flake8 errors. (simpeg#1424)
  Remove the parameters argument from docstring (simpeg#1417)
  Add release notes for v0.21.1 (simpeg#1416)
  Fix hard dask dependency (simpeg#1415)
  Publish documentation on azure (simpeg#1412)
  Add release notes for SimPEG v0.21 (simpeg#1409)
  Bump Black version to 24.3.0 (simpeg#1403)
  Remove link to "twitter" (simpeg#1406)
  Add Ying and Williams to AUTHORS.rst (simpeg#1405)
  Dask MetaSim (simpeg#1199)
  ...

# Conflicts:
#	simpeg/electromagnetics/base_1d_stitched.py
#	simpeg/electromagnetics/frequency_domain/simulation_1d_stitched.py
#	simpeg/electromagnetics/time_domain/receivers.py
#	simpeg/electromagnetics/time_domain/simulation_1d_stitched.py
#	simpeg/electromagnetics/utils/em1d_utils.py
#	simpeg/potential_fields/magnetics/_numba_functions.py
#	simpeg/regularization/laterally_constrained.py
#	simpeg/regularization/regularization_mesh_lateral.py
#	simpeg/regularization/rotated.py
#	simpeg/utils/__init__.py
#	simpeg/utils/model_utils.py
#	tests/base/regularizations/test_full_gradient.py
#	tests/base/regularizations/test_regularization.py
#	tests/base/test_mass_matrices.py
#	tests/base/test_model_utils.py
#	tests/base/test_utils.py
#	tests/em/fdem/inverse/adjoint/test_FDEM_adjointEB.py
#	tests/em/fdem/inverse/derivs/test_FDEM_derivs.py
#	tests/pf/test_forward_Mag_Linear.py
thibaut-kobold added a commit to thibaut-kobold/simpeg that referenced this pull request May 9, 2024
…ting_strategy

* commit 'fe444e2d714ab1a3f1541575a9f8c4ad1e74894b': (86 commits)
  Fix distance calculation in `convert_survey_3d_to_2d_lines` (simpeg#1390)
  Rename spontaneous potential to self potential (simpeg#1422)
  Lowercase simpeg for generating coverage on Azure (simpeg#1443)
  Replace SimPEG for simpeg across docstrings (simpeg#1438)
  Update copyright year in __init__.py (simpeg#1436)
  Move to a PEP8 compliant package name. (simpeg#1430)
  Fix rst syntax in release notes for v0.21.0 (simpeg#1434)
  Replace use of `refine_tree_xyz` in DCIP tutorials (simpeg#1381)
  Add new Issue template for making a release (simpeg#1410)
  Safely run reviewdog on `pull_request_target` events (simpeg#1427)
  Use reviewdog to annotate PR's with black and flake8 errors. (simpeg#1424)
  Remove the parameters argument from docstring (simpeg#1417)
  Add release notes for v0.21.1 (simpeg#1416)
  Fix hard dask dependency (simpeg#1415)
  Publish documentation on azure (simpeg#1412)
  Add release notes for SimPEG v0.21 (simpeg#1409)
  Bump Black version to 24.3.0 (simpeg#1403)
  Remove link to "twitter" (simpeg#1406)
  Add Ying and Williams to AUTHORS.rst (simpeg#1405)
  Dask MetaSim (simpeg#1199)
  ...

# Conflicts:
#	simpeg/utils/__init__.py
#	simpeg/utils/model_utils.py
#	tests/base/test_model_utils.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants