Skip to content

sorry to touch so many files#77

Merged
florisvb merged 9 commits into
florisvb:masterfrom
pavelkomarov:master
May 30, 2025
Merged

sorry to touch so many files#77
florisvb merged 9 commits into
florisvb:masterfrom
pavelkomarov:master

Conversation

@pavelkomarov
Copy link
Copy Markdown
Collaborator

Here's some potential Pavelization. Opening a PR early to give more chance for feedback. Ideally we merge in stages to keep code review manageable and make sure we have buy-in from one another.

:return: **x_hat** (np.array[float]) -- integral of dxdt_hat
"""
x = scipy.integrate.cumulative_trapezoid(dxdt_hat)
first_value = x[0] - np.mean(dxdt_hat[0:1])
Copy link
Copy Markdown
Collaborator Author

@pavelkomarov pavelkomarov May 28, 2025

Choose a reason for hiding this comment

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

What is this doing? You have an array dxdt_hat, and you take the slice [0:1], which includes the 0 index and excludes the 1 index. So this is equivalent to just taking dxdt_hat[0]. Then you take the mean of that single entry, which returns that same scalar value again, and then you subtract it off x[0]. But dxdt[0] and x[0] have different units, right? I'm confused. Would it make more sense to just assume the first_value = 0?

:param dt:
:return:
def _x_hat_using_finite_difference(x, dt):
"""Find a smoothed estimate of the true function by taking FD and then integrating with trapezoids
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is my interpretation correct here? Why differentiate only to immediately integrate?



# simple finite difference
def finite_difference(x, dt):
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

All places FD gets used now import from the main FD code, per #79.

except ImportError:
pass

__friedrichs_kernel__ = utility.__friedrichs_kernel__
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There are many places you denote 'private' functions with double underscores on each side. Double underscores are typically for builtin "magic" functions, like basic indexing and math operators. Last I know the convention was prepending a single underscore for privates. Sphinx still gives those a miss, only building docs for the ones that don't start with an underscore. I've been changing the standard to reflect what I think the community is more used to as I go.

I'm also just removing places where you alias a function to its own name. It's easy enough just to call it with utility._whatever later on and save this line.


def get_filenames(path, contains, does_not_contain=('~', '.pyc')):
"""
Create list of files found in given path that contain or do not contain certain strings.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We have grep -IR . -e "string" for this, and you're not using this one anywhere, so I think it should go away.

dt = 0.01


class TestLM(TestCase):
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I didn't even know that pytest can run unittest TestCases, but evidently it can. There's no need to have dependency on both, though. It's simpler and fewer lines to do tests the pytest way.

…This also involved touching all the __init__ files, which led me to discover the convolution code wasn't really in the right place, since it's such a basic utility and used by multiple modules. It now lives in the utilities.

# make derivative go to zero at ends (optional)
if options['pad_to_zero_dxdt']:
if pad_to_zero_dxdt:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Why would you need to pad and make the derivative go to zero at the edges? Does that allow this method to be applied to aperiodic functions with any success? In spectral-derivatives, I just tell the user it's only going to work on periodic functions.

@florisvb florisvb merged commit d33abd9 into florisvb:master May 30, 2025
@florisvb
Copy link
Copy Markdown
Owner

Thanks for all your work Pavel!

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