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

run_properties$summary table durations incorrect. #101

Open
nohelix opened this issue Mar 26, 2024 · 4 comments
Open

run_properties$summary table durations incorrect. #101

nohelix opened this issue Mar 26, 2024 · 4 comments

Comments

@nohelix
Copy link
Collaborator

nohelix commented Mar 26, 2024

❗ Related to #100

Issue

All durations listed regardless of type, i.e. for type 0 trials even type 1 trial durations are listed.

Repeatability

Import file in #100 or Red1_edge_BBN_60dB_1-2000ms_12s_BG_PKN_0dB_20240325-101031_BOX#007.zip
Halt during naming
look at run_properties$stim_encoding_table and at run_properties$summary

You should get:
run_properties$stim_encoding_table

  Repeat_number Type Stim Source Freq (kHz) Inten (dB) Dur (ms) Delay (s) Nose Out TL (s) Time Out (s) Stim_ID
1             1    1         BBN          0         60     2000       1 4               2            0       1
2             1    1         BBN          0         60      300       1 4               2            0       2
3             1    1         BBN          0         60      100       1 4               2            0       3
4             1    1         BBN          0         60       50       1 4               2            0       4
5             1    1         BBN          0         60       10       1 4               2            0       5
6             1    1         BBN          0         60        5       1 4               2            0       6
7             1    1         BBN          0         60        1       1 4               2            0       7
8             3    0         BBN          0         60        0       1 4               2           12       8

run_properties$summary

# A tibble: 2 × 7
# Groups:   Freq (kHz), Delay (s), Type [2]
  `Freq (kHz)` `Delay (s)`  Type dB_min dB_max dB_step_size duration    
         <dbl> <chr>       <dbl>  <dbl>  <dbl>        <dbl> <list>      
1            0 1 4             0     60     60            0 <df [8 × 1]>
2            0 1 4             1     60     60            0 <df [8 × 1]>

⬆️ duration should be <df [1 × 1]> for type 0 and <df [7 × 1]> for type 1

nohelix added a commit that referenced this issue Mar 27, 2024
I had tried to match the old form but that apparently caused issues.
nohelix added a commit that referenced this issue Mar 27, 2024
@nohelix nohelix reopened this Mar 27, 2024
@nohelix
Copy link
Collaborator Author

nohelix commented Mar 27, 2024

Change in Get_File_Summary_BBN_Tone should be fine

Original Output:

Browse[2]> file_frequency_ranges %>%
+     dplyr::group_by(`Freq (kHz)`, `Delay (s)`, `Type`) %>%
+     dplyr::summarise(dB_min = min(dB),
+                      dB_max = max(dB),
+                      dB_step_size = dB - lag(dB, default = first(dB)),
+                      duration = list(run_properties$duration),
+                      .groups = 'keep')
Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in dplyr 1.1.0.
ℹ Please use `reframe()` instead.
ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()` always returns an ungrouped data frame and adjust accordingly.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
# A tibble: 7 × 7
# Groups:   Freq (kHz), Delay (s), Type [1]
  `Freq (kHz)` `Delay (s)`  Type dB_min dB_max dB_step_size duration    
         <dbl> <chr>       <dbl>  <dbl>  <dbl>        <dbl> <list>      
1            0 1 4             1     15     75            0 <df [1 × 1]>
2            0 1 4             1     15     75           10 <df [1 × 1]>
3            0 1 4             1     15     75           10 <df [1 × 1]>
4            0 1 4             1     15     75           10 <df [1 × 1]>
5            0 1 4             1     15     75           10 <df [1 × 1]>
6            0 1 4             1     15     75           10 <df [1 × 1]>
7            0 1 4             1     15     75           10 <df [1 × 1]>

Bad code output:

Browse[2]> file_frequency_ranges %>%
+     dplyr::group_by(`Freq (kHz)`, `Delay (s)`, `Type`) %>%
+     dplyr::summarise(dB_min = min(dB),
+                      dB_max = max(dB),
+                      dB_step_size = dB - lag(dB, default = first(dB)),
+                      temp = unique(Type),
+                      duration = list(filter(run_properties$stim_encoding_table, Type == temp)$`Dur (ms)` %>% unique %>% as.data.frame()),
+                      .groups = 'keep') %>%
+     select(-temp)
Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in dplyr 1.1.0.
ℹ Please use `reframe()` instead.
ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()` always returns an ungrouped data frame and adjust accordingly.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
# A tibble: 7 × 7
# Groups:   Freq (kHz), Delay (s), Type [1]
  `Freq (kHz)` `Delay (s)`  Type dB_min dB_max dB_step_size duration    
         <dbl> <chr>       <dbl>  <dbl>  <dbl>        <dbl> <list>      
