Skip to content

Allow getting derivative at arbitrary time points in tendency#14

Merged
SBlokhuizen merged 26 commits intodevelopfrom
feature/refactor-derivatives
Feb 6, 2025
Merged

Allow getting derivative at arbitrary time points in tendency#14
SBlokhuizen merged 26 commits intodevelopfrom
feature/refactor-derivatives

Conversation

@SBlokhuizen
Copy link
Copy Markdown
Collaborator

@SBlokhuizen SBlokhuizen commented Feb 6, 2025

This PR rewrites how derivatives are handled in the tendency classes. Before, you could only get the derivatives at the start or end of the tendency. This implementation extends this so the derivative can be obtain at any point in the tendency time range.

This might be necessary for example when using a repeated tendency, followed by a smooth tendency. The repeated tendency can end at any point in a tendency, and the smooth tendency should be able to match the derivative for the last tendency. For example:
image

Main changes in this PR:

  • Introduction of of get_derivative/get_value methods, these replace the get_start_value, get_end_value, get_start_derivative and get_end_derivative methods.
  • There were some issues due to the ambiguity of passing/returning floats, lists, and numpy arrays to the get_value/get_derivative methods. For clarity, I have changed these functions to only take in numpy arrays, and only output numpy arrays, at the expense that you have to map these back to a single float if only the at a single point is required.

@SBlokhuizen SBlokhuizen self-assigned this Feb 6, 2025
Copy link
Copy Markdown
Collaborator

@maarten-ic maarten-ic left a comment

Choose a reason for hiding this comment

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

Nice start! I've got a couple of comments to polish the PR, let me know if anything's unclear 🙂

else:
assert tendency.base == approx(expected_base)
assert tendency.amplitude == approx(expected_amplitude)
with (
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's move this to a fixture that's automatically used by all tests in this file?

@pytest.fixture(autouse=True)
def patch_periodic_base_tendency():
    arr = np.array([0])
    with (
        patch.object(PeriodicBaseTendency, "get_value", return_value=(arr, arr)),
        patch.object(PeriodicBaseTendency, "get_derivative", return_value=arr),
    ):
        yield

@SBlokhuizen SBlokhuizen merged commit b189bc4 into develop Feb 6, 2025
4 checks passed
@SBlokhuizen SBlokhuizen deleted the feature/refactor-derivatives branch February 6, 2025 15:33
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.

2 participants