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

257 add smoothing functions #289

Merged
merged 13 commits into from
Jan 17, 2024
Merged

257 add smoothing functions #289

merged 13 commits into from
Jan 17, 2024

Conversation

msmiyels
Copy link
Collaborator

Modularized smoothing functions with example notebook.

There is one flake8 error, that wants [x : x, y : y] with no whitespace between the letters ([x:x, y:y]). However, once corrected, black re-formats it to the version with whitespaces. May give an error in the GitHub actions.

How we want to handle this?

Cheers,
Micha

@msmiyels msmiyels linked an issue Jan 15, 2024 that may be closed by this pull request
5 tasks
@nmaarnio
Copy link
Collaborator

I will review this today or tomorrow! When it comes to the linting issue, add # noqa: E203 at the end of the problematic line. That should do the trick

@msmiyels
Copy link
Collaborator Author

Ahh, good to know 👀 It did 🐱‍🏍

Thank you 😎

Copy link
Collaborator

@nmaarnio nmaarnio left a comment

Choose a reason for hiding this comment

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

Hey, looks really good overall and the notebook is very illustrative! I noticed a few things regarding the style and docs that I pointed out in the comments.

One a bit bigger question: I noticed that the filters don't seem to necessarily require raster data, but actually any 2D Numpy data (so in other words, raster metadata is not needed). Do you think these functions still best fit under the raster processing category? Maybe more specifically I am thinking about the function signatures, so I propose we either do one of these modifications:

  1. Change raster inputs to Numpy array inputs
  2. Return the raster metadata in the (out_image, out_meta) format as other raster processing functions, even if the metadata is not modified

Additionally, please also include the .md files in the docs folder ;). I noticed these are missing for the surface derivatives too, so you can add both in this PR.

Comment on lines 30 to 34
Parameters:
raster: The input raster dataset.
method: The method to use for filtering. Can be either "mean" or "median". Default to "mean".
size: The size of the filter window. E.g., 3 means a 3x3 window. Default to 3.
shape: The shape of the filter window. Can be either "square" or "circle". Default to "circle".
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole file seems to use smaller indentation than all other files. Change this to use 4 spaces.

Comment on lines 41 to 43
InvalidParameterValueException: If the filter size is smaller than 3.
If the filter size is not an odd number.
If the shape is not "square" or "circle".
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have so far formatted multiline docstring entries so that the next lines are indented one unit further than the first one, like this:

Suggested change
InvalidParameterValueException: If the filter size is smaller than 3.
If the filter size is not an odd number.
If the shape is not "square" or "circle".
InvalidParameterValueException: If the filter size is smaller than 3.
If the filter size is not an odd number.
If the shape is not "square" or "circle".

If you could change all parameter and raises sections to follow this style, that would be good!

shape: The shape of the filter window. Can be either "square" or "circle". Default to "circle".

Returns:
np.ndarray: The filtered raster array.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove the np.ndarray from the beginning and simply have "The filtered raster array". Apply this change to the other functions in this file, too.



@beartype
def get_kernel_size(sigma, truncate, size):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function, and create_grid, gaussian_kernel and mexican_hat_kernel, all are missing parameter types and return types. Please add them.

shape: The shape of the kernel. Can be either "square" or "circle".

Returns:
np.ndarray: The generated kernel.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove the return type also here.



@beartype
def _lee_additive_noise(window: np.ndarray, add_noise_var: Number) -> Number:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like all these private functions to have even just a short one line docstring that describes them a little bit – just so that we document our functions a bit more even if end users don't use these. No need to use the full args, returns, raises -template.


Parameters:
raster: The input raster dataset.
size = The size of the filter window. E.g., 3 means a 3x3 window. Default to 3.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The = should be : here. This same typo is also in the following docstrings in this file.

Copy link
Collaborator Author

@msmiyels msmiyels Jan 17, 2024

Choose a reason for hiding this comment

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

Happens when you lean on auto-docstring generation 😔 Sorry for those, I'll check these parts better before PR in the future 🕵️‍♂️

@msmiyels
Copy link
Collaborator Author

Ahoi Niko,

thank you for the good review ⚡

Oh man, you're totally right. Missed the metadata point completely 🤦‍♂️
I'll stick to the structure for the existing raster_processing tools and add the out_meta to the output.

Will address this and any other point ASAP 🚀

Best,
Micha

@msmiyels msmiyels marked this pull request as draft January 16, 2024 21:24
@msmiyels
Copy link
Collaborator Author

msmiyels commented Jan 17, 2024

Ahoi Niko 🏴‍☠️

think I got everything on the requested changes list covered so far 🤗

The docs stuff was pretty new to me, when did we add that? 👀 However, the build marked some minor docstring inconsistencies in the derivatives module, which are contained in the PR as well.

The notebook has been changed due to returning tuple instead of np.ndarray, too.

Let me know if there are other things to be changed 🐱‍👤

Cheers,
Micha

Edit:
We do not use the findpeaks package for the implemented filters, so there's no need to keep it in (or change) the eis_toolkit requirements 🧩

@msmiyels msmiyels marked this pull request as ready for review January 17, 2024 09:33
@nmaarnio
Copy link
Collaborator

Looks great now! ✨ It's basically ready to be merged, but I noticed one cell in the notebook didn't unpack the out_image, out_meta tuple and therefore threw an error; if you quickly fix that, I'll merge then!

We have had the doc files since the beginning, but I have forgotten them from time to time myself and they haven't been discussed very frequently. However, it was only a couple months ago we started automatically building a PDF out of the docs and also publishing them here: https://gispocoding.github.io/eis_toolkit/

Regarding findpeaks: Good, makes things a bit simpler :D

@msmiyels
Copy link
Collaborator Author

Thank you ✨ Notebook is ready, then let's get it merged 😎

Good to know this for the doc's 🦄 Pretty handy ⚙

@nmaarnio nmaarnio merged commit 1e81919 into master Jan 17, 2024
6 checks passed
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.

Add smoothing functions
2 participants