1            0 1 4             1     15     75            0 <df [1 × 1]>
2            0 1 4             1     15     75           10 <df [1 × 1]>
3            0 1 4             1     15     75           10 <df [1 × 1]>
4            0 1 4             1     15     75           10 <df [1 × 1]>
5            0 1 4             1     15     75           10 <df [1 × 1]>
6            0 1 4             1     15     75           10 <df [1 × 1]>
7            0 1 4             1     15     75           10 <df [1 × 1]>

Issue maybe in Computed File Name

  1. Crash in graphing_unrolled.R is due to 187: Generate_Graph [Z:/Behavior-autoanalysis/graphing unrolled.R#220] which references file_name.
    filtered_graph_data = filter(graph_data, str_detect(file_name,
  2. Only 2 changes I made were in these 2 places. However, the file_name seems to pass the name check so I am looking into what is going on.

@nohelix
Copy link
Collaborator Author

nohelix commented Mar 27, 2024

Original File name:                  BBN_15-75dB_100ms_4s
frequency range fix File name:       BBN_15-75dB_100ms_4s 

Same name and appears to work in testing environment.

@nohelix
Copy link
Collaborator Author

nohelix commented Mar 27, 2024

Fails in live environment

File name: BBN_80dB_0-2000ms_12s_BG_PKN_0dB
101 failed in live enviornment.zip

Warning: Error in filter: ℹ In argument: `str_detect(file_name, pattern = glue("_{current_durations}ms_"))`.
Caused by error in `str_detect()`:
! Can't recycle `string` (size 13) to match `pattern` (size 0).
  208: <Anonymous>
  207: signalCondition
  206: signal_abort
  205: abort
  204: <Anonymous>
  203: signalCondition
  202: signal_abort
  201: abort
  200: stop_vctrs
  199: stop_incompatible
  198: stop_incompatible_size
  197: vctrs::vec_size_common
  196: check_lengths
  195: str_detect
  194: eval
  193: mask$eval_all_filter
  191: filter_eval
  190: filter_rows
  189: filter.data.frame
  187: Generate_Graph [Z:/Behavior-autoanalysis/graphing unrolled.R#220]
  186: Generate_Extra_Graphs [Z:/Behavior-autoanalysis/main.R#2034]
  185: <reactive:extra_graphs> [Z:\Behavior-autoanalysis/app.R#407]
  183: .func
  180: contextFunc
  179: env$runWith
  172: ctx$run
  171: self$.updateValue
  169: extra_graphs
  168: renderPlot [Z:\Behavior-autoanalysis/app.R#411]
  166: func
  126: drawPlot
  112: <reactive:plotObj>
   96: drawReactive
   83: renderFunc
   82: output$plotRxn
    1: runApp
Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

@nohelix
Copy link
Collaborator Author

nohelix commented Mar 27, 2024

Output non working:

Calculated run statistics.
Warning in Build_Filename() :
  Caution: mismatch in provided filename: edge_BBN_80dB_1-2000ms_12s_BG_PKN_0dB
         calculated filename by contents: BBN_80dB_0-2000ms_12s_BG_PKN_0dB

File name: BBN_80dB_0-2000ms_12s_BG_PKN_0dB
Warning in Check_Assigned_Filename() :
  ACTION REQUIRED: Was rat run on the wrong file?
ERROR: Filename -- BBN_80dB_0-2000ms_12s_BG_PKN_0dB -- does not match
     Assignment -- edge_BBN_80dB_1-2000ms_12s_BG_PKN_40dB

Filename checks complete.

Output working:

Calculated run statistics.
Warning in Build_Filename() :
  Caution: mismatch in provided filename: edge_BBN_80dB_1-2000ms_12s_BG_PKN_0dB
         calculated filename by contents: BBN_80dB_0-2000ms_12s_BG_PKN_0dB

File name: BBN_80dB_0-2000ms_12s_BG_PKN_0dB
Warning in Check_Assigned_Filename() :
  ACTION REQUIRED: Was rat run on the wrong file?
ERROR: Filename -- BBN_80dB_0-2000ms_12s_BG_PKN_0dB -- does not match
     Assignment -- edge_BBN_80dB_1-2000ms_12s_BG_PKN_40dB

Filename checks complete.

Only code difference:

dB_step_size = dB - lag(dB, default = first(dB)),
duration = list(run_properties$duration),
.groups = 'keep')

vs.

dB_step_size = dB - lag(dB, default = first(dB)),
`temp = unique(Type),
duration = list(filter(run_properties$stim_encoding_table, Type == temp)$`Dur (ms)` %>% unique %>% as.data.frame()),
                         .groups = 'keep') %>%
 select(-temp)

See above comment where the outputs and names are identical.

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

1 participant