Skip to content

Commit

Permalink
Add scaling factor to fix mean_waveforms and CSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
morriscb committed Nov 30, 2023
1 parent ef35a6c commit 1c61e26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def channel_locations(self) -> np.ndarray:

@classmethod
def from_json(cls, probe_meta: dict) -> "CurrentSourceDensity":
scale = probe_meta.get("scale_mean_waveform_and_csd", 1)
with h5py.File(probe_meta['csd_path'], "r") as csd_file:
return CurrentSourceDensity(
data=csd_file["current_source_density"][:],
data=csd_file["current_source_density"][:] / scale,
timestamps=csd_file["timestamps"][:],
interpolated_channel_locations=csd_file["csd_locations"][:]
)
Expand Down
8 changes: 6 additions & 2 deletions allensdk/brain_observatory/ecephys/_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def from_json(
)
mean_waveforms = _read_waveforms_to_dictionary(
probe['mean_waveforms_path'],
local_to_global_unit_map
local_to_global_unit_map,
mean_waveform_scale=probe.get('scale_mean_waveform_and_csd', 1)
)
spike_amplitudes = _read_spike_amplitudes_to_dictionary(
probe["spike_amplitudes_path"],
Expand Down Expand Up @@ -132,6 +133,7 @@ def _read_waveforms_to_dictionary(
waveforms_path,
local_to_global_unit_map=None,
peak_channel_map=None,
mean_waveform_scale=1,
):
""" Builds a lookup table for unitwise waveform data
Expand All @@ -146,6 +148,8 @@ def _read_waveforms_to_dictionary(
Maps unit identifiers to indices of peak channels. If provided,
the output will contain only samples on the peak
channel for each unit.
mean_waveform_scale : float, optional
Divide out a scaling from the mean_waveform. Default 1.
Returns
-------
Expand All @@ -171,7 +175,7 @@ def _read_waveforms_to_dictionary(
if peak_channel_map is not None:
waveform = waveform[:, peak_channel_map[unit_id]]

output_waveforms[unit_id] = np.squeeze(waveform)
output_waveforms[unit_id] = np.squeeze(waveform) / mean_waveform_scale

return output_waveforms

Expand Down
10 changes: 10 additions & 0 deletions allensdk/brain_observatory/ecephys/write_nwb/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ class Probe(RaisingSchema):
help="""amplitude scale factor converting raw amplitudes to Volts.
Default converts from bits -> uV -> V""",
)
scale_mean_waveform_and_csd = Float(
default=1,
allow_none=True,
help="""Amount to scale the mean waveform and CSD by. (data / scale).
This is a fix for a set of data documented in the change log.
The values for unit amplitudes were changed in the input_json
file and do not use this scale.
If the data in LIMS for these sessions is updated, this scaling
is not needed. Default is 1"""
)


class InvalidEpoch(RaisingSchema):
Expand Down

0 comments on commit 1c61e26

Please sign in to comment.