-
Notifications
You must be signed in to change notification settings - Fork 12
period channelinfo function #122
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -488,3 +488,131 @@ | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| export channel_info | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
| period_channelinfo(data::LegendData, period::DataPeriod; kwargs...) | ||||||||||||||||||||||||
| Get channel information for a given period, combining all runs in that period. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| this channel info takes all runs in this period and creates a combined channelinfo | ||||||||||||||||||||||||
| for :usability, :is_blinded, :psd_usability, :low_aoe_status, :high_aoe_status, :lq_status, :ann_status, :coax_rt_status only the 'best' value is taken, i.e. the one with the highest priority in the hierarchy | ||||||||||||||||||||||||
| all the other column entries should remain the same over different runs | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| all kwargs and filterby can be used as in the usual channelinfo | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| make sure to include "Tables" by "using Tables" before using this function | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function period_channelinfo(data::LegendData, period::DataPeriod; kwargs...) | ||||||||||||||||||||||||
| filekey_array = get_filekey_array(data, period) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These functions all need comments; otherwise, this is not maintainable. |
||||||||||||||||||||||||
| chinfo_array = get_chinfo_array(data, filekey_array; kwargs...) | ||||||||||||||||||||||||
| merged_chinfo = vcat(chinfo_array...) | ||||||||||||||||||||||||
| red_chinfo = merge_and_reduce_chinfo(merged_chinfo) | ||||||||||||||||||||||||
| sorted_chinfo = sort_chinfo(red_chinfo) | ||||||||||||||||||||||||
| extended = get(kwargs, :extended, false) | ||||||||||||||||||||||||
| hierarchies = get_hierarchies(extended) | ||||||||||||||||||||||||
| column_order = get_column_order(extended) | ||||||||||||||||||||||||
| final_chinfo = Table(apply_hierarchies(sorted_chinfo, hierarchies, column_order)) | ||||||||||||||||||||||||
| return final_chinfo | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function get_filekey_array(l200, period) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your function arguments need types. |
||||||||||||||||||||||||
| rinfo = runinfo(l200, period) |> filterby(@pf $cal.is_analysis_run) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are actively filtering here by channelinfo(l200, :p03, :r000, :cal)In the case where you load the |
||||||||||||||||||||||||
| return [i.cal.startkey for i in rinfo] | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is equivalent to
Suggested change
|
||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function get_chinfo_array(l200, filekey_array; kwargs...) | ||||||||||||||||||||||||
| extended = get(kwargs, :extended, false) | ||||||||||||||||||||||||
| return [channelinfo(l200, fk; kwargs...) for fk in filekey_array] | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function merge_and_reduce_chinfo(merged_chinfo) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this function doing? This looks like it could be simplified a lot with standard |
||||||||||||||||||||||||
| grouped = Dict{Any, Dict{Symbol, Vector}}() | ||||||||||||||||||||||||
| for row in Tables.rows(merged_chinfo) | ||||||||||||||||||||||||
| detector = row.detector | ||||||||||||||||||||||||
| detector_group = get!(grouped, detector, Dict(col => [] for col in propertynames(row) if col != :detector)) | ||||||||||||||||||||||||
| for col in propertynames(row) | ||||||||||||||||||||||||
| if col != :detector | ||||||||||||||||||||||||
| push!(detector_group[col], getproperty(row, col)) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| red_chinfo = (; detector = collect(keys(grouped))) | ||||||||||||||||||||||||
| for col in propertynames(first(Tables.rows(merged_chinfo))) | ||||||||||||||||||||||||
| if col != :detector | ||||||||||||||||||||||||
| red_chinfo = merge(red_chinfo, (; (col => [grouped[d][col] for d in keys(grouped)]))) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| return red_chinfo | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function sort_chinfo(red_chinfo) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you want to achieve with this function? sort(red_chinfoTypes are also missing. |
||||||||||||||||||||||||
| sorted_indices = sortperm(red_chinfo.detector) | ||||||||||||||||||||||||
| sorted_chinfo = (; detector = red_chinfo.detector[sorted_indices]) | ||||||||||||||||||||||||
| for col in propertynames(red_chinfo) | ||||||||||||||||||||||||
| if col != :detector | ||||||||||||||||||||||||
| sorted_chinfo = merge(sorted_chinfo, (; (col => red_chinfo[col][sorted_indices]))) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| return sorted_chinfo | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function apply_hierarchies(sorted_chinfo, hierarchies, column_order) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Types to the arguments |
||||||||||||||||||||||||
| final_chinfo = (;) | ||||||||||||||||||||||||
| for col in column_order | ||||||||||||||||||||||||
| if col in keys(hierarchies) | ||||||||||||||||||||||||
| hierarchy = hierarchies[col] | ||||||||||||||||||||||||
| if isempty(hierarchy) | ||||||||||||||||||||||||
| # Skip applying hierarchy if it's empty | ||||||||||||||||||||||||
| final_chinfo = merge(final_chinfo, (; (col => sorted_chinfo[col]))) | ||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| hierarchy_index = Dict(x => i for (i, x) in enumerate(hierarchy)) | ||||||||||||||||||||||||
| final_chinfo = merge(final_chinfo, (; (col => [ | ||||||||||||||||||||||||
| begin | ||||||||||||||||||||||||
| valid_values = filter(x -> haskey(hierarchy_index, x), sorted_chinfo[col][i]) | ||||||||||||||||||||||||
| valid_values == [] ? nothing : valid_values[argmin(hierarchy_index[x] for x in valid_values)] | ||||||||||||||||||||||||
| end for i in 1:length(sorted_chinfo.detector) | ||||||||||||||||||||||||
| ]))) | ||||||||||||||||||||||||
| else | ||||||||||||||||||||||||
| final_chinfo = merge(final_chinfo, (; (col => [ | ||||||||||||||||||||||||
| sorted_chinfo[col][i] isa AbstractVector ? first(unique(sorted_chinfo[col][i])) : sorted_chinfo[col][i] | ||||||||||||||||||||||||
| for i in 1:length(sorted_chinfo.detector) | ||||||||||||||||||||||||
| ]))) | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| return final_chinfo | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function get_hierarchies(extended::Bool) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the
Suggested change
|
||||||||||||||||||||||||
| base_hierarchies = Dict( | ||||||||||||||||||||||||
| :usability => [:on, :ac, :off], | ||||||||||||||||||||||||
| :is_blinded => [true, false], | ||||||||||||||||||||||||
| :psd_usability => [:on, :off], | ||||||||||||||||||||||||
| :low_aoe_status => [:valid, :present, :missing, :unknown], | ||||||||||||||||||||||||
| :high_aoe_status => [:valid, :present, :missing, :unknown], | ||||||||||||||||||||||||
| :lq_status => [:valid, :present, :missing, :unknown], | ||||||||||||||||||||||||
| :ann_status => [:valid, :present, :missing, :unknown], | ||||||||||||||||||||||||
| :coax_rt_status => [:valid, :present, :missing, :unknown] | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| return base_hierarchies | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function get_column_order(extended::Bool) | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this function doing and can you not move this to the outer function?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order of the columns was changed in the prior steps and I wanted to keep the original order (as in the usual channelinfo) |
||||||||||||||||||||||||
| base_columns = [ | ||||||||||||||||||||||||
| :detector, :channel, :fcid, :rawid, :system, :processable, | ||||||||||||||||||||||||
| :usability, :is_blinded, :psd_usability, :low_aoe_status, :high_aoe_status, | ||||||||||||||||||||||||
| :lq_status, :ann_status, :coax_rt_status, :is_bb_like, | ||||||||||||||||||||||||
| :det_type, :location, :detstring, :fiber, :position | ||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||
| if extended | ||||||||||||||||||||||||
| extended_columns = [ | ||||||||||||||||||||||||
| :cc4ch, :daqcrate, :daqcard, :hvcard, :hvch, | ||||||||||||||||||||||||
| :enrichment, :mass, :total_volume, :active_volume, :fccd | ||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||
| return vcat(base_columns, extended_columns) | ||||||||||||||||||||||||
| else | ||||||||||||||||||||||||
| return base_columns | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| end | ||||||||||||||||||||||||
| export period_channelinfo | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is great as a first draft, however this should become a dispatch onto the existing
channelinfo