diff --git a/allensdk/brain_observatory/ecephys/_current_source_density.py b/allensdk/brain_observatory/ecephys/_current_source_density.py index d088d9081..b319812e6 100644 --- a/allensdk/brain_observatory/ecephys/_current_source_density.py +++ b/allensdk/brain_observatory/ecephys/_current_source_density.py @@ -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"][:] ) diff --git a/allensdk/brain_observatory/ecephys/_units.py b/allensdk/brain_observatory/ecephys/_units.py index 9d61964cb..7128b8879 100644 --- a/allensdk/brain_observatory/ecephys/_units.py +++ b/allensdk/brain_observatory/ecephys/_units.py @@ -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"], @@ -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 @@ -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 ------- @@ -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 diff --git a/allensdk/brain_observatory/ecephys/write_nwb/schemas.py b/allensdk/brain_observatory/ecephys/write_nwb/schemas.py index 9626923a2..8b0bb0f34 100644 --- a/allensdk/brain_observatory/ecephys/write_nwb/schemas.py +++ b/allensdk/brain_observatory/ecephys/write_nwb/schemas.py @@ -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):