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

Sample rate importing as float #14

Open
rjp109 opened this issue Aug 16, 2024 · 6 comments
Open

Sample rate importing as float #14

rjp109 opened this issue Aug 16, 2024 · 6 comments

Comments

@rjp109
Copy link

rjp109 commented Aug 16, 2024

Just in case anyone else comes across this issue:

When running '01_preprocess_signals.py' it doesn't seem to work with a sample rate other than 256Hz (I'm using 250Hz) since it seems to be importing the sample rate as a float rather than int. I managed to solve this by adding the following after line 134:
datasets['sampling_frequency_in_hz']=datasets['sampling_frequency_in_hz'].astype(int)

The error i was getting:
Traceback (most recent call last): File "C:\Users\rp17047\somnotate\example_pipeline\01_preprocess_signals.py", line 167, in <module> time, frequencies, preprocessed_signal = preprocess(signal, dataset['sampling_frequency_in_hz'], File "C:\Users\rp17047\somnotate\example_pipeline\01_preprocess_signals.py", line 84, in preprocess frequencies, time, spectrogram = get_spectrogram(raw_signal, File "C:\Users\rp17047\AppData\Local\miniconda3\envs\somnotate_env\lib\site-packages\lspopt\lsp.py", line 145, in spectrogram_lspopt H, taper_weights = lspopt(n=nperseg, c_parameter=c_parameter) File "C:\Users\rp17047\AppData\Local\miniconda3\envs\somnotate_env\lib\site-packages\lspopt\lsp.py", line 56, in lspopt h = np.vstack((np.ones((n,)), 2 * t1)) File "C:\Users\rp17047\AppData\Local\miniconda3\envs\somnotate_env\lib\site-packages\numpy\core\numeric.py", line 191, in ones a = empty(shape, dtype, order) TypeError: 'float' object cannot be interpreted as an integer

@paulbrodersen
Copy link
Owner

Are you specifying the sampling frequency as a float in the spreadsheet, and/or the time_resolution in the configuration file?

@rjp109
Copy link
Author

rjp109 commented Aug 16, 2024

I just used 'General' formatting in the spreadsheet on excel (although I did also try changing the format to 'Number'). I did not change the time-resolution, and kept it as 1. Should this be changed..? I score 4sec epochs.

@paulbrodersen
Copy link
Owner

I am trying to work out which bit of code is promoting the integer sampling_frequency_in_hz to a float. As far as I can tell, nothing in my code is doing it, so as long as you specify an integer in the spreadsheet, my expectation is that it should remain an integer.

I just used 'General' formatting in the spreadsheet on excel (although I did also try changing the format to 'Number').

  1. Are you reading in the spreadsheet as an excel spreadsheet (.xls) or as a CSV (.csv)?
  2. If you are using a CSV, what format does the sampling_frequency_in_hz have once you have edited the sheet in excel (i.e. is its value 250 or 250.0)? You can check this by opening the CSV in any text editor (e.g. notepad).

I did not change the time-resolution, and kept it as 1. Should this be changed..? I score 4sec epochs.

No, that is fine.

@rjp109
Copy link
Author

rjp109 commented Aug 21, 2024

Hi, I am reading it as a csv and it's value is 250 when I open it in a text editor. As I say, the line I added seems to fix the issue so hopefully it's not much of a problem, although odd...

@pantelisantonoudiou
Copy link
Contributor

I would like to also add here that I also get an error when the sampling rate number is either float or integer in the csv file. The error for float is from the lsp.py package. The error regarding regarding the int was during check_dataframe saying that my type was int64. My temporary solution was to add an extra type np.int64: 'sampling_frequency_in_hz' : (np.int64, int, float). Hope this helps.

@paulbrodersen
Copy link
Owner

@pantelisantonoudiou It does, thank you!

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

No branches or pull requests

3 participants