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

Wrap grdhisteq #1433

Merged
merged 61 commits into from
Mar 9, 2022
Merged

Wrap grdhisteq #1433

merged 61 commits into from
Mar 9, 2022

Conversation

maxrjones
Copy link
Member

@maxrjones maxrjones commented Aug 10, 2021

Description of proposed changes

This PR will wrap the gmt module grdhisteq.

Preview docs at https://pygmt-git-grdhisteq-gmt.vercel.app/api/generated/pygmt.grdhisteq.html

Fixes #1399

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@weiji14 weiji14 added the feature Brand new feature label Aug 10, 2021
@maxrjones maxrjones marked this pull request as draft August 10, 2021 23:18
@maxrjones maxrjones self-assigned this Aug 24, 2021
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

Gentle push on this. I'm starting a project using Sentinel 2 data so I imagine this function would come in handy at some point for doing histogram equalized plots 😄

Looking at https://docs.generic-mapping-tools.org/6.2/grdhisteq.html closely, it seems that both grid outputs (-G) and table outputs (-D) are possible. Happy to only do grid outputs for now, but if you want to do table outputs too, the triangulate implementation at #731 can be a good resource to follow.

P.S. Recommend to update branch and resolve merge conflict before applying suggested changes below.

pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
pygmt/tests/test_grdhisteq.py Outdated Show resolved Hide resolved
pygmt/tests/test_grdhisteq.py Outdated Show resolved Hide resolved
pygmt/src/grdhisteq.py Show resolved Hide resolved
pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
@maxrjones
Copy link
Member Author

maxrjones commented Sep 19, 2021

Gentle push on this. I'm starting a project using Sentinel 2 data so I imagine this function would come in handy at some point for doing histogram equalized plots 😄

I'll try to wrap up the remaining tasks (i.e., polishing docstring, adding table output test) tomorrow.

Edit: I will need a bit longer to finish this, since the implementation will depend on the results from GenericMappingTools/gmt#5785.

@weiji14 weiji14 added this to the 0.5.0 milestone Sep 19, 2021
@maxrjones
Copy link
Member Author

I changed the implementation a bit relative to #731 to support ASCII or pandas.DataFrame output for writing out the equalized histogram.

Still, the code is a bit clunky in order to support four different output types (pandas.DataFrame, xarray.DataArray, netCDF, or ASCII). What would you think about having two PyGMT functions for GMT's grdhisteq module rather than just one? One function could write out the data ranges of histogram equalization to a pd.DataFrame or ASCII table and the other could write out the cumulative distribution statistics to a netCDF file or xarray.DataArray. I guess coming up with the names for these would be harder than the current implementation, but I think it would be more user friendly long-term.

@weiji14 weiji14 added the final review call This PR requires final review and approval from a second reviewer label Mar 3, 2022
@maxrjones
Copy link
Member Author

Nice one. Looking forward to using this in my project soon! I'm getting sick of arbitrarily stretching optical satellite images...

Thanks for all your helpful feedback!

pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
pygmt/src/grdhisteq.py Show resolved Hide resolved
pygmt/src/grdhisteq.py Show resolved Hide resolved
pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
pygmt/src/grdhisteq.py Show resolved Hide resolved
pygmt/src/grdhisteq.py Show resolved Hide resolved
Comment on lines +349 to +356
if isinstance(outfile, str) and output_type != "file":
msg = (
f"Changing 'output_type' from '{output_type}' to 'file' "
"since 'outfile' parameter is set. Please use output_type='file' "
"to silence this warning."
)
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2)
output_type = "file"
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should raise an exception here rather than give a warning? Sometimes people just ignore warnings.

Copy link
Member Author

Choose a reason for hiding this comment

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

There was a bit of a discussion about this following this comment #1284 (review). See #1284 (comment) for a specific discussion about raising a warning versus exception. I think we should follow that lead, although we could move this to a helper function to make it more clear that the logic is used for multiple modules.

pygmt/src/grdhisteq.py Show resolved Hide resolved
@seisman seisman merged commit 4186400 into main Mar 9, 2022
@seisman seisman deleted the grdhisteq branch March 9, 2022 16:07
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Mar 9, 2022
@weiji14 weiji14 mentioned this pull request Mar 12, 2022
10 tasks
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
Co-authored-by: Wei Ji <[email protected]>
Co-authored-by: Dongdong Tian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Brand new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a function wrapping GMT's grdhisteq module
4 participants