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

Tremor weekly aggregates #78

Merged
merged 6 commits into from
Nov 28, 2024
Merged

Tremor weekly aggregates #78

merged 6 commits into from
Nov 28, 2024

Conversation

nienketimmermans
Copy link
Contributor

Hey Erik, ik heb de weekly aggregation geïmplementeerd. Het moet alleen nog wel getest worden op een grotere hoeveelheid data.

@Erikpostt Erikpostt requested a review from Copilot November 27, 2024 10:31

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 5 changed files in this pull request and generated no suggestions.

Files not reviewed (1)
  • tests/data/5.quantification/tremor/weekly_tremor.json: Language not supported
Comments skipped due to low confidence (1)

src/paradigma/tremor/tremor_analysis.py:85

  • Corrected spelling from 'treshold' to 'threshold'.
movement_check = df['low_freq_power'] <= config.movement_threshold # little non-tremor arm movement
@Erikpostt Erikpostt requested a review from Copilot November 27, 2024 10:40

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 5 changed files in this pull request and generated no suggestions.

Files not reviewed (1)
  • tests/data/5.quantification/tremor/weekly_tremor.json: Language not supported
Comments skipped due to low confidence (1)

src/paradigma/tremor/tremor_analysis_config.py:126

  • The 'valid_day_threshold_hr' is set to 0, which might be a placeholder value. Ensure it is updated to the intended value (e.g., 10) before deployment.
self.valid_day_threshold_hr: float = 0
valid_days = [day for day, count in nr_windows_per_day.items()
if count * config.window_length_s / 3600 >= config.valid_day_threshold_hr]
df_aggregates = pd.DataFrame({'nr_valid_days': [len(valid_days)]}) # save number of valid days
Copy link
Contributor

Choose a reason for hiding this comment

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

Waarom is dit een list?

Copy link
Contributor Author

@nienketimmermans nienketimmermans Nov 27, 2024

Choose a reason for hiding this comment

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

Ik krijg een error als ik de vierkante haken weglaat, misschien omdat het een kolom moet worden in de dataframe? Het is wel maar één waarde


# determine valid days
daytime_hours = range(config.daytime_hours_lower_bound,config.daytime_hours_upper_bound)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wil je inclusief of exclusief de upper bound? In dit geval wordt ie geëxcludeerd volgens mij.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exclusief de upper bound, later nog even checken of dat ook echt gebeurt.


# calculate weekly tremor time
df_aggregates['tremor_time'] = np.sum(df_filtered['pred_tremor_checked']) / df_filtered.shape[0] * 100
Copy link
Contributor

Choose a reason for hiding this comment

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

Wil je de tremor specifiek kwantificeren in no arm movements (<= config.movement_threshold)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ja, ik zal later nog de no arm movement detectie opslaan in de detectie stap. Dan hoef ik de feature hier niet opnieuw met de threshold te vergelijken (wordt bij tremor detectie ook al gedaan)


# calculate weekly tremor power measures
tremor_power = df_filtered['tremor_power'][df_filtered['pred_tremor_checked']==1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Chained indexing kan onvoorspelbaar zijn soms, dus gebruik van .loc is vaak handiger om te doen.

Suggested change
tremor_power = df_filtered['tremor_power'][df_filtered['pred_tremor_checked']==1]
tremor_power = df_filtered.loc[df_filtered['pred_tremor_checked'] == 1, 'tremor_power']

Comment on lines 180 to 181
df_features = df_features[l_feature_cols]
Copy link
Contributor

Choose a reason for hiding this comment

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

Tenzij je l_feature_cols nog een keer gebruikt zou ik hier één regel van maken

Suggested change
l_feature_cols = ['tremor_power','low_freq_power']
df_features = df_features[l_feature_cols]
df_features = df_features[['tremor_power', 'low_freq_power']]



def quantify_tremor_io(path_to_feature_input: Union[str, Path], path_to_prediction_input: Union[str, Path], output_path: Union[str, Path], config: TremorQuantificationConfig) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Het idee van de io wrapper is dat het alleen de data laadt, een functie draait (de functie naam minus io), en de data opslaat. Zou je het zo kunnen omschrijven, en dan wellicht de andere stappen in de functie quantify_tremor doen? Wellicht moet de inhoud van quantify_tremor dan naar een nieuwe functie, of de andere code naar een nieuwe functie. Your call. ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aangepast!

Copy link
Contributor

Choose a reason for hiding this comment

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

Wat is de key "0" hier precies? Is het het idee dat je per deelnemer één json hebt, en dat de key hier het week nr is? Misschien kan je dit dan duidelijk maken door het niet "0" maar "week_0" oid te noemen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heb dit nu weggelaten, omdat we voorlopig de data opslaan per week per participant.

@@ -29,15 +29,15 @@ def test_2_extract_features_tremor_output(shared_datadir: Path):

def test_3_tremor_detection_output(shared_datadir: Path):
Copy link
Contributor

Choose a reason for hiding this comment

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

Waarom hebben je functies een numering? Is dat makkelijker om de stappen te volgen?

Copy link
Contributor

@Erikpostt Erikpostt left a comment

Choose a reason for hiding this comment

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

Hey Nienke, ziet er goed uit. Paar dingetjes je nog kan verschuiven voor ik het merge.

{
"metadata": {
"nr_valid_days": 1,
"nr_windows_daytime": 182,
Copy link
Contributor

Choose a reason for hiding this comment

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

Je zou deze nog kunnen combineren met de window length om het te converteren naar seconden/minuten/uur.

Copy link
Contributor

@Erikpostt Erikpostt left a comment

Choose a reason for hiding this comment

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

Merging!

@Erikpostt Erikpostt merged commit 47d778d into main Nov 28, 2024
1 check passed
@nienketimmermans nienketimmermans deleted the tremor_weekly_aggregates branch December 3, 2024 15:35
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.

2 participants