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

Impedance ("Z score") feature is added #165

Merged
merged 37 commits into from
Oct 5, 2023

Conversation

mariarv
Copy link
Contributor

@mariarv mariarv commented Mar 24, 2020

The "impedance" feature takes the maximum of impedance of the neuron. Impedance is calculated by dividing the power spectrum of the voltage trace by the power spectrum of ZAP current. An example of impedance profile and its maximum (star symbol on the plot) for corresponding current and voltage traces is attached.
Screenshot 2020-03-24 at 16 42 58

efel/_version.py Outdated Show resolved Hide resolved
efel/_version.py Outdated Show resolved Hide resolved
efel/pyfeatures/pyfeatures.py Outdated Show resolved Hide resolved
efel/pyfeatures/pyfeatures.py Outdated Show resolved Hide resolved
efel/pyfeatures/pyfeatures.py Outdated Show resolved Hide resolved
efel/pyfeatures/pyfeatures.py Outdated Show resolved Hide resolved
efel/pyfeatures/pyfeatures.py Outdated Show resolved Hide resolved
freq = numpy.fft.fftfreq(len(volt), d=0.0001)
Z = ((fft_volt) / (fft_cur))
signalPhase = numpy.angle(fft_volt)
norm_Z = abs(Z[1:150]) / max(abs(Z[1:150]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have to hardcode 150 here ? It should at least be a general eFEL setting

@anilbey
Copy link
Contributor

anilbey commented Apr 30, 2020

I was trying to undo the _versioneer change. Let me reopen it.

@anilbey
Copy link
Contributor

anilbey commented Apr 30, 2020

I don't have permission to push, @mariarv did you enable the "allow contributors to make changes" option?

@anilbey
Copy link
Contributor

anilbey commented Apr 30, 2020

The issue was automatically getting closed when I wanted to push after a rebase while my default git push behaviour was matching. Now I set it to simple (I can push now) but the PR needs to be reopened.

Impedance feature PR BlueBrain#165 merged with master
@anilbey anilbey reopened this Apr 30, 2020
@anilbey
Copy link
Contributor

anilbey commented May 15, 2020

The only conflict with master is the presence of "impedance" feature in the featurenames.json.

@wvangeit
Copy link
Contributor

Sure, but that file should be changed in a way that it doesn't cause a merge conflict with getting that into master

@anilbey
Copy link
Contributor

anilbey commented May 15, 2020

It's tricky:
If I merge it by keeping "impedance", master branch will fail since "impedance" feature does not exist.
If I merge it by removing "impedance", this branch will fail.

@anilbey
Copy link
Contributor

anilbey commented May 15, 2020

I can merge master here. I think that would be the best.

@wvangeit
Copy link
Contributor

But I think there is something wrong with the exact line or so. I've never seen a merge conflict when adding features.

@anilbey
Copy link
Contributor

anilbey commented May 15, 2020

Previously the sorting order of lines was different and there was also the removal of duplicates. That had created the original merge conflict and after resolving it in 4117769, git still kept the conflict statement

@wvangeit
Copy link
Contributor

That looks better :-)

normalized_voltage = voltage_trace - holding_voltage
current_trace = current()
if current_trace is not None:
current_base = numpy.median(current_trace[0:10])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we still need a current_base feature for this, the 0:10 should not be hardcoded

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and also the "median" option for both voltage_base and current_base features.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we can use the current base feature with median but how can we set the range [0:10] there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariarv should this be 0:10? Wouldn't it be better to use the same range as voltage_base?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started using current_base in latest commit

Z = fft_volt / fft_cur
norm_Z = abs(Z) / max(abs(Z))
# physiological range of frequencies range [0,100]
smooth_Z = gaussian_filter1d(norm_Z[0:100], 10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this range should still become an efel setting, so that we don't hardcoded '100'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in latest commit. New efel setting is impedance_max_freq and its default value is 50, to be consistent with this paper: https://pubmed.ncbi.nlm.nih.gov/1992481/

normalized_voltage = voltage_trace - holding_voltage
current_trace = current()
if current_trace is not None:
current_base = numpy.median(current_trace[0:10])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should be called holding_current to be consistent with holding_voltage?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in latest commit

@codecov-commenter
Copy link

codecov-commenter commented May 28, 2020

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (4dfe0e4) 53.45% compared to head (cdaec47) 53.59%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #165      +/-   ##
==========================================
+ Coverage   53.45%   53.59%   +0.14%     
==========================================
  Files          30       30              
  Lines        8394     8426      +32     
  Branches     3677     3677              
==========================================
+ Hits         4487     4516      +29     
- Misses       1261     1264       +3     
  Partials     2646     2646              
Files Coverage Δ
efel/api.py 98.77% <100.00%> (+<0.01%) ⬆️
tests/test_allfeatures.py 96.03% <ø> (ø)
tests/test_pyfeatures.py 100.00% <100.00%> (ø)
efel/pyfeatures/pyfeatures.py 90.56% <88.88%> (-0.35%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AurelienJaquier
Copy link
Collaborator

Hi there! People from BBP are starting to do single cell optimisation and they will need this feature, so I will make some changes to this PR soon.
I just have one question: @mariarv is there a reason you take into account the 0 Hz frequency here? I believe impedance at this frequency it is just resistance, and the few references I read about neuron impedance were not using it to compute Z. Also, when taking it into account, the smoothed Z at 0 Hz becomes very close to the maximum Z, thus we might have a problem for other traces if Z(0 Hz) becomes the max. See below plots using your data for Z with / without 0Hz datapoint.

(1st plot: without 0Hz)
impedance_without_freq0
(2nd plot: with 0Hz)
impedance_with_freq0

@mariarv
Copy link
Contributor Author

mariarv commented Oct 4, 2023

Hi @AurelienJaquier. Sure, you can get rid of 0 Hz, ideally it should not matter, as the peak of impedance shall not be at 0 Hz.
Cheers,
Maria

Jaquier Aurélien Tristan and others added 2 commits October 4, 2023 16:18
@AurelienJaquier
Copy link
Collaborator

Thanks @mariarv for the clarifications.

I think this PR is good to be merged. Maybe @anilbey could give it a final check?

docs/source/eFeatures.rst Show resolved Hide resolved
efel/pyfeatures/pyfeatures.py Show resolved Hide resolved
@anilbey anilbey self-requested a review October 5, 2023 08:35
Copy link
Contributor

@anilbey anilbey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good thanks everyone

@AurelienJaquier AurelienJaquier merged commit 010be6c into BlueBrain:master Oct 5, 2023
6 checks passed
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

Successfully merging this pull request may close these issues.

6 participants