-
Notifications
You must be signed in to change notification settings - Fork 18
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
velocity to strain rate with gauge length support #399
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4624f1d
velocity to strain rate fd
ahmadtourei 2720d66
fix docs
ahmadtourei 3aced1c
merge master
d-chambers 651af45
support step argument in diff, allow gauge_multiple
d-chambers 9b59423
fix doctest
d-chambers 12012e8
rename fd version of function
d-chambers 5af8310
Merge branch 'master' of github.com:dasdae/dascore into vel_to_sr
d-chambers c4fad84
fix docs
d-chambers 52b458b
staggered only for step = 1, cleanup
d-chambers 9fd5344
update velocity_to_strain
d-chambers e1ee4c2
fix coverage and doc tests
d-chambers 40b8ab8
update docs
d-chambers 5db19fa
fix doctest indent
d-chambers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"""Tests for converting velocity to strain-rate.""" | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from dascore.exceptions import PatchAttributeError | ||
from dascore.units import get_quantity | ||
|
||
|
||
class TestStrainRateConversion: | ||
"""Tests for converting velocity to strain-rate.""" | ||
|
||
@pytest.fixture(scope="class") | ||
def patch_strain_rate_default(self, terra15_das_patch): | ||
"""Return the default terra15 converted to strain rate.""" | ||
return terra15_das_patch.velocity_to_strain_rate() | ||
|
||
def test_attrs(self, patch_strain_rate_default): | ||
"""Ensure the attributes were updated with strain_rate.""" | ||
attrs = patch_strain_rate_default.attrs | ||
assert attrs["data_type"] == "strain_rate" | ||
|
||
def test_data_different(self, patch_strain_rate_default, terra15_das_patch): | ||
"""The data should have changed.""" | ||
data1 = patch_strain_rate_default.data | ||
data2 = terra15_das_patch.data | ||
assert not np.all(np.equal(data1, data2)) | ||
|
||
def test_raises_on_strain_rate(self, patch_strain_rate_default): | ||
"""It does not make sense to apply this twice.""" | ||
with pytest.raises(PatchAttributeError, match="velocity"): | ||
_ = patch_strain_rate_default.velocity_to_strain_rate() | ||
|
||
def test_update_units(self, patch_strain_rate_default, terra15_das_patch): | ||
"""Ensure units are updated. See issue #144.""" | ||
new_units = get_quantity(patch_strain_rate_default.attrs.data_units) | ||
old_units = get_quantity(terra15_das_patch.attrs.data_units) | ||
assert new_units != old_units | ||
assert new_units == old_units / get_quantity("m") | ||
|
||
|
||
class TestFdStrainRateConversion: | ||
"""Tests for converting velocity to strain-rate in the forward diff function.""" | ||
|
||
@pytest.fixture(scope="class") | ||
def patch_strain_rate_default(self, terra15_das_patch): | ||
"""Return the default terra15 converted to strain rate.""" | ||
return terra15_das_patch.velocity_to_strain_rate_fd() | ||
|
||
def test_attrs(self, patch_strain_rate_default): | ||
"""Ensure the attributes were updated with strain_rate.""" | ||
attrs = patch_strain_rate_default.attrs | ||
assert attrs["data_type"] == "strain_rate" | ||
|
||
def test_raises_on_strain_rate(self, patch_strain_rate_default): | ||
"""It does not make sense to apply this twice.""" | ||
with pytest.raises(PatchAttributeError, match="velocity"): | ||
_ = patch_strain_rate_default.velocity_to_strain_rate_fd() | ||
|
||
def test_update_units(self, patch_strain_rate_default, terra15_das_patch): | ||
"""Ensure units are updated. See issue #144.""" | ||
new_units = get_quantity(patch_strain_rate_default.attrs.data_units) | ||
old_units = get_quantity(terra15_das_patch.attrs.data_units) | ||
assert new_units != old_units | ||
assert new_units == old_units / get_quantity("m") | ||
|
||
def test_even_gauge_multiple(self, terra15_das_patch): | ||
"""Compare output shape with coord shape for even gauge multiple.""" | ||
strain_rate_patch = terra15_das_patch.velocity_to_strain_rate_fd(4) | ||
assert strain_rate_patch.data.shape == strain_rate_patch.coords.shape | ||
|
||
def test_odd_gauge_multiple(self, terra15_das_patch): | ||
"""Compare output shape with coord shape for odd gauge multiple.""" | ||
strain_rate_patch = terra15_das_patch.velocity_to_strain_rate_fd(5) | ||
assert strain_rate_patch.data.shape == strain_rate_patch.coords.shape | ||
|
||
@pytest.mark.parametrize("sample", (1, 2, 3, 4, 5)) | ||
def test_shape_different(self, terra15_das_patch, sample): | ||
"""Ensure shape of the output is correctly changed.""" | ||
strain_rate_patch = terra15_das_patch.velocity_to_strain_rate_fd(sample) | ||
shape_1 = len(strain_rate_patch.coords.get_array("distance")) | ||
shape_2 = len(terra15_das_patch.coords.get_array("distance")) | ||
assert shape_1 == shape_2 - sample |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@d-chambers can you please double check if we need to divide by gauge length here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't actually need this; numpy.grad takes a dx parameter to properly normalize in that function call. This makes me feel better, I was worried the outputs were scaled wrong 😓.