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

from_npz() method for loading #169

Closed
vigji opened this issue Sep 8, 2023 · 5 comments
Closed

from_npz() method for loading #169

vigji opened this issue Sep 8, 2023 · 5 comments

Comments

@vigji
Copy link
Contributor

vigji commented Sep 8, 2023

As far as I could find in the docs, there is a convenient method for saving a Tsd as a npc file, but putting it back together would always require to do:

file = np.load("my_path/my_tsd.npz")
time_support = nap.IntervalSet(file['start'], file['end'])
nap.Tsd(t=file['t'], d=file['d'], time_support=time_support)

which is not that much work, but it would be probably better to have a class method like (similarly to pandas from_csv()):

class Tsd:
    ...
    @classmethod
    def from_npz(cls, file_path):
        file = np.load(file_path)
        time_support = nap.IntervalSet(file['start'], file['end'])
        return cls(t=file['t'], d=file['d'], time_support=time_support)

So that the interface would be super simple:

loaded_obj = Tsd.from_npz("my_path/my_tsd.npz")

What would you think about that?

@gviejo
Copy link
Contributor

gviejo commented Sep 8, 2023

The idea was to use nap.load_file(filename) but yes I agree this could be an extra convenient way for it.

@vigji
Copy link
Contributor Author

vigji commented Sep 9, 2023

the advantage would be to keep all the io-related naming conventions in a single place! (and a oo interface). Can do a PR with tests

@gviejo
Copy link
Contributor

gviejo commented Sep 11, 2023

Yes go for it

@vigji vigji mentioned this issue Sep 12, 2023
@tsloan1377
Copy link

I'm similarly interested in being able to load LFP, spike, and behavior data that is already processed and saved as numpy arrays and csv files.
From what I can see in the documentation, most of the I/O functionality is set up to load from the BIDS format as in the example notebooks/data.

Since this issue is still open an option to directly import from numpy files is of interest, or in the works.

As of right now, what would be the path of least resistance to have a numpy arrays and pandas dataframes of data wrapped into pynapple data structures? Renaming my files and folder structure to the BIDS specification outlined here? Or directly wrangling the datatypes into the same format as data = nap.load_session() provides?

Thanks in advance for your advice on the matter.

@vigji
Copy link
Contributor Author

vigji commented Jul 17, 2024

This has now been addressed in #313, even if the method is not public the logic is there

@vigji vigji closed this as completed Jul 17, 2024
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

No branches or pull requests

3 participants