harmonica icon indicating copy to clipboard operation
harmonica copied to clipboard

Add grid size check for corrupted .grd files (#451)

Open Nanakjoth opened this issue 6 months ago • 2 comments

Summary

Add a simple check in load_oasis_montaj_grid to raise a clear ValueError if the number of grid elements does not match the expected shape. This helps users quickly see if a .grd file is corrupted or incomplete.


What changed

  • Added an explicit element count check before .reshape().
  • Raises a clear error instead of NumPy’s reshape error.
  • Manually tested by creating a fake .grd with missing elements.

Closes #451.

Nanakjoth avatar Jul 03 '25 12:07 Nanakjoth

Hi @Nanakjoth. Thanks for taking the time to work on this and opening the PR!

I like the error message you added. Before we merge this PR I would like to add some test that checks that the error is being raised when a corrupted file has been passed. We could add the sample corrupted file you used to manually test the function to harmonica/tests/data, name it something like incomplete_grid.grd, and add a test function in harmonica/tests/test_oasis.py that tries to load the file and checks your error was raised. We can use pytest.raises to run the check.

Would you like to work on that test?

santisoler avatar Jul 16 '25 23:07 santisoler

Hi @santisoler, Absolutely, I would love to do it.

I actually thought about adding it at the same time as the fix but didn’t get around to it, so thanks for suggesting, that helps a lot.

Will update the PR shortly! 🚀

Nanakjoth avatar Jul 17 '25 04:07 Nanakjoth