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

Improve get_file_size efficiency for .npy files #1439

Merged
merged 5 commits into from
Dec 13, 2024

Conversation

fdeguire03
Copy link

Description

Currently, caiman.bsae.movies.get_file_size requires reading an entire .npy file into memory to infer its shape. This update modifies the function to read only the file header, greatly improving runtime efficiency.

Fixed #1431

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Branching

  • All PRs should be made against the dev branch. The main branch is not often merged back to dev.
  • If you want to get your PR out to the world faster (urgent bugfix), poke pgunn to cut a release; this will get it onto github and into conda faster

Has your PR been tested?

If you're fixing a bug or introducing a new feature it is recommended you run the tests by typing

caimanmanager test

and

caimanmanager demotest

prior to submitting your pull request.

Please describe any additional tests that you ran to verify your changes. If they are fast you can also
include them in the folder 'caiman/tests/and name themtest_***.py` so they can be included in our lists of tests.

No additional tests were added, as the change modifies internal behavior without introducing new user-facing functionality or regressions. Existing test coverage should adequately validate this change.

elif version == (2, 0):
shape, _, _ = np.lib.format.read_array_header_2_0(f)
else:
raise ValueError(f"Unsupported .npy file version: {version}. Update this code to handle it.")
Copy link
Member

Choose a reason for hiding this comment

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

"this code" -> "caiman.base.movies.get_file_size()"

@pgunn
Copy link
Member

pgunn commented Dec 13, 2024

Generally looks good!

@fdeguire03 fdeguire03 marked this pull request as draft December 13, 2024 16:59
@fdeguire03 fdeguire03 marked this pull request as ready for review December 13, 2024 17:04
@pgunn
Copy link
Member

pgunn commented Dec 13, 2024

I've tested this code a bit and it looks good; this is a part of the numpy API I haven't played around with much.

@pgunn
Copy link
Member

pgunn commented Dec 13, 2024

Thanks for the contribution, both this and the preceding diff!

@pgunn pgunn merged commit 2b29d49 into flatironinstitute:dev Dec 13, 2024
@fdeguire03 fdeguire03 deleted the dev branch December 13, 2024 17:06
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