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

Allow using lists of kwargs in morph_stats features #1021

Merged
merged 9 commits into from
Apr 13, 2022

Conversation

eleftherioszisis
Copy link
Contributor

@eleftherioszisis eleftherioszisis commented Apr 8, 2022

Summary:

  • Added new config support for adding the same feature multiple times with different arguments (see below)
  • If kwargs are populated in feature they are appended to its name (f'{mode}_{feature_name}__{suffix}')
  • The suffix includes each feature's kwarg present in the config, apart from neurite_type, e.g. variant:branch-order__method:uylings
  • Config sanitization has become the point where all different versions are converted to the single valid one for the rest of the program.
  • Made protected all the functions apart from extract_stats, extract_dataframe, and main.
  • Sanitization has moved from main to extract_stats to guarantee that regardless of the entry point in the module, i.e. using any of the three functions in the previous point, the config is sanitized the same way.

A list of features looks like this:

morphology:
  soma_radius:
    modes:
      - mean
  max_radial_distance:
    modes:
      - mean
neurite:
  section_lengths:
    modes:
      - max
      - sum
  section_volumes:
    modes:
      - sum
  section_branch_orders:
    modes:
      - max
      - raw
  segment_midpoints:
    modes:
      - max
  max_radial_distance:
    modes:
      - mean
  principal_direction_extents:
    kwargs:
      - direction: 1
      - direction: 0
    modes:
      - min
      - sum
  partition_asymmetry:
    kwargs:
        - variant: branch-order
          method: petilla
        - variant: length
          method: uylings
    modes:
        - min
        - max
neurite_type:
- AXON
- APICAL_DENDRITE
- BASAL_DENDRITE
- ALL

Using that extract_stats results to:

{'all': {'max_partition_asymmetry__variant:branch-order__method:petilla': 0.9,
         'max_partition_asymmetry__variant:length__method:uylings': 0.8795344229855895,
         'max_section_branch_orders': 10,
         'max_section_lengths': 11.758282,
         'max_segment_midpoints_0': 64.40167236328125,
         'max_segment_midpoints_1': 48.48197937011719,
         'max_segment_midpoints_2': 53.750946044921875,
         'mean_max_radial_distance': 99.58946,
         'min_partition_asymmetry__variant:branch-order__method:petilla': 0.0,
         'min_partition_asymmetry__variant:length__method:uylings': 0.00030289197373727377,
         'min_principal_direction_extents__direction:0': 80.01260723801528,
         'min_principal_direction_extents__direction:1': 5.274489134421081,
         'raw_section_branch_orders': [0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7,
                                       7, 8, 8, 9, 9, 10, 10, 0, 1, 1, 2, 2, 3,
                                       3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
                                       10, 10, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
                                       6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 0, 1, 1,
                                       2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
                                       9, 9, 10, 10],
         'sum_principal_direction_extents__direction:0': 356.3872399244001,
         'sum_principal_direction_extents__direction:1': 25.26438016226154,
         'sum_section_lengths': 840.68524,
         'sum_section_volumes': 1104.9077745403258},
...
 'morphology': {'mean_max_radial_distance': 99.58946,
                'mean_soma_radius': 0.13065629977308288}}

Notice how the multiple feature entries with different kwargs result into different name:

 min_principal_direction_extents__direction:1

Closes #1015

@codecov-commenter
Copy link

codecov-commenter commented Apr 8, 2022

Codecov Report

Merging #1021 (25106ce) into master (f4cb039) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #1021   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           36        36           
  Lines         2401      2403    +2     
=========================================
+ Hits          2401      2403    +2     

@eleftherioszisis eleftherioszisis marked this pull request as ready for review April 9, 2022 17:04
Copy link
Member

@adrien-berchet adrien-berchet left a comment

Choose a reason for hiding this comment

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

Nice, thanks for this!

Comment on lines +78 to +81
Either a list of features: [feature_name, {kwargs: {}, modes: []}] or
a dictionary of features {feature_name: {kwargs: {}, modes: []}}.
- kwargs is an optional entry allowing to pass kwargs to the feature function
- modes is an aggregation operation provided as a string such as:
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to keep both formats? Shouldn't we raise a deprecation warning for the dict format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure where we stand wrt to deprecating the old formats. @mgeplf , should I add warnings for all previous config layouts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, the way I was thinking about adding this was to make, the kwargs (which was poorly named), a list:

neurite:
    partition_asymmetry:
        kwargs:
           - {}
           - { variant: 'length',  method: 'petilla' }

and then isinstance kwargs to see if it was a dict (and then use the old behavior), or a list(and then use the new behavior. I think the config could be more minimal this way; however, the modes would be the same for both kwargs variants.

Copy link
Contributor Author

@eleftherioszisis eleftherioszisis Apr 11, 2022

Choose a reason for hiding this comment

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

I like this. I will change it accordingly!
@lidakanari , @adrien-berchet , that would work for you right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have implemented @mgeplf suggestion for multiple kwargs. @lidakanari , @adrien-berchet could you please try it and let me know if it works for you?Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM; but let's wait for the feedback on usage.

neurom/apps/morph_stats.py Show resolved Hide resolved
@lidakanari
Copy link
Contributor

Yep, that works well for me, thanks!

@eleftherioszisis eleftherioszisis changed the title Allow using lists of features instead of dicts Allow using lists of kwargs in morph_stats features Apr 13, 2022
@eleftherioszisis eleftherioszisis merged commit 1ecce98 into master Apr 13, 2022
@eleftherioszisis eleftherioszisis deleted the zisis/morph-stats-lists branch April 13, 2022 10:42
@adrien-berchet
Copy link
Member

Looks perfect, thank you very much!

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.

Is there a way to define optional arguments from morph_stats application?
5 participants