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

signal.py and bdot_probe.py #1652

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

aminaahmed1803
Copy link

@aminaahmed1803 aminaahmed1803 commented Jul 29, 2022

  • Added functionality for plasmapy.analysis
  • Created bdot_probe.py module:
  1. calc_bfield() function.
  • Created sginal.py module:
  1. remove_offset() function.
  2. band_pass_filter() function.

All functions do not use units.
All functions strictly use 1D numpy arrays.

data_array[:] = [x - meansub for x in data_array]
return data_array

def band_pass_filter(data_array: np.ndarray, cutoff: float, sampling_frequency: float, order: int) -> np.ndarray:
Copy link
Contributor

Choose a reason for hiding this comment

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

This function implements a high-pass filter, not a band-pass filter. Consider renaming this function "high_pass_filter" or implement the high and low cutoffs

@rocco8773 rocco8773 self-assigned this Jul 30, 2022
Copy link
Member

@rocco8773 rocco8773 left a comment

Choose a reason for hiding this comment

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

Thank you for working on this. I've left a few comments for changes.

How comfortable are you with writing tests? We'll need to cover the functionality being introduced here. @namurphy Has put together a rather robust testing guide that you can use for reference.

@@ -0,0 +1,31 @@
"""_summary_
Copy link
Member

Choose a reason for hiding this comment

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

Remove this file from this pull request (PR). We'll include this in its own PR.

@@ -0,0 +1,46 @@
"""_summary_
Copy link
Member

Choose a reason for hiding this comment

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

Rename this file signal.py.

Comment on lines 12 to 20
"""_summary_ : Function which preforms mean subtraction

Args:
data_array (array): array containing values from which to mean sub
start_idx (int): idx of where to start obtaining mean from
end_idx (int): idx of where to stop obtaining mean from
Returns:
data_array (array): array after mean_sub is preformed
"""
Copy link
Member

Choose a reason for hiding this comment

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

We use the numpydoc style for our documentation. Can you please look into converting your docstrings?

You can also refer to our documentation guide.

@aminaahmed1803
Copy link
Author

aminaahmed1803 commented Aug 2, 2022 via email

@github-actions github-actions bot added the plasmapy.diagnostics Related to the plasmapy.diagnostics subpackage label Aug 2, 2022
import numpy as np
import scipy.io as spio
import scipy.integrate as sp
from scipy import signal
Copy link
Member

Choose a reason for hiding this comment

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

Additonally, I can't change the name to signal.py because that causes a circular import issue. Numpy already has a module called signal.py

That's not technically a circular import issue. You can, since it's sort of necessary here, do

Suggested change
from scipy import signal
import scipy.signal

And then you can refer to this later on as

    b, a = scipy.signal.butter(order, normal_cutoff, btype='highpass', analog=False)

if len(bdot_data) != len(times):
raise Exception("length of time and voltage arrays in not equal\n")

bdot_data[:] = [x / loop_area for x in bdot_data]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bdot_data[:] = [x / loop_area for x in bdot_data]
bdot_data /= loop_area

As you wrote it, this would run the division via Python rather than numpy (slow!) and modify the array in-place, which is fine for performance reasons, but really, really, really needs to be explicitly stated in the documentation.

Comment on lines 40 to 41
field_arr = sp.cumtrapz(bdot_data, times) # Tesla
new_time = times[1:]
Copy link
Member

Choose a reason for hiding this comment

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

I definitely agree with Steve here: #1648 (comment) that if we do initial = 0 in cumtrapz, we don't need to modify the times array and could skip the whole new_time thing.

Comment on lines 20 to 24
start_idx: int
Index of value in array from where to start calulating offset.

end_idx: int
Index of value in array from where to end calulating offset.
Copy link
Member

Choose a reason for hiding this comment

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

Typos:

Suggested change
start_idx: int
Index of value in array from where to start calulating offset.
end_idx: int
Index of value in array from where to end calulating offset.
start_idx: int
Index of value in array from where to start calculating offset.
end_idx: int
Index of value in array from where to end calculating offset.

"""
data_array = np.array(data_array)
meansub = np.mean(data_array[start_idx:end_idx])
data_array[:] = [x - meansub for x in data_array]
Copy link
Member

Choose a reason for hiding this comment

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

Same caveat as above, don't use loops for this!

from warnings import warn


def remove_offset(data_array: np.ndarray, start_idx: int, end_idx: int) -> np.ndarray:
Copy link
Member

Choose a reason for hiding this comment

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

This whole function seems overly complicated for a two-liner:

offset_region = data_array[start_idx, end_idx]
data_array -= offset_region.mean()

Perhaps we could skip it?

@aminaahmed1803
Copy link
Author

aminaahmed1803 commented Aug 3, 2022 via email

@StanczakDominik
Copy link
Member

Hey, I've made a couple changes to your branch, please pull them via git pull :)

I didn't quite understand what you are saying. Should I change the code or
just completely remove the function? It would be great if you could rephrase it so I can understand it better.

Yeah, sorry, that's on me - communication, especially clear communication, can be difficult 😅 I do think that since this function can be expressed as a numpy one-liner, it isn't necessary and can be removed - which I did in 6e645ba.

I also could not reproduce your signal-related error. Can you tell me whether you're still getting it after pulling in the changes?

@aminaahmed1803
Copy link
Author

aminaahmed1803 commented Aug 17, 2022 via email

@StanczakDominik
Copy link
Member

It does look like an env problem! Since from the previous error logs it looks like you're using anaconda, I'll point out the instructions over at https://docs.plasmapy.org/en/stable/contributing/install_dev.html#conda, ending at and including the pip install -e . part. If you still have issues, I'm sure we can figure them out :)

@namurphy namurphy added status: dormant PRs that are stalled size: large 100 ≤ changed lines < 500 labels May 26, 2023
@namurphy namurphy added this to the Future milestone Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plasmapy.diagnostics Related to the plasmapy.diagnostics subpackage size: large 100 ≤ changed lines < 500 status: dormant PRs that are stalled
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants