I’m trying to run the analyses included as parts of the “drifting gratings” and “natural movies” analyses on new/updated time-traces. Basically I have data exactly in the same form as the data downloaded via the brain observatory package in the sdk:
so rather than calling dg.get_response() to get the precomputed values, I’d like to update the time traces in data_set and recompute the analyses from scratch.
For your questions, I mean 2. I have downloaded the dFF traces, and made modifications to them based on a new algorithm. For all intents and purposes, these can be considered an array in python of the same size and type as the dFF trace matrix I loaded. I want to re-incorporate those new dFF traces and redo the analysis to see if the tuning curves and other distributions are preserved.
StimulusAnalysis objects (the base class of DriftingGratings & NaturalMovie) are constructed with a BrainObservatoryNwbDataSet, which they use to access data. To access dff, they call the get_dff_traces method on their BrainObservatoryNwbDataSet. What you need is an object that behaves almost exactly like a BrainObservatoryNwbDataSet, but whose get_dff_traces method returns your traces instead of the ones in the NWB file.
One caveat is that sweepwise stimuli (those with discrete presentations, like gratings) use the average fluorescence over the 1 second preceding stimulus onset as f_0, rather than using a running window. The running window df/f is used when a continuous signal is desired, such as when analyzing the response to natural movies, or when analyzing running speed data. The upshot is that altering the way this running window df/f is calculated will not impact analysis metrics calculated from sweepwise stimuli. For more information, please see the white paper.
Good luck! Please let us know if you have further questions.
Nile
I’ve been trying to get this working right, and I’m starting to get some annoying errors. So one thing is that it looks like there’s an error in line 18 (should that not be “if self.dff_timestamps is None:” instead of “if self.dff_timestamps is not None:”?). Second I’m trying to extract a specific neuron, and I’m getting the following issue:
I get the error:
—> 12 regular_data_set = cache.get_ophys_experiments(exp_id, dff_traces=None)
TypeError: get_ophys_experiments() got an unexpected keyword argument ‘dff_traces’
Interestingly, if I replace the dff traces, it seems to work OK:
OK, update: somehow I confused “get_ophys_experiments” and " get_ophys_experiment_data". I can seemingly create data objects now. I’m getting a second issue, though, in that the actual responses are not being recomputed. For example, using the above code I try:
This returns all zeros, meaning that the responses are identical and the random time traces don’t seem to be effecting the calculations! Any idea how to fix that?
I think you’re running into the sweepwise stimuli caveat I mentioned above. For stimuli like drifting gratings that are presented in discrete sweeps, the analysis uses the (neuropil-subtracted) fluorescence rather than df/f (see here). As described in the whitepaper, the mean fluorescence during the pre-sweep period is used to normalize these values. The running df/f traces are used only when analyzing continuous stimuli.
If you want to get_response to return values based on your df/f traces, you could hack get_sweep_response (linked above) so that it reports a running df/f as the sweep response rather than normalizing corrected_fluorescence to the pre-sweep period.