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

Automatic insertion of pre-computed LFP data from NWB (i.e. ImportedLFP) #1229

Open
pauladkisson opened this issue Feb 13, 2025 · 1 comment
Labels
enhancement New feature or request NWB ingestion Problems with loading nwb files into spyglass

Comments

@pauladkisson
Copy link

I have some LFP data in an NWB file that I would like to insert into spyglass. I see that lfp/lfp_imported.py has an ImportedLFP table, but its make() method is NotImplemented.

I tried to just directly insert into ImportedLFP, but had some trouble with the intricacies of the AnalysisNwbfile.

@samuelbray32 samuelbray32 added enhancement New feature or request NWB ingestion Problems with loading nwb files into spyglass labels Feb 14, 2025
@samuelbray32
Copy link
Collaborator

samuelbray32 commented Feb 15, 2025

In case you have time to take a stab at this before we do, here's steps for using the AnalysisNwbfile table:

  1. Create a file and get its path on your system
lfp_file_name = AnalysisNwbfile().create(key["nwb_file_name"])
analysis_file_abspath = AnalysisNwbfile().get_abs_path(lfp_file_name)
  1. Prepare whatever data you're inserting (in this case, load in the lfp data and timestamps
  2. Make the nwb objects and write them into the file
  # Create dynamic table region and electrode series, write/close file
        with pynwb.NWBHDF5IO(
            path=analysis_file_abs_path, mode="a", load_namespaces=True
        ) as io:
            nwbf = io.read()

            # get the indices of the electrodes in the electrode table
            elect_ind = get_electrode_indices(nwbf, electrode_ids)

            electrode_table_region = nwbf.create_electrode_table_region(
                elect_ind, "filtered electrode table"
            )
            es = pynwb.ecephys.ElectricalSeries(
                name="filtered data",
                data=np.empty(tuple(output_shape_list), dtype=data_dtype),
                electrodes=electrode_table_region,
                timestamps=np.empty(output_shape_list[time_axis]),
                description=description,
            )
            if data_type == "LFP":
                ecephys_module = nwbf.create_processing_module(
                    name="ecephys", description=description
                )
                ecephys_module.add(pynwb.ecephys.LFP(electrical_series=es))
            else:
                nwbf.add_scratch(es)

            io.write(nwbf)
  1. during that creation note the object_id of the added nwb object
lfp_object_id = es.object_id
  1. Insert an entry into the AnalysisNwbfile table
AnalysisNwbfile().add(nwb_file_name, analysis_file_name)
  1. Insert into the table you're populating
ImportedLFP.insert1(
    {
        "nwb_file_name": nwb_file_name,
        ---
        ---
        ---
        "lfp_object_id" : lfp_object_id,
        "analysis_file_name" : lfp_file_name
    }
  • Example Code from LFPV1.make and FirFilterParameter.filter_data_nwb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request NWB ingestion Problems with loading nwb files into spyglass
Projects
None yet
Development

No branches or pull requests

2 participants