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

Add support for n-dimensional coordinates on BlockReduce #198

Merged
merged 7 commits into from
Jul 30, 2019

Conversation

santisoler
Copy link
Member

Include additional coordinates when reducing data and observation points.

Fixes #195

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 and verde/__init__.py.
  • Write detailed docstrings for all functions/classes/methods.
  • If adding new functionality, add an example to the docstring, gallery, and/or tutorials.

@santisoler santisoler changed the title WIP Add support for n-dimensional coordinates to BlockReduce WIP Add support for n-dimensional coordinates on BlockReduce Jul 24, 2019
@santisoler santisoler changed the title WIP Add support for n-dimensional coordinates on BlockReduce Add support for n-dimensional coordinates on BlockReduce Jul 24, 2019
@santisoler
Copy link
Member Author

@leouieda I think this solves the issue, but please take a look at it because I'm not so familiar with Verde source code (it's highly probable that I missed something).

@santisoler santisoler requested a review from leouieda July 24, 2019 15:38
verde/blockreduce.py Outdated Show resolved Hide resolved
@leouieda
Copy link
Member

Hi @santisoler this looks really nice! I made a few comments on the wording of the docs but the code looks good to me. I had to figure out how the original code worked again (of course I didn't remember).

One thing I'm wondering is if we should make this optional and turned off by default. This changes the behavior of the class and might break existing code that's relying on BlockReduce to drop coordinates like lon, lat = BlockReduce(...).filter(coordinates, data).

This could be done with a flag drop_coords=True (or something like that) to BlockReduce. The code could stay the same but drop the coordinates from the tuple before doing the reductions if it's true.

@santisoler
Copy link
Member Author

Thanks @leouieda!

I see the problem by returning n coordinates when only two were expected before this PR.
Although I'm not a big fan of adding so many flags that configure this little things. But I know Verde is already on > 1.0.0 and we should ensure backward compatibility.

I leave the decision to you. Let me know what you decide and I'll make any change you propose.

@leouieda
Copy link
Member

Yeah, this would have been good as a default if I had the foresight. But for now, we shouldn't break the API. We can put a warning later on if we decide to change the default to True for a 2.0.0 release.

@santisoler
Copy link
Member Author

@leouieda I gave this a second thought. The problematic line you mentioned is not quite right. BlockReduce.filter() currently returns two tuples: blocked_coordinates and blocked_data.
The common usage is:

coordinates, data = BlockReduce(...).filter(coordinates, data)

So the number of output variables is not changed on this PR, therefore it's not breaking backward compatibility.

Nevertheless it could create problems if the user use it like this:

(lon, lat), data = BlockReduce(...).filter(coordinates, data)

But I don't think this is the recommended way according to the documentation.

I'm on a grey area here (mainly due to my lack of experience with supporting backward compatibility).
What do you think? Should we still add the drop_coords flag?

@leouieda
Copy link
Member

I'm on a grey area here (mainly due to my lack of experience with supporting backward compatibility). What do you think? Should we still add the drop_coords flag?

Yep, I always forget that filter returns 3 things always. But it the docstring says that it's only the first 2 coordinates. So even if there are no users relying on this, I don't want to break the promises made in the docstring. I don't think it's a usability problem if we have the drop_coords argument.

Actually, I probably would never use BlockReduce on gravity and magnetic data this way. These are really sensitive to the vertical dimension so averaging out the height seems like a big introduction of errors. Instead, I would the BlockMean coordinates to set the point masses and fit the entire dataset.

But it's good to have the option of not dropping coordinates since the average height, etc, might be useful for other things.

@santisoler santisoler requested a review from leouieda July 30, 2019 13:02
Copy link
Member

@leouieda leouieda left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks, Santi!

@leouieda leouieda merged commit 20c906b into master Jul 30, 2019
@leouieda leouieda deleted the block_reduce_ndims branch July 30, 2019 22:26
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.

Support n-dimensional coordinates in BlockReduce
2 participants