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

Refactor interpolation #486

Merged
merged 47 commits into from
Aug 24, 2021
Merged

Conversation

CagtayFabry
Copy link
Member

@CagtayFabry CagtayFabry commented Aug 18, 2021

Changes

I have reworked the xarray handling a little to now work with xarray dimensions instead of coordinates which is probably what we actually want. Mentioned here #476 (comment)

It is now possible to keep e.g. a single timestamp as an xarray coordinate in a constant orientations with shape=[3,3]

Related Issues

Closes # (add issue numbers)

Checks

  • updated CHANGELOG.md
  • updated tests
  • updated doc/
  • update example/tutorial notebooks

else: # full interpolation with overlapping times
coordinates = ut.xr_interp_coordinates_in_time(self.coordinates, time)

if len(coordinates) == 1: # remove "time dimension" for single value cases
Copy link
Member Author

@CagtayFabry CagtayFabry Aug 18, 2021

Choose a reason for hiding this comment

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

The len(coordinates) == 1 check can be pretty unstable imo @vhirtham
at first I was surprised this works without even knowing what it does. Using len(coordinates.time) == 1 here is probably what we want.

The problem is we cannot (or don't want to) guarantee that time is actually the first dimension

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, this is why you find this specific line below the processing of the inputs. coordinates and orientations should already be formatted correctly to match the specific internal structure I was abusing here. So it is pretty stable I guess unless you change the order of instructions in the __init__. But in this case, we have a ton of tests that will fail.

Not sure about len(coordinates.time) == 1. You might need to check the existence of coordinates.time first since static coordinates shouldn't have this attribute. Checking the passed time classes length shouldn't help much either since it gives no indication if coordinates actually have this extra dimension. I guess we can get it more self-explaining but at the price of additional checks. Not sure if it is worth it for class internal code that already, has a comment to state what it does.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, this is why you find this specific line below the processing of the inputs. coordinates and orientations should already be formatted correctly to match the specific internal structure I was abusing here. So it is pretty stable I guess unless you change the order of instructions in the __init__. But in this case, we have a ton of tests that will fail.

I don't think the current __init__ prevents passing additional dimensions in coordinate dimensions for example?

Not sure about len(coordinates.time) == 1. You might need to check the existence of coordinates.time first since static coordinates shouldn't have this attribute. Checking the passed time classes length shouldn't help much either since it gives no indication if coordinates actually have this extra dimension. I guess we can get it more self-explaining but at the price of additional checks. Not sure if it is worth it for class internal code that already, has a comment to state what it does.

wouldn't len(coordinates) == 1 also fail here if there was no time dimension?
len(LocalCoordinateSystem().coordinates) == 3

Copy link
Collaborator

@vhirtham vhirtham Aug 19, 2021

Choose a reason for hiding this comment

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

I don't think the current __init__ prevents passing additional dimensions in coordinate dimensions for example?

Just checked _build_coordinates and it seems that you are correct. Currently, a DataArray will be just passed through if I didn't miss something. But I consider this as a bug that should be fixed. The LCS shouldn't store any data that is not necessary to do its job

I disagree, the LCS should work perfectly fine for all data arrays that meet the required layout. Why would we restrict it any further?
If memory is a concern I will gladly leave that to the user (and it should be an easy fix) since our internal methods don't add any unnecessary overhead. We don't have to guarantee restoring all and everything on serialization etc. but that is not the point if you simply want to 'use' the LCS class for whatever purpose

weldx/util.py Outdated

return dsx_out.transpose(..., "c", "v")
if len(da.time) == 1: # remove "time dimension" for static case
return da.isel({"time": 0})
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the replacement we should use instead of return coordinates[0].values or even return coordinates[0], explicitly naming the dimension

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agreed with you in the case of this generalized function. However, as the internal structure in the LCS was well defined, accessing per index was safe and probably faster (no lookups).

@codecov
Copy link

codecov bot commented Aug 18, 2021

Codecov Report

Merging #486 (2a03c05) into master (914a2d4) will decrease coverage by 0.03%.
The diff coverage is 96.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #486      +/-   ##
==========================================
- Coverage   96.84%   96.80%   -0.04%     
==========================================
  Files          89       91       +2     
  Lines        5548     5548              
==========================================
- Hits         5373     5371       -2     
- Misses        175      177       +2     
Impacted Files Coverage Δ
weldx/asdf/extension.py 100.00% <ø> (ø)
weldx/asdf/validators.py 99.32% <ø> (ø)
weldx/asdf/util.py 84.88% <87.50%> (+0.05%) ⬆️
weldx/util/xarray.py 98.29% <92.50%> (ø)
weldx/geometry.py 99.44% <95.65%> (-0.13%) ⬇️
weldx/util/util.py 99.11% <99.11%> (ø)
weldx/asdf/file.py 97.43% <100.00%> (+0.54%) ⬆️
...gs/core/transformations/local_coordinate_system.py 100.00% <100.00%> (ø)
weldx/transformations/cs_manager.py 98.72% <100.00%> (ø)
weldx/transformations/local_cs.py 97.04% <100.00%> (-0.07%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 914a2d4...2a03c05. Read the comment docs.

@CagtayFabry CagtayFabry self-assigned this Aug 18, 2021
@CagtayFabry
Copy link
Member Author

Hope my comments do not sound/read too harshly. It is not meant to be harsh. Just not sure if the internal changes on the LCS are really that necessary (except for the renamings). We can apply them, but I am not convinced that they are advantageous here.

The thing is that without using explicit xarray syntax we basically prevent ourselves from ever having any dimensions besides time, c, v in our dataarrays (like a length dimension/coordinate along the path)

as for performance, I would really like to see a benchmark first for these tiny changes to consider this 😉

@vhirtham
Copy link
Collaborator

Hope my comments do not sound/read too harshly. It is not meant to be harsh. Just not sure if the internal changes on the LCS are really that necessary (except for the renamings). We can apply them, but I am not convinced that they are advantageous here.

The thing is that without using explicit xarray syntax we basically prevent ourselves from ever having any dimensions besides time, c, v in our dataarrays (like a length dimension/coordinate along the path)

I am just talking about the LCS internals. I don't think it will ever need more than those 3 dimensions. But nevermind. As I said, we can do it.

as for performance, I would really like to see a benchmark first for these tiny changes to consider this 😉

No need for a benchmark. Direct access is always the fastest data access method you can have, but it won't matter much since its contribution to the total execution time of our scripts, it is probably irrelevant. 😉

@CagtayFabry CagtayFabry added refactor transformations everything related to the LCS / CSM labels Aug 23, 2021
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@CagtayFabry CagtayFabry marked this pull request as ready for review August 24, 2021 08:49
@CagtayFabry CagtayFabry requested a review from vhirtham August 24, 2021 08:49
@pep8speaks
Copy link

Hello @CagtayFabry! Thanks for updating this PR.

Line 1:6: E999 SyntaxError: invalid syntax

@CagtayFabry CagtayFabry merged commit 2d7dba5 into BAMWelDX:master Aug 24, 2021
@CagtayFabry CagtayFabry deleted the refactor_interpolation branch August 24, 2021 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor transformations everything related to the LCS / CSM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